Skip to content

Commit

Permalink
update: automatically use realtime when add "realtime" events
Browse files Browse the repository at this point in the history
  • Loading branch information
Maplemx committed Oct 24, 2024
1 parent b73dd3c commit b1a6480
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Agently/plugins/agent_component/EventListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def __init__(self, agent: object):

def add(self, event:str, listener: callable, *, is_await:bool=False, is_agent_event:bool=False):
event = event.replace(".", "->")
if event == "realtime":
self.agent.settings.set("use_realtime", True)
if event.startswith("realtime:"):
self.agent.settings.set("use_realtime", True)
event_data = event.replace(" ", "").split(":")
hooks = event_data[1].replace("->", ".").split("&")
hook_list = []
Expand Down Expand Up @@ -55,8 +58,8 @@ async def realtime_hook_handler(data):
await listener(data)
else:
listener(data)
if event not in (self.listeners.get(trace_back=False) or {}):
self.listeners.update(event, [])
if "realtime" not in (self.listeners.get(trace_back=False) or {}):
self.listeners.update("realtime", [])
self.listeners.append("realtime", { "listener": realtime_hook_handler, "is_await": is_await })
else:
if is_agent_event:
Expand All @@ -83,6 +86,7 @@ def on_finally(self, listener: callable, *, is_await:bool=False, is_agent_event:
return self.agent

def on_realtime(self, listener: callable, *, is_await:bool=False, is_agent_event:bool=False):
self.agent.settings.set("use_realtime", True)
self.add("realtime", listener, is_await=is_await, is_agent_event=is_agent_event)
return self.agent

Expand Down

0 comments on commit b1a6480

Please sign in to comment.