Documentation
¶
Index ¶
- Variables
- func AddCustomServiceHeader(w http.ResponseWriter, key, value string)
- func ChatCompletionID() string
- func ProcessResponse(responseBody []byte, vendor string, contentEncoding string, ...) ([]byte, error)
- func ProcessToolCalls(toolCalls []interface{}, vendor string) []interface{}
- func ProxyRequest(w http.ResponseWriter, r *http.Request, creds []config.Credential, ...)
- func RequestID() string
- func SystemFingerprint() string
- func ToolCallID() string
- type APIClient
- type APIClientInterface
- type ResponseStandardizer
- type StreamProcessor
Constants ¶
This section is empty.
Variables ¶
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 ¶
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