Documentation
¶
Index ¶
- func ApplyChatOptions(opts *ChatOptions, options ...ChatOption)
- func ApplyStreamOptions(opts *ChatOptions, options ...StreamOption)
- type AuthenticationError
- type BaseProvider
- func (b *BaseProvider) Close() error
- func (b *BaseProvider) DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)
- func (b *BaseProvider) HandleHTTPError(resp *http.Response, body []byte) error
- func (b *BaseProvider) LogRequest(req *http.Request)
- func (b *BaseProvider) LogResponse(resp *http.Response)
- func (b *BaseProvider) Name() string
- func (b *BaseProvider) ValidateModel(model string, supportedModels []string) error
- type BaseProviderConfig
- type ChatOption
- func WithMaxTokens(maxTokens int) ChatOption
- func WithMetadata(key, value string) ChatOption
- func WithModel(model string) ChatOption
- func WithStopSequences(sequences ...string) ChatOption
- func WithSystemPrompt(prompt string) ChatOption
- func WithTemperature(temperature float64) ChatOption
- func WithTopP(topP float64) ChatOption
- type ChatOptions
- type ContextLengthError
- type Event
- type EventType
- type InvalidModelError
- type Message
- type Provider
- type ProviderError
- type RateLimitError
- type Registry
- func (r *Registry) Close() error
- func (r *Registry) Count() int
- func (r *Registry) Get(name string) (Provider, error)
- func (r *Registry) Has(name string) bool
- func (r *Registry) List() []string
- func (r *Registry) Register(name string, p Provider) error
- func (r *Registry) Unregister(name string) error
- type Response
- type RetryConfig
- type StreamOption
- func StreamWithMaxTokens(maxTokens int) StreamOption
- func StreamWithMetadata(key, value string) StreamOption
- func StreamWithModel(model string) StreamOption
- func StreamWithStopSequences(sequences ...string) StreamOption
- func StreamWithSystemPrompt(prompt string) StreamOption
- func StreamWithTemperature(temperature float64) StreamOption
- func StreamWithTopP(topP float64) StreamOption
- type StreamingNotSupportedError
- type ThinkingBlock
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyChatOptions ¶
func ApplyChatOptions(opts *ChatOptions, options ...ChatOption)
ApplyChatOptions applies a list of ChatOption functions to ChatOptions
func ApplyStreamOptions ¶
func ApplyStreamOptions(opts *ChatOptions, options ...StreamOption)
ApplyStreamOptions applies a list of StreamOption functions to ChatOptions
Types ¶
type AuthenticationError ¶
AuthenticationError represents an authentication failure
func NewAuthenticationError ¶
func NewAuthenticationError(provider, reason string) *AuthenticationError
NewAuthenticationError creates a new AuthenticationError
func (*AuthenticationError) Error ¶
func (e *AuthenticationError) Error() string
Error implements the error interface
type BaseProvider ¶
type BaseProvider struct {
// contains filtered or unexported fields
}
BaseProvider provides common functionality for all provider implementations
func NewBaseProvider ¶
func NewBaseProvider(config BaseProviderConfig) *BaseProvider
NewBaseProvider creates a new BaseProvider with the given configuration
func (*BaseProvider) Close ¶
func (b *BaseProvider) Close() error
Close releases resources held by the base provider
func (*BaseProvider) DoRequest ¶
DoRequest executes an HTTP request with retry logic and error handling
func (*BaseProvider) HandleHTTPError ¶
func (b *BaseProvider) HandleHTTPError(resp *http.Response, body []byte) error
HandleHTTPError converts HTTP errors to provider-specific errors
func (*BaseProvider) LogRequest ¶
func (b *BaseProvider) LogRequest(req *http.Request)
LogRequest logs details about an HTTP request (for debugging)
func (*BaseProvider) LogResponse ¶
func (b *BaseProvider) LogResponse(resp *http.Response)
LogResponse logs details about an HTTP response (for debugging)
func (*BaseProvider) ValidateModel ¶
func (b *BaseProvider) ValidateModel(model string, supportedModels []string) error
ValidateModel checks if a model is supported and returns an error if not
type BaseProviderConfig ¶
type BaseProviderConfig struct {
Name string
HTTPClient *http.Client
Logger logger.LoggerInterface
RetryConfig RetryConfig
}
BaseProviderConfig contains configuration for creating a BaseProvider
type ChatOption ¶
type ChatOption func(*ChatOptions)
ChatOption is a function that modifies ChatOptions
func WithMaxTokens ¶
func WithMaxTokens(maxTokens int) ChatOption
WithMaxTokens sets the maximum number of tokens to generate
func WithMetadata ¶
func WithMetadata(key, value string) ChatOption
WithMetadata adds custom metadata to the request
func WithModel ¶
func WithModel(model string) ChatOption
WithModel sets the model to use for the request
func WithStopSequences ¶
func WithStopSequences(sequences ...string) ChatOption
WithStopSequences sets the sequences that will stop generation
func WithSystemPrompt ¶
func WithSystemPrompt(prompt string) ChatOption
WithSystemPrompt sets the system prompt for the conversation
func WithTemperature ¶
func WithTemperature(temperature float64) ChatOption
WithTemperature sets the sampling temperature (0.0 to 1.0)
func WithTopP ¶
func WithTopP(topP float64) ChatOption
WithTopP sets the nucleus sampling parameter (0.0 to 1.0)
type ChatOptions ¶
type ChatOptions struct {
Model string
MaxTokens int
Temperature float64
TopP float64
StopSequences []string
SystemPrompt string
Stream bool
Metadata map[string]string
}
ChatOptions contains configuration options for chat requests
func DefaultChatOptions ¶
func DefaultChatOptions() *ChatOptions
DefaultChatOptions returns ChatOptions with sensible defaults
type ContextLengthError ¶
ContextLengthError represents a context length exceeded error
func NewContextLengthError ¶
func NewContextLengthError(provider, model string, requestTokens, maxTokens int) *ContextLengthError
NewContextLengthError creates a new ContextLengthError
func (*ContextLengthError) Error ¶
func (e *ContextLengthError) Error() string
Error implements the error interface
type InvalidModelError ¶
InvalidModelError represents an invalid model identifier error
func NewInvalidModelError ¶
func NewInvalidModelError(provider, model string, supportedModels []string) *InvalidModelError
NewInvalidModelError creates a new InvalidModelError
func (*InvalidModelError) Error ¶
func (e *InvalidModelError) Error() string
Error implements the error interface
type Provider ¶
type Provider interface {
// Chat sends a complete chat request and waits for the full response
Chat(ctx context.Context, messages []Message, opts ...ChatOption) (Response, error)
// Stream sends a streaming chat request and returns a channel for events
Stream(ctx context.Context, messages []Message, opts ...StreamOption) (<-chan Event, error)
// Name returns the provider's name
Name() string
// Models returns the list of supported model identifiers
Models() []string
// Close releases any resources held by the provider
Close() error
}
Provider defines the interface for LLM providers
type ProviderError ¶
ProviderError represents a provider-specific error with additional context
func NewProviderError ¶
func NewProviderError(provider, model string, err error) *ProviderError
NewProviderError creates a new ProviderError
func (*ProviderError) Error ¶
func (e *ProviderError) Error() string
Error implements the error interface
func (*ProviderError) Unwrap ¶
func (e *ProviderError) Unwrap() error
Unwrap returns the underlying error
type RateLimitError ¶
type RateLimitError struct {
Provider string
RetryAfter int // seconds until retry is allowed
LimitType string
CurrentUsage int
Limit int
}
RateLimitError represents a rate limiting error
func NewRateLimitError ¶
func NewRateLimitError(provider string, retryAfter int) *RateLimitError
NewRateLimitError creates a new RateLimitError with retry information
func NewRateLimitErrorWithDetails ¶
func NewRateLimitErrorWithDetails(provider, limitType string, currentUsage, limit int) *RateLimitError
NewRateLimitErrorWithDetails creates a detailed RateLimitError
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
Error implements the error interface
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages registered LLM providers in a thread-safe manner
func (*Registry) Get ¶
Get retrieves a provider by name Returns an error if the provider is not found
func (*Registry) Register ¶
Register adds a provider to the registry Returns an error if a provider with the same name is already registered
func (*Registry) Unregister ¶
Unregister removes a provider from the registry Returns an error if the provider is not found
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int // Maximum number of retry attempts
InitialBackoff time.Duration // Initial backoff duration
MaxBackoff time.Duration // Maximum backoff duration
Multiplier float64 // Backoff multiplier for exponential backoff
RetryableStatusCodes []int // HTTP status codes that should trigger retries
}
RetryConfig configures retry behavior for failed requests
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns sensible default retry configuration
type StreamOption ¶
type StreamOption func(*ChatOptions)
StreamOption is a function that modifies ChatOptions for streaming requests
func StreamWithMaxTokens ¶
func StreamWithMaxTokens(maxTokens int) StreamOption
StreamWithMaxTokens sets the maximum number of tokens for streaming requests
func StreamWithMetadata ¶
func StreamWithMetadata(key, value string) StreamOption
StreamWithMetadata adds metadata for streaming requests
func StreamWithModel ¶
func StreamWithModel(model string) StreamOption
StreamWithModel sets the model to use for streaming requests
func StreamWithStopSequences ¶
func StreamWithStopSequences(sequences ...string) StreamOption
StreamWithStopSequences sets stop sequences for streaming requests
func StreamWithSystemPrompt ¶
func StreamWithSystemPrompt(prompt string) StreamOption
StreamWithSystemPrompt sets the system prompt for streaming requests
func StreamWithTemperature ¶
func StreamWithTemperature(temperature float64) StreamOption
StreamWithTemperature sets the temperature for streaming requests
func StreamWithTopP ¶
func StreamWithTopP(topP float64) StreamOption
StreamWithTopP sets the top_p for streaming requests
type StreamingNotSupportedError ¶
StreamingNotSupportedError represents an error when streaming is not supported
func NewStreamingNotSupportedError ¶
func NewStreamingNotSupportedError(provider, model, reason string) *StreamingNotSupportedError
NewStreamingNotSupportedError creates a new StreamingNotSupportedError
func (*StreamingNotSupportedError) Error ¶
func (e *StreamingNotSupportedError) Error() string
Error implements the error interface
type ThinkingBlock ¶
ThinkingBlock represents a thinking/reasoning block from Claude's extended thinking