first commit
This commit is contained in:
78
src/daemon_boyfriend/config.py
Normal file
78
src/daemon_boyfriend/config.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""Configuration management using pydantic-settings."""
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings loaded from environment variables."""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
)
|
||||
|
||||
# Discord Configuration
|
||||
discord_token: str = Field(..., description="Discord bot token")
|
||||
discord_guild_id: int | None = Field(
|
||||
None, description="Test guild ID for faster command sync during development"
|
||||
)
|
||||
command_prefix: str = Field("!", description="Legacy command prefix")
|
||||
|
||||
# AI Provider Configuration
|
||||
ai_provider: Literal["openai", "openrouter", "anthropic"] = Field(
|
||||
"openai", description="Which AI provider to use"
|
||||
)
|
||||
ai_model: str = Field("gpt-4o", description="AI model to use")
|
||||
ai_max_tokens: int = Field(1024, ge=100, le=4096, description="Max tokens for AI response")
|
||||
ai_temperature: float = Field(0.7, ge=0.0, le=2.0, description="AI temperature")
|
||||
|
||||
# Provider API Keys
|
||||
openai_api_key: str | None = Field(None, description="OpenAI API key")
|
||||
openrouter_api_key: str | None = Field(None, description="OpenRouter API key")
|
||||
anthropic_api_key: str | None = Field(None, description="Anthropic API key")
|
||||
|
||||
# SearXNG Configuration
|
||||
searxng_base_url: str = Field(
|
||||
"http://localhost:8080", description="SearXNG instance URL"
|
||||
)
|
||||
searxng_timeout: int = Field(10, description="Search timeout in seconds")
|
||||
|
||||
# Rate Limiting
|
||||
rate_limit_messages: int = Field(10, description="Messages per user per minute")
|
||||
rate_limit_searches: int = Field(5, description="Searches per user per minute")
|
||||
|
||||
# Logging
|
||||
log_level: str = Field("INFO", description="Logging level")
|
||||
|
||||
# Bot Behavior
|
||||
bot_name: str = Field("Daemon Boyfriend", description="Bot display name")
|
||||
bot_personality: str = Field(
|
||||
"helpful, witty, and slightly mischievous",
|
||||
description="Bot personality description for system prompt",
|
||||
)
|
||||
max_conversation_history: int = Field(
|
||||
20, description="Max messages to keep in conversation memory per user"
|
||||
)
|
||||
|
||||
def get_api_key(self) -> str:
|
||||
"""Get the API key for the configured provider."""
|
||||
key_map = {
|
||||
"openai": self.openai_api_key,
|
||||
"openrouter": self.openrouter_api_key,
|
||||
"anthropic": self.anthropic_api_key,
|
||||
}
|
||||
key = key_map.get(self.ai_provider)
|
||||
if not key:
|
||||
raise ValueError(
|
||||
f"No API key configured for provider '{self.ai_provider}'. "
|
||||
f"Set {self.ai_provider.upper()}_API_KEY in your environment."
|
||||
)
|
||||
return key
|
||||
|
||||
|
||||
# Global settings instance
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user