From ec1f2362c5b81e8fbf7817fbc87444932fe0dd5c Mon Sep 17 00:00:00 2001 From: Moishe Lettvin Date: Fri, 12 Jan 2024 08:39:56 -0500 Subject: [PATCH] add on_first_other_participant_joined event --- src/dailyai/services/ai_services.py | 4 +--- src/dailyai/services/daily_transport_service.py | 9 ++++++++- .../theoretical-to-real/02-llm-say-one-thing.py | 10 ++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/dailyai/services/ai_services.py b/src/dailyai/services/ai_services.py index d1d308c8f..4c39a5cd3 100644 --- a/src/dailyai/services/ai_services.py +++ b/src/dailyai/services/ai_services.py @@ -29,7 +29,7 @@ class AIService: while True: frame = await self.input_queue.get() - print(f"{self.__class__.__name__} got frame:", frame.frame_type) + self.logger.debug(f"{self.__class__.__name__} got frame:", frame.frame_type) if frame.frame_type == FrameType.END_STREAM: self.input_queue.task_done() await self.output_queue.put(QueueFrame(FrameType.END_STREAM, None)) @@ -80,7 +80,6 @@ class LLMService(AIService): messages: list[dict[str, str]] = frame.frame_data async for message in self.run_llm_async_sentences(messages): - print("got message", message) await self.output_queue.put(QueueFrame(FrameType.SENTENCE_FRAME, message)) @@ -100,7 +99,6 @@ class TTSService(AIService): if not self.output_queue: raise Exception("Output queue must be set before using the run method.") - print(frame.frame_type) if frame.frame_type == FrameType.SENTENCE_FRAME: if type(frame.frame_data) != str: raise Exception("TTS service requires a string for the data field") diff --git a/src/dailyai/services/daily_transport_service.py b/src/dailyai/services/daily_transport_service.py index 2962834da..e26bd8195 100644 --- a/src/dailyai/services/daily_transport_service.py +++ b/src/dailyai/services/daily_transport_service.py @@ -45,6 +45,8 @@ class DailyTransportService(EventHandler): self.camera_height = 768 self.camera_enabled = False + self.other_participant_has_joined = False + self.camera_thread = None self.frame_consumer_thread = None @@ -231,6 +233,9 @@ class DailyTransportService(EventHandler): def stop(self): self.stop_threads.set() + def on_first_other_participant_joined(self): + pass + def call_joined(self, join_data, client_error): self.logger.info(f"Call_joined: {join_data}, {client_error}") @@ -241,7 +246,9 @@ class DailyTransportService(EventHandler): pass def on_participant_joined(self, participant): - pass + if not self.other_participant_has_joined and participant["id"] != self.my_participant_id: + self.other_participant_has_joined = True + self.on_first_other_participant_joined() def on_participant_left(self, participant, reason): if len(self.client.participants()) < 2: diff --git a/src/samples/theoretical-to-real/02-llm-say-one-thing.py b/src/samples/theoretical-to-real/02-llm-say-one-thing.py index 95d465295..f09103bfb 100644 --- a/src/samples/theoretical-to-real/02-llm-say-one-thing.py +++ b/src/samples/theoretical-to-real/02-llm-say-one-thing.py @@ -34,14 +34,8 @@ async def main(room_url): llm_task = asyncio.create_task(llm.run()) - has_joined = False - @transport.event_handler("on_participant_joined") - async def on_participant_joined(transport, participant): - nonlocal has_joined - if participant["id"] == transport.my_participant_id or has_joined: - return - - has_joined = True + @transport.event_handler("on_first_other_participant_joined") + async def on_first_other_participant_joined(transport): await asyncio.gather(llm_task, tts.run()) # wait for the output queue to be empty, then leave the meeting