x
This commit is contained in:
+28
-5
@@ -29,14 +29,37 @@ def _to_float(value: Any, default: float) -> float:
|
||||
return default
|
||||
|
||||
|
||||
def resolve_model_profile(
|
||||
catalog_path: str, requested_model: str | None, requested_tp: int
|
||||
) -> tuple[str, dict[str, Any], dict[str, str]]:
|
||||
def load_catalog(catalog_path: str = "config.json") -> dict[str, Any]:
|
||||
content = json.loads(Path(catalog_path).read_text(encoding="utf-8"))
|
||||
if not isinstance(content, dict):
|
||||
raise ValueError("config.json must be a JSON object")
|
||||
default_model = content.get("default_model")
|
||||
profiles = {k: v for k, v in content.items() if k != "default_model"}
|
||||
return content
|
||||
|
||||
|
||||
def resolve_runtime_settings(content: dict[str, Any]) -> dict[str, Any]:
|
||||
services = content.get("services", {})
|
||||
api_service = dict(services.get("api", {}))
|
||||
openai_service = dict(services.get("openai", {}))
|
||||
models = dict(content.get("models", {}))
|
||||
return {
|
||||
"host": str(api_service.get("host", "0.0.0.0")),
|
||||
"port": _to_int(api_service.get("port"), 8000),
|
||||
"openai_host": str(openai_service.get("host", "0.0.0.0")),
|
||||
"openai_port": _to_int(openai_service.get("port"), 8001),
|
||||
"api_key": str(content.get("api_key", "")).strip() or None,
|
||||
"tensor_parallel_size": _to_int(content.get("tensor_parallel_size"), 2),
|
||||
"dtype": str(content.get("dtype", "bfloat16")),
|
||||
"revision": str(content.get("revision", "")).strip() or None,
|
||||
"model_key": str(models.get("selected", "")).strip() or None,
|
||||
}
|
||||
|
||||
|
||||
def resolve_model_profile(
|
||||
content: dict[str, Any], requested_model: str | None, requested_tp: int
|
||||
) -> tuple[str, dict[str, Any], dict[str, str]]:
|
||||
models = dict(content.get("models", {}))
|
||||
profiles = dict(models.get("profiles", {}))
|
||||
default_model = models.get("default")
|
||||
model_key = requested_model or default_model
|
||||
if not model_key or model_key not in profiles:
|
||||
raise ValueError(f"model profile '{model_key}' not found in config.json")
|
||||
|
||||
Reference in New Issue
Block a user