proxy

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownVendor   = errors.New("unknown vendor")
	ErrInvalidResponse = errors.New("invalid vendor response")
)

Error types for common API client errors

Functions

func AddCustomServiceHeader

func AddCustomServiceHeader(w http.ResponseWriter, key, value string)

AddCustomServiceHeader adds a custom header specific to the proxy service. This function can be used to add service identification or custom metadata headers.

func ChatCompletionID

func ChatCompletionID() string

ChatCompletionID generates a chat completion ID with format: chatcmpl-{10chars}

func ProcessResponse

func ProcessResponse(responseBody []byte, vendor string, contentEncoding string, originalModel string) ([]byte, error)

ProcessResponse processes the API response, ensuring all required fields are present

func ProcessToolCalls

func ProcessToolCalls(toolCalls []interface{}, vendor string) []interface{}

ProcessToolCalls processes a list of tool calls, adding or updating IDs as needed. It handles vendor-specific logic for ID generation and validates/splits malformed arguments. Returns the processed tool calls array.

func ProxyRequest

func ProxyRequest(w http.ResponseWriter, r *http.Request, creds []config.Credential, models []config.VendorModel, apiClient APIClientInterface, modelSelector selector.Selector)

ProxyRequest handles the incoming request, routes it to the appropriate vendor, and forwards the response

func RequestID

func RequestID() string

RequestID generates a request ID with format: req_{16chars}

func SystemFingerprint

func SystemFingerprint() string

SystemFingerprint generates a system fingerprint with format: fp_{9chars}

func ToolCallID

func ToolCallID() string

ToolCallID generates a tool call ID with format: call_{16chars}

Types

type APIClient

type APIClient struct {
	BaseURLs map[string]string
	// contains filtered or unexported fields
}

APIClient handles communication with vendor APIs

func NewAPIClient

func NewAPIClient() *APIClient

NewAPIClient creates a new API client with configured base URLs

func (*APIClient) SendRequest

func (c *APIClient) SendRequest(w http.ResponseWriter, r *http.Request, selection *selector.VendorSelection, modifiedBody []byte, originalModel string) error

SendRequest sends a request to the vendor API and streams the response back

type APIClientInterface

type APIClientInterface interface {
	SendRequest(w http.ResponseWriter, r *http.Request, selection *selector.VendorSelection, modifiedBody []byte, originalModel string) error
}

APIClientInterface defines the interface for API clients

type ResponseStandardizer

type ResponseStandardizer struct {
	// contains filtered or unexported fields
}

ResponseStandardizer handles vendor response standardization

func NewResponseStandardizer

func NewResponseStandardizer() *ResponseStandardizer

NewResponseStandardizer creates a new response standardizer

type StreamProcessor

type StreamProcessor struct {
	ConversationID    string
	Timestamp         int64
	SystemFingerprint string
	Vendor            string
	OriginalModel     string
	// contains filtered or unexported fields
}

StreamProcessor handles stateful processing of streaming responses

func NewStreamProcessor

func NewStreamProcessor(conversationID string, timestamp int64, systemFingerprint string, vendor string, originalModel string) *StreamProcessor

NewStreamProcessor creates a new stream processor with conversation-level values

func (*StreamProcessor) ProcessChunk

func (sp *StreamProcessor) ProcessChunk(chunk []byte) []byte

ProcessChunk processes a single chunk of a streaming response with consistent conversation-level values

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL