39 lines
761 B
Python
39 lines
761 B
Python
from pathlib import Path
|
|
from typing import Annotated, Literal
|
|
|
|
import yaml
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class CodexConfig(BaseModel):
|
|
provider: Literal["codex"]
|
|
model: str = "gpt-5.6-luna"
|
|
|
|
credential_path: Path | None = None
|
|
|
|
|
|
class OpenAiConfig(BaseModel):
|
|
provider: Literal["openai"]
|
|
model: str
|
|
|
|
api_key_env: str = "API_KEY"
|
|
base_url_env: str = "BASE_URL"
|
|
|
|
|
|
LLMConfig = Annotated[
|
|
CodexConfig | OpenAiConfig,
|
|
Field(discriminator="provider")
|
|
]
|
|
|
|
|
|
class AppConfig(BaseModel):
|
|
llm: LLMConfig
|
|
|
|
|
|
def load_config(path: str | Path = "config.yaml") -> AppConfig:
|
|
path = Path(path)
|
|
|
|
with path.open("r", encoding="utf-8") as file:
|
|
data = yaml.safe_load(file)
|
|
|
|
return AppConfig.model_validate(data) |