chat_completions

package
v6.0.10 Latest Latest
Warning

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

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

Documentation

Overview

Package openai provides utilities to translate OpenAI Chat Completions request JSON into OpenAI Responses API request JSON using gjson/sjson. It supports tools, multimodal text/image inputs, and Structured Outputs. The package handles the conversion of OpenAI API requests into the format expected by the OpenAI Responses API, including proper mapping of messages, tools, and generation parameters.

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

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

ConvertCodexResponseToOpenAI translates a single chunk of a streaming response from the Codex API format to the OpenAI Chat Completions streaming format. It processes various Codex 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
  • 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 an OpenAI-compatible JSON response

func ConvertCodexResponseToOpenAINonStream

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

ConvertCodexResponseToOpenAINonStream converts a non-streaming Codex response to a non-streaming OpenAI response. This function processes the complete Codex 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 (unused in current implementation)
  • 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: An OpenAI-compatible JSON response containing all message content and metadata

func ConvertOpenAIRequestToCodex

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

ConvertOpenAIRequestToCodex converts an OpenAI Chat Completions request JSON into an OpenAI Responses API request JSON. The transformation follows the examples defined in docs/2.md exactly, including tools, multi-turn dialog, multimodal text/image handling, and Structured Outputs mapping.

Parameters:

  • modelName: The name of the model to use for the request
  • rawJSON: The raw JSON request data from the OpenAI Chat Completions API
  • stream: A boolean indicating if the request is for a streaming response

Returns:

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

Types

type ConvertCliToOpenAIParams

type ConvertCliToOpenAIParams struct {
	ResponseID        string
	CreatedAt         int64
	Model             string
	FunctionCallIndex int
}

ConvertCliToOpenAIParams holds parameters for response conversion.

Jump to

Keyboard shortcuts

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