42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
"""Runtime configuration; resolved values are recorded with every quality run."""
|
|
import os
|
|
from dataclasses import asdict, dataclass
|
|
from .llm_client import DEFAULT_MODEL
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class QualityConfig:
|
|
model: str = DEFAULT_MODEL
|
|
review_model: str = DEFAULT_MODEL
|
|
reasoning: str = "high"
|
|
read_reasoning: str = "medium"
|
|
max_calls: int = 40
|
|
max_output_tokens: int = 12000
|
|
timeout_seconds: int = 180
|
|
max_elapsed_seconds: int = 1800
|
|
max_api_attempts: int = 3
|
|
experience_enabled: bool = True
|
|
read_model: str | None = None
|
|
|
|
@classmethod
|
|
def from_env(cls):
|
|
model = os.getenv("CADMIND_QUALITY_MODEL", os.getenv("CADMIND_MODEL", DEFAULT_MODEL))
|
|
cfg = cls(model=model, review_model=os.getenv("CADMIND_REVIEW_MODEL", model),
|
|
reasoning=os.getenv("CADMIND_REASONING", "high"),
|
|
read_reasoning=os.getenv("CADMIND_READ_REASONING", "medium"),
|
|
max_calls=int(os.getenv("CADMIND_MAX_CALLS", "40")),
|
|
max_output_tokens=int(os.getenv("CADMIND_MAX_OUTPUT_TOKENS", "12000")),
|
|
timeout_seconds=int(os.getenv("CADMIND_API_TIMEOUT", "180")),
|
|
max_elapsed_seconds=int(os.getenv("CADMIND_MAX_SECONDS", "1800")),
|
|
max_api_attempts=int(os.getenv("CADMIND_API_ATTEMPTS", "3")),
|
|
experience_enabled=os.getenv("CADMIND_EXPERIENCE", "1") != "0",
|
|
read_model=os.getenv("CADMIND_READ_MODEL") or None)
|
|
if min(cfg.max_calls, cfg.max_output_tokens, cfg.timeout_seconds, cfg.max_elapsed_seconds, cfg.max_api_attempts) <= 0:
|
|
raise ValueError("CADmind budget values must be positive")
|
|
if any(effort not in {"none", "low", "medium", "high", "xhigh", "max", "ultra"} for effort in (cfg.reasoning, cfg.read_reasoning)):
|
|
raise ValueError("Invalid CADMIND_REASONING")
|
|
return cfg
|
|
|
|
def to_dict(self):
|
|
return asdict(self)
|