Documentation
¶
Index ¶
- type AnthropicMessagesTranslator
- func NewAnthropicToAWSAnthropicTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) AnthropicMessagesTranslator
- func NewAnthropicToAnthropicTranslator(version string, modelNameOverride internalapi.ModelNameOverride) AnthropicMessagesTranslator
- func NewAnthropicToGCPAnthropicTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) AnthropicMessagesTranslator
- type CohereRerankTranslator
- type ImageGenerationTranslator
- type LLMTokenUsage
- type OpenAIChatCompletionTranslator
- func NewChatCompletionOpenAIToAWSBedrockTranslator(modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
- func NewChatCompletionOpenAIToAzureOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
- func NewChatCompletionOpenAIToGCPAnthropicTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
- func NewChatCompletionOpenAIToGCPVertexAITranslator(modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
- func NewChatCompletionOpenAIToOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
- type OpenAICompletionTranslator
- type OpenAIEmbeddingTranslator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnthropicMessagesTranslator ¶ added in v0.3.0
type AnthropicMessagesTranslator interface {
// RequestBody translates the request body.
// - `raw` is the raw request body.
// - `body` is the request body parsed into the [anthropicschema.MessagesRequest].
// - `forceBodyMutation` is true if the translator should always mutate the body, even if no changes are made.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
RequestBody(raw []byte, body *anthropicschema.MessagesRequest, forceBodyMutation bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
err error,
)
// ResponseHeaders translates the response headers.
// - `headers` is the response headers.
// - This returns `headerMutation` that can be nil to indicate no mutation.
ResponseHeaders(headers map[string]string) (
headerMutation *extprocv3.HeaderMutation,
err error,
)
// ResponseBody translates the response body. When stream=true, this is called for each chunk of the response body.
// - `body` is the response body either chunk or the entire body, depending on the context.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
// - This returns `tokenUsage` that is extracted from the body and will be used to do token rate limiting.
// - This returns `responseModel` that is the model name from the response (may differ from request model).
ResponseBody(respHeaders map[string]string, body io.Reader, endOfStream bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
tokenUsage LLMTokenUsage,
responseModel internalapi.ResponseModel,
err error,
)
}
AnthropicMessagesTranslator translates the request and response messages between the client and the backend API schemas for /v1/messages endpoint of Anthropic.
This is created per request and is not thread-safe.
func NewAnthropicToAWSAnthropicTranslator ¶ added in v0.4.0
func NewAnthropicToAWSAnthropicTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) AnthropicMessagesTranslator
NewAnthropicToAWSAnthropicTranslator creates a translator for Anthropic to AWS Bedrock Anthropic format. AWS Bedrock supports the native Anthropic Messages API, so this is essentially a passthrough translator with AWS-specific path modifications.
func NewAnthropicToAnthropicTranslator ¶ added in v0.4.0
func NewAnthropicToAnthropicTranslator(version string, modelNameOverride internalapi.ModelNameOverride) AnthropicMessagesTranslator
NewAnthropicToAnthropicTranslator creates a passthrough translator for Anthropic.
func NewAnthropicToGCPAnthropicTranslator ¶ added in v0.3.0
func NewAnthropicToGCPAnthropicTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) AnthropicMessagesTranslator
NewAnthropicToGCPAnthropicTranslator creates a translator for Anthropic to GCP Anthropic format. This is essentially a passthrough translator with GCP-specific modifications.
type CohereRerankTranslator ¶ added in v0.4.0
type CohereRerankTranslator interface {
// RequestBody translates the request body.
// - `raw` is the raw request body.
// - `body` is the request body parsed into the Cohere rerank v2 request.
// - `onRetry` is true if this is a retry request.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
RequestBody(raw []byte, body *cohereschema.RerankV2Request, onRetry bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
err error,
)
// ResponseHeaders translates the response headers.
// - `headers` is the response headers.
// - This returns `headerMutation` that can be nil to indicate no mutation.
ResponseHeaders(headers map[string]string) (
headerMutation *extprocv3.HeaderMutation,
err error,
)
// ResponseBody translates the response body.
// - `body` is the response body.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
// - This returns `tokenUsage` that is extracted from the body and will be used to do token rate limiting.
// - This returns `responseModel` that is the model name from the response (may differ from request model).
ResponseBody(respHeaders map[string]string, body io.Reader, endOfStream bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
tokenUsage LLMTokenUsage,
responseModel internalapi.ResponseModel,
err error,
)
// ResponseError translates the response error. This is called when the upstream response status code is not successful (2xx).
// - `respHeaders` is the response headers.
// - `body` is the response body that contains the error message.
ResponseError(respHeaders map[string]string, body io.Reader) (headerMutation *extprocv3.HeaderMutation, bodyMutation *extprocv3.BodyMutation, err error)
}
CohereRerankTranslator translates the request and response messages between the client and the backend API schemas for /v2/rerank endpoint of Cohere.
This is created per request and is not thread-safe.
func NewRerankCohereToCohereTranslator ¶ added in v0.4.0
func NewRerankCohereToCohereTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) CohereRerankTranslator
NewRerankCohereToCohereTranslator implements [Factory] for Cohere Rerank v2 translation.
type ImageGenerationTranslator ¶ added in v0.4.0
type ImageGenerationTranslator interface {
// RequestBody translates the request body.
// - raw is the raw request body.
// - body is the request body parsed into the OpenAI SDK [openaisdk.ImageGenerateParams].
// - forceBodyMutation is true if the translator should always mutate the body, even if no changes are made.
// - This returns headerMutation and bodyMutation that can be nil to indicate no mutation.
RequestBody(raw []byte, body *openaisdk.ImageGenerateParams, forceBodyMutation bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
err error,
)
// ResponseHeaders translates the response headers.
// - headers is the response headers.
// - This returns headerMutation that can be nil to indicate no mutation.
ResponseHeaders(headers map[string]string) (
headerMutation *extprocv3.HeaderMutation,
err error,
)
// ResponseBody translates the response body.
// - body is the response body.
// - This returns headerMutation and bodyMutation that can be nil to indicate no mutation.
// - This returns responseModel that is the model name from the response (may differ from request model).
ResponseBody(respHeaders map[string]string, body io.Reader, endOfStream bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
tokenUsage LLMTokenUsage,
responseModel internalapi.ResponseModel,
err error,
)
// ResponseError translates the response error. This is called when the upstream response status code is not successful (2xx).
// - respHeaders is the response headers.
// - body is the response body that contains the error message.
ResponseError(respHeaders map[string]string, body io.Reader) (headerMutation *extprocv3.HeaderMutation, bodyMutation *extprocv3.BodyMutation, err error)
}
ImageGenerationTranslator translates the request and response messages between the client and the backend API schemas for /v1/images/generations endpoint of OpenAI.
This is created per request and is not thread-safe.
func NewImageGenerationOpenAIToOpenAITranslator ¶ added in v0.4.0
func NewImageGenerationOpenAIToOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride, span tracing.ImageGenerationSpan) ImageGenerationTranslator
NewImageGenerationOpenAIToOpenAITranslator implements [Factory] for OpenAI to OpenAI image generation translation.
type LLMTokenUsage ¶
type LLMTokenUsage struct {
// InputTokens is the number of tokens consumed from the input.
InputTokens uint32
// OutputTokens is the number of tokens consumed from the output.
OutputTokens uint32
// TotalTokens is the total number of tokens consumed.
TotalTokens uint32
// CachedInputTokens is the total number of tokens read from cache.
CachedInputTokens uint32
}
LLMTokenUsage represents the token usage reported usually by the backend API in the response body.
type OpenAIChatCompletionTranslator ¶ added in v0.2.0
type OpenAIChatCompletionTranslator interface {
// RequestBody translates the request body.
// - `raw` is the raw request body.
// - `body` is the request body parsed into the [openai.ChatCompletionRequest].
// - `forceBodyMutation` is true if the translator should always mutate the body, even if no changes are made.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
RequestBody(raw []byte, body *openai.ChatCompletionRequest, forceBodyMutation bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
err error,
)
// ResponseHeaders translates the response headers.
// - `headers` is the response headers.
// - This returns `headerMutation` that can be nil to indicate no mutation.
ResponseHeaders(headers map[string]string) (
headerMutation *extprocv3.HeaderMutation,
err error,
)
// ResponseBody translates the response body. When stream=true, this is called for each chunk of the response body.
// - `body` is the response body either chunk or the entire body, depending on the context.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
// - This returns `tokenUsage` that is extracted from the body and will be used to do token rate limiting.
// - This returns `responseModel` that is the model name from the response (may differ from request model).
ResponseBody(respHeaders map[string]string, body io.Reader, endOfStream bool, span tracing.ChatCompletionSpan) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
tokenUsage LLMTokenUsage,
responseModel internalapi.ResponseModel,
err error,
)
// ResponseError translates the response error. This is called when the upstream response status code is not successful (2xx).
// - `respHeaders` is the response headers.
// - `body` is the response body that contains the error message.
ResponseError(respHeaders map[string]string, body io.Reader) (headerMutation *extprocv3.HeaderMutation, bodyMutation *extprocv3.BodyMutation, err error)
}
OpenAIChatCompletionTranslator translates the request and response messages between the client and the backend API schemas for /v1/chat/completion endpoint of OpenAI.
This is created per request and is not thread-safe.
func NewChatCompletionOpenAIToAWSBedrockTranslator ¶
func NewChatCompletionOpenAIToAWSBedrockTranslator(modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
NewChatCompletionOpenAIToAWSBedrockTranslator implements [Factory] for OpenAI to AWS Bedrock translation.
func NewChatCompletionOpenAIToAzureOpenAITranslator ¶ added in v0.2.0
func NewChatCompletionOpenAIToAzureOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
NewChatCompletionOpenAIToAzureOpenAITranslator implements [Factory] for OpenAI to Azure OpenAI translations. Except RequestBody method requires modification to satisfy Microsoft Azure OpenAI spec https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#chat-completions, other interface methods are identical to NewChatCompletionOpenAIToOpenAITranslator's interface implementations.
func NewChatCompletionOpenAIToGCPAnthropicTranslator ¶ added in v0.3.0
func NewChatCompletionOpenAIToGCPAnthropicTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
NewChatCompletionOpenAIToGCPAnthropicTranslator implements [Factory] for OpenAI to GCP Anthropic translation. This translator converts OpenAI ChatCompletion API requests to GCP Anthropic API format.
func NewChatCompletionOpenAIToGCPVertexAITranslator ¶ added in v0.3.0
func NewChatCompletionOpenAIToGCPVertexAITranslator(modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
NewChatCompletionOpenAIToGCPVertexAITranslator implements [Factory] for OpenAI to GCP Gemini translation. This translator converts OpenAI ChatCompletion API requests to GCP Gemini API format.
func NewChatCompletionOpenAIToOpenAITranslator ¶
func NewChatCompletionOpenAIToOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator
NewChatCompletionOpenAIToOpenAITranslator implements [Factory] for OpenAI to OpenAI translation.
type OpenAICompletionTranslator ¶ added in v0.4.0
type OpenAICompletionTranslator interface {
// RequestBody translates the request body.
// - `raw` is the raw request body.
// - `body` is the request body parsed into the [openai.CompletionRequest].
// - `onRetry` is true if this is a retry request.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
RequestBody(raw []byte, body *openai.CompletionRequest, onRetry bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
err error,
)
// ResponseHeaders translates the response headers.
// - `headers` is the response headers.
// - This returns `headerMutation` that can be nil to indicate no mutation.
ResponseHeaders(headers map[string]string) (
headerMutation *extprocv3.HeaderMutation,
err error,
)
// ResponseBody translates the response body. When stream=true, this is called for each chunk of the response body.
// - `body` is the response body either chunk or the entire body, depending on the context.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
// - This returns `tokenUsage` that is extracted from the body and will be used to do token rate limiting.
// - This returns `responseModel` that is the model name from the response (may differ from request model).
ResponseBody(respHeaders map[string]string, body io.Reader, endOfStream bool, span tracing.CompletionSpan) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
tokenUsage LLMTokenUsage,
responseModel internalapi.ResponseModel,
err error,
)
// ResponseError translates the response error. This is called when the upstream response status code is not successful (2xx).
// - `respHeaders` is the response headers.
// - `body` is the response body that contains the error message.
ResponseError(respHeaders map[string]string, body io.Reader) (headerMutation *extprocv3.HeaderMutation, bodyMutation *extprocv3.BodyMutation, err error)
}
OpenAICompletionTranslator translates the request and response messages between the client and the backend API schemas for /v1/completions endpoint of OpenAI.
This is created per request and is not thread-safe.
func NewCompletionOpenAIToOpenAITranslator ¶ added in v0.4.0
func NewCompletionOpenAIToOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAICompletionTranslator
NewCompletionOpenAIToOpenAITranslator implements [Factory] for OpenAI to OpenAI translation for completions.
type OpenAIEmbeddingTranslator ¶ added in v0.3.0
type OpenAIEmbeddingTranslator interface {
// RequestBody translates the request body.
// - `raw` is the raw request body.
// - `body` is the request body parsed into the [openai.EmbeddingRequest].
// - `onRetry` is true if this is a retry request.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
RequestBody(raw []byte, body *openai.EmbeddingRequest, onRetry bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
err error,
)
// ResponseHeaders translates the response headers.
// - `headers` is the response headers.
// - This returns `headerMutation` that can be nil to indicate no mutation.
ResponseHeaders(headers map[string]string) (
headerMutation *extprocv3.HeaderMutation,
err error,
)
// ResponseBody translates the response body.
// - `body` is the response body.
// - This returns `headerMutation` and `bodyMutation` that can be nil to indicate no mutation.
// - This returns `tokenUsage` that is extracted from the body and will be used to do token rate limiting.
// - This returns `responseModel` that is the model name from the response (may differ from request model).
ResponseBody(respHeaders map[string]string, body io.Reader, endOfStream bool) (
headerMutation *extprocv3.HeaderMutation,
bodyMutation *extprocv3.BodyMutation,
tokenUsage LLMTokenUsage,
responseModel internalapi.ResponseModel,
err error,
)
// ResponseError translates the response error. This is called when the upstream response status code is not successful (2xx).
// - `respHeaders` is the response headers.
// - `body` is the response body that contains the error message.
ResponseError(respHeaders map[string]string, body io.Reader) (headerMutation *extprocv3.HeaderMutation, bodyMutation *extprocv3.BodyMutation, err error)
}
OpenAIEmbeddingTranslator translates the request and response messages between the client and the backend API schemas for /v1/embeddings endpoint of OpenAI.
This is created per request and is not thread-safe.
func NewEmbeddingOpenAIToAzureOpenAITranslator ¶ added in v0.4.0
func NewEmbeddingOpenAIToAzureOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride, span tracing.EmbeddingsSpan) OpenAIEmbeddingTranslator
NewEmbeddingOpenAIToAzureOpenAITranslator implements [Factory] for OpenAI to Azure OpenAI translation for embeddings.
func NewEmbeddingOpenAIToOpenAITranslator ¶ added in v0.3.0
func NewEmbeddingOpenAIToOpenAITranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride, span tracing.EmbeddingsSpan) OpenAIEmbeddingTranslator
NewEmbeddingOpenAIToOpenAITranslator implements [Factory] for OpenAI to OpenAI translation for embeddings.
Source Files
¶
- anthropic_anthropic.go
- anthropic_awsanthropic.go
- anthropic_gcpanthropic.go
- cohere_rerank_v2.go
- gemini_helper.go
- imagegeneration_openai_openai.go
- jsonschema_helper.go
- openai_awsbedrock.go
- openai_azureopenai.go
- openai_azureopenai_embeddings.go
- openai_completions.go
- openai_embeddings.go
- openai_gcpanthropic.go
- openai_gcpanthropic_stream.go
- openai_gcpvertexai.go
- openai_openai.go
- translator.go
- util.go