openai

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package openai implements the llm.Provider contract against the OpenAI Chat Completions API. Stdlib-only.

Translation notes:

  • llm.ContentBlock is folded into OpenAI's flatter message shape: an assistant turn collapses text blocks into one message.content and tool_use blocks into message.tool_calls; a user turn's tool_result blocks become separate role:"tool" messages.
  • Stop reasons are normalized to the engine's vocabulary ("stop"→"end_turn", "tool_calls"→"tool_use", "length"→"max_tokens").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider)

Option configures a Provider.

func WithAPIKey

func WithAPIKey(k string) Option

WithAPIKey overrides the key picked up from OPENAI_API_KEY.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL points the client at a custom origin (Azure, proxies, tests).

func WithChatPath

func WithChatPath(p string) Option

WithChatPath overrides the chat completions path (default "/v1/chat/completions").

func WithCompat

func WithCompat() Option

WithCompat marks this provider as targeting a non-OpenAI endpoint. Disables json_schema response_format (not supported by most compat endpoints). stream_options is kept enabled since most compat endpoints support it.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient swaps the underlying http.Client.

func WithNoStreamOptions

func WithNoStreamOptions() Option

WithNoStreamOptions disables stream_options (for endpoints like Gemini that reject it).

type Provider

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

Provider is an OpenAI Chat Completions client.

func New

func New(opts ...Option) (*Provider, error)

New constructs a Provider. OPENAI_API_KEY is required unless WithAPIKey is supplied. OPENAI_BASE_URL overrides the default origin.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req llm.Request) (<-chan llm.Event, error)

Stream sends req to /v1/chat/completions with stream=true and forwards streamed events onto the returned channel.

Jump to

Keyboard shortcuts

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