Elffuss BraidHub

kikocis/llama-stack public

2e30ba2d48a0 · 2.1 KiBRawPermalink
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the terms described in the LICENSE file in
5# the root directory of this source tree.
6
7import importlib
8import inspect
9from typing import Dict, List
10
11from llama_stack.apis.agents import Agents
12from llama_stack.apis.inference import Inference
13from llama_stack.apis.memory import Memory
14from llama_stack.apis.safety import Safety
15from llama_stack.apis.telemetry import Telemetry
16
17from .datatypes import Api, ApiEndpoint, ProviderSpec, remote_provider_spec
18
19# These are the dependencies needed by the distribution server.
20# `llama-stack` is automatically installed by the installation script.
21SERVER_DEPENDENCIES = [
22 "fastapi",
23 "fire",
24 "uvicorn",
25]
26
27
28def stack_apis() -> List[Api]:
29 return [v for v in Api]
30
31
32def api_endpoints() -> Dict[Api, List[ApiEndpoint]]:
33 apis = {}
34
35 protocols = {
36 Api.inference: Inference,
37 Api.safety: Safety,
38 Api.agents: Agents,
39 Api.memory: Memory,
40 Api.telemetry: Telemetry,
41 }
42
43 for api, protocol in protocols.items():
44 endpoints = []
45 protocol_methods = inspect.getmembers(protocol, predicate=inspect.isfunction)
46
47 for name, method in protocol_methods:
48 if not hasattr(method, "__webmethod__"):
49 continue
50
51 webmethod = method.__webmethod__
52 route = webmethod.route
53
54 if webmethod.method == "GET":
55 method = "get"
56 elif webmethod.method == "DELETE":
57 method = "delete"
58 else:
59 method = "post"
60 endpoints.append(ApiEndpoint(route=route, method=method, name=name))
61
62 apis[api] = endpoints
63
64 return apis
65
66
67def api_providers() -> Dict[Api, Dict[str, ProviderSpec]]:
68 ret = {}
69 for api in stack_apis():
70 name = api.name.lower()
71 module = importlib.import_module(f"llama_stack.providers.registry.{name}")
72 ret[api] = {
73 "remote": remote_provider_spec(api),
74 **{a.provider_id: a for a in module.available_providers()},
75 }
76
77 return ret