openai

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package openai provides an llm.Provider backed by OpenAI's Chat Completions API. It is a thin hand-written client over net/http; it pulls in no third-party deps and lives out of the core so the console binary does not link it (it ships as the console-plugin-openai executable).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenAI

type OpenAI struct {
	APIKey  string
	Model   string
	BaseURL string
	HTTP    *http.Client
}

OpenAI is an llm.Provider backed by OpenAI's Chat Completions API.

func New

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

New constructs an OpenAI provider. If apiKey is empty, it falls back to the OPENAI_API_KEY environment variable. Defaults: Model "gpt-4o-mini", BaseURL "https://api.openai.com", and a 60s HTTP client.

func (*OpenAI) Complete

func (o *OpenAI) Complete(ctx context.Context, req llm.Request) (string, error)

Complete sends a single completion request to the Chat Completions API and returns the text of the assistant's reply.

func (*OpenAI) Name

func (o *OpenAI) Name() string

Name identifies the provider.

type Option

type Option func(*OpenAI)

Option configures an OpenAI provider in New.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL overrides the API base URL (e.g. to point at a test server).

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client used for requests.

func WithModel

func WithModel(model string) Option

WithModel sets the default model id used when a Request does not specify one.

Jump to

Keyboard shortcuts

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