provider

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnthropicModels = []CatalogModel{

	{ID: "claude-opus-4-7", Name: "Claude Opus 4.7", ActiveByDefault: true, InputPricePerM: 15, OutputPricePerM: 75, SupportsImages: true},
	{ID: "claude-opus-4-6", Name: "Claude Opus 4.6", ActiveByDefault: true, InputPricePerM: 15, OutputPricePerM: 75, SupportsImages: true},
	{ID: "claude-sonnet-4-6", Name: "Claude Sonnet 4.6", ActiveByDefault: true, InputPricePerM: 3, OutputPricePerM: 15, SupportsImages: true},
	{ID: "claude-haiku-4-5-20251001", Name: "Claude Haiku 4.5", ActiveByDefault: true, InputPricePerM: 0.80, OutputPricePerM: 4, SupportsImages: true},

	{ID: "claude-opus-4-5-20251101", Name: "Claude Opus 4.5", ActiveByDefault: false, InputPricePerM: 15, OutputPricePerM: 75, SupportsImages: true},
	{ID: "claude-opus-4-1-20250805", Name: "Claude Opus 4.1", ActiveByDefault: false, InputPricePerM: 15, OutputPricePerM: 75, SupportsImages: true},
	{ID: "claude-sonnet-4-5-20250929", Name: "Claude Sonnet 4.5", ActiveByDefault: false, InputPricePerM: 3, OutputPricePerM: 15, SupportsImages: true},

	{ID: "claude-opus-4-20250514", Name: "Claude Opus 4", ActiveByDefault: false, InputPricePerM: 15, OutputPricePerM: 75, SupportsImages: true},
	{ID: "claude-sonnet-4-20250514", Name: "Claude Sonnet 4", ActiveByDefault: false, InputPricePerM: 3, OutputPricePerM: 15, SupportsImages: true},
}

AnthropicModels is the authoritative list of Anthropic models. Maintained by contributors — see file header for instructions. All listed Claude models are multimodal and accept image input.

View Source
var OpenAIModels = []CatalogModel{

	{ID: "gpt-5", Name: "GPT-5", ActiveByDefault: true, InputPricePerM: 10, OutputPricePerM: 30, SupportsImages: true},
	{ID: "gpt-5-mini", Name: "GPT-5 Mini", ActiveByDefault: true, InputPricePerM: 1.50, OutputPricePerM: 6, SupportsImages: true},
	{ID: "gpt-5-nano", Name: "GPT-5 Nano", ActiveByDefault: false, InputPricePerM: 0.10, OutputPricePerM: 0.40, SupportsImages: true},

	{ID: "gpt-4.1", Name: "GPT-4.1", ActiveByDefault: true, InputPricePerM: 2, OutputPricePerM: 8, SupportsImages: true},
	{ID: "gpt-4.1-mini", Name: "GPT-4.1 Mini", ActiveByDefault: true, InputPricePerM: 0.40, OutputPricePerM: 1.60, SupportsImages: true},
	{ID: "gpt-4.1-nano", Name: "GPT-4.1 Nano", ActiveByDefault: false, InputPricePerM: 0.10, OutputPricePerM: 0.40, SupportsImages: true},

	{ID: "gpt-4o", Name: "GPT-4o", ActiveByDefault: false, InputPricePerM: 2.50, OutputPricePerM: 10, SupportsImages: true},
	{ID: "gpt-4o-mini", Name: "GPT-4o Mini", ActiveByDefault: false, InputPricePerM: 0.15, OutputPricePerM: 0.60, SupportsImages: true},

	{ID: "o4-mini", Name: "o4 Mini", ActiveByDefault: true, InputPricePerM: 1.10, OutputPricePerM: 4.40, SupportsImages: true},
	{ID: "o3", Name: "o3", ActiveByDefault: true, InputPricePerM: 10, OutputPricePerM: 40, SupportsImages: true},
	{ID: "o3-mini", Name: "o3 Mini", ActiveByDefault: false, InputPricePerM: 1.10, OutputPricePerM: 4.40},
	{ID: "o1", Name: "o1", ActiveByDefault: false, InputPricePerM: 15, OutputPricePerM: 60, SupportsImages: true},
	{ID: "o1-mini", Name: "o1 Mini", ActiveByDefault: false, InputPricePerM: 1.50, OutputPricePerM: 6},
}

OpenAIModels is the authoritative list of OpenAI models. Maintained by contributors — see file header for instructions. SupportsImages marks multimodal models. The o*-mini reasoning models are text-only; the GPT-4o/4.1/5 families and o1/o3/o4-mini accept images.

Functions

func ProbeImageSupport added in v0.6.0

func ProbeImageSupport(ctx context.Context, p Provider, modelID string) (supports bool, definitive bool, err error)

ProbeImageSupport sends a single minimal image to the model and reports whether it was accepted. Return values:

  • (true, true, nil): the model accepted the image and responded.
  • (false, true, nil): the provider rejected the request for an image/modality reason.
  • (false, false, err): inconclusive (network/auth/rate-limit/etc.) — do NOT cache; retry later.

Types

type AnthropicProvider

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

AnthropicProvider implements Provider for the Anthropic Messages API.

func NewAnthropicProvider

func NewAnthropicProvider() *AnthropicProvider

func (*AnthropicProvider) ID

func (p *AnthropicProvider) ID() string

func (*AnthropicProvider) Models

func (p *AnthropicProvider) Models() []ModelInfo

func (*AnthropicProvider) StreamChat

func (p *AnthropicProvider) StreamChat(ctx context.Context, req StreamRequest) (<-chan StreamEvent, error)

type CatalogModel added in v0.2.3

type CatalogModel struct {
	ID              string
	Name            string
	ActiveByDefault bool
	InputPricePerM  float64 // USD per 1M input tokens (0 = unknown)
	OutputPricePerM float64 // USD per 1M output tokens (0 = unknown)
	SupportsImages  bool    // whether the model accepts image input
}

CatalogModel is a statically-known model for a provider that does not expose a live /v1/models discovery endpoint.

type ContentPart

type ContentPart struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

type Embedder added in v0.2.1

type Embedder interface {
	// Embed returns embedding vectors for the given input strings.
	Embed(ctx context.Context, inputs []string) ([][]float32, error)
	EmbedModel() string
}

Embedder is an optional interface that providers can implement to support text embeddings (used for agentic memory semantic recall).

type MessageImage added in v0.6.0

type MessageImage struct {
	MediaType string `json:"mediaType"`
	Data      string `json:"data"`
}

MessageImage is an image attached to a message, carried provider-neutrally. Data is base64-encoded image bytes; MediaType is e.g. "image/jpeg".

type ModelInfo

type ModelInfo struct {
	ID              string  `json:"id"`
	Name            string  `json:"name"`
	ProviderID      string  `json:"providerId"`
	Default         bool    `json:"default"`
	ActiveByDefault bool    `json:"activeByDefault"`
	InputPricePerM  float64 `json:"inputPricePerM"`
	OutputPricePerM float64 `json:"outputPricePerM"`
	SupportsImages  bool    `json:"supportsImages"`
}

type ModelMessage

type ModelMessage struct {
	Role       string          `json:"role"`
	Content    json.RawMessage `json:"content,omitempty"`
	ToolCalls  json.RawMessage `json:"tool_calls,omitempty"`
	ToolCallID string          `json:"tool_call_id,omitempty"`
	Name       string          `json:"name,omitempty"`
	// Images carries image attachments for a tool-result message. Providers
	// render these per their API: Anthropic embeds them in the tool_result
	// content block; OpenAI-family inject a follow-up user message.
	Images []MessageImage `json:"images,omitempty"`
}

type ModelRefresher added in v0.1.3

type ModelRefresher interface {
	RefreshModels()
}

ModelRefresher is an optional interface that providers can implement to support dynamic model list refreshing.

type OpenAIProvider

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

OpenAIProvider implements Provider for the OpenAI Chat Completions API. Also used for OpenRouter and Ollama (same API format, different base URL).

func NewEmbedProvider added in v0.2.1

func NewEmbedProvider(providerID, apiKey, model string) (*OpenAIProvider, error)

NewEmbedProvider creates an OpenAIProvider configured for embedding. providerID must be "openai", "openrouter", or "ollama". If apiKey is non-empty it overrides the env var key. If model is non-empty it is stored as the provider model (used for embedding).

func NewOllamaProvider

func NewOllamaProvider() *OpenAIProvider

NewOllamaProvider creates an OpenAI-compatible provider for Ollama. When OLLAMA_BASE_URL points to a cloud endpoint (not localhost), the model list is fetched dynamically from /v1/models. For local Ollama, a static fallback list is used.

func NewOpenAIProvider

func NewOpenAIProvider() *OpenAIProvider

func NewOpenRouterProvider

func NewOpenRouterProvider() *OpenAIProvider

NewOpenRouterProvider creates an OpenAI-compatible provider for OpenRouter.

func (*OpenAIProvider) Embed added in v0.2.1

func (p *OpenAIProvider) Embed(ctx context.Context, inputs []string) ([][]float32, error)

func (*OpenAIProvider) EmbedModel added in v0.2.1

func (p *OpenAIProvider) EmbedModel() string

func (*OpenAIProvider) ID

func (p *OpenAIProvider) ID() string

func (*OpenAIProvider) Models

func (p *OpenAIProvider) Models() []ModelInfo

func (*OpenAIProvider) RefreshModels added in v0.1.3

func (p *OpenAIProvider) RefreshModels()

RefreshModels clears the cached model list so the next call to Models() will re-fetch from the endpoint (for cloud providers). Not safe to call concurrently with Models().

func (*OpenAIProvider) StreamChat

func (p *OpenAIProvider) StreamChat(ctx context.Context, req StreamRequest) (<-chan StreamEvent, error)

type Provider

type Provider interface {
	ID() string
	Models() []ModelInfo
	StreamChat(ctx context.Context, req StreamRequest) (<-chan StreamEvent, error)
}

func NewChatProvider added in v0.2.1

func NewChatProvider(providerID, apiKey, model string) (Provider, error)

NewChatProvider creates a Provider configured for LLM inference (chat/summarization). providerID must be "anthropic", "openai", "openrouter", or "ollama". If apiKey is non-empty it overrides the env-var key. If model is non-empty it is used as the model ID for inference.

func NewProviderWithConfig added in v0.2.1

func NewProviderWithConfig(providerID, apiKey, baseURL string) (Provider, error)

NewProviderWithConfig creates a Provider with explicit credentials, used when credentials come from the DB rather than environment variables. providerID must be "anthropic", "openai", "openrouter", or "ollama". Env-var values are used as the base; apiKey and baseURL override them when non-empty.

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Get

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

func (*Registry) List

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

func (*Registry) ListModels

func (r *Registry) ListModels() []ModelInfo

func (*Registry) ModelSupportsImages added in v0.6.0

func (r *Registry) ModelSupportsImages(modelID string) bool

ModelSupportsImages reports whether the given model accepts image input. Unknown models default to false.

func (*Registry) RefreshModels added in v0.1.3

func (r *Registry) RefreshModels()

RefreshModels clears cached model lists for all providers that support it, forcing re-fetch on next Models() call.

func (*Registry) Register

func (r *Registry) Register(p Provider)

func (*Registry) RegisterCustomModel

func (r *Registry) RegisterCustomModel(modelID, providerID string)

func (*Registry) ResolveProvider

func (r *Registry) ResolveProvider(modelID string) Provider

func (*Registry) UnregisterCustomModel

func (r *Registry) UnregisterCustomModel(modelID string)

type StreamEvent

type StreamEvent struct {
	Type         StreamEventType `json:"type"`
	Text         string          `json:"text,omitempty"`
	ToolCallID   string          `json:"toolCallId,omitempty"`
	ToolName     string          `json:"toolName,omitempty"`
	ToolInput    json.RawMessage `json:"toolInput,omitempty"`
	FinishReason *string         `json:"finishReason,omitempty"`
	Usage        *TokenUsage     `json:"usage,omitempty"`
	Error        string          `json:"error,omitempty"`
}

type StreamEventType

type StreamEventType string
const (
	EventTextDelta     StreamEventType = "text-delta"
	EventToolCallStart StreamEventType = "tool-call-start"
	EventToolCallDelta StreamEventType = "tool-call-delta"
	EventToolCallEnd   StreamEventType = "tool-call-end"
	EventReasoning     StreamEventType = "reasoning"
	EventFinish        StreamEventType = "finish"
	EventUsage         StreamEventType = "usage"
	EventError         StreamEventType = "error"
)

type StreamRequest

type StreamRequest struct {
	Model       string           `json:"model"`
	System      []string         `json:"system"`
	Messages    []ModelMessage   `json:"messages"`
	Tools       []ToolDefinition `json:"tools"`
	Temperature float64          `json:"temperature,omitempty"`
	MaxTokens   int              `json:"maxTokens,omitempty"`
	Abort       context.Context  `json:"-"`
}

type TokenUsage

type TokenUsage struct {
	InputTokens      int `json:"inputTokens,omitempty"`
	OutputTokens     int `json:"outputTokens,omitempty"`
	ReasoningTokens  int `json:"reasoningTokens,omitempty"`
	CacheReadTokens  int `json:"cacheReadTokens,omitempty"`
	CacheWriteTokens int `json:"cacheWriteTokens,omitempty"`
}

TokenUsage carries per-message token accounting from a provider. Fields are non-zero where the provider reports them.

type ToolDefinition

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

Jump to

Keyboard shortcuts

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