openai

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultModel = "gpt-5.4-mini"
)
View Source
const ProviderName = "openai"

ProviderName is the registry key under which this client registers.

Variables

This section is empty.

Functions

func Factory

func Factory(cfg llm.APIConfig, model string, opts ...llm.Option) (llm.Client, error)

Factory adapts New into a llm.ClientFactory. Registered into pkg/llm.DefaultRegistry() by pkg/llm/builtins; downstream apps that want to register OpenAI on a non-default registry can call this directly.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements llm.Client backed by OpenAI's Chat Completions API.

func New

func New(cfg llm.APIConfig, model string, opts ...llm.Option) *Client

New builds an OpenAI client from provider config and applies the given options. Options can be re-applied at runtime via Apply.

func (*Client) Apply

func (c *Client) Apply(opts ...llm.Option)

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, messages []llm.Message, toolSet []tools.Tool) (llm.Response, error)

func (*Client) Model

func (c *Client) Model() string

func (*Client) Name

func (c *Client) Name() string

Name provider name

func (*Client) SetModel

func (c *Client) SetModel(m string)

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, messages []llm.Message, toolSet []tools.Tool, sink llm.ChunkSink) (llm.Response, error)

Stream is the chunked variant of Complete. It opens a streaming SSE connection to OpenAI's chat endpoint, forwards each delta to sink as a Chunk, and returns the fully-assembled Response (content, tool calls, usage) once the server emits its terminal data: [DONE] frame.

On context cancellation the underlying request transport aborts; the scanner loop honors ctx.Err() between reads and returns llm.ErrInterrupted in that case so the agent's interrupt path treats it like any other cancelled completion.

func (*Client) SupportsDeferLoading

func (c *Client) SupportsDeferLoading() bool

SupportsDeferLoading reports false — OpenAI relies on automatic prefix-prompt caching. Mutating the tools array between turns changes the request prefix and invalidates the cache.

Jump to

Keyboard shortcuts

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