openai

package
v0.1.0-beta.10 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package openai implements agent.ChatModel against the OpenAI Chat Completions API. The package uses only net/http and encoding/json.

Wire reference:

Index

Constants

View Source
const DefaultBaseURL = "https://api.openai.com"

DefaultBaseURL is the production OpenAI API endpoint. Override via Option WithBaseURL for tests, proxies, or OpenAI-compatible endpoints (Azure OpenAI, vLLM, llama.cpp, Ollama in OpenAI mode).

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider)

Option configures a Provider during construction.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the API base URL.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient overrides the HTTP client.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger overrides the slog.Logger.

func WithOrganization

func WithOrganization(org string) Option

WithOrganization sets the OpenAI-Organization header.

type Provider

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

Provider implements agent.ChatModel against the OpenAI Chat Completions API. Construct with New; do not zero-value.

func New

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

New constructs a Provider authenticated with the given API key.

func (*Provider) Generate

func (p *Provider) Generate(ctx context.Context, req agent.ChatRequest) (agent.ChatResponse, error)

Generate dispatches a synchronous Chat Completions request.

func (*Provider) Stream

Stream dispatches a streaming Chat Completions request.

Jump to

Keyboard shortcuts

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