Documentation
¶
Index ¶
- Constants
- func GetProvidersWithStatus(store *Store) map[Provider][]ProviderInfo
- func IsReady(meta ProviderMeta) bool
- func Register(meta ProviderMeta, factory ProviderFactory)
- type AuthMethod
- type ChunkType
- type CompletionOptions
- type CompletionResponse
- type ConnectionInfo
- type CurrentModelInfo
- type LLMProvider
- type Message
- type ModelCache
- type ModelInfo
- type Provider
- type ProviderFactory
- type ProviderInfo
- type ProviderMeta
- type ProviderStatus
- type Registry
- func (r *Registry) GetAllMetas() []ProviderMeta
- func (r *Registry) GetMeta(provider Provider, authMethod AuthMethod) (ProviderMeta, bool)
- func (r *Registry) GetProvider(ctx context.Context, provider Provider, authMethod AuthMethod) (LLMProvider, error)
- func (r *Registry) GetProvidersWithStatus(store *Store) map[Provider][]ProviderInfo
- func (r *Registry) GetReadyProviders() []ProviderMeta
- func (r *Registry) IsReady(meta ProviderMeta) bool
- func (r *Registry) Register(meta ProviderMeta, factory ProviderFactory)
- type Store
- func (s *Store) CacheModels(provider Provider, authMethod AuthMethod, models []ModelInfo) error
- func (s *Store) ClearModelCache() error
- func (s *Store) ClearSearchProvider() error
- func (s *Store) Connect(provider Provider, authMethod AuthMethod) error
- func (s *Store) Disconnect(provider Provider) error
- func (s *Store) GetAllCachedModels() map[string][]ModelInfo
- func (s *Store) GetCachedModels(provider Provider, authMethod AuthMethod) ([]ModelInfo, bool)
- func (s *Store) GetConnection(provider Provider) (ConnectionInfo, bool)
- func (s *Store) GetConnections() map[string]ConnectionInfo
- func (s *Store) GetCurrentModel() *CurrentModelInfo
- func (s *Store) GetSearchProvider() string
- func (s *Store) IsConnected(provider Provider, authMethod AuthMethod) bool
- func (s *Store) SetCurrentModel(modelID string, provider Provider, authMethod AuthMethod) error
- func (s *Store) SetSearchProvider(name string) error
- type StoreData
- type StreamChunk
- type Tool
- type ToolCall
- type ToolResult
- type Usage
Constants ¶
const ( // ModelCacheTTL is the time-to-live for cached models ModelCacheTTL = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func GetProvidersWithStatus ¶
func GetProvidersWithStatus(store *Store) map[Provider][]ProviderInfo
GetProvidersWithStatus returns all providers grouped by provider name with their status
func IsReady ¶
func IsReady(meta ProviderMeta) bool
IsReady checks if all required environment variables are set for a provider
func Register ¶
func Register(meta ProviderMeta, factory ProviderFactory)
Register registers a provider with its metadata and factory
Types ¶
type AuthMethod ¶
type AuthMethod string
AuthMethod represents an authentication method
const ( AuthAPIKey AuthMethod = "api_key" AuthVertex AuthMethod = "vertex" AuthBedrock AuthMethod = "bedrock" )
type CompletionOptions ¶
type CompletionOptions struct {
Model string
Messages []Message
MaxTokens int
Temperature float64
Tools []Tool
SystemPrompt string
}
CompletionOptions contains options for a completion request
type CompletionResponse ¶
type CompletionResponse struct {
Content string `json:"content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
StopReason string `json:"stop_reason"` // "end_turn", "tool_use", "max_tokens"
Usage Usage `json:"usage"`
}
CompletionResponse represents a completion response
func Complete ¶
func Complete(ctx context.Context, provider LLMProvider, opts CompletionOptions) (CompletionResponse, error)
Complete is a helper function that collects stream chunks into a complete response This provides non-streaming output from any LLMProvider
type ConnectionInfo ¶
type ConnectionInfo struct {
AuthMethod AuthMethod `json:"authMethod"`
ConnectedAt time.Time `json:"connectedAt"`
}
ConnectionInfo stores connection information for a provider
type CurrentModelInfo ¶
type CurrentModelInfo struct {
ModelID string `json:"modelId"`
Provider Provider `json:"provider"`
AuthMethod AuthMethod `json:"authMethod"`
}
CurrentModelInfo stores the current model with its provider info
type LLMProvider ¶
type LLMProvider interface {
// Stream sends a completion request and returns a channel of streaming chunks
Stream(ctx context.Context, opts CompletionOptions) <-chan StreamChunk
// ListModels returns the available models for this provider
ListModels(ctx context.Context) ([]ModelInfo, error)
// Name returns the provider name
Name() string
}
LLMProvider is the interface that all providers must implement
func GetProvider ¶
func GetProvider(ctx context.Context, provider Provider, authMethod AuthMethod) (LLMProvider, error)
GetProvider returns a provider instance for the given provider and auth method
type Message ¶
type Message struct {
Role string `json:"role"` // "user", "assistant", "system"
Content string `json:"content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolResult *ToolResult `json:"tool_result,omitempty"`
}
Message represents a chat message
type ModelCache ¶
ModelCache stores cached model information
type ModelInfo ¶
type ModelInfo struct {
ID string `json:"id"`
Name string `json:"name"`
DisplayName string `json:"displayName,omitempty"`
}
ModelInfo represents information about an available model
type ProviderFactory ¶
type ProviderFactory func(ctx context.Context) (LLMProvider, error)
ProviderFactory creates a new LLMProvider instance
type ProviderInfo ¶
type ProviderInfo struct {
Meta ProviderMeta
Status ProviderStatus
}
ProviderInfo contains provider metadata with its current status
type ProviderMeta ¶
type ProviderMeta struct {
Provider Provider
AuthMethod AuthMethod
EnvVars []string // Required environment variables
DisplayName string
}
ProviderMeta contains static metadata about a provider
func GetAllMetas ¶
func GetAllMetas() []ProviderMeta
GetAllMetas returns all registered provider metadata
func GetMeta ¶
func GetMeta(provider Provider, authMethod AuthMethod) (ProviderMeta, bool)
GetMeta returns the metadata for a specific provider configuration
func GetReadyProviders ¶
func GetReadyProviders() []ProviderMeta
GetReadyProviders returns all providers that have their required env vars configured
func (ProviderMeta) Key ¶
func (m ProviderMeta) Key() string
Key returns a unique key for this provider configuration
type ProviderStatus ¶
type ProviderStatus string
ProviderStatus represents the connection status of a provider
const ( StatusConnected ProviderStatus = "connected" StatusAvailable ProviderStatus = "available" StatusNotConfigured ProviderStatus = "not_configured" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages provider registration and discovery
func (*Registry) GetAllMetas ¶
func (r *Registry) GetAllMetas() []ProviderMeta
GetAllMetas returns all registered provider metadata
func (*Registry) GetMeta ¶
func (r *Registry) GetMeta(provider Provider, authMethod AuthMethod) (ProviderMeta, bool)
GetMeta returns the metadata for a specific provider configuration
func (*Registry) GetProvider ¶
func (r *Registry) GetProvider(ctx context.Context, provider Provider, authMethod AuthMethod) (LLMProvider, error)
GetProvider returns a provider instance for the given provider and auth method
func (*Registry) GetProvidersWithStatus ¶
func (r *Registry) GetProvidersWithStatus(store *Store) map[Provider][]ProviderInfo
GetProvidersWithStatus returns all providers grouped by provider name with their status
func (*Registry) GetReadyProviders ¶
func (r *Registry) GetReadyProviders() []ProviderMeta
GetReadyProviders returns all providers that have their required env vars configured
func (*Registry) IsReady ¶
func (r *Registry) IsReady(meta ProviderMeta) bool
IsReady checks if all required environment variables are set for a provider
func (*Registry) Register ¶
func (r *Registry) Register(meta ProviderMeta, factory ProviderFactory)
Register registers a provider with its metadata and factory
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages provider configuration persistence
func (*Store) CacheModels ¶
func (s *Store) CacheModels(provider Provider, authMethod AuthMethod, models []ModelInfo) error
CacheModels saves model information for a provider
func (*Store) ClearModelCache ¶
ClearModelCache clears all cached models
func (*Store) ClearSearchProvider ¶
ClearSearchProvider clears the search provider (use default)
func (*Store) Connect ¶
func (s *Store) Connect(provider Provider, authMethod AuthMethod) error
Connect saves a connection for a provider
func (*Store) Disconnect ¶
Disconnect removes a connection for a provider
func (*Store) GetAllCachedModels ¶
GetAllCachedModels returns all cached models grouped by provider key
func (*Store) GetCachedModels ¶
func (s *Store) GetCachedModels(provider Provider, authMethod AuthMethod) ([]ModelInfo, bool)
GetCachedModels returns cached models if they exist and are not expired
func (*Store) GetConnection ¶
func (s *Store) GetConnection(provider Provider) (ConnectionInfo, bool)
GetConnection returns the connection info for a provider
func (*Store) GetConnections ¶
func (s *Store) GetConnections() map[string]ConnectionInfo
GetConnections returns all connections
func (*Store) GetCurrentModel ¶
func (s *Store) GetCurrentModel() *CurrentModelInfo
GetCurrentModel returns the current model info
func (*Store) GetSearchProvider ¶
GetSearchProvider returns the current search provider name
func (*Store) IsConnected ¶
func (s *Store) IsConnected(provider Provider, authMethod AuthMethod) bool
IsConnected checks if a provider is connected with the specified auth method
func (*Store) SetCurrentModel ¶
func (s *Store) SetCurrentModel(modelID string, provider Provider, authMethod AuthMethod) error
SetCurrentModel sets the current model with provider info
func (*Store) SetSearchProvider ¶
SetSearchProvider sets the search provider
type StoreData ¶
type StoreData struct {
Connections map[string]ConnectionInfo `json:"connections"` // key: provider
Models map[string]ModelCache `json:"models"` // key: provider:authMethod
Current *CurrentModelInfo `json:"current"` // current model with provider info
SearchProvider *string `json:"searchProvider,omitempty"` // search provider name (exa, serper, brave)
}
StoreData is the persisted data structure
type StreamChunk ¶
type StreamChunk struct {
Type ChunkType
Text string // For text chunks
ToolID string // For tool_start chunks
ToolName string // For tool_start chunks
Response *CompletionResponse // For done chunks
Error error // For error chunks
}
StreamChunk represents a chunk in a streaming response
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters interface{} `json:"parameters"` // JSON Schema
}
Tool represents a tool definition
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Input string `json:"input"` // JSON string
}
ToolCall represents a tool call from the model