Elffuss BraidHub

kikocis/llama-stack public

main · 1.9 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 asyncio
8
9from typing import List, Optional
10
11import fire
12import httpx
13from termcolor import cprint
14
15from .memory_banks import * # noqa: F403
16
17
18class MemoryBanksClient(MemoryBanks):
19 def __init__(self, base_url: str):
20 self.base_url = base_url
21
22 async def initialize(self) -> None:
23 pass
24
25 async def shutdown(self) -> None:
26 pass
27
28 async def list_available_memory_banks(self) -> List[MemoryBankSpec]:
29 async with httpx.AsyncClient() as client:
30 response = await client.get(
31 f"{self.base_url}/memory_banks/list",
32 headers={"Content-Type": "application/json"},
33 )
34 response.raise_for_status()
35 return [MemoryBankSpec(**x) for x in response.json()]
36
37 async def get_serving_memory_bank(
38 self, bank_type: MemoryBankType
39 ) -> Optional[MemoryBankSpec]:
40 async with httpx.AsyncClient() as client:
41 response = await client.get(
42 f"{self.base_url}/memory_banks/get",
43 params={
44 "bank_type": bank_type.value,
45 },
46 headers={"Content-Type": "application/json"},
47 )
48 response.raise_for_status()
49 j = response.json()
50 if j is None:
51 return None
52 return MemoryBankSpec(**j)
53
54
55async def run_main(host: str, port: int, stream: bool):
56 client = MemoryBanksClient(f"http://{host}:{port}")
57
58 response = await client.list_available_memory_banks()
59 cprint(f"list_memory_banks response={response}", "green")
60
61
62def main(host: str, port: int, stream: bool = True):
63 asyncio.run(run_main(host, port, stream))
64
65
66if __name__ == "__main__":
67 fire.Fire(main)