File size: 1,608 Bytes
d787a09 | 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 | """Application configuration.
Everything has a safe offline default. With no environment at all, ParaPilot
runs fully offline on the deterministic stub provider.
"""
from __future__ import annotations
from functools import lru_cache
from pathlib import Path
from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
# Repository root (…/parapilot). config.py lives in app/, so parents[1].
ROOT_DIR = Path(__file__).resolve().parents[1]
class Settings(BaseSettings):
"""Runtime settings, overridable via environment / .env."""
model_config = SettingsConfigDict(
env_prefix="PARAPILOT_",
env_file=".env",
extra="ignore",
)
# Provider: "stub" (default, offline), "anthropic", or "openai".
provider: str = "stub"
anthropic_model: str = "claude-3-5-haiku-latest"
openai_model: str = "gpt-4o-mini"
# Retrieval / generation.
confidence_threshold: float = 0.12
top_k: int = 4
# Storage.
db_url: str = "sqlite:///./parapilot.db"
corpus_dir: str = "data/corpus"
# Optional case law (off by default).
enable_caselaw: bool = False
@property
def corpus_path(self) -> Path:
p = Path(self.corpus_dir)
return p if p.is_absolute() else ROOT_DIR / p
@property
def anthropic_api_key(self) -> Optional[str]:
import os
return os.getenv("ANTHROPIC_API_KEY")
@property
def openai_api_key(self) -> Optional[str]:
import os
return os.getenv("OPENAI_API_KEY")
@lru_cache
def get_settings() -> Settings:
return Settings()
|