Documentation
¶
Overview ¶
Package openai adapts OpenAI's Chat Completions API to the provider-agnostic llm.Model port. It speaks the HTTP API directly (no vendor SDK), so the agent keeps its single-binary shape and the adapter stays a thin, fully-testable mapping. Chat Completions is stateless - the full conversation is sent on every call - which matches the port, and it is the format every OpenAI-compatible endpoint (local models, gateways) speaks, so the same adapter reaches all of them by changing the base URL. The default model is GPT-5.5.
Index ¶
Constants ¶
const (
// DefaultModel is the model used when none is configured.
DefaultModel = "gpt-5.5"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an llm.Model backed by the OpenAI Chat Completions API.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL overrides the API base URL, so any OpenAI-compatible endpoint (a local server, a gateway) can be targeted. An unsafe URL (plaintext http to a non-loopback host, where the API key could be sniffed in transit) is rejected and the secure default is kept, so the override can never downgrade the transport. See llm.SafeBaseURL.
func WithHTTPClient ¶
WithHTTPClient injects the HTTP client (tests supply a mock transport).
func WithMaxTokens ¶
WithMaxTokens sets the per-turn output ceiling (a request's own MaxTokens wins; 0 leaves it to the model's default).
func WithToolGrammar ¶
func WithToolGrammar() Option
WithToolGrammar makes the client constrain a tool-using request to a grammar compiled from the offered tools, so the backend can only sample a structurally valid tool call: a real tool name bound to arguments that satisfy that tool's schema. It targets a local runtime that honors the grammar request field (a local model server), which is where a weaker model needs the structural guarantee most; a hosted endpoint that does not recognize the field simply ignores it. The constraint is attached only when every offered tool's schema can be compiled, so a request never advertises a tool the grammar would forbid. Off by default.
func WithVision ¶
func WithVision() Option
WithVision marks the served model as able to accept image input, so a user message that carries an image is encoded as OpenAI vision content (a content array with image_url parts) instead of being refused. It is off by default: an arbitrary OpenAI-compatible endpoint may serve a text-only model, and silently dropping an image would let a picture vanish from a turn. Enable it only when the configured model can see; the hosted GPT and Gemini models do.