Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/cli/modules/server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
import json
from pathlib import Path
from typing import Optional, Dict, Any, List
from typing import Optional, Dict, Any, List, cast


class ServerConfig:
Expand Down Expand Up @@ -113,21 +113,35 @@ def get_model_config(self, model_name: str) -> Optional[Dict[str, Any]]:
model_name: Name of the model.

Returns:
Model configuration dict, or None if not found.
Model configuration dict, or None if not found. Relative paths are resolved
against the config file's directory, allowing for configs to be packaged with models.
"""
config = self.load_config()
models = config.get("models", {})
return models.get(model_name)
models = cast(Dict[str, Dict[str, Any]], config.get("models", {}))
model = models.get(model_name)
return self._resolve_model_paths(model) if model else None

def get_all_models(self) -> Dict[str, Dict[str, Any]]:
"""
Get all model configurations.

Returns:
Dictionary mapping model names to their configurations.
Dictionary mapping model names to their configurations. Relative paths are resolved
against the config file's directory, allowing for configs to be packaged with models.
"""
config = self.load_config()
return config.get("models", {})
models = cast(Dict[str, Dict[str, Any]], config.get("models", {}))
return {name: self._resolve_model_paths(cfg) for name, cfg in models.items()}

def _resolve_model_paths(self, model_config: Dict[str, Any]) -> Dict[str, Any]:
"""Return a copy of model_config with a relative model_path made
absolute by joining it onto the config file's directory."""
resolved = dict(model_config)
path = resolved.get("model_path")
if path and not Path(path).is_absolute():
resolved["model_path"] = str((self.config_file.parent / path).resolve())

return resolved

def remove_model_config(self, model_name: str) -> bool:
"""
Expand Down
5 changes: 5 additions & 0 deletions src/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ async def lifespan(app: FastAPI):
if not model_config:
logger.warning(f"Startup: model '{name}' not in config, skipping")
continue

model_path = model_config.get("model_path")
if model_path and not Path(model_path).is_absolute():
model_config["model_path"] = str((config_file.parent / model_path).resolve())

try:
await _registry.register_load(ModelLoadConfig(**model_config))
logger.info(f"Startup: loaded '{name}'")
Expand Down