feat: config loading for models.yaml and api_keys.yaml

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
tlg
2026-04-04 07:30:13 +02:00
parent a64f32b590
commit 690ad46d88
2 changed files with 135 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
import os
from dataclasses import dataclass, field
from pathlib import Path
import yaml
def _config_dir() -> Path:
return Path(os.environ.get("LLMUX_CONFIG_DIR", "/config"))
@dataclass
class PhysicalModel:
type: str # "llm", "asr", "tts"
backend: str # "transformers", "llamacpp", "chatterbox"
estimated_vram_gb: float
model_id: str = ""
model_file: str = ""
mmproj_file: str = ""
supports_vision: bool = False
supports_tools: bool = False
default_language: str = ""
variant: str = ""
@dataclass
class VirtualModel:
physical: str
params: dict = field(default_factory=dict)
@dataclass
class ApiKey:
key: str
name: str
def load_models_config(
config_path: Path | None = None,
) -> tuple[dict[str, PhysicalModel], dict[str, VirtualModel]]:
if config_path is None:
config_path = _config_dir() / "models.yaml"
with open(config_path) as f:
raw = yaml.safe_load(f)
physical: dict[str, PhysicalModel] = {}
for model_id, attrs in raw["physical_models"].items():
physical[model_id] = PhysicalModel(
type=attrs["type"],
backend=attrs["backend"],
estimated_vram_gb=attrs["estimated_vram_gb"],
model_id=attrs.get("model_id", ""),
model_file=attrs.get("model_file", ""),
mmproj_file=attrs.get("mmproj_file", ""),
supports_vision=attrs.get("supports_vision", False),
supports_tools=attrs.get("supports_tools", False),
default_language=attrs.get("default_language", ""),
variant=attrs.get("variant", ""),
)
virtual: dict[str, VirtualModel] = {}
for model_name, attrs in raw["virtual_models"].items():
virtual[model_name] = VirtualModel(
physical=attrs["physical"],
params=attrs.get("params", {}),
)
return physical, virtual
def load_api_keys(config_path: Path | None = None) -> list[ApiKey]:
if config_path is None:
config_path = _config_dir() / "api_keys.yaml"
with open(config_path) as f:
raw = yaml.safe_load(f)
return [ApiKey(key=entry["key"], name=entry["name"]) for entry in raw["api_keys"]]