gemini

package
v6.0.16 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package gemini provides request translation functionality for Codex to Gemini API compatibility. It handles parsing and transforming Codex API requests into Gemini API format, extracting model information, system instructions, message contents, and tool declarations. The package performs JSON data transformation to ensure compatibility between Codex API format and Gemini API's expected format.

Package gemini provides response translation functionality for Codex to Gemini API compatibility. This package handles the conversion of Codex API responses into Gemini-compatible JSON format, transforming streaming events and non-streaming responses into the format expected by Gemini API clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertCodexResponseToGemini

func ConvertCodexResponseToGemini(_ context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string

ConvertCodexResponseToGemini converts Codex streaming response format to Gemini format. This function processes various Codex event types 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. The function maintains state across multiple calls to ensure proper response sequencing.

Parameters:

  • ctx: The context for the request, used for cancellation and timeout handling
  • modelName: The name of the model being used for the response
  • rawJSON: The raw JSON response from the Codex API
  • param: A pointer to a parameter object for maintaining state between calls

Returns:

  • []string: A slice of strings, each containing a Gemini-compatible JSON response

func ConvertCodexResponseToGeminiNonStream

func ConvertCodexResponseToGeminiNonStream(_ context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string

ConvertCodexResponseToGeminiNonStream converts a non-streaming Codex response to a non-streaming Gemini response. This function processes the complete Codex response and transforms it into a single Gemini-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 Gemini 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
  • rawJSON: The raw JSON response from the Codex API
  • param: A pointer to a parameter object for the conversion (unused in current implementation)

Returns:

  • string: A Gemini-compatible JSON response containing all message content and metadata

func ConvertGeminiRequestToCodex

func ConvertGeminiRequestToCodex(modelName string, inputRawJSON []byte, _ bool) []byte

ConvertGeminiRequestToCodex parses and transforms a Gemini API request into Codex API format. It extracts the model name, system instruction, message contents, and tool declarations from the raw JSON request and returns them in the format expected by the Codex API. The function performs comprehensive transformation including: 1. Model name mapping and generation configuration extraction 2. System instruction conversion to Codex format 3. Message content conversion with proper role mapping 4. Tool call and tool result handling with FIFO queue for ID matching 5. Tool declaration and tool choice configuration mapping

Parameters:

  • modelName: The name of the model to use for the request
  • rawJSON: The raw JSON request data from the Gemini API
  • stream: A boolean indicating if the request is for a streaming response (unused in current implementation)

Returns:

  • []byte: The transformed request data in Codex API format

Types

type ConvertCodexResponseToGeminiParams

type ConvertCodexResponseToGeminiParams struct {
	Model             string
	CreatedAt         int64
	ResponseID        string
	LastStorageOutput string
}

ConvertCodexResponseToGeminiParams holds parameters for response conversion.

Jump to

Keyboard shortcuts

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