diff --git a/src/llama_stack/apis/models/models.py b/src/llama_stack/apis/models/models.py index 903bd6510..005b26d9f 100644 --- a/src/llama_stack/apis/models/models.py +++ b/src/llama_stack/apis/models/models.py @@ -90,12 +90,14 @@ class OpenAIModel(BaseModel): :object: The object type, which will be "model" :created: The Unix timestamp in seconds when the model was created :owned_by: The owner of the model + :custom_metadata: Llama Stack-specific metadata including model_type, provider info, and additional metadata """ id: str object: Literal["model"] = "model" created: int owned_by: str + custom_metadata: dict[str, Any] | None = None class OpenAIListModelsResponse(BaseModel): diff --git a/src/llama_stack/core/routing_tables/models.py b/src/llama_stack/core/routing_tables/models.py index be17be3d4..1fb1186cd 100644 --- a/src/llama_stack/core/routing_tables/models.py +++ b/src/llama_stack/core/routing_tables/models.py @@ -134,6 +134,12 @@ class ModelsRoutingTable(CommonRoutingTableImpl, Models): object="model", created=int(time.time()), owned_by="llama_stack", + custom_metadata={ + "model_type": model.model_type, + "provider_id": model.provider_id, + "provider_resource_id": model.provider_resource_id, + **model.metadata, + }, ) for model in all_models ] diff --git a/tests/unit/distribution/routers/test_routing_tables.py b/tests/unit/distribution/routers/test_routing_tables.py index 87ebcef00..8c1838ba3 100644 --- a/tests/unit/distribution/routers/test_routing_tables.py +++ b/tests/unit/distribution/routers/test_routing_tables.py @@ -166,6 +166,14 @@ async def test_models_routing_table(cached_disk_dist_registry): assert "test_provider/test-model" in openai_model_ids assert "test_provider/test-model-2" in openai_model_ids + # Verify custom_metadata is populated with Llama Stack-specific data + for openai_model in openai_models.data: + assert openai_model.custom_metadata is not None + assert "model_type" in openai_model.custom_metadata + assert "provider_id" in openai_model.custom_metadata + assert "provider_resource_id" in openai_model.custom_metadata + assert openai_model.custom_metadata["provider_id"] == "test_provider" + # Test get_object_by_identifier model = await table.get_object_by_identifier("model", "test_provider/test-model") assert model is not None