Documentation
¶
Overview ¶
Package translator provides request and response translation functionality between different AI API formats. It acts as a wrapper around the SDK translator registry, providing convenient functions for translating requests and responses between OpenAI, Claude, Gemini, and other API formats.
Index ¶
- func NeedConvert(from, to string) bool
- func Register(from, to string, request interfaces.TranslateRequestFunc, ...)
- func Request(from, to, modelName string, rawJSON []byte, stream bool) []byte
- func Response(from, to string, ctx context.Context, modelName string, ...) []string
- func ResponseNonStream(from, to string, ctx context.Context, modelName string, ...) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NeedConvert ¶
NeedConvert checks if a response translation is needed between two API formats.
Parameters:
- from: The source API format identifier
- to: The target API format identifier
Returns:
- bool: True if response translation is needed, false otherwise
func Register ¶
func Register(from, to string, request interfaces.TranslateRequestFunc, response interfaces.TranslateResponse)
Register registers a new translator for converting between two API formats.
Parameters:
- from: The source API format identifier
- to: The target API format identifier
- request: The request translation function
- response: The response translation function
func Request ¶
Request translates a request from one API format to another.
Parameters:
- from: The source API format identifier
- to: The target API format identifier
- modelName: The model name for the request
- rawJSON: The raw JSON request data
- stream: Whether this is a streaming request
Returns:
- []byte: The translated request JSON
func Response ¶
func Response(from, to string, ctx context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string
Response translates a streaming response from one API format to another.
Parameters:
- from: The source API format identifier
- to: The target API format identifier
- ctx: The context for the translation
- modelName: The model name for the response
- originalRequestRawJSON: The original request JSON
- requestRawJSON: The translated request JSON
- rawJSON: The raw response JSON
- param: Additional parameters for translation
Returns:
- []string: The translated response lines
func ResponseNonStream ¶
func ResponseNonStream(from, to string, ctx context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) string
ResponseNonStream translates a non-streaming response from one API format to another.
Parameters:
- from: The source API format identifier
- to: The target API format identifier
- ctx: The context for the translation
- modelName: The model name for the response
- originalRequestRawJSON: The original request JSON
- requestRawJSON: The translated request JSON
- rawJSON: The raw response JSON
- param: Additional parameters for translation
Returns:
- string: The translated response JSON
Types ¶
This section is empty.