provider

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RetryCount atomic.Int64

RetryCount is the number of retries performed by any RetryTransport in this process. It is a process counter so a turn's metrics can report its delta without reaching into each provider's HTTP client.

Functions

This section is empty.

Types

type AnthropicProvider

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

func NewAnthropicProvider

func NewAnthropicProvider(cfg config.GatewayConfig) *AnthropicProvider

func (*AnthropicProvider) Models

func (p *AnthropicProvider) Models(ctx context.Context) ([]string, error)

func (*AnthropicProvider) Name

func (p *AnthropicProvider) Name() string

func (*AnthropicProvider) Stream

func (p *AnthropicProvider) Stream(ctx context.Context, model string, history []Message, tools []ToolSpec) (<-chan StreamChunk, error)

type CopilotProvider added in v0.5.2

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

CopilotProvider talks to Copilot's OpenAI-compatible endpoint; exchanges OAuth token for cached short-lived JWT.

func NewCopilotProvider added in v0.5.2

func NewCopilotProvider(cfg config.CopilotConfig) *CopilotProvider

NewCopilotProvider builds a Copilot provider from config.

func (*CopilotProvider) HasToken added in v0.6.0

func (p *CopilotProvider) HasToken() bool

HasToken reports OAuth token availability for `gocode doctor`; checks env and saved file.

func (*CopilotProvider) Models added in v0.5.2

func (p *CopilotProvider) Models(ctx context.Context) ([]string, error)

func (*CopilotProvider) Name added in v0.5.2

func (p *CopilotProvider) Name() string

func (*CopilotProvider) Stream added in v0.5.2

func (p *CopilotProvider) Stream(ctx context.Context, model string, history []Message, tools []ToolSpec) (<-chan StreamChunk, error)

func (*CopilotProvider) TokenEnvName added in v0.6.0

func (p *CopilotProvider) TokenEnvName() string

TokenEnvName returns the environment variable this provider reads first.

type GatewayProxyProvider

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

func NewGatewayProxyProvider

func NewGatewayProxyProvider(name string, cfg config.GatewayConfig) *GatewayProxyProvider

func (*GatewayProxyProvider) Models

func (p *GatewayProxyProvider) Models(ctx context.Context) ([]string, error)

func (*GatewayProxyProvider) Name

func (p *GatewayProxyProvider) Name() string

func (*GatewayProxyProvider) Stream

func (p *GatewayProxyProvider) Stream(ctx context.Context, model string, history []Message, tools []ToolSpec) (<-chan StreamChunk, error)

func (*GatewayProxyProvider) WithStreamUsage added in v0.7.5

func (p *GatewayProxyProvider) WithStreamUsage(enabled bool) *GatewayProxyProvider

WithStreamUsage turns on stream_options.include_usage for this provider. Parsing usage needs no switch; only the request opt-in does.

type Message

type Message struct {
	Role       string     `json:"role"`
	Content    string     `json:"content"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
	// ReasoningContent must be replayed into history; MiniMax/DeepSeek require the full chain across tool-call turns.
	ReasoningContent string `json:"reasoning_content,omitempty"`
}

type OllamaProvider

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

func NewOllamaProvider

func NewOllamaProvider(host string) (*OllamaProvider, error)

func (*OllamaProvider) Models

func (o *OllamaProvider) Models(ctx context.Context) ([]string, error)

func (*OllamaProvider) Name

func (o *OllamaProvider) Name() string

func (*OllamaProvider) Stream

func (o *OllamaProvider) Stream(ctx context.Context, model string, history []Message, tools []ToolSpec) (<-chan StreamChunk, error)

type Provider

type Provider interface {
	Name() string
	Models(ctx context.Context) ([]string, error)
	Stream(ctx context.Context, model string, history []Message, tools []ToolSpec) (<-chan StreamChunk, error)
}

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Active

func (r *Registry) Active() (Provider, error)

func (*Registry) ActiveName

func (r *Registry) ActiveName() string

func (*Registry) ContextWindow added in v0.7.4

func (r *Registry) ContextWindow(model string) int

ContextWindow returns the context window for model in tokens. Registered prefixes win over built-in family defaults when they match at least as much text, so an explicit registration can always override a default. An unknown model falls back to defaultContextWindow.

func (*Registry) Get added in v0.2.0

func (r *Registry) Get(name string) Provider

func (*Registry) List

func (r *Registry) List() []string

func (*Registry) Register

func (r *Registry) Register(p Provider)

func (*Registry) RegisterContextWindow added in v0.7.4

func (r *Registry) RegisterContextWindow(model string, tokens int)

RegisterContextWindow records the context window of a model or model family. The model is matched as a case-insensitive prefix, so registering "gpt-4o" also covers "gpt-4o-mini". A non-positive token count or empty prefix is ignored.

func (*Registry) Switch

func (r *Registry) Switch(name string) error

type RetryTransport added in v0.4.0

type RetryTransport struct {
	Base         http.RoundTripper
	MaxRetries   int
	InitialDelay time.Duration
	MaxDelay     time.Duration
}

RetryTransport wraps an http.RoundTripper with retry logic for transient errors.

func NewRetryTransport added in v0.4.0

func NewRetryTransport(base http.RoundTripper) *RetryTransport

NewRetryTransport creates a new RetryTransport with sensible defaults.

func (*RetryTransport) RoundTrip added in v0.4.0

func (t *RetryTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip retries 429/500/502/503/504 for idempotent methods only. POSTs are never replayed: a failed POST may already have been accepted and billed upstream.

type StreamChunk

type StreamChunk struct {
	Delta string
	// Reasoning streams separately and is replayed next turn; MiniMax/DeepSeek require the full chain.
	Reasoning string
	ToolCalls []ToolCall
	// ToolCallDelta, when non-nil, carries one fragment of a tool call as it
	// streams. ToolCalls still arrives complete for compatibility: a consumer
	// that ignores deltas sees exactly the behaviour it saw before.
	ToolCallDelta *ToolCallDelta
	Done          bool
	Err           error
	// FinishReason is the provider stop reason; empty if unreported. "length"/"max_tokens" means truncated.
	FinishReason string
	// Usage, when non-nil, carries provider-reported token counts. Parsing is
	// always on; a provider that never reports usage leaves it nil and the
	// agent loop falls back to its local estimate.
	Usage *Usage
}

type ToolCall

type ToolCall struct {
	ID   string          `json:"id"`
	Name string          `json:"name"`
	Args json.RawMessage `json:"args"`
}

type ToolCallDelta added in v0.7.5

type ToolCallDelta struct {
	Index     int
	ID        string
	Name      string
	ArgsDelta string
}

ToolCallDelta is one streamed fragment of a tool call. Index identifies the call inside the assistant message; ID and Name are best-effort, because some dialects deliver them on a later fragment (a consumer must handle empties). ArgsDelta is the raw JSON fragment to append to the call's argument buffer.

type ToolSpec

type ToolSpec struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

type Usage added in v0.7.5

type Usage struct {
	PromptTokens     int
	CompletionTokens int
}

Usage reports the token counts a provider attributes to one request. It is advisory: a provider that reports nothing leaves StreamChunk.Usage nil, and a provider that reports only one side leaves the other at zero.

Jump to

Keyboard shortcuts

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