Elffuss BraidHub

kikocis/llama-stack public

main · 1.4 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
7from typing import Any, List, Tuple
8
9from llama_stack.distribution.datatypes import * # noqa: F403
10
11
12async def get_routing_table_impl(
13 api: Api,
14 inner_impls: List[Tuple[str, Any]],
15 routing_table_config: Dict[str, List[RoutableProviderConfig]],
16 _deps,
17) -> Any:
18 from .routing_tables import (
19 MemoryBanksRoutingTable,
20 ModelsRoutingTable,
21 ShieldsRoutingTable,
22 )
23
24 api_to_tables = {
25 "memory_banks": MemoryBanksRoutingTable,
26 "models": ModelsRoutingTable,
27 "shields": ShieldsRoutingTable,
28 }
29 if api.value not in api_to_tables:
30 raise ValueError(f"API {api.value} not found in router map")
31
32 impl = api_to_tables[api.value](inner_impls, routing_table_config)
33 await impl.initialize()
34 return impl
35
36
37async def get_auto_router_impl(api: Api, routing_table: RoutingTable, _deps) -> Any:
38 from .routers import InferenceRouter, MemoryRouter, SafetyRouter
39
40 api_to_routers = {
41 "memory": MemoryRouter,
42 "inference": InferenceRouter,
43 "safety": SafetyRouter,
44 }
45 if api.value not in api_to_routers:
46 raise ValueError(f"API {api.value} not found in router map")
47
48 impl = api_to_routers[api.value](routing_table)
49 await impl.initialize()
50 return impl