62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
"""Application configuration"""
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
from pydantic import field_validator
|
|
from typing import List, Union
|
|
import json
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings"""
|
|
|
|
# Ollama
|
|
ollama_base_url: str = "http://localhost:11434"
|
|
ollama_model: str = "codellama:7b"
|
|
|
|
# Database
|
|
database_url: str = "sqlite+aiosqlite:///./review.db"
|
|
|
|
# Security
|
|
secret_key: str = "change-this-to-a-secure-random-string"
|
|
encryption_key: str = "change-this-to-a-secure-random-string"
|
|
|
|
# Master Git tokens (optional, используются если не указаны в проекте)
|
|
master_gitea_token: str = ""
|
|
master_github_token: str = ""
|
|
master_bitbucket_token: str = ""
|
|
|
|
# Server
|
|
host: str = "0.0.0.0"
|
|
port: int = 8000
|
|
debug: bool = True
|
|
|
|
# CORS - можно задать как строку с запятой или JSON массив
|
|
cors_origins: Union[List[str], str] = "http://localhost:5173,http://localhost:3000"
|
|
|
|
@field_validator('cors_origins', mode='before')
|
|
@classmethod
|
|
def parse_cors_origins(cls, v):
|
|
if isinstance(v, str):
|
|
# Если строка с запятыми
|
|
if ',' in v:
|
|
return [origin.strip() for origin in v.split(',')]
|
|
# Если JSON массив
|
|
try:
|
|
parsed = json.loads(v)
|
|
if isinstance(parsed, list):
|
|
return parsed
|
|
except (json.JSONDecodeError, ValueError):
|
|
pass
|
|
# Если одиночная строка
|
|
return [v.strip()]
|
|
return v
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
case_sensitive=False
|
|
)
|
|
|
|
|
|
settings = Settings()
|
|
|