Package model/openai
Go module github.com/bide-ai/bide; all packages.
github.com/bide-ai/bide/model/openai · pkg.go.dev · Stability: core
Package openai adapts the OpenAI Chat Completions API to agent.Model.
type Model
go
type Model struct {
// contains filtered or unexported fields
}Model is an OpenAI Chat Completions API adapter implementing agent.Model.
Constructors and functions
func New(apiKey string, opts ...Option) *Model: New constructs an OpenAI-compatible adapter.
Methods
func (m *Model) Describe() agent.ModelInfo: Describe reports the adapter's identity: provider "openai" (the Chat Completions API, also when WithBaseURL points it at a compatible server), the configured model ID, and support for a JSON-schema response format.func (m Model) Format(f fmt.State, _ rune): Format writes String for every verb, so no fmt verb (%v, %+v, %#v, %s, %x, ...) prints the key.func (m *Model) RequiresToolsForRequired() bool: RequiresToolsForRequired implements agent.ToolRules: OpenAI refuses tool choice "required" with no tools declared.func (m *Model) Stream(ctx context.Context, req agent.Request) (*agent.Stream, error): Stream implements agent.Model.func (m Model) String() string: String describes the adapter by its model id.func (m *Model) ToolNameRule() *regexp.Regexp: ToolNameRule implements agent.ToolRules: the tool names OpenAI accepts,^[a-zA-Z0-9_-]{1,64}$, so agent.New refuses any other name when the agent is built.
type Option
go
type Option func(*Model)Option configures a Model in New.
Constructors and functions
func WithBaseURL(u string) Option: WithBaseURL sets the API host, for a proxy or a compatible endpoint; /chat/completions is appended to it.func WithHTTPClient(c *http.Client) Option: WithHTTPClient sets the HTTP client requests are sent with.func WithMaxCompletionTokens(use bool) Option: WithMaxCompletionTokens chooses the request field that carries the token limit (WithMaxTokens, or Sampling.MaxTokens): max_completion_tokens when use is true, max_tokens when false.func WithMaxResponseBytes(n int64) Option: WithMaxResponseBytes caps how many bytes of one streamed reply the adapter reads: a reply that runs longer fails with agent.ErrResponseTooLarge, which middleware.Retryable does not retry.func WithMaxTokens(n int) Option: WithMaxTokens sets the default limit on tokens in a reply; a request's Sampling.MaxTokens overrides it.func WithModel(id string) Option: WithModel sets the model ID sent with every request.func WithStrictSchema() Option: WithStrictSchema sends every tool's input schema in OpenAI strict mode, rewritten by schema.OpenAIStrict.func WithToolResultCodec(c provider.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).