gemini

package
v8.0.36 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 16 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) [][]byte

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:

  • [][]byte: A slice of Gemini-compatible JSON responses

func ConvertCodexResponseToGeminiNonStream

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

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:

  • []byte: A Gemini-compatible JSON response containing all message content and metadata

func ConvertGeminiRequestToCodex

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

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

func GeminiTokenCount

func GeminiTokenCount(ctx context.Context, count int64) []byte

Types

type ConvertCodexResponseToGeminiParams

type ConvertCodexResponseToGeminiParams struct {
	Model      string
	CreatedAt  int64
	ResponseID string
	// StorageOutputs queues completed function-call chunks in stream order
	// until the next non-storage event flushes them. A queue (not a single
	// slot) so consecutive function calls can never overwrite each other.
	StorageOutputs     [][]byte
	HasOutputTextDelta bool
	LastImageHashByID  map[string][32]byte
	// PendingThoughtSignature holds a completed reasoning item's
	// encrypted_content until the next visible part can carry it as a
	// Gemini thoughtSignature, mirroring native Gemini part placement.
	PendingThoughtSignature string
	// SeenReasoningSignatures deduplicates repeated reasoning done events
	// by item ID + signature hash within one response stream.
	SeenReasoningSignatures map[[32]byte]bool
	// HasReasoningDelta and StreamedReasoningItems record whether reasoning
	// deltas were already emitted for the current or keyed reasoning item so
	// done-only reasoning summaries can fall back cleanly.
	HasReasoningDelta      bool
	StreamedReasoningItems map[string]bool
}

ConvertCodexResponseToGeminiParams holds parameters for response conversion.

Jump to

Keyboard shortcuts

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