Skip to content

Commit 15d71d9

Browse files
committed
feat: add model-specific config loading
1 parent 03cc82d commit 15d71d9

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

src/balatrollm/config.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,65 @@
33
import json
44
from dataclasses import asdict, dataclass, field
55
from pathlib import Path
6+
from typing import Any
7+
8+
import yaml
69

710
from . import __version__
811

912

13+
def load_model_config(
14+
model: str, config_path: Path = Path("config/models.yaml")
15+
) -> dict[str, Any]:
16+
"""Load model-specific configuration from models.yaml.
17+
18+
Merges model-specific settings with global defaults to create final
19+
parameters for OpenAI client requests.
20+
21+
Args:
22+
model: Model identifier (e.g., 'openai/gpt-oss-20b')
23+
config_path: Path to models.yaml file
24+
25+
Returns:
26+
Dictionary containing merged configuration for the model
27+
28+
Raises:
29+
FileNotFoundError: If config file doesn't exist
30+
KeyError: If model not found in configuration
31+
"""
32+
if not config_path.exists():
33+
raise FileNotFoundError(f"Model config file not found: {config_path}")
34+
with config_path.open() as f:
35+
config = yaml.safe_load(f)
36+
37+
model_config = None
38+
for model_entry in config.get("models", []):
39+
if model_entry.get("model") == model:
40+
model_config = model_entry.copy()
41+
break
42+
if model_config is None:
43+
raise KeyError(f"Model '{model}' not found in {config_path}")
44+
45+
defaults = config.get("defaults", {})
46+
47+
# Start with defaults, then merge model config
48+
# For nested dicts like extra_body, we need deep merging
49+
final_config = defaults.copy()
50+
51+
for key, value in model_config.items():
52+
if (
53+
key in final_config
54+
and isinstance(final_config[key], dict)
55+
and isinstance(value, dict)
56+
):
57+
# Deep merge for nested dicts
58+
final_config[key] = {**final_config[key], **value}
59+
else:
60+
final_config[key] = value
61+
62+
return final_config
63+
64+
1065
@dataclass
1166
class Config:
1267
"""Configuration for LLMBot.

0 commit comments

Comments
 (0)