From c7c816feb3f2cbcdd2038fe8d28aaa1debfa2ed9 Mon Sep 17 00:00:00 2001 From: Chad Bailey Date: Mon, 22 Jan 2024 16:09:46 +0000 Subject: [PATCH] more updates to bots arguing --- .../services/daily_transport_service.py | 2 +- src/dailyai/services/fal_ai_services.py | 3 +- .../09a-characters-arguing.py | 14 ++- .../09b-debate-generator.py | 119 ++++++++++++++++++ 4 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 src/samples/theoretical-to-real/09b-debate-generator.py diff --git a/src/dailyai/services/daily_transport_service.py b/src/dailyai/services/daily_transport_service.py index 681c02a4e..45c4701eb 100644 --- a/src/dailyai/services/daily_transport_service.py +++ b/src/dailyai/services/daily_transport_service.py @@ -50,7 +50,7 @@ class DailyTransportService(EventHandler): self.camera_height = 768 self.camera_enabled = False - self.send_queue = asyncio.Queue() + self.send_queue = asyncio.Queue(maxsize=5) self.receive_queue = asyncio.Queue() self.other_participant_has_joined = False diff --git a/src/dailyai/services/fal_ai_services.py b/src/dailyai/services/fal_ai_services.py index 8527cb168..6b9fe275f 100644 --- a/src/dailyai/services/fal_ai_services.py +++ b/src/dailyai/services/fal_ai_services.py @@ -24,8 +24,7 @@ class FalImageGenService(ImageGenService): print("past fal handler init, about to wait for iter_events...") for event in handler.iter_events(): if isinstance(event, fal.apps.InProgress): - print('Request in progress') - print(event.logs) + pass result = handler.get() diff --git a/src/samples/theoretical-to-real/09a-characters-arguing.py b/src/samples/theoretical-to-real/09a-characters-arguing.py index 9c7c174d6..817fde8b0 100644 --- a/src/samples/theoretical-to-real/09a-characters-arguing.py +++ b/src/samples/theoretical-to-real/09a-characters-arguing.py @@ -8,6 +8,7 @@ from dailyai.services.daily_transport_service import DailyTransportService from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService from dailyai.services.fal_ai_services import FalImageGenService +from dailyai.services.open_ai_services import OpenAIImageGenService from dailyai.queue_frame import QueueFrame, FrameType async def main(room_url:str): @@ -19,7 +20,7 @@ async def main(room_url:str): room_url, None, "Respond bot", - 5, + 600, ) transport.mic_enabled = True transport.mic_sample_rate = 16000 @@ -31,12 +32,13 @@ async def main(room_url:str): tts1 = AzureTTSService() tts2 = ElevenLabsTTSService() dalle = FalImageGenService(image_size="1024x1024") + # dalle = OpenAIImageGenService(image_size="1024x1024") bot1_messages = [ - {"role": "system", "content": "You are a stern librarian. You strongly believe that a hot dog is a sandwich. Start by stating this fact in a few sentences, then be prepared to debate this with the user. Your responses should only be a few sentences long."}, + {"role": "system", "content": "You are a stern librarian. You strongly believe that a hot dog is a sandwich. Start by stating this fact in a few sentences, then be prepared to debate this with the user. You shouldn't ever compromise on the fundamental truth that a hot dog is a sandwich. Your responses should only be a few sentences long."}, ] bot2_messages = [ - {"role": "system", "content": "You are a silly cat, and you strongly believe that a hot dog is not a sandwich. Debate this with the user, only responding with a few sentences."}, + {"role": "system", "content": "You are a silly cat, and you strongly believe that a hot dog is not a sandwich. Debate this with the user, only responding with a few sentences. Don't ever accept that a hot dog is a sandwich."}, ] async def get_bot1_statement(): @@ -66,10 +68,10 @@ async def main(room_url:str): return all_audio async def argue(): - for i in range(1, 5): + for i in range(100): print(f"In iteration {i}") - bot1_description = "An older woman dressed as a librarian, cartoon, serious, highly detailed, 8k" + bot1_description = "A woman conservatively dressed as a librarian in a library surrounded by books, cartoon, serious, highly detailed" (audio1, image_data1) = await asyncio.gather( get_bot1_statement(), dalle.run_image_gen(bot1_description) @@ -81,7 +83,7 @@ async def main(room_url:str): ] ) - bot2_description = "A cat dressed in a hot dog costume, cartoon, bright colors, funny, highly detailed, 8k" + bot2_description = "A cat dressed in a hot dog costume, cartoon, bright colors, funny, highly detailed" (audio2, image_data2) = await asyncio.gather( get_bot2_statement(), dalle.run_image_gen(bot2_description) diff --git a/src/samples/theoretical-to-real/09b-debate-generator.py b/src/samples/theoretical-to-real/09b-debate-generator.py new file mode 100644 index 000000000..edfb64616 --- /dev/null +++ b/src/samples/theoretical-to-real/09b-debate-generator.py @@ -0,0 +1,119 @@ +import argparse +import asyncio +import requests +import time +import urllib.parse + +from dailyai.services.daily_transport_service import DailyTransportService +from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService +from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService +from dailyai.services.fal_ai_services import FalImageGenService +from dailyai.services.open_ai_services import OpenAIImageGenService +from dailyai.queue_frame import QueueFrame, FrameType + +async def main(room_url:str): + global transport + global llm + global tts + + transport = DailyTransportService( + room_url, + None, + "Respond bot", + 600, + ) + transport.mic_enabled = True + transport.mic_sample_rate = 16000 + transport.camera_enabled = True + transport.camera_width = 1024 + transport.camera_height = 1024 + + llm = AzureLLMService() + tts1 = AzureTTSService() + tts2 = ElevenLabsTTSService() + dalle = FalImageGenService(image_size="1024x1024") + # dalle = OpenAIImageGenService(image_size="1024x1024") + + topic = "Are pokemon edible?" + affirmative = "A woman dressed as a cowboy, outside on a ranch" + negative = "Pikachu in a business suit" + + topic = "Is a hot dog a sandwich?" + affirmative = "A woman conservatively dressed as a librarian in a library surrounded by books" + negative = "A cat dressed in a hot dog costume" + + + + bot1_messages = [ + {"role": "system", "content": f"You are {affirmative}. You're in a debate, and the topic is: '{topic}'. You're arguing the affirmative. Start by stating this fact in a few sentences, then be prepared to debate this with the user. You shouldn't ever agree with the user. Your responses should only be a few sentences long."}, + ] + bot2_messages = [ + {"role": "system", "content": f"You are {negative}. You're in a debate, and the topic is: '{topic}'. You're arguing the negative. Debate this with the user, only responding with a few sentences. Don't ever agree with the user."}, + ] + + async def get_bot1_statement(): + # Run the LLMs synchronously for the back-and-forth + bot1_msg = await llm.run_llm(bot1_messages) + print(f"bot1_msg: {bot1_msg}") + bot1_messages.append({"role": "assistant", "content": bot1_msg}) + bot2_messages.append({"role": "user", "content": bot1_msg}) + + all_audio = bytearray() + async for audio in tts1.run_tts(bot1_msg): + all_audio.extend(audio) + + return all_audio + + async def get_bot2_statement(): + # Run the LLMs synchronously for the back-and-forth + bot2_msg = await llm.run_llm(bot2_messages) + print(f"bot2_msg: {bot2_msg}") + bot2_messages.append({"role": "assistant", "content": bot2_msg}) + bot1_messages.append({"role": "user", "content": bot2_msg}) + + all_audio = bytearray() + async for audio in tts2.run_tts(bot2_msg): + all_audio.extend(audio) + + return all_audio + + async def argue(): + for i in range(100): + print(f"In iteration {i}") + + bot1_description = f"{affirmative}, cartoon, highly detailed" + + (audio1, image_data1) = await asyncio.gather( + get_bot1_statement(), dalle.run_image_gen(bot1_description) + ) + await transport.send_queue.put( + [ + QueueFrame(FrameType.IMAGE, image_data1[1]), + QueueFrame(FrameType.AUDIO, audio1), + ] + ) + + bot2_description = f"{negative}, cartoon, bright colors, funny, highly detailed" + + (audio2, image_data2) = await asyncio.gather( + get_bot2_statement(), dalle.run_image_gen(bot2_description) + ) + await transport.send_queue.put( + [ + QueueFrame(FrameType.IMAGE, image_data2[1]), + QueueFrame(FrameType.AUDIO, audio2), + ] + ) + + await asyncio.gather(transport.run(), argue()) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Simple Daily Bot Sample") + parser.add_argument( + "-u", "--url", type=str, required=True, help="URL of the Daily room to join" + ) + + args, unknown = parser.parse_known_args() + + asyncio.run(main(args.url))