provider

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSupportedProviders

func GetSupportedProviders() []string

GetSupportedProviders returns a list of all supported provider IDs.

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)
}

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 {
	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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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