Documentation
¶
Overview ¶
Package openai provides request translation functionality for OpenAI to Gemini API compatibility. It converts OpenAI Chat Completions requests into Gemini compatible JSON using gjson/sjson only.
Package openai provides response translation functionality for Gemini to OpenAI API compatibility. This package handles the conversion of Gemini API responses into OpenAI Chat Completions-compatible JSON format, transforming streaming events and non-streaming responses into the format expected by OpenAI API clients. It supports both streaming and non-streaming modes, handling text content, tool calls, reasoning content, and usage metadata appropriately.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertGeminiResponseToOpenAI ¶
func ConvertGeminiResponseToOpenAI(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string
ConvertGeminiResponseToOpenAI translates a single chunk of a streaming response from the Gemini API format to the OpenAI Chat Completions streaming format. It processes various Gemini event types and transforms them into OpenAI-compatible JSON responses. The function handles text content, tool calls, reasoning content, and usage metadata, outputting responses that match the OpenAI API format. It supports incremental updates for streaming responses.
Parameters:
- ctx: The context for the request, used for cancellation and timeout handling
- modelName: The name of the model being used for the response (unused in current implementation)
- rawJSON: The raw JSON response from the Gemini API
- param: A pointer to a parameter object for maintaining state between calls
Returns:
- []string: A slice of strings, each containing an OpenAI-compatible JSON response
func ConvertGeminiResponseToOpenAINonStream ¶
func ConvertGeminiResponseToOpenAINonStream(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string
ConvertGeminiResponseToOpenAINonStream converts a non-streaming Gemini response to a non-streaming OpenAI response. This function processes the complete Gemini response and transforms it into a single OpenAI-compatible JSON response. It handles message content, tool calls, reasoning content, and usage metadata, combining all the information into a single response that matches the OpenAI API format.
Parameters:
- ctx: The context for the request, used for cancellation and timeout handling
- modelName: The name of the model being used for the response (unused in current implementation)
- rawJSON: The raw JSON response from the Gemini API
- param: A pointer to a parameter object for the conversion (unused in current implementation)
Returns:
- string: An OpenAI-compatible JSON response containing all message content and metadata
func ConvertOpenAIRequestToGemini ¶
ConvertOpenAIRequestToGemini converts an OpenAI Chat Completions request (raw JSON) into a complete Gemini request JSON. All JSON construction uses sjson and lookups use gjson.
Parameters:
- modelName: The name of the model to use for the request
- rawJSON: The raw JSON request data from the OpenAI API
- stream: A boolean indicating if the request is for a streaming response (unused in current implementation)
Returns:
- []byte: The transformed request data in Gemini API format
Types ¶
This section is empty.