Documentation
¶
Overview ¶
Package openai provides OpenAI API client implementations. This file contains the factory function for creating OpenAI threads.
Package openai provides a client implementation for interacting with OpenAI and OpenAI-compatible AI models. It implements the LLM Thread interface for managing conversations, tool execution, and message processing.
Index ¶
- func ExtractMessages(data []byte, toolResults map[string]tooltypes.StructuredToolResult) ([]llmtypes.Message, error)
- func ExtractResponsesMessages(rawMessages []byte, toolResults map[string]tooltypes.StructuredToolResult) ([]llmtypes.Message, error)
- func GetAPIKeyEnvVar(config llmtypes.Config) string
- func GetBaseURL(config llmtypes.Config) string
- func GetConfiguredBaseURL(config llmtypes.Config) string
- func IsOpenAIModel(model string) bool
- func IsReasoningModel(model string) bool
- func NewThread(config llmtypes.Config) (llmtypes.Thread, error)
- func RecordUsesResponsesMode(metadata map[string]any, rawMessages []byte) bool
- func StreamResponsesMessages(rawMessages []byte, toolResults map[string]tooltypes.StructuredToolResult) ([]responses.StreamableMessage, error)
- type StreamableMessage
- type Thread
- func (t *Thread) AddUserMessage(ctx context.Context, message string, imagePaths ...string)
- func (t *Thread) CompactContext(ctx context.Context) error
- func (t *Thread) GetMessages() ([]llmtypes.Message, error)
- func (t *Thread) Provider() string
- func (t *Thread) SaveConversation(ctx context.Context, summarize bool) error
- func (t *Thread) SendMessage(ctx context.Context, message string, handler llmtypes.MessageHandler, ...) (finalOutput string, err error)
- func (t *Thread) ShortSummary(ctx context.Context) (string, error)
- func (t *Thread) SwapContext(_ context.Context, summary string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractMessages ¶
func ExtractMessages(data []byte, toolResults map[string]tooltypes.StructuredToolResult) ([]llmtypes.Message, error)
ExtractMessages converts the internal message format to the common format
func ExtractResponsesMessages ¶
func ExtractResponsesMessages(rawMessages []byte, toolResults map[string]tooltypes.StructuredToolResult) ([]llmtypes.Message, error)
ExtractResponsesMessages extracts messages from Responses API conversation data. This is a wrapper around the responses package's ExtractMessages function.
func GetAPIKeyEnvVar ¶
GetAPIKeyEnvVar returns the API key environment variable name from configuration. Priority: custom api_key_env_var > platform default > fallback to OPENAI_API_KEY.
func GetBaseURL ¶
GetBaseURL returns the base URL resolved from environment, config, and platform defaults.
func GetConfiguredBaseURL ¶
GetConfiguredBaseURL returns only explicit base URL overrides from environment or config.
func IsOpenAIModel ¶
IsOpenAIModel checks if the given model is a valid OpenAI model (reasoning or non-reasoning).
func IsReasoningModel ¶
IsReasoningModel checks if the given model supports reasoning capabilities.
func NewThread ¶
NewThread creates a new OpenAI thread based on the configuration. It dispatches between the Chat Completions API and the Responses API based on api_mode.
func RecordUsesResponsesMode ¶
RecordUsesResponsesMode determines if a conversation should be interpreted using Responses API parsing.
func StreamResponsesMessages ¶
func StreamResponsesMessages(rawMessages []byte, toolResults map[string]tooltypes.StructuredToolResult) ([]responses.StreamableMessage, error)
StreamResponsesMessages parses raw Responses API messages into streamable format. This is a wrapper around the responses package's StreamMessages function.
Types ¶
type StreamableMessage ¶
type StreamableMessage struct {
Kind string // "text", "tool-use", "tool-result", "thinking"
Role string // "user", "assistant", "system"
Content string // Text content
RawItem json.RawMessage
ToolName string // For tool use/result
ToolCallID string // For matching tool results
Input string // For tool use (JSON string)
}
StreamableMessage contains parsed message data for streaming
func StreamMessages ¶
func StreamMessages(rawMessages json.RawMessage, toolResults map[string]tooltypes.StructuredToolResult) ([]StreamableMessage, error)
StreamMessages parses raw messages into streamable format for conversation streaming
type Thread ¶
type Thread struct {
*base.Thread // Embedded base thread for shared functionality
// contains filtered or unexported fields
}
Thread implements the Thread interface using OpenAI's API. It embeds base.Thread to inherit common functionality.
func NewOpenAIThread ¶
NewOpenAIThread creates a new thread with OpenAI's API
func (*Thread) AddUserMessage ¶
AddUserMessage adds a user message with optional images to the thread
func (*Thread) CompactContext ¶
CompactContext performs comprehensive context compacting by creating a detailed summary
func (*Thread) GetMessages ¶
GetMessages returns the current messages in the thread
func (*Thread) SaveConversation ¶
SaveConversation saves the current thread to the conversation store
func (*Thread) SendMessage ¶
func (t *Thread) SendMessage( ctx context.Context, message string, handler llmtypes.MessageHandler, opt llmtypes.MessageOpt, ) (finalOutput string, err error)
SendMessage sends a message to the LLM and processes the response
func (*Thread) ShortSummary ¶
ShortSummary generates a concise summary of the conversation using a faster model.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package copilotdefaults builds OpenAI-compatible model defaults from the Copilot model catalog.
|
Package copilotdefaults builds OpenAI-compatible model defaults from the Copilot model catalog. |
|
preset
|
|
|
codex
Package codex provides preset configurations for Codex CLI models.
|
Package codex provides preset configurations for Codex CLI models. |
|
openai
Package openai provides preset configurations for OpenAI models
|
Package openai provides preset configurations for OpenAI models |
|
Package responses implements storage types for the OpenAI Responses API.
|
Package responses implements storage types for the OpenAI Responses API. |