Documentation
¶
Overview ¶
Package config provides configuration management for the Hapax LLM server. It includes support for various LLM providers, token validation, caching, and runtime behavior customization.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheConfig ¶ added in v0.0.5
type CacheConfig struct {
// Enable turns caching on/off (default: false)
Enable bool `yaml:"enable"`
// Type specifies the caching strategy:
// - "memory": In-memory cache (cleared on restart)
// - "redis": Redis-based persistent cache
// - "file": File-based persistent cache
Type string `yaml:"type"`
// TTL specifies how long to keep cached responses (default: 24h)
TTL time.Duration `yaml:"ttl"`
// MaxSize limits the cache size:
// - For memory cache: maximum number of entries
// - For file cache: maximum total size in bytes
MaxSize int64 `yaml:"max_size"`
// Dir specifies the directory for file-based cache
Dir string `yaml:"dir,omitempty"`
// Redis configuration (only used if Type is "redis")
Redis *RedisCacheConfig `yaml:"redis,omitempty"`
}
CacheConfig defines caching behavior for LLM responses. Caching can significantly improve performance and reduce API costs by storing and reusing responses for identical prompts.
type Config ¶
type Config struct {
Server ServerConfig `yaml:"server"`
LLM LLMConfig `yaml:"llm"`
Logging LoggingConfig `yaml:"logging"`
Routes []RouteConfig `yaml:"routes"`
}
Config represents the complete server configuration. It combines server settings, LLM configuration, logging preferences, and route definitions into a single, cohesive configuration structure.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a configuration with sensible defaults
type LLMConfig ¶
type LLMConfig struct {
// Provider specifies the LLM provider (e.g., "openai", "anthropic", "ollama")
Provider string `yaml:"provider"`
// Model is the name of the model to use (e.g., "gpt-4", "claude-3-haiku")
Model string `yaml:"model"`
// APIKey is the authentication key for the provider's API
// Use environment variables (e.g., ${OPENAI_API_KEY}) for secure configuration
APIKey string `yaml:"api_key"`
// Endpoint is the API endpoint URL
// For Ollama, this is typically "http://localhost:11434"
// For OpenAI/Anthropic, this is their respective API endpoints
Endpoint string `yaml:"endpoint"`
// SystemPrompt is the default system message for all conversations
SystemPrompt string `yaml:"system_prompt"`
// MaxContextTokens specifies the maximum combined tokens (input + output)
// This is model-dependent:
// - GPT-4 Turbo: 128,000 tokens
// - Claude-3-Haiku: 200,000 tokens
// - Llama2: Varies by version
MaxContextTokens int `yaml:"max_context_tokens"`
// Cache configuration (optional)
Cache *CacheConfig `yaml:"cache,omitempty"`
// Retry configuration (optional)
Retry *RetryConfig `yaml:"retry,omitempty"`
// Options contains provider-specific generation parameters
Options map[string]interface{} `yaml:"options"`
}
LLMConfig holds LLM-specific configuration. It supports multiple providers (OpenAI, Anthropic, Ollama) and includes settings for token validation, caching, and generation parameters.
type LoggingConfig ¶
type LoggingConfig struct {
// Level sets logging verbosity: debug, info, warn, error
Level string `yaml:"level"`
// Format specifies log output format: json or text
Format string `yaml:"format"`
}
LoggingConfig holds logging-specific configuration.
type RedisCacheConfig ¶ added in v0.0.5
type RedisCacheConfig struct {
// Address is the Redis server address (e.g., "localhost:6379")
Address string `yaml:"address"`
// Password for Redis authentication (optional)
Password string `yaml:"password"`
// DB is the Redis database number to use
DB int `yaml:"db"`
}
RedisCacheConfig holds Redis-specific cache configuration.
type RetryConfig ¶ added in v0.0.5
type RetryConfig struct {
// MaxRetries is the maximum number of retry attempts (default: 3)
MaxRetries int `yaml:"max_retries"`
// InitialDelay is the delay before the first retry (default: 1s)
InitialDelay time.Duration `yaml:"initial_delay"`
// MaxDelay caps the maximum delay between retries (default: 30s)
MaxDelay time.Duration `yaml:"max_delay"`
// Multiplier increases the delay after each retry (default: 2)
// The delay pattern will be: initial_delay * (multiplier ^ retry_count)
Multiplier float64 `yaml:"multiplier"`
// RetryableErrors specifies which error types should trigger retries
// Common values: "rate_limit", "timeout", "server_error"
RetryableErrors []string `yaml:"retryable_errors"`
}
RetryConfig defines the retry behavior for failed API calls. This helps handle transient errors and rate limiting gracefully.
type RouteConfig ¶
type RouteConfig struct {
// Path is the URL path to match
Path string `yaml:"path"`
// Handler specifies which handler to use for this route
Handler string `yaml:"handler"`
}
RouteConfig holds route-specific configuration.
type ServerConfig ¶
type ServerConfig struct {
// Port specifies the HTTP server port (default: 8080)
Port int `yaml:"port"`
// ReadTimeout is the maximum duration for reading the entire request,
// including the body (default: 30s)
ReadTimeout time.Duration `yaml:"read_timeout"`
// WriteTimeout is the maximum duration before timing out writes of the response
// (default: 30s)
WriteTimeout time.Duration `yaml:"write_timeout"`
// MaxHeaderBytes controls the maximum number of bytes the server will
// read parsing the request header's keys and values (default: 1MB)
MaxHeaderBytes int `yaml:"max_header_bytes"`
// ShutdownTimeout specifies how long to wait for the server to shutdown
// gracefully before forcing termination (default: 30s)
ShutdownTimeout time.Duration `yaml:"shutdown_timeout"`
}
ServerConfig holds server-specific configuration for the HTTP server. It defines timeouts, limits, and operational parameters.