mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-11 19:56:03 +00:00
chore(api)!: Add a parameter to inspect to only list v1 apis by default
use parameter api_filter to pick from v1, v1alpha, v1beta, deprecated
This commit is contained in:
parent
467801b78b
commit
73e860a6e6
8 changed files with 152 additions and 20 deletions
|
|
@ -956,7 +956,22 @@ paths:
|
||||||
List routes.
|
List routes.
|
||||||
|
|
||||||
List all available API routes with their methods and implementing providers.
|
List all available API routes with their methods and implementing providers.
|
||||||
parameters: []
|
parameters:
|
||||||
|
- name: api_filter
|
||||||
|
in: query
|
||||||
|
description: >-
|
||||||
|
Optional filter to control which routes are returned. Can be an API level
|
||||||
|
('v1', 'v1alpha', 'v1beta') to show non-deprecated routes at that level,
|
||||||
|
or 'deprecated' to show deprecated routes across all levels. If not specified,
|
||||||
|
returns only non-deprecated v1 routes.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- v1
|
||||||
|
- v1alpha
|
||||||
|
- v1beta
|
||||||
|
- deprecated
|
||||||
deprecated: false
|
deprecated: false
|
||||||
/v1/models:
|
/v1/models:
|
||||||
get:
|
get:
|
||||||
|
|
|
||||||
18
docs/static/llama-stack-spec.html
vendored
18
docs/static/llama-stack-spec.html
vendored
|
|
@ -1258,7 +1258,23 @@
|
||||||
],
|
],
|
||||||
"summary": "List routes.",
|
"summary": "List routes.",
|
||||||
"description": "List routes.\nList all available API routes with their methods and implementing providers.",
|
"description": "List routes.\nList all available API routes with their methods and implementing providers.",
|
||||||
"parameters": [],
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "api_filter",
|
||||||
|
"in": "query",
|
||||||
|
"description": "Optional filter to control which routes are returned. Can be an API level ('v1', 'v1alpha', 'v1beta') to show non-deprecated routes at that level, or 'deprecated' to show deprecated routes across all levels. If not specified, returns only non-deprecated v1 routes.",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"v1",
|
||||||
|
"v1alpha",
|
||||||
|
"v1beta",
|
||||||
|
"deprecated"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"deprecated": false
|
"deprecated": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
17
docs/static/llama-stack-spec.yaml
vendored
17
docs/static/llama-stack-spec.yaml
vendored
|
|
@ -953,7 +953,22 @@ paths:
|
||||||
List routes.
|
List routes.
|
||||||
|
|
||||||
List all available API routes with their methods and implementing providers.
|
List all available API routes with their methods and implementing providers.
|
||||||
parameters: []
|
parameters:
|
||||||
|
- name: api_filter
|
||||||
|
in: query
|
||||||
|
description: >-
|
||||||
|
Optional filter to control which routes are returned. Can be an API level
|
||||||
|
('v1', 'v1alpha', 'v1beta') to show non-deprecated routes at that level,
|
||||||
|
or 'deprecated' to show deprecated routes across all levels. If not specified,
|
||||||
|
returns only non-deprecated v1 routes.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- v1
|
||||||
|
- v1alpha
|
||||||
|
- v1beta
|
||||||
|
- deprecated
|
||||||
deprecated: false
|
deprecated: false
|
||||||
/v1/models:
|
/v1/models:
|
||||||
get:
|
get:
|
||||||
|
|
|
||||||
18
docs/static/stainless-llama-stack-spec.html
vendored
18
docs/static/stainless-llama-stack-spec.html
vendored
|
|
@ -1258,7 +1258,23 @@
|
||||||
],
|
],
|
||||||
"summary": "List routes.",
|
"summary": "List routes.",
|
||||||
"description": "List routes.\nList all available API routes with their methods and implementing providers.",
|
"description": "List routes.\nList all available API routes with their methods and implementing providers.",
|
||||||
"parameters": [],
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "api_filter",
|
||||||
|
"in": "query",
|
||||||
|
"description": "Optional filter to control which routes are returned. Can be an API level ('v1', 'v1alpha', 'v1beta') to show non-deprecated routes at that level, or 'deprecated' to show deprecated routes across all levels. If not specified, returns only non-deprecated v1 routes.",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"v1",
|
||||||
|
"v1alpha",
|
||||||
|
"v1beta",
|
||||||
|
"deprecated"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"deprecated": false
|
"deprecated": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
17
docs/static/stainless-llama-stack-spec.yaml
vendored
17
docs/static/stainless-llama-stack-spec.yaml
vendored
|
|
@ -956,7 +956,22 @@ paths:
|
||||||
List routes.
|
List routes.
|
||||||
|
|
||||||
List all available API routes with their methods and implementing providers.
|
List all available API routes with their methods and implementing providers.
|
||||||
parameters: []
|
parameters:
|
||||||
|
- name: api_filter
|
||||||
|
in: query
|
||||||
|
description: >-
|
||||||
|
Optional filter to control which routes are returned. Can be an API level
|
||||||
|
('v1', 'v1alpha', 'v1beta') to show non-deprecated routes at that level,
|
||||||
|
or 'deprecated' to show deprecated routes across all levels. If not specified,
|
||||||
|
returns only non-deprecated v1 routes.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- v1
|
||||||
|
- v1alpha
|
||||||
|
- v1beta
|
||||||
|
- deprecated
|
||||||
deprecated: false
|
deprecated: false
|
||||||
/v1/models:
|
/v1/models:
|
||||||
get:
|
get:
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,16 @@ from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from llama_stack.apis.version import LLAMA_STACK_API_V1
|
from llama_stack.apis.version import (
|
||||||
|
LLAMA_STACK_API_V1,
|
||||||
|
)
|
||||||
from llama_stack.providers.datatypes import HealthStatus
|
from llama_stack.providers.datatypes import HealthStatus
|
||||||
from llama_stack.schema_utils import json_schema_type, webmethod
|
from llama_stack.schema_utils import json_schema_type, webmethod
|
||||||
|
|
||||||
# Valid API level values for filtering routes
|
# Valid values for the route filter parameter.
|
||||||
ApiLevel = Literal["v1", "v1alpha", "v1beta", "deprecated"]
|
# Actual API levels: v1, v1alpha, v1beta (filters by level, excludes deprecated)
|
||||||
|
# Special filter value: "deprecated" (shows deprecated routes regardless of level)
|
||||||
|
ApiFilter = Literal["v1", "v1alpha", "v1beta", "deprecated"]
|
||||||
|
|
||||||
|
|
||||||
@json_schema_type
|
@json_schema_type
|
||||||
|
|
@ -67,13 +71,12 @@ class Inspect(Protocol):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@webmethod(route="/inspect/routes", method="GET", level=LLAMA_STACK_API_V1)
|
@webmethod(route="/inspect/routes", method="GET", level=LLAMA_STACK_API_V1)
|
||||||
async def list_routes(self, api_level: ApiLevel | None = None) -> ListRoutesResponse:
|
async def list_routes(self, api_filter: ApiFilter | None = None) -> ListRoutesResponse:
|
||||||
"""List routes.
|
"""List routes.
|
||||||
|
|
||||||
List all available API routes with their methods and implementing providers.
|
List all available API routes with their methods and implementing providers.
|
||||||
|
|
||||||
:param api_level: Optional filter for API level. Can be 'v1', 'v1alpha', 'v1beta', or 'deprecated'.
|
:param api_filter: Optional filter to control which routes are returned. Can be an API level ('v1', 'v1alpha', 'v1beta') to show non-deprecated routes at that level, or 'deprecated' to show deprecated routes across all levels. If not specified, returns only non-deprecated v1 routes.
|
||||||
If not specified, returns only non-deprecated v1 APIs and providers.
|
|
||||||
:returns: Response containing information about all available routes.
|
:returns: Response containing information about all available routes.
|
||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ from llama_stack.apis.inspect import (
|
||||||
RouteInfo,
|
RouteInfo,
|
||||||
VersionInfo,
|
VersionInfo,
|
||||||
)
|
)
|
||||||
|
from llama_stack.apis.version import LLAMA_STACK_API_V1
|
||||||
from llama_stack.core.datatypes import StackRunConfig
|
from llama_stack.core.datatypes import StackRunConfig
|
||||||
from llama_stack.core.external import load_external_apis
|
from llama_stack.core.external import load_external_apis
|
||||||
from llama_stack.core.server.routes import get_all_api_routes
|
from llama_stack.core.server.routes import get_all_api_routes
|
||||||
|
|
@ -39,20 +40,20 @@ class DistributionInspectImpl(Inspect):
|
||||||
async def initialize(self) -> None:
|
async def initialize(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def list_routes(self, api_level: str | None = None) -> ListRoutesResponse:
|
async def list_routes(self, api_filter: str | None = None) -> ListRoutesResponse:
|
||||||
run_config: StackRunConfig = self.config.run_config
|
run_config: StackRunConfig = self.config.run_config
|
||||||
|
|
||||||
# Helper function to determine if a route should be included based on api_level filter
|
# Helper function to determine if a route should be included based on api_filter
|
||||||
def should_include_route(webmethod) -> bool:
|
def should_include_route(webmethod) -> bool:
|
||||||
if api_level is None:
|
if api_filter is None:
|
||||||
# Default: only non-deprecated v1 APIs
|
# Default: only non-deprecated v1 APIs
|
||||||
return not webmethod.deprecated and webmethod.level == "v1"
|
return not webmethod.deprecated and webmethod.level == LLAMA_STACK_API_V1
|
||||||
elif api_level == "deprecated":
|
elif api_filter == "deprecated":
|
||||||
# Include only deprecated routes
|
# Special filter: show deprecated routes regardless of their actual level
|
||||||
return webmethod.deprecated
|
return bool(webmethod.deprecated)
|
||||||
else:
|
else:
|
||||||
# Include routes matching the specified level (non-deprecated)
|
# Filter by API level (non-deprecated routes only)
|
||||||
return not webmethod.deprecated and webmethod.level == api_level
|
return not webmethod.deprecated and webmethod.level == api_filter
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
external_apis = load_external_apis(run_config)
|
external_apis = load_external_apis(run_config)
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,54 @@ class TestInspect:
|
||||||
version = llama_stack_client.inspect.version()
|
version = llama_stack_client.inspect.version()
|
||||||
assert version is not None
|
assert version is not None
|
||||||
assert version.version is not None
|
assert version.version is not None
|
||||||
|
|
||||||
|
def test_list_routes_default(self, llama_stack_client: LlamaStackAsLibraryClient | LlamaStackClient):
|
||||||
|
"""Test list_routes with default filter (non-deprecated v1 routes)."""
|
||||||
|
response = llama_stack_client.routes.list()
|
||||||
|
assert response is not None
|
||||||
|
assert hasattr(response, "data")
|
||||||
|
routes = response.data
|
||||||
|
assert len(routes) > 0
|
||||||
|
|
||||||
|
# All routes should be non-deprecated
|
||||||
|
# Check that we don't see any /openai/ routes (which are deprecated)
|
||||||
|
openai_routes = [r for r in routes if "/openai/" in r.route]
|
||||||
|
assert len(openai_routes) == 0, "Default filter should not include deprecated /openai/ routes"
|
||||||
|
|
||||||
|
# Should see standard v1 routes like /inspect/routes, /health, /version
|
||||||
|
paths = [r.route for r in routes]
|
||||||
|
assert "/inspect/routes" in paths or "/v1/inspect/routes" in paths
|
||||||
|
assert "/health" in paths or "/v1/health" in paths
|
||||||
|
|
||||||
|
def test_list_routes_filter_by_deprecated(self, llama_stack_client: LlamaStackAsLibraryClient | LlamaStackClient):
|
||||||
|
"""Test list_routes with deprecated filter."""
|
||||||
|
response = llama_stack_client.routes.list(api_filter="deprecated")
|
||||||
|
assert response is not None
|
||||||
|
assert hasattr(response, "data")
|
||||||
|
routes = response.data
|
||||||
|
|
||||||
|
# When filtering for deprecated, we should get deprecated routes
|
||||||
|
# At minimum, we should see some /openai/ routes which are deprecated
|
||||||
|
if len(routes) > 0:
|
||||||
|
# If there are any deprecated routes, they should include openai routes
|
||||||
|
openai_routes = [r for r in routes if "/openai/" in r.route]
|
||||||
|
assert len(openai_routes) > 0, "Deprecated filter should include /openai/ routes"
|
||||||
|
|
||||||
|
def test_list_routes_filter_by_v1(self, llama_stack_client: LlamaStackAsLibraryClient | LlamaStackClient):
|
||||||
|
"""Test list_routes with v1 filter."""
|
||||||
|
response = llama_stack_client.routes.list(api_filter="v1")
|
||||||
|
assert response is not None
|
||||||
|
assert hasattr(response, "data")
|
||||||
|
routes = response.data
|
||||||
|
assert len(routes) > 0
|
||||||
|
|
||||||
|
# Should not include deprecated routes
|
||||||
|
openai_routes = [r for r in routes if "/openai/" in r.route]
|
||||||
|
assert len(openai_routes) == 0
|
||||||
|
|
||||||
|
# Should include v1 routes
|
||||||
|
paths = [r.route for r in routes]
|
||||||
|
assert any(
|
||||||
|
"/v1/" in p or p.startswith("/inspect/") or p.startswith("/health") or p.startswith("/version")
|
||||||
|
for p in paths
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue