Documentation
¶
Index ¶
- Variables
- func AppendBedrockEndpoint(endpoint string, model string, streaming bool) (string, error)
- func AppendMessages(protocol Protocol, body map[string]any, messages []Message)
- func AppendProtocolEndpoint(endpoint string, protocol Protocol) (string, error)
- func BuildDenyResponse(protocol Protocol, model, text string) map[string]any
- func BuildDenyWireResponse(protocol Protocol, model, denyText string, streaming bool) ([]byte, string, error)
- func BuildSimpleRequest(protocol Protocol, systemPrompt, userContent string, options map[string]any) map[string]any
- func ConvertAnthropicHeadersToOpenAI(headers http.Header)
- func ConvertAnthropicMessagesToOpenAI(body []byte) ([]byte, map[string]string, error)
- func ConvertOpenAIChatToAnthropic(body []byte, model string, toolNameMap map[string]string) ([]byte, error)
- func ConvertOpenAIEmbeddingsToVertex(body []byte) ([]byte, error)
- func ConvertVertexEmbeddingsToOpenAI(body []byte, model string) ([]byte, error)
- func ExtractRequestContent(protocol Protocol, body map[string]any) []string
- func ExtractResponseText(protocol Protocol, body map[string]any) string
- func ExtractStreamEventText(protocol Protocol, event map[string]any) string
- func IsStreaming(protocol Protocol, body map[string]any) bool
- func NumericUsage(value any, round bool) int64
- func PrependMessages(protocol Protocol, body map[string]any, messages []Message)
- func ProviderUsesOpenAIChat(provider string) bool
- func RegisterLLMRequestVars(r *http.Request, requestDocument Document, protocol Protocol, ...)
- func RegisterUsageContextDocumentVars(r *http.Request, document Document, promptTokens int64, completionTokens int64)
- func RequestContent(protocol Protocol, body map[string]any) any
- func StringValue(value any) string
- func ValidateProviderProtocol(provider string, protocol Protocol) error
- type Document
- type Message
- type Protocol
- type ResponseMetadata
Constants ¶
This section is empty.
Variables ¶
var ( OpenAIChat = Protocol{ OverrideKey: "openai-chat", RequestType: "ai_chat", Endpoint: "/v1/chat/completions", } OpenAIResponses = Protocol{ OverrideKey: "openai-responses", RequestType: "ai_chat", Endpoint: "/v1/responses", } OpenAIEmbeddings = Protocol{ OverrideKey: "openai-embeddings", RequestType: "ai_chat", Endpoint: "/v1/embeddings", } AnthropicMessages = Protocol{ OverrideKey: "anthropic-messages", RequestType: "ai_chat", Endpoint: "/v1/messages", } BedrockConverse = Protocol{ OverrideKey: "bedrock-converse", RequestType: "ai_chat", Endpoint: "/converse", } Passthrough = Protocol{ OverrideKey: "passthrough", RequestType: "ai_chat", } )
Functions ¶
func AppendBedrockEndpoint ¶
AppendBedrockEndpoint appends the model path to a Bedrock endpoint.
func AppendMessages ¶
func AppendProtocolEndpoint ¶
AppendProtocolEndpoint appends the protocol-specific path to an OpenAI-compatible endpoint.
func BuildDenyResponse ¶
func BuildDenyWireResponse ¶
func BuildSimpleRequest ¶
func ExtractRequestContent ¶
func ExtractStreamEventText ¶
func NumericUsage ¶
NumericUsage converts a usage counter value. Fractional float64 values are rounded when round is true and truncated otherwise. Unsupported types return -1.
func PrependMessages ¶
func ProviderUsesOpenAIChat ¶
ProviderUsesOpenAIChat reports whether the provider speaks the OpenAI chat protocol.
func RegisterLLMRequestVars ¶
func RegisterLLMRequestVars(r *http.Request, requestDocument Document, protocol Protocol, responseDocument Document)
RegisterLLMRequestVars publishes the shared request variables for single- and multi-instance AI proxying.
func RegisterUsageContextDocumentVars ¶
func RegisterUsageContextDocumentVars(r *http.Request, document Document, promptTokens int64, completionTokens int64)
RegisterUsageContextDocumentVars publishes the raw usage and token usage variables from a response document.
func StringValue ¶
StringValue returns value when it is a string and an empty string otherwise.
func ValidateProviderProtocol ¶
ValidateProviderProtocol accepts native protocols and the converters supported by APISIX 3.17. Passthrough preserves the catch-all provider path.
Types ¶
type Document ¶
Document is a decoded AI JSON payload. Callers should decode each request or non-streaming response once and pass the document to all extractors.
func DecodeDocument ¶
func (Document) IsStreaming ¶
type ResponseMetadata ¶
func ExtractResponseMetadata ¶
func ExtractResponseMetadata(protocol Protocol, body []byte) ResponseMetadata
func ExtractResponseMetadataDocument ¶
func ExtractResponseMetadataDocument(protocol Protocol, document Document) ResponseMetadata