Versions in this module Expand all Collapse all v0 v0.3.1 Aug 27, 2026 v0.3.0 Aug 27, 2026 Changes in this version + const DefaultGeminiEndpoint + const DefaultOpenAIEndpoint + const MaxResponseBytes + var ErrProviderAuth = errors.New("provider authentication failed") + var ErrProviderRequest = errors.New("invalid provider request") + var ErrProviderUnavailable = errors.New("provider unavailable") + var ErrRateLimited = errors.New("provider rate limited") + var ErrResponseTooLarge = errors.New("provider response too large") + var ErrStreamEarlyExit = errors.New("llm: stream early exit") + func DefaultEarlyExit(content string, toolCalls []ToolCall) bool + func EnsureUsage(resp *CompletionResponse, req CompletionRequest) bool + func EstimateCompletionTokens(content string, toolCalls []ToolCall) int + func EstimateMessagesTokens(messages []Message) int + func EstimateTokens(text string) int + func IsRetryable(err error) bool + func IsStreamEarlyExit(err error) bool + func LooksCompleteStructured(s string) bool + func LooksCompleteToolCalls(toolCalls []ToolCall) bool + func TokenizerAvailable() bool + func WithRetry(ctx context.Context, config *ProviderConfig, ...) error + type Choice struct + Delta Message + FinishReason string + Index int + Logprobs *Logprobs + Message Message + type CompletionRequest struct + EarlyExit EarlyExitFunc + MaxTokens int + Messages []Message + Model string + StopSequences []string + Stream bool + SystemPrompt string + Temperature float64 + ToolChoice interface{} + Tools []ToolDefinition + type CompletionResponse struct + Choices []Choice + Created int64 + ID string + Metadata map[string]interface{} + Model string + Object string + SystemFingerprint string + Usage Usage + func CollectStream(ctx context.Context, ...) (*CompletionResponse, error) + type ConversationHistory struct + func NewConversationHistory() *ConversationHistory + func (ch *ConversationHistory) AddMessage(message Message) + func (ch *ConversationHistory) Clear() + func (ch *ConversationHistory) GetLastN(n int) []Message + func (ch *ConversationHistory) GetMessages() []Message + func (ch *ConversationHistory) ReplaceMessage(i int, message Message) + func (ch *ConversationHistory) Size() int + type EarlyExitFunc func(content string, toolCalls []ToolCall) bool + type Function struct + Description string + Name string + Parameters map[string]interface{} + type FunctionCall struct + Arguments string + Name string + type GeminiProvider struct + func NewGeminiProvider(config *ProviderConfig) (*GeminiProvider, error) + func (p *GeminiProvider) Close() error + func (p *GeminiProvider) Complete(ctx context.Context, req CompletionRequest) (*CompletionResponse, error) + func (p *GeminiProvider) CompleteStream(ctx context.Context, req CompletionRequest, callback StreamCallback) error + func (p *GeminiProvider) CompleteStreamWithMode(ctx context.Context, req CompletionRequest, callback StreamCallback, ...) error + func (p *GeminiProvider) CompleteWithMode(ctx context.Context, req CompletionRequest, mode StreamMode) (*CompletionResponse, error) + func (p *GeminiProvider) GetConfig() map[string]interface{} + func (p *GeminiProvider) GetDefaultModels() []string + func (p *GeminiProvider) GetMaxTokens(model string) int + func (p *GeminiProvider) GetModels(ctx context.Context) ([]string, error) + func (p *GeminiProvider) GetName() string + func (p *GeminiProvider) GetStreamingConfig() *StreamingConfig + func (p *GeminiProvider) IsHealthy(ctx context.Context) error + func (p *GeminiProvider) SetConfig(config map[string]interface{}) error + func (p *GeminiProvider) SetStreamingConfig(config *StreamingConfig) error + func (p *GeminiProvider) SupportsStreaming() bool + func (p *GeminiProvider) SupportsToolCalls() bool + type Logprobs struct + TokenLogprobs []float64 + Tokens []string + TopLogprobs []map[string]float64 + type Message struct + Content string + Metadata map[string]interface{} + Name string + Role string + ToolCallID string + ToolCalls []ToolCall + type OllamaMessage struct + Content string + Role string + type OllamaModelInfo struct + Digest string + ModifiedAt time.Time + Name string + Size int64 + type OllamaModelsResponse struct + Models []OllamaModelInfo + type OllamaOptions struct + NumPredict int + Stop []string + Temperature float64 + TopK int + TopP float64 + type OllamaProvider struct + func NewOllamaProvider(config *ProviderConfig) (*OllamaProvider, error) + func (p *OllamaProvider) Close() error + func (p *OllamaProvider) Complete(ctx context.Context, req CompletionRequest) (*CompletionResponse, error) + func (p *OllamaProvider) CompleteStream(ctx context.Context, req CompletionRequest, callback StreamCallback) error + func (p *OllamaProvider) CompleteStreamWithMode(ctx context.Context, req CompletionRequest, callback StreamCallback, ...) error + func (p *OllamaProvider) CompleteWithMode(ctx context.Context, req CompletionRequest, mode StreamMode) (*CompletionResponse, error) + func (p *OllamaProvider) DeleteModel(ctx context.Context, model string) error + func (p *OllamaProvider) EstimateMessagesTokens(messages []Message) int + func (p *OllamaProvider) EstimateTokens(text string) int + func (p *OllamaProvider) GetConfig() map[string]interface{} + func (p *OllamaProvider) GetDefaultModels() []string + func (p *OllamaProvider) GetMaxTokens(model string) int + func (p *OllamaProvider) GetModels(ctx context.Context) ([]string, error) + func (p *OllamaProvider) GetName() string + func (p *OllamaProvider) GetProviderInfo() map[string]interface{} + func (p *OllamaProvider) GetStreamingConfig() *StreamingConfig + func (p *OllamaProvider) GetTokenLimit(model string) int + func (p *OllamaProvider) IsHealthy(ctx context.Context) error + func (p *OllamaProvider) PullModel(ctx context.Context, model string) error + func (p *OllamaProvider) SetConfig(config map[string]interface{}) error + func (p *OllamaProvider) SetStreamingConfig(config *StreamingConfig) error + func (p *OllamaProvider) SupportsStreaming() bool + func (p *OllamaProvider) SupportsToolCalls() bool + func (p *OllamaProvider) ValidateModel(model string) error + type OllamaRequest struct + Format string + KeepAlive string + Messages []OllamaMessage + Model string + Options OllamaOptions + Stream bool + type OllamaResponse struct + CreatedAt time.Time + Done bool + Error string + Message OllamaMessage + Model string + type OpenAIProvider struct + func NewOpenAIProvider(config *ProviderConfig) (*OpenAIProvider, error) + func (p *OpenAIProvider) Close() error + func (p *OpenAIProvider) Complete(ctx context.Context, req CompletionRequest) (*CompletionResponse, error) + func (p *OpenAIProvider) CompleteStream(ctx context.Context, req CompletionRequest, callback StreamCallback) error + func (p *OpenAIProvider) CompleteStreamWithMode(ctx context.Context, req CompletionRequest, callback StreamCallback, ...) error + func (p *OpenAIProvider) CompleteWithMode(ctx context.Context, req CompletionRequest, mode StreamMode) (*CompletionResponse, error) + func (p *OpenAIProvider) EstimateMessagesTokens(messages []Message) int + func (p *OpenAIProvider) EstimateTokens(text string) int + func (p *OpenAIProvider) GetConfig() map[string]interface{} + func (p *OpenAIProvider) GetDefaultModels() []string + func (p *OpenAIProvider) GetMaxTokens(model string) int + func (p *OpenAIProvider) GetModels(ctx context.Context) ([]string, error) + func (p *OpenAIProvider) GetName() string + func (p *OpenAIProvider) GetProviderInfo() map[string]interface{} + func (p *OpenAIProvider) GetStreamingConfig() *StreamingConfig + func (p *OpenAIProvider) GetTokenLimit(model string) int + func (p *OpenAIProvider) IsHealthy(ctx context.Context) error + func (p *OpenAIProvider) SetConfig(config map[string]interface{}) error + func (p *OpenAIProvider) SetStreamingConfig(config *StreamingConfig) error + func (p *OpenAIProvider) SupportsStreaming() bool + func (p *OpenAIProvider) SupportsToolCalls() bool + func (p *OpenAIProvider) ValidateModel(model string) error + type Provider interface + Close func() error + Complete func(ctx context.Context, req CompletionRequest) (*CompletionResponse, error) + CompleteStream func(ctx context.Context, req CompletionRequest, callback StreamCallback) error + CompleteStreamWithMode func(ctx context.Context, req CompletionRequest, callback StreamCallback, ...) error + CompleteWithMode func(ctx context.Context, req CompletionRequest, mode StreamMode) (*CompletionResponse, error) + GetConfig func() map[string]interface{} + GetModels func(ctx context.Context) ([]string, error) + GetName func() string + GetStreamingConfig func() *StreamingConfig + IsHealthy func(ctx context.Context) error + SetConfig func(config map[string]interface{}) error + SetStreamingConfig func(config *StreamingConfig) error + SupportsStreaming func() bool + type ProviderConfig struct + APIKey string + Endpoint string + Headers map[string]string + MaxTokens int + Metadata map[string]interface{} + Model string + Name string + RetryCount int + RetryDelay time.Duration + Streaming *StreamingConfig + Temperature float64 + Timeout time.Duration + Type string + func DefaultProviderConfig() *ProviderConfig + type ProviderError struct + Body string + Provider string + RetryAfter time.Duration + StatusCode int + func NewProviderError(provider string, resp *http.Response) *ProviderError + func NewTransportError(provider string, err error) *ProviderError + func (e *ProviderError) Error() string + func (e *ProviderError) Retryable() bool + func (e *ProviderError) Unwrap() error + type ProviderManager struct + func NewProviderManager() *ProviderManager + func (pm *ProviderManager) Close() error + func (pm *ProviderManager) Complete(ctx context.Context, providerName string, req CompletionRequest) (*CompletionResponse, error) + func (pm *ProviderManager) CompleteStream(ctx context.Context, providerName string, req CompletionRequest, ...) error + func (pm *ProviderManager) CompleteStreamWithMode(ctx context.Context, providerName string, req CompletionRequest, ...) error + func (pm *ProviderManager) CompleteWithMode(ctx context.Context, providerName string, req CompletionRequest, ...) (*CompletionResponse, error) + func (pm *ProviderManager) DisableStreaming(providerName string) error + func (pm *ProviderManager) EnableStreaming(providerName string) error + func (pm *ProviderManager) GetAllModels(ctx context.Context) (map[string][]string, error) + func (pm *ProviderManager) GetDefaultProvider() (Provider, error) + func (pm *ProviderManager) GetProvider(name string) (Provider, error) + func (pm *ProviderManager) GetProviderModels(ctx context.Context, providerName string) ([]string, error) + func (pm *ProviderManager) HealthCheck(ctx context.Context) map[string]error + func (pm *ProviderManager) ListProviders() []string + func (pm *ProviderManager) RegisterProvider(name string, provider Provider) error + func (pm *ProviderManager) SetDefaultProvider(name string) error + func (pm *ProviderManager) SetStreamingMode(providerName string, mode StreamMode) error + func (pm *ProviderManager) UnregisterProvider(name string) error + type SimpleTokenCounter struct + func NewSimpleTokenCounter() *SimpleTokenCounter + func (stc *SimpleTokenCounter) CountMessagesTokens(messages []Message) (int, error) + func (stc *SimpleTokenCounter) CountTokens(text string) (int, error) + type StreamCallback func(chunk CompletionResponse) error + type StreamCollector struct + func NewStreamCollector() *StreamCollector + func (c *StreamCollector) Add(chunk CompletionResponse) + func (c *StreamCollector) Content() string + func (c *StreamCollector) Response() *CompletionResponse + func (c *StreamCollector) ToolCalls() []ToolCall + type StreamMode string + const StreamModeAuto + const StreamModeForced + const StreamModeNone + type StreamingConfig struct + BufferSize int + ChunkSize int + Enabled bool + FlushDelay int + KeepAlive bool + Mode StreamMode + func DefaultStreamingConfig() *StreamingConfig + type TokenCounter interface + CountMessagesTokens func(messages []Message) (int, error) + CountTokens func(text string) (int, error) + type ToolCall struct + Function FunctionCall + ID string + Index int + Metadata map[string]interface{} + Type string + type ToolDefinition struct + Function Function + Type string + type Usage struct + CompletionTokens int + PromptTokens int + TotalTokens int