 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package gemini provides request translation functionality for Gemini to OpenAI API. It handles parsing and transforming Gemini API requests into OpenAI Chat Completions API format, extracting model information, generation config, message contents, and tool declarations. The package performs JSON data transformation to ensure compatibility between Gemini API format and OpenAI API's expected format.
Package gemini provides response translation functionality for OpenAI to Gemini API. This package handles the conversion of OpenAI Chat Completions API responses into Gemini API-compatible JSON format, transforming streaming events and non-streaming responses into the format expected by Gemini API clients. It supports both streaming and non-streaming modes, handling text content, tool calls, and usage metadata appropriately.
Index ¶
- func ConvertGeminiRequestToOpenAI(modelName string, inputRawJSON []byte, stream bool) []byte
- func ConvertOpenAIResponseToGemini(_ context.Context, _ string, ...) []string
- func ConvertOpenAIResponseToGeminiNonStream(_ context.Context, _ string, ...) string
- type ConvertOpenAIResponseToGeminiParams
- type ToolCallAccumulator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertGeminiRequestToOpenAI ¶
ConvertGeminiRequestToOpenAI parses and transforms a Gemini API request into OpenAI Chat Completions API format. It extracts the model name, generation config, message contents, and tool declarations from the raw JSON request and returns them in the format expected by the OpenAI API.
func ConvertOpenAIResponseToGemini ¶
func ConvertOpenAIResponseToGemini(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string
ConvertOpenAIResponseToGemini converts OpenAI Chat Completions streaming response format to Gemini API format. This function processes OpenAI streaming chunks and transforms them into Gemini-compatible JSON responses. It handles text content, tool calls, and usage metadata, outputting responses that match the Gemini API format.
Parameters:
- ctx: The context for the request.
- modelName: The name of the model.
- rawJSON: The raw JSON response from the OpenAI API.
- param: A pointer to a parameter object for the conversion.
Returns:
- []string: A slice of strings, each containing a Gemini-compatible JSON response.
func ConvertOpenAIResponseToGeminiNonStream ¶
func ConvertOpenAIResponseToGeminiNonStream(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string
ConvertOpenAIResponseToGeminiNonStream converts a non-streaming OpenAI response to a non-streaming Gemini response.
Parameters:
- ctx: The context for the request.
- modelName: The name of the model.
- rawJSON: The raw JSON response from the OpenAI API.
- param: A pointer to a parameter object for the conversion.
Returns:
- string: A Gemini-compatible JSON response.
Types ¶
type ConvertOpenAIResponseToGeminiParams ¶
type ConvertOpenAIResponseToGeminiParams struct {
	// Tool calls accumulator for streaming
	ToolCallsAccumulator map[int]*ToolCallAccumulator
	// Content accumulator for streaming
	ContentAccumulator strings.Builder
	// Track if this is the first chunk
	IsFirstChunk bool
}
    ConvertOpenAIResponseToGeminiParams holds parameters for response conversion