Documentation
¶
Index ¶
- Variables
- func GetDefaultModel(provider string) string
- func NewProvider(config core.LLMConfig) (core.LLMProvider, error)
- type BaseProvider
- type Config
- type Function
- type GeminiStudioProvider
- func (p *GeminiStudioProvider) Chat(ctx context.Context, messages []types.Message) (string, error)
- func (p *GeminiStudioProvider) Complete(ctx context.Context, prompt string) (string, error)
- func (p *GeminiStudioProvider) CompleteWithFunctions(ctx context.Context, prompt string, functions []types.Function) (string, error)
- func (p *GeminiStudioProvider) GetAPIKey() string
- func (p *GeminiStudioProvider) GetConfig() *core.LLMConfig
- func (p *GeminiStudioProvider) GetContextWindowSize() int
- func (p *GeminiStudioProvider) SupportsFunction() bool
- type GeminiVertexProvider
- func (p *GeminiVertexProvider) Chat(ctx context.Context, messages []types.Message) (string, error)
- func (p *GeminiVertexProvider) Complete(ctx context.Context, prompt string) (string, error)
- func (p *GeminiVertexProvider) CompleteWithFunctions(ctx context.Context, prompt string, functions []types.Function) (string, error)
- func (p *GeminiVertexProvider) GetAPIKey() string
- func (p *GeminiVertexProvider) GetConfig() *types.LLMConfig
- func (p *GeminiVertexProvider) GetContextWindowSize() int
- func (p *GeminiVertexProvider) SupportsFunction() bool
- type Message
- type OpenAIProvider
- type Provider
- type Role
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTokenLimitExceeded is returned when the input would exceed the model's context limit ErrTokenLimitExceeded = errors.New("token limit exceeded for model context window") // ErrRateLimitExceeded is returned when the API rate limit would be exceeded ErrRateLimitExceeded = errors.New("rate limit exceeded for API requests") // ErrInvalidTokenCount is returned when token counting fails ErrInvalidTokenCount = errors.New("failed to count tokens in input") )
Functions ¶
func GetDefaultModel ¶
GetDefaultModel returns the default model for a provider
func NewProvider ¶
func NewProvider(config core.LLMConfig) (core.LLMProvider, error)
NewProvider creates a new LLM provider based on the configuration
Types ¶
type BaseProvider ¶
type BaseProvider struct {
// contains filtered or unexported fields
}
BaseProvider provides common functionality for LLM providers
func NewBaseProvider ¶
func NewBaseProvider(config *Config) (*BaseProvider, error)
NewBaseProvider creates a new base provider with token management
func (*BaseProvider) CheckTokenLimit ¶
func (p *BaseProvider) CheckTokenLimit(messages []Message) error
CheckTokenLimit checks if the input would exceed the model's context limit
func (*BaseProvider) GetTokenUsage ¶
func (p *BaseProvider) GetTokenUsage() token.UsageMetrics
GetTokenUsage returns the current token usage metrics
func (*BaseProvider) ResetTokenUsage ¶
func (p *BaseProvider) ResetTokenUsage()
ResetTokenUsage resets the token usage metrics
func (*BaseProvider) Stop ¶
func (p *BaseProvider) Stop()
Stop stops the provider's background processes
func (*BaseProvider) WaitForRateLimit ¶
func (p *BaseProvider) WaitForRateLimit()
WaitForRateLimit waits if necessary to respect the rate limit
type Config ¶
type Config struct {
Model string
Temperature float32
MaxTokens int
TopP float32
FrequencyPenalty float32
PresencePenalty float32
Stop []string
APIKey string
BaseURL string
APIVersion string
Timeout float32
MaxRPM int // Maximum requests per minute
EnableTokenCheck bool // Whether to enable token counting and limits
}
Config holds configuration for an LLM provider
type Function ¶
type Function struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]interface{} `json:"parameters"`
}
Function represents a function that can be called by the LLM
type GeminiStudioProvider ¶
type GeminiStudioProvider struct {
// contains filtered or unexported fields
}
GeminiStudioProvider implements the Provider interface for Google's Gemini model via AI Studio
func NewGeminiStudioProvider ¶
func NewGeminiStudioProvider(ctx context.Context, config *core.LLMConfig) (*GeminiStudioProvider, error)
NewGeminiStudioProvider creates a new Gemini provider instance using AI Studio
func (*GeminiStudioProvider) CompleteWithFunctions ¶
func (p *GeminiStudioProvider) CompleteWithFunctions(ctx context.Context, prompt string, functions []types.Function) (string, error)
CompleteWithFunctions generates a completion with function calling support
func (*GeminiStudioProvider) GetAPIKey ¶
func (p *GeminiStudioProvider) GetAPIKey() string
GetAPIKey returns the API key
func (*GeminiStudioProvider) GetConfig ¶
func (p *GeminiStudioProvider) GetConfig() *core.LLMConfig
GetConfig returns the current configuration
func (*GeminiStudioProvider) GetContextWindowSize ¶
func (p *GeminiStudioProvider) GetContextWindowSize() int
GetContextWindowSize returns the context window size for the model
func (*GeminiStudioProvider) SupportsFunction ¶
func (p *GeminiStudioProvider) SupportsFunction() bool
SupportsFunction returns whether function calling is supported
type GeminiVertexProvider ¶
type GeminiVertexProvider struct {
// contains filtered or unexported fields
}
GeminiVertexProvider implements Provider interface using Google Vertex AI's Gemini model
func NewGeminiVertexProvider ¶
func NewGeminiVertexProvider(ctx context.Context, projectID, location, credentials string, config *types.LLMConfig) (*GeminiVertexProvider, error)
NewGeminiVertexProvider creates a new Vertex AI Gemini provider instance
func (*GeminiVertexProvider) CompleteWithFunctions ¶
func (p *GeminiVertexProvider) CompleteWithFunctions(ctx context.Context, prompt string, functions []types.Function) (string, error)
CompleteWithFunctions generates a completion with function calling support
func (*GeminiVertexProvider) GetAPIKey ¶
func (p *GeminiVertexProvider) GetAPIKey() string
GetAPIKey returns the API key
func (*GeminiVertexProvider) GetConfig ¶
func (p *GeminiVertexProvider) GetConfig() *types.LLMConfig
GetConfig returns the provider's configuration
func (*GeminiVertexProvider) GetContextWindowSize ¶
func (p *GeminiVertexProvider) GetContextWindowSize() int
GetContextWindowSize returns the context window size for the model
func (*GeminiVertexProvider) SupportsFunction ¶
func (p *GeminiVertexProvider) SupportsFunction() bool
SupportsFunction returns whether the provider supports function calling
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider implements Provider interface using OpenAI's API
func NewOpenAIProvider ¶
func NewOpenAIProvider(apiKey string, model string, verbose bool) *OpenAIProvider
NewOpenAIProvider creates a new OpenAI provider instance
func (*OpenAIProvider) CompleteWithFunctions ¶
func (p *OpenAIProvider) CompleteWithFunctions(ctx context.Context, messages []types.Message, functions []core.FunctionDefinition) (string, error)
CompleteWithFunctions generates a completion with function calling support
func (*OpenAIProvider) GetAPIKey ¶
func (p *OpenAIProvider) GetAPIKey() string
GetAPIKey returns the API key used by the provider
type Provider ¶
type Provider interface {
// Complete generates a completion for a prompt
Complete(ctx context.Context, prompt string) (string, error)
// CompleteWithFunctions generates a completion with function calling support
CompleteWithFunctions(ctx context.Context, prompt string, functions []Function) (string, error)
// Chat generates a response in a chat conversation
Chat(ctx context.Context, messages []Message) (string, error)
// GetAPIKey returns the API key for the provider
GetAPIKey() string
// GetConfig returns the current configuration
GetConfig() *Config
// SupportsFunction returns whether the provider supports function calling
SupportsFunction() bool
// GetContextWindowSize returns the context window size for the model
GetContextWindowSize() int
// GetTokenUsage returns the current token usage metrics
GetTokenUsage() token.UsageMetrics
// ResetTokenUsage resets the token usage metrics
ResetTokenUsage()
}
Provider defines the interface for language model providers