Help us shape the future of Go! Take the 2026 Go Developer Survey

openai

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package openai adapts the OpenAI Chat Completions API to agent.Model. Because that API is the de-facto standard, this one adapter — via WithBaseURL — runs on OpenAI, Ollama (local), DeepSeek, Groq, Together, OpenRouter, vLLM, LM Studio, Azure, Mistral, xAI, and any other OpenAI-compatible endpoint. That's how "run on any model" is one adapter, not N.

Zero external deps (net/http + stdlib). Tool schemas use schema.OpenAIStrict when WithStrictSchema is set (genuine OpenAI structured-output strict mode — which many SDKs, incl. agenticenv, leave unused); off by default for max compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

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

func New

func New(apiKey string, opts ...Option) *Model

New constructs an OpenAI-compatible adapter. For non-OpenAI endpoints set WithBaseURL (e.g. "http://localhost:11434/v1" for Ollama) and WithModel.

func (*Model) Stream

func (m *Model) Stream(ctx context.Context, req agent.Request) (*agent.Stream, error)

type Option

type Option func(*Model)

func WithBaseURL

func WithBaseURL(u string) Option

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

func WithMaxTokens

func WithMaxTokens(n int) Option

func WithModel

func WithModel(id string) Option

func WithStrictSchema

func WithStrictSchema() Option

func WithToolResultCodec added in v0.2.0

func WithToolResultCodec(c agent.ToolResultCodec) Option

WithToolResultCodec encodes tool results sent to the model with c instead of raw JSON (for example GCF, to cut tokens on structured output). The journal keeps the JSON form; only what the model reads changes. Default is JSON.

Jump to

Keyboard shortcuts

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