temp / shared /config.py
CheeksTheGeek's picture
Initial commit: LLM Code Deployment System
c5292d8 unverified
"""Configuration management for LLM Code Deployment system."""
import os
from pathlib import Path
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", extra="ignore")
# Student Configuration
student_secret: str = Field(default="", description="Secret key for authentication")
student_email: str = Field(default="", description="Student email address")
student_api_port: int = Field(default=8000, description="Student API port")
# GitHub Configuration
github_token: str = Field(default="", description="GitHub personal access token")
github_username: str = Field(default="", description="GitHub username")
# LLM Configuration
anthropic_api_key: str = Field(default="", description="Anthropic API key")
openai_api_key: str = Field(default="", description="OpenAI API key")
llm_provider: Literal["anthropic", "openai", "aipipe"] = Field(
default="aipipe", description="LLM provider to use"
)
llm_model: str = Field(
default="google/gemini-2.0-flash-lite-001", description="LLM model to use"
)
# AIPipe Configuration
aipipe_token: str = Field(default="", description="AIPipe API token")
aipipe_base_url: str = Field(
default="https://aipipe.org/openrouter/v1",
description="AIPipe base URL"
)
# Instructor Configuration
instructor_api_port: int = Field(default=8001, description="Instructor API port")
database_url: str = Field(
default="postgresql://localhost:5432/llm_deployment", description="Database URL"
)
evaluation_api_url: str = Field(
default="http://localhost:8001/api/evaluate", description="Evaluation API URL"
)
# Task Configuration
task_timeout_minutes: int = Field(default=10, description="Task timeout in minutes")
max_retry_attempts: int = Field(default=3, description="Maximum retry attempts")
retry_delays: str = Field(default="1,2,4,8", description="Retry delays in seconds")
# Paths
generated_repos_dir: Path = Field(
default=Path("./generated_repos"), description="Directory for generated repos"
)
task_templates_dir: Path = Field(
default=Path("./templates"), description="Directory for task templates"
)
submissions_csv: Path = Field(
default=Path("./submissions.csv"), description="Path to submissions CSV"
)
# Logging
log_level: str = Field(default="INFO", description="Logging level")
log_file: Path = Field(default=Path("./logs/app.log"), description="Log file path")
def get_retry_delays(self) -> list[int]:
"""Parse retry delays from comma-separated string."""
return [int(d.strip()) for d in self.retry_delays.split(",")]
def ensure_directories(self) -> None:
"""Ensure all required directories exist."""
self.generated_repos_dir.mkdir(parents=True, exist_ok=True)
self.task_templates_dir.mkdir(parents=True, exist_ok=True)
self.log_file.parent.mkdir(parents=True, exist_ok=True)
# Global settings instance
settings = Settings()