forked from phoenix-oss/llama-stack-mirror
Idiomatic REST API: Inspect (#779)
# What does this PR do? Since provider list returns a map grouping providers by API, we should not be using data. This PR fixes the types to just be the plain dict, basically reverting back to previous behavior ## Test Plan llama-stack on fix-provider-list [$] 🅒 stack❯ LLAMA_STACK_CONFIG="/Users/dineshyv/.llama/distributions/llamastack-together/together-run.yaml" pytest -v tests/client-sdk/safety/test_safety.py
This commit is contained in:
parent
e239280932
commit
678ab29129
2 changed files with 19 additions and 13 deletions
|
@ -4,7 +4,7 @@
|
||||||
# This source code is licensed under the terms described in the LICENSE file in
|
# This source code is licensed under the terms described in the LICENSE file in
|
||||||
# the root directory of this source tree.
|
# the root directory of this source tree.
|
||||||
|
|
||||||
from typing import Dict, List, Protocol, runtime_checkable
|
from typing import List, Protocol, runtime_checkable
|
||||||
|
|
||||||
from llama_models.schema_utils import json_schema_type, webmethod
|
from llama_models.schema_utils import json_schema_type, webmethod
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
@ -38,13 +38,17 @@ class ListProvidersResponse(BaseModel):
|
||||||
data: List[ProviderInfo]
|
data: List[ProviderInfo]
|
||||||
|
|
||||||
|
|
||||||
|
class ListRoutesResponse(BaseModel):
|
||||||
|
data: List[RouteInfo]
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class Inspect(Protocol):
|
class Inspect(Protocol):
|
||||||
@webmethod(route="/providers/list", method="GET")
|
@webmethod(route="/inspect/providers", method="GET")
|
||||||
async def list_providers(self) -> ListProvidersResponse: ...
|
async def list_providers(self) -> ListProvidersResponse: ...
|
||||||
|
|
||||||
@webmethod(route="/routes/list", method="GET")
|
@webmethod(route="/inspect/routes", method="GET")
|
||||||
async def list_routes(self) -> Dict[str, List[RouteInfo]]: ...
|
async def list_routes(self) -> ListRoutesResponse: ...
|
||||||
|
|
||||||
@webmethod(route="/health", method="GET")
|
@webmethod(route="/health", method="GET")
|
||||||
async def health(self) -> HealthInfo: ...
|
async def health(self) -> HealthInfo: ...
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
# the root directory of this source tree.
|
# the root directory of this source tree.
|
||||||
|
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
from typing import Dict, List
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from llama_stack.apis.inspect import (
|
from llama_stack.apis.inspect import (
|
||||||
HealthInfo,
|
HealthInfo,
|
||||||
Inspect,
|
Inspect,
|
||||||
|
ListProvidersResponse,
|
||||||
|
ListRoutesResponse,
|
||||||
ProviderInfo,
|
ProviderInfo,
|
||||||
RouteInfo,
|
RouteInfo,
|
||||||
VersionInfo,
|
VersionInfo,
|
||||||
|
@ -38,36 +39,37 @@ class DistributionInspectImpl(Inspect):
|
||||||
async def initialize(self) -> None:
|
async def initialize(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def list_providers(self) -> Dict[str, List[ProviderInfo]]:
|
async def list_providers(self) -> ListProvidersResponse:
|
||||||
run_config = self.config.run_config
|
run_config = self.config.run_config
|
||||||
|
|
||||||
ret = {}
|
ret = []
|
||||||
for api, providers in run_config.providers.items():
|
for api, providers in run_config.providers.items():
|
||||||
ret[api] = [
|
ret.append(
|
||||||
ProviderInfo(
|
ProviderInfo(
|
||||||
provider_id=p.provider_id,
|
provider_id=p.provider_id,
|
||||||
provider_type=p.provider_type,
|
provider_type=p.provider_type,
|
||||||
)
|
)
|
||||||
for p in providers
|
for p in providers
|
||||||
]
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def list_routes(self) -> Dict[str, List[RouteInfo]]:
|
async def list_routes(self) -> ListRoutesResponse:
|
||||||
run_config = self.config.run_config
|
run_config = self.config.run_config
|
||||||
|
|
||||||
ret = {}
|
ret = []
|
||||||
all_endpoints = get_all_api_endpoints()
|
all_endpoints = get_all_api_endpoints()
|
||||||
for api, endpoints in all_endpoints.items():
|
for api, endpoints in all_endpoints.items():
|
||||||
providers = run_config.providers.get(api.value, [])
|
providers = run_config.providers.get(api.value, [])
|
||||||
ret[api.value] = [
|
ret.append(
|
||||||
RouteInfo(
|
RouteInfo(
|
||||||
route=e.route,
|
route=e.route,
|
||||||
method=e.method,
|
method=e.method,
|
||||||
provider_types=[p.provider_type for p in providers],
|
provider_types=[p.provider_type for p in providers],
|
||||||
)
|
)
|
||||||
for e in endpoints
|
for e in endpoints
|
||||||
]
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def health(self) -> HealthInfo:
|
async def health(self) -> HealthInfo:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue