mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-31 03:43:53 +00:00
currently the `inspect` API for providers is really a `list` API. Create a new `providers` API which has a GET `providers/{provider_id}` inspect API
which returns "user friendly" configuration to the end user. Also add a GET `/providers` endpoint which returns the list of providers as `inspect/providers` does today.
This API follows CRUD and is more intuitive/RESTful.
This work is part of the RFC at #1359
Signed-off-by: Charlie Doern <cdoern@redhat.com>
59 lines
1.7 KiB
Python
59 lines
1.7 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 pydantic import BaseModel
|
|
|
|
from llama_stack.apis.providers import GetProviderResponse, ListProvidersResponse, ProviderInfo, Providers
|
|
|
|
from .datatypes import StackRunConfig
|
|
from .stack import redact_sensitive_fields
|
|
|
|
|
|
class ProviderImplConfig(BaseModel):
|
|
run_config: StackRunConfig
|
|
|
|
|
|
async def get_provider_impl(config, deps):
|
|
impl = ProviderImpl(config, deps)
|
|
await impl.initialize()
|
|
return impl
|
|
|
|
|
|
class ProviderImpl(Providers):
|
|
def __init__(self, config, deps):
|
|
self.config = config
|
|
self.deps = deps
|
|
|
|
async def initialize(self) -> None:
|
|
pass
|
|
|
|
async def list_providers(self) -> ListProvidersResponse:
|
|
run_config = self.config.run_config
|
|
ret = []
|
|
for api, providers in run_config.providers.items():
|
|
ret.extend(
|
|
[
|
|
ProviderInfo(
|
|
api=api,
|
|
provider_id=p.provider_id,
|
|
provider_type=p.provider_type,
|
|
)
|
|
for p in providers
|
|
]
|
|
)
|
|
|
|
return ListProvidersResponse(data=ret)
|
|
|
|
async def inspect_provider(self, provider_id: str) -> GetProviderResponse:
|
|
run_config = self.config.run_config
|
|
safe_config = StackRunConfig(**redact_sensitive_fields(run_config.model_dump()))
|
|
ret = None
|
|
for _, providers in safe_config.providers.items():
|
|
for p in providers:
|
|
if p.provider_id == provider_id:
|
|
ret = p
|
|
|
|
return GetProviderResponse(data=ret)
|