provider

package
v1.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnthropicProvider

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

AnthropicProvider implements Provider for the Anthropic Messages API.

func NewAnthropicProvider

func NewAnthropicProvider(name, model, baseURL, authMethod string, oauthCfg *auth.DeviceFlowConfig, store auth.Store) *AnthropicProvider

NewAnthropicProvider creates a new Anthropic provider adapter. If baseURL is empty, the default Anthropic API URL is used.

func (*AnthropicProvider) Authenticate

func (p *AnthropicProvider) Authenticate() error

func (*AnthropicProvider) ID

func (p *AnthropicProvider) ID() string

func (*AnthropicProvider) Query

func (p *AnthropicProvider) Query(ctx context.Context, messages []Message, opts QueryOpts) (<-chan StreamChunk, error)

func (*AnthropicProvider) Validate

func (p *AnthropicProvider) Validate() error

type GeminiProvider

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

GeminiProvider implements Provider for the Google Gemini API.

func NewGeminiProvider

func NewGeminiProvider(name, model, baseURL, authMethod string, oauthCfg *auth.DeviceFlowConfig, store auth.Store) *GeminiProvider

NewGeminiProvider creates a new Gemini provider adapter. If baseURL is empty, the default Gemini API URL is used.

func (*GeminiProvider) Authenticate

func (p *GeminiProvider) Authenticate() error

func (*GeminiProvider) ID

func (p *GeminiProvider) ID() string

func (*GeminiProvider) Query

func (p *GeminiProvider) Query(ctx context.Context, messages []Message, opts QueryOpts) (<-chan StreamChunk, error)

func (*GeminiProvider) Validate

func (p *GeminiProvider) Validate() error

type Message

type Message struct {
	Role    Role   `json:"role"`
	Content string `json:"content"`
}

Message represents a single message in a conversation.

type OpenAICompatProvider

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

OpenAICompatProvider implements Provider for OpenAI-compatible APIs with a configurable base URL. It reuses the OpenAI SSE parsing logic.

func NewOpenAICompatProvider

func NewOpenAICompatProvider(name, model, baseURL string, authMethod config.AuthMethod, store auth.Store) *OpenAICompatProvider

NewOpenAICompatProvider creates a new OpenAI-compatible provider adapter. The auth method determines whether an Authorization header is sent.

func (*OpenAICompatProvider) Authenticate

func (p *OpenAICompatProvider) Authenticate() error

func (*OpenAICompatProvider) ID

func (p *OpenAICompatProvider) ID() string

func (*OpenAICompatProvider) Query

func (p *OpenAICompatProvider) Query(ctx context.Context, messages []Message, opts QueryOpts) (<-chan StreamChunk, error)

func (*OpenAICompatProvider) Validate

func (p *OpenAICompatProvider) Validate() error

type OpenAIProvider

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

OpenAIProvider implements Provider for the OpenAI Chat Completions API.

func NewOpenAIProvider

func NewOpenAIProvider(name, model, baseURL, authMethod string, oauthCfg *auth.DeviceFlowConfig, store auth.Store) *OpenAIProvider

NewOpenAIProvider creates a new OpenAI provider adapter. If baseURL is empty, the default OpenAI API URL is used.

func (*OpenAIProvider) Authenticate

func (p *OpenAIProvider) Authenticate() error

func (*OpenAIProvider) ID

func (p *OpenAIProvider) ID() string

func (*OpenAIProvider) Query

func (p *OpenAIProvider) Query(ctx context.Context, messages []Message, opts QueryOpts) (<-chan StreamChunk, error)

func (*OpenAIProvider) Validate

func (p *OpenAIProvider) Validate() error

type Provider

type Provider interface {
	// ID returns the unique identifier for this provider (from config name).
	ID() string

	// Query sends messages to the provider and returns a channel of streaming chunks.
	Query(ctx context.Context, messages []Message, opts QueryOpts) (<-chan StreamChunk, error)

	// Authenticate performs any necessary authentication (API key validation, OAuth flow).
	Authenticate() error

	// Validate checks that the provider is reachable and properly configured.
	Validate() error
}

Provider is the interface that all LLM provider adapters must implement.

type QueryOpts

type QueryOpts struct {
	MaxTokens   int              `json:"max_tokens,omitempty"`
	Temperature float64          `json:"temperature,omitempty"`
	Tools       []ToolDefinition `json:"tools,omitempty"`
}

QueryOpts holds options for a query.

type Registry

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

Registry holds all configured providers and provides access to them.

func NewRegistry

func NewRegistry(cfg *config.Config) (*Registry, error)

NewRegistry creates a Registry from the application config. It instantiates provider adapters for each entry in config.Providers.

func NewRegistryWithStore

func NewRegistryWithStore(cfg *config.Config, store auth.Store) (*Registry, error)

NewRegistryWithStore creates a Registry using the given auth store. This allows callers to pre-populate API keys before creating the registry.

func NewTestRegistry added in v0.2.0

func NewTestRegistry(primary Provider, all ...Provider) *Registry

NewTestRegistry creates a Registry for testing. The primary parameter is the primary provider; all are added to the registry's provider list.

func (*Registry) Healthy

func (r *Registry) Healthy() []Provider

Healthy returns providers that pass Validate(). Providers that fail validation are silently excluded.

func (*Registry) Primary

func (r *Registry) Primary() Provider

Primary returns the primary provider.

func (*Registry) Providers

func (r *Registry) Providers() []Provider

Providers returns all registered providers.

type Response

type Response struct {
	ProviderID string
	Content    string
	ToolCalls  []ToolCall
	Error      error
}

Response represents a complete response from a single provider.

type Role

type Role string

Role represents a message role in a conversation.

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleSystem    Role = "system"
)

type StreamChunk

type StreamChunk struct {
	// Delta is the incremental text content.
	Delta string
	// Done indicates this is the final chunk.
	Done bool
	// ToolCalls contains any tool calls emitted in the final chunk.
	// Only populated when Done is true and the model requested tool use.
	ToolCalls []ToolCall
	// InputTokens is the total input tokens for this request.
	// Only populated when Done is true.
	InputTokens int
	// OutputTokens is the total output tokens for this response.
	// Only populated when Done is true.
	OutputTokens int
	// Error is set if the provider encountered an error.
	Error error
}

StreamChunk represents a single chunk of a streaming response.

type ToolCall

type ToolCall struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

ToolCall represents a tool invocation from the model.

type ToolDefinition

type ToolDefinition struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Parameters  interface{} `json:"parameters"`
}

ToolDefinition defines a tool the model can call.

Jump to

Keyboard shortcuts

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