Documentation
¶
Overview ¶
Package openai implements the text and function-tool subset of the OpenAI-compatible streaming Chat Completions protocol.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrProtocol = errors.New("openai: invalid or unsupported streaming response") ErrIncomplete = errors.New("openai: incomplete model response") ErrRemote = errors.New("openai: provider reported an error") ErrLimit = errors.New("openai: response exceeds protocol limits") ErrTransport = errors.New("openai: request or stream transport failed") ErrUnsupported = errors.New("openai: model requires an unsupported response mode") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is immutable after construction and supports concurrent completions provided its supplied HTTP transport supports concurrent use.
func New ¶
New configures one provider endpoint. Redirects and automatic retries are deliberately not enabled. A supplied HTTP client is shallow-copied.
func (*Client) Complete ¶
func (c *Client) Complete(ctx context.Context, req agent.ModelRequest, emit func(string) error) (agent.ModelResponse, error)
Complete sends one request and assembles a complete response from SSE events. No partial tool calls are returned as executable results after failure.
type Config ¶
type Config struct {
BaseURL string
Model string
APIKey string
HTTPClient *http.Client
IncludeUsage bool
}
Config is explicit: no environment lookup or default remote destination. BaseURL includes the API prefix, such as https://api.openai.com/v1. HTTP is accepted only for loopback hosts. IncludeUsage requests the optional streaming usage extension; disable it for endpoints that do not implement it.
type HTTPError ¶
type HTTPError struct{ StatusCode int }
HTTPError reports a non-success status without exposing the provider's body.
type ResponsesClient ¶
type ResponsesClient struct {
// contains filtered or unexported fields
}
ResponsesClient implements Model for the Responses API without server-side conversation IDs. Native history is an explicit same-context opt-in.
func NewResponses ¶
func NewResponses(cfg ResponsesConfig) (*ResponsesClient, error)
func (*ResponsesClient) Complete ¶
func (c *ResponsesClient) Complete(ctx context.Context, req agent.ModelRequest, emit func(string) error) (agent.ModelResponse, error)
func (*ResponsesClient) NativeHistoryFormat ¶
func (c *ResponsesClient) NativeHistoryFormat() string
type ResponsesConfig ¶
type ResponsesConfig struct {
BaseURL string
Model string
APIKey string
MaxOutputTokens int64
HTTPClient *http.Client
// NativeHistoryScope opts into native output items for one trusted provider
// account/context. Use a non-secret label; never reuse it across accounts.
NativeHistoryScope string
}
ResponsesConfig selects the stateless Responses subset. MaxOutputTokens must be positive. Only caller-registered functions are sent.