feat: model registry with virtual-to-physical resolution
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
36
kischdle/llmux/llmux/model_registry.py
Normal file
36
kischdle/llmux/llmux/model_registry.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from llmux.config import PhysicalModel, VirtualModel, load_models_config
|
||||
|
||||
|
||||
class ModelRegistry:
|
||||
def __init__(
|
||||
self,
|
||||
physical: dict[str, PhysicalModel],
|
||||
virtual: dict[str, VirtualModel],
|
||||
):
|
||||
self._physical = physical
|
||||
self._virtual = virtual
|
||||
|
||||
@classmethod
|
||||
def from_config(cls) -> "ModelRegistry":
|
||||
physical, virtual = load_models_config()
|
||||
return cls(physical, virtual)
|
||||
|
||||
def list_virtual_models(self) -> list[dict]:
|
||||
return [
|
||||
{
|
||||
"id": name,
|
||||
"object": "model",
|
||||
"created": 0,
|
||||
"owned_by": "llmux",
|
||||
}
|
||||
for name in self._virtual
|
||||
]
|
||||
|
||||
def resolve(self, virtual_name: str) -> tuple[str, PhysicalModel, dict]:
|
||||
"""Resolve a virtual model name to (physical_id, PhysicalModel, params)."""
|
||||
vm = self._virtual[virtual_name] # raises KeyError if unknown
|
||||
pm = self._physical[vm.physical]
|
||||
return vm.physical, pm, dict(vm.params)
|
||||
|
||||
def get_physical(self, physical_id: str) -> PhysicalModel:
|
||||
return self._physical[physical_id] # raises KeyError if unknown
|
||||
Reference in New Issue
Block a user