tyndale-ai-service/app/config.py

50 lines
1.5 KiB
Python

from typing import Literal
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""Application configuration loaded from environment variables."""
llm_mode: Literal["local", "remote", "openai", "asksage"] = "local"
llm_remote_url: str = ""
llm_remote_token: str = ""
# OpenAI configuration
openai_api_key: str = ""
openai_model: str = "gpt-4o-mini"
# AskSage configuration
asksage_email: str = ""
asksage_api_key: str = ""
asksage_model: str = "gpt-4o"
# CORS configuration
cors_origins: str = "http://localhost:3000"
# Authentication settings
auth_enabled: bool = False # Set to True in production
auth_audience: str = "" # Backend Cloud Run URL (e.g., https://backend-xxx.run.app)
allowed_service_accounts: str = "" # Comma-separated list of allowed service account emails
@property
def cors_origins_list(self) -> list[str]:
"""Parse comma-separated CORS origins into a list."""
return [origin.strip() for origin in self.cors_origins.split(",") if origin.strip()]
@property
def allowed_service_accounts_list(self) -> list[str]:
"""Parse comma-separated allowed service accounts into a list."""
return [sa.strip() for sa in self.allowed_service_accounts.split(",") if sa.strip()]
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
# Constants
MAX_MESSAGE_LENGTH: int = 10_000
# Global settings instance
settings = Settings()