openai

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package openai provides an implementation of the Provider interface for OpenAI.

v0.10.0 #166 — OpenAI ReasoningProvider implementation via the Responses API.

OpenAI's reasoning models (o3, o4-mini, gpt-5 reasoning class) expose reasoning summaries through the Responses API at /v1/responses, NOT through Chat Completions. The Responses API accepts an "input" array (role + content strings) and returns an "output" array containing alternating "reasoning" and "message" items. Each reasoning item carries a "summary" array of summary_text entries — these become trace.Steps.

trace.Signed is always false for OpenAI: the API returns the summary in plaintext and accepts unsigned mutations on round-trip. Anthropic differs; see the Anthropic adapter for the signed-trace path.

Empty-trace handling: o3 omits the reasoning summary >90% of the time per community reports. The bridge surfaces an empty trace.Steps; H-CoT then emits SkipReasoningTraceEmpty after exhausting its retry budget.

v0.10.0 #166 — OpenAI ImageProvider implementation.

The Chat Completions API accepts a multimodal content array (text + image_url parts) on user messages. Inline image bytes are base64-encoded as data: URLs; URL refs pass through verbatim. The Detail hint is forwarded to OpenAI as the image_url.detail field ("low" → fixed 85 tokens, "high" → tiled at 768px, "auto" → server decides).

This intentionally builds a separate request struct rather than reusing the text-only ChatCompletion path: the wire shape diverges (content as array vs string), and modeling them on one struct would force a pointer-y union that obscures the diff between the two paths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOpenAIProvider

func NewOpenAIProvider(config *core.ProviderConfig) (core.Provider, error)

NewOpenAIProvider creates a new OpenAI provider

Types

type OpenAIProvider

type OpenAIProvider struct {
	*core.BaseProvider
	// contains filtered or unexported fields
}

OpenAIProvider is an implementation of the Provider interface for OpenAI

func (*OpenAIProvider) ChatCompletion

ChatCompletion generates a chat completion

func (*OpenAIProvider) ChatWithImages added in v0.10.0

ChatWithImages implements core.ImageProvider.

The supplied images are appended to the LAST user message in the request; if no user message is present a synthetic empty-text user message is appended to host the image parts. Existing system / assistant messages pass through as plain text content parts so the wire shape stays uniformly multimodal.

func (*OpenAIProvider) ChatWithReasoning added in v0.10.0

ChatWithReasoning implements core.ReasoningProvider via the OpenAI Responses API. The supplied request's Messages map to the input array; MaxTokens / Temperature pass through. Reasoning summaries are extracted into the returned ThinkingTrace; the final assistant text becomes the ChatCompletionResponse's first choice.

func (*OpenAIProvider) Close

func (p *OpenAIProvider) Close() error

Close closes the provider and releases any resources

func (*OpenAIProvider) CountTokens

func (p *OpenAIProvider) CountTokens(ctx context.Context, text string, modelID string) (int, error)

CountTokens counts the number of tokens in a text

func (*OpenAIProvider) CreateEmbedding

func (p *OpenAIProvider) CreateEmbedding(ctx context.Context, request *core.EmbeddingRequest) (*core.EmbeddingResponse, error)

CreateEmbedding creates an embedding

func (*OpenAIProvider) GetModels

func (p *OpenAIProvider) GetModels(ctx context.Context) ([]core.ModelInfo, error)

GetModels returns a list of available models

func (*OpenAIProvider) StreamingChatCompletion

func (p *OpenAIProvider) StreamingChatCompletion(ctx context.Context, request *core.ChatCompletionRequest, callback func(response *core.ChatCompletionResponse) error) error

StreamingChatCompletion generates a streaming chat completion

func (*OpenAIProvider) TextCompletion

TextCompletion generates a text completion

Jump to

Keyboard shortcuts

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