File size: 1,125 Bytes
9fb722e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import annotations

from typing import Any

from hearthnet.bus import CapabilityBus


class RagFacade:
    def __init__(self, bus: CapabilityBus) -> None:
        self.bus = bus

    async def query(self, query: str, *, corpus: str = "demo", k: int = 5) -> dict[str, Any]:
        return await self.bus.call(
            "rag.query", (1, 0), {"params": {"corpus": corpus}, "input": {"query": query, "k": k}}
        )


class ChatFacade:
    def __init__(self, bus: CapabilityBus) -> None:
        self.bus = bus

    async def send(self, recipient: str, body: str) -> dict[str, Any]:
        return await self.bus.call(
            "chat.send", (1, 0), {"params": {}, "input": {"recipient": recipient, "body": body}}
        )


class MarketplaceFacade:
    def __init__(self, bus: CapabilityBus) -> None:
        self.bus = bus

    async def post(self, title: str, body: str, *, category: str = "info") -> dict[str, Any]:
        return await self.bus.call(
            "market.post",
            (1, 0),
            {"params": {}, "input": {"title": title, "body": body, "category": category}},
        )