-
Notifications
You must be signed in to change notification settings - Fork 37
/
api.py
46 lines (38 loc) · 1.38 KB
/
api.py
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
39
40
41
42
43
44
45
46
import enum
from typing import Annotated
from livekit.agents import llm
import logging
logger = logging.getLogger("temperature-control")
logger.setLevel(logging.INFO)
class Zone(enum.Enum):
LIVING_ROOM = "living_room"
BEDROOM = "bedroom"
KITCHEN = "kitchen"
BATHROOM = "bathroom"
OFFICE = "office"
class AssistantFnc(llm.FunctionContext):
def __init__(self) -> None:
super().__init__()
self._temperature = {
Zone.LIVING_ROOM: 22,
Zone.BEDROOM: 20,
Zone.KITCHEN: 24,
Zone.BATHROOM: 23,
Zone.OFFICE: 21,
}
@llm.ai_callable(description="get the temperature in a specific room")
def get_temperature(
self, zone: Annotated[Zone, llm.TypeInfo(description="The specific zone")]
):
logger.info("get temp - zone %s", zone)
temp = self._temperature[Zone(zone)]
return f"The temperature in the {zone} is {temp}C"
@llm.ai_callable(description="set the temperature in a specific room")
def set_temperature(
self,
zone: Annotated[Zone, llm.TypeInfo(description="The specific zone")],
temp: Annotated[int, llm.TypeInfo(description="The temperature to set")],
):
logger.info("set temo - zone %s, temp: %s", zone, temp)
self._temperature[Zone(zone)] = temp
return f"The temperature in the {zone} is now {temp}C"