chat_completions

package
v6.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package openai provides request translation functionality for OpenAI to Gemini CLI API compatibility. It converts OpenAI Chat Completions requests into Gemini CLI compatible JSON using gjson/sjson only.

Package openai provides response translation functionality for Gemini CLI to OpenAI API compatibility. This package handles the conversion of Gemini CLI 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 ConvertOpenAIRequestToOpenAI

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

ConvertOpenAIRequestToOpenAI converts an OpenAI Chat Completions request (raw JSON) into a complete Gemini CLI 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 CLI API format

func ConvertOpenAIResponseToOpenAI

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

ConvertOpenAIResponseToOpenAI translates a single chunk of a streaming response from the Gemini CLI API format to the OpenAI Chat Completions streaming format. It processes various Gemini CLI 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 CLI 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 ConvertOpenAIResponseToOpenAINonStream

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

ConvertOpenAIResponseToOpenAINonStream converts a non-streaming Gemini CLI response to a non-streaming OpenAI response. This function processes the complete Gemini CLI 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
  • rawJSON: The raw JSON response from the Gemini CLI API
  • param: A pointer to a parameter object for the conversion

Returns:

  • string: An OpenAI-compatible JSON response containing all message content and metadata

Types

This section is empty.

Jump to

Keyboard shortcuts

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