Spaces:
Sleeping
Sleeping
File size: 3,295 Bytes
c5292d8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | """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()
|