provider

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrModelProviderMismatch = errors.New("model-provider mismatch")

ErrModelProviderMismatch indicates a model name belongs to a different provider.

Functions

func GetSupportedProviders

func GetSupportedProviders() []string

GetSupportedProviders returns a list of all supported provider IDs.

func ValidateModelProvider added in v0.6.0

func ValidateModelProvider(providerType, model string) error

ValidateModelProvider checks whether the given model name is clearly incompatible with the provider type. Returns ErrModelProviderMismatch when the model prefix matches a known exclusion for the provider.

An empty model is always valid (the provider will use its default).

Types

type GenerateParams

type GenerateParams struct {
	Model       string
	Messages    []Message
	Tools       []Tool
	Temperature float64
	MaxTokens   int
}

GenerateParams contains parameters for generation.

type Message

type Message struct {
	Role      string
	Content   string
	ToolCalls []ToolCall
	Metadata  map[string]interface{}
}

Message represents a chat message.

type ModelInfo

type ModelInfo struct {
	ID             string
	Name           string
	ContextWindow  int
	SupportsVision bool
	SupportsTools  bool
	IsReasoning    bool
}

ModelInfo describes an available model.

type Provider

type Provider interface {
	// ID returns the unique identifier of the provider (e.g., "openai", "anthropic").
	ID() string

	// Generate streams responses for the given conversation.
	// It returns an iterator that yields StreamEvents.
	Generate(ctx context.Context, params GenerateParams) (iter.Seq2[StreamEvent, error], error)

	// ListModels returns a list of available models.
	ListModels(ctx context.Context) ([]ModelInfo, error)
}

Provider defines the interface for LLM providers.

type Registry

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

Registry manages the registration and lookup of providers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new provider registry.

func (*Registry) Get

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

Get returns a provider by ID. It handles aliases (e.g., "gpt" -> "openai").

func (*Registry) List

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

List returns a list of all registered providers.

func (*Registry) Register

func (r *Registry) Register(p Provider)

Register adds a provider to the registry.

type StreamEvent

type StreamEvent struct {
	Type       StreamEventType
	Text       string
	ToolCall   *ToolCall
	Error      error
	ThoughtLen int // length of filtered thought text (diagnostics only)
	Usage      *Usage
}

StreamEvent represents a single event in the generation stream.

type StreamEventType

type StreamEventType string

StreamEventType defines the type of event in a generation stream.

const (
	StreamEventPlainText StreamEventType = "text_delta"
	StreamEventToolCall  StreamEventType = "tool_call"
	StreamEventThought   StreamEventType = "thought"
	StreamEventError     StreamEventType = "error"
	StreamEventDone      StreamEventType = "done"
)

func (StreamEventType) Valid

func (t StreamEventType) Valid() bool

Valid reports whether t is a known stream event type.

func (StreamEventType) Values

func (t StreamEventType) Values() []StreamEventType

Values returns all known stream event types.

type Tool

type Tool struct {
	Name        string
	Description string
	Parameters  map[string]interface{} // JSON schema
}

Tool represents a tool definition.

type ToolCall

type ToolCall struct {
	Index            *int // streaming chunk correlation (OpenAI Index field)
	ID               string
	Name             string
	Arguments        string // JSON string
	Thought          bool   // Gemini: part is a thinking step
	ThoughtSignature []byte // Gemini: opaque signature to echo back
}

ToolCall represents a request for tool execution.

type Usage added in v0.5.0

type Usage struct {
	InputTokens  int64
	OutputTokens int64
	TotalTokens  int64
	CacheTokens  int64 // Anthropic prompt caching
}

Usage holds token usage data returned by the provider.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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