gemini

package
v6.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2025 License: MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertGeminiRequestToOpenAI

func ConvertGeminiRequestToOpenAI(modelName string, inputRawJSON []byte, stream bool) []byte

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.

func GeminiTokenCount added in v6.2.33

func GeminiTokenCount(ctx context.Context, count int64) string

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

type ToolCallAccumulator

type ToolCallAccumulator struct {
	ID        string
	Name      string
	Arguments strings.Builder
}

ToolCallAccumulator holds the state for accumulating tool call data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL