mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 10:54:19 +00:00
# What does this PR do? - add --version to llama stack CLI - add /version endpoint - run OpenAPI generator for the new endpoint ## Test Plan **CLI** <img width="184" alt="image" src="https://github.com/user-attachments/assets/3acb1d22-453e-4b79-baf6-e98e88d0671c" /> **endpoint** <img width="430" alt="image" src="https://github.com/user-attachments/assets/79cdd670-493b-40cf-8f9e-28a4ac0988ac" /> ## Sources Please link relevant resources if necessary. ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Ran pre-commit to handle lint / formatting issues. - [ ] Read the [contributor guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md), Pull Request section? - [ ] Updated relevant documentation. - [ ] Wrote necessary unit or integration tests.
77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
from importlib.metadata import version
|
|
from typing import Dict, List
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from llama_stack.apis.inspect import (
|
|
HealthInfo,
|
|
Inspect,
|
|
ProviderInfo,
|
|
RouteInfo,
|
|
VersionInfo,
|
|
)
|
|
from llama_stack.distribution.datatypes import StackRunConfig
|
|
from llama_stack.distribution.server.endpoints import get_all_api_endpoints
|
|
|
|
|
|
class DistributionInspectConfig(BaseModel):
|
|
run_config: StackRunConfig
|
|
|
|
|
|
async def get_provider_impl(config, deps):
|
|
impl = DistributionInspectImpl(config, deps)
|
|
await impl.initialize()
|
|
return impl
|
|
|
|
|
|
class DistributionInspectImpl(Inspect):
|
|
def __init__(self, config, deps):
|
|
self.config = config
|
|
self.deps = deps
|
|
|
|
async def initialize(self) -> None:
|
|
pass
|
|
|
|
async def list_providers(self) -> Dict[str, List[ProviderInfo]]:
|
|
run_config = self.config.run_config
|
|
|
|
ret = {}
|
|
for api, providers in run_config.providers.items():
|
|
ret[api] = [
|
|
ProviderInfo(
|
|
provider_id=p.provider_id,
|
|
provider_type=p.provider_type,
|
|
)
|
|
for p in providers
|
|
]
|
|
|
|
return ret
|
|
|
|
async def list_routes(self) -> Dict[str, List[RouteInfo]]:
|
|
run_config = self.config.run_config
|
|
|
|
ret = {}
|
|
all_endpoints = get_all_api_endpoints()
|
|
for api, endpoints in all_endpoints.items():
|
|
providers = run_config.providers.get(api.value, [])
|
|
ret[api.value] = [
|
|
RouteInfo(
|
|
route=e.route,
|
|
method=e.method,
|
|
provider_types=[p.provider_type for p in providers],
|
|
)
|
|
for e in endpoints
|
|
]
|
|
return ret
|
|
|
|
async def health(self) -> HealthInfo:
|
|
return HealthInfo(status="OK")
|
|
|
|
async def version(self) -> VersionInfo:
|
|
return VersionInfo(version=version("llama-stack"))
|