minor cleanup
This commit is contained in:
@@ -34,6 +34,7 @@ class LLMContextAggregator(AIService):
|
|||||||
bot_participant_id=None,
|
bot_participant_id=None,
|
||||||
complete_sentences=True,
|
complete_sentences=True,
|
||||||
pass_through=True):
|
pass_through=True):
|
||||||
|
super().__init__()
|
||||||
self.messages = messages
|
self.messages = messages
|
||||||
self.bot_participant_id = bot_participant_id
|
self.bot_participant_id = bot_participant_id
|
||||||
self.role = role
|
self.role = role
|
||||||
@@ -82,5 +83,5 @@ class LLMAssistantContextAggregator(LLMContextAggregator):
|
|||||||
self, messages: list[dict], bot_participant_id=None, complete_sentences=True
|
self, messages: list[dict], bot_participant_id=None, complete_sentences=True
|
||||||
):
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
messages, "assistan", bot_participant_id, complete_sentences, pass_through=True
|
messages, "assistant", bot_participant_id, complete_sentences, pass_through=True
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -391,10 +391,10 @@ class DailyTransportService(EventHandler):
|
|||||||
all_audio_frames.extend(chunk)
|
all_audio_frames.extend(chunk)
|
||||||
|
|
||||||
b.extend(chunk)
|
b.extend(chunk)
|
||||||
l = len(b) - (len(b) % smallest_write_size)
|
truncated_length: int = len(b) - (len(b) % smallest_write_size)
|
||||||
if l:
|
if truncated_length:
|
||||||
self.mic.write_frames(bytes(b[:l]))
|
self.mic.write_frames(bytes(b[:truncated_length]))
|
||||||
b = b[l:]
|
b = b[truncated_length:]
|
||||||
elif isinstance(frame, ImageQueueFrame):
|
elif isinstance(frame, ImageQueueFrame):
|
||||||
self._set_image(frame.image)
|
self._set_image(frame.image)
|
||||||
elif isinstance(frame, SpriteQueueFrame):
|
elif isinstance(frame, SpriteQueueFrame):
|
||||||
@@ -406,7 +406,8 @@ class DailyTransportService(EventHandler):
|
|||||||
# if there are leftover audio bytes, write them now; failing to do so
|
# if there are leftover audio bytes, write them now; failing to do so
|
||||||
# can cause static in the audio stream.
|
# can cause static in the audio stream.
|
||||||
if len(b):
|
if len(b):
|
||||||
self.mic.write_frames(bytes(b))
|
truncated_length = len(b) - (len(b) % 160)
|
||||||
|
self.mic.write_frames(bytes(b[:truncated_length]))
|
||||||
b = bytearray()
|
b = bytearray()
|
||||||
|
|
||||||
if isinstance(frame, StartStreamQueueFrame):
|
if isinstance(frame, StartStreamQueueFrame):
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import aiohttp
|
|||||||
|
|
||||||
from dailyai.queue_frame import TextQueueFrame
|
from dailyai.queue_frame import TextQueueFrame
|
||||||
from dailyai.services.daily_transport_service import DailyTransportService
|
from dailyai.services.daily_transport_service import DailyTransportService
|
||||||
from dailyai.services.open_ai_services import OpenAIImageGenService
|
from dailyai.services.fal_ai_services import FalImageGenService
|
||||||
|
|
||||||
local_joined = False
|
local_joined = False
|
||||||
participant_joined = False
|
participant_joined = False
|
||||||
@@ -25,14 +25,14 @@ async def main(room_url):
|
|||||||
transport.camera_width = 1024
|
transport.camera_width = 1024
|
||||||
transport.camera_height = 1024
|
transport.camera_height = 1024
|
||||||
|
|
||||||
imagegen = OpenAIImageGenService(image_size="1024x1024", aiohttp_session=session)
|
imagegen = FalImageGenService(image_size="1024x1024", aiohttp_session=session)
|
||||||
image_task = asyncio.create_task(
|
image_task = asyncio.create_task(
|
||||||
imagegen.run_to_queue(
|
imagegen.run_to_queue(
|
||||||
transport.send_queue, [
|
transport.send_queue, [
|
||||||
TextQueueFrame("a cat in the style of picasso")]))
|
TextQueueFrame("a cat in the style of picasso")]))
|
||||||
|
|
||||||
@transport.event_handler("on_participant_joined")
|
@transport.event_handler("on_first_other_participant_joined")
|
||||||
async def on_participant_joined(transport, participant):
|
async def on_first_other_participant_joined(transport):
|
||||||
await image_task
|
await image_task
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
|||||||
@@ -40,11 +40,8 @@ async def main(room_url: str):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@transport.event_handler("on_participant_joined")
|
@transport.event_handler("on_first_other_participant_joined")
|
||||||
async def on_joined(transport, participant):
|
async def on_first_other_participant_joined(transport):
|
||||||
if participant["id"] == transport.my_participant_id:
|
|
||||||
return
|
|
||||||
|
|
||||||
await azure_tts.say("My friend the LLM is now going to tell a joke about llamas.", transport.send_queue)
|
await azure_tts.say("My friend the LLM is now going to tell a joke about llamas.", transport.send_queue)
|
||||||
|
|
||||||
async def buffer_to_send_queue():
|
async def buffer_to_send_queue():
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import requests
|
|
||||||
import time
|
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
from dailyai.services.daily_transport_service import DailyTransportService
|
from dailyai.services.daily_transport_service import DailyTransportService
|
||||||
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
|
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
|
||||||
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
||||||
from dailyai.queue_frame import QueueFrame
|
|
||||||
|
|
||||||
async def main(room_url:str):
|
async def main(room_url:str):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@@ -43,15 +39,17 @@ async def main(room_url:str):
|
|||||||
# Run the LLMs synchronously for the back-and-forth
|
# Run the LLMs synchronously for the back-and-forth
|
||||||
bot1_msg = await llm.run_llm(bot1_messages)
|
bot1_msg = await llm.run_llm(bot1_messages)
|
||||||
print(f"bot1_msg: {bot1_msg}")
|
print(f"bot1_msg: {bot1_msg}")
|
||||||
bot1_messages.append({"role": "assistant", "content": bot1_msg})
|
if bot1_msg:
|
||||||
bot2_messages.append({"role": "user", "content": bot1_msg})
|
bot1_messages.append({"role": "assistant", "content": bot1_msg})
|
||||||
|
bot2_messages.append({"role": "user", "content": bot1_msg})
|
||||||
|
|
||||||
await tts1.say(bot1_msg, transport.send_queue)
|
await tts1.say(bot1_msg, transport.send_queue)
|
||||||
|
|
||||||
bot2_msg = await llm.run_llm(bot2_messages)
|
bot2_msg = await llm.run_llm(bot2_messages)
|
||||||
print(f"bot2_msg: {bot2_msg}")
|
print(f"bot2_msg: {bot2_msg}")
|
||||||
bot2_messages.append({"role": "assistant", "content": bot2_msg})
|
if bot2_msg:
|
||||||
bot1_messages.append({"role": "user", "content": bot2_msg})
|
bot2_messages.append({"role": "assistant", "content": bot2_msg})
|
||||||
|
bot1_messages.append({"role": "user", "content": bot2_msg})
|
||||||
|
|
||||||
await tts2.say(bot2_msg, transport.send_queue)
|
await tts2.say(bot2_msg, transport.send_queue)
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import requests
|
|
||||||
import time
|
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
from dailyai.services.daily_transport_service import DailyTransportService
|
from dailyai.services.daily_transport_service import DailyTransportService
|
||||||
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
|
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
|
||||||
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
||||||
from dailyai.services.fal_ai_services import FalImageGenService
|
from dailyai.services.fal_ai_services import FalImageGenService
|
||||||
from dailyai.services.open_ai_services import OpenAIImageGenService
|
from dailyai.queue_frame import AudioQueueFrame, ImageQueueFrame
|
||||||
from dailyai.queue_frame import QueueFrame, AudioQueueFrame, ImageQueueFrame
|
|
||||||
|
|
||||||
async def main(room_url:str):
|
async def main(room_url:str):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@@ -34,7 +30,6 @@ async def main(room_url:str):
|
|||||||
tts1 = AzureTTSService()
|
tts1 = AzureTTSService()
|
||||||
tts2 = ElevenLabsTTSService(session)
|
tts2 = ElevenLabsTTSService(session)
|
||||||
dalle = FalImageGenService(image_size="1024x1024", aiohttp_session=session)
|
dalle = FalImageGenService(image_size="1024x1024", aiohttp_session=session)
|
||||||
# dalle = OpenAIImageGenService(image_size="1024x1024")
|
|
||||||
|
|
||||||
bot1_messages = [
|
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. 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."},
|
{"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."},
|
||||||
@@ -42,26 +37,28 @@ async def main(room_url:str):
|
|||||||
bot2_messages = [
|
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. Don't ever accept that a hot dog is a sandwich."},
|
{"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():
|
async def get_bot1_statement():
|
||||||
# Run the LLMs synchronously for the back-and-forth
|
# Run the LLMs synchronously for the back-and-forth
|
||||||
bot1_msg = await llm.run_llm(bot1_messages)
|
bot1_msg = await llm.run_llm(bot1_messages)
|
||||||
print(f"bot1_msg: {bot1_msg}")
|
print(f"bot1_msg: {bot1_msg}")
|
||||||
bot1_messages.append({"role": "assistant", "content": bot1_msg})
|
if bot1_msg:
|
||||||
bot2_messages.append({"role": "user", "content": bot1_msg})
|
bot1_messages.append({"role": "assistant", "content": bot1_msg})
|
||||||
|
bot2_messages.append({"role": "user", "content": bot1_msg})
|
||||||
|
|
||||||
all_audio = bytearray()
|
all_audio = bytearray()
|
||||||
async for audio in tts1.run_tts(bot1_msg):
|
async for audio in tts1.run_tts(bot1_msg):
|
||||||
all_audio.extend(audio)
|
all_audio.extend(audio)
|
||||||
|
|
||||||
return all_audio
|
return all_audio
|
||||||
|
|
||||||
async def get_bot2_statement():
|
async def get_bot2_statement():
|
||||||
# Run the LLMs synchronously for the back-and-forth
|
# Run the LLMs synchronously for the back-and-forth
|
||||||
bot2_msg = await llm.run_llm(bot2_messages)
|
bot2_msg = await llm.run_llm(bot2_messages)
|
||||||
print(f"bot2_msg: {bot2_msg}")
|
print(f"bot2_msg: {bot2_msg}")
|
||||||
bot2_messages.append({"role": "assistant", "content": bot2_msg})
|
if bot2_msg:
|
||||||
bot1_messages.append({"role": "user", "content": bot2_msg})
|
bot2_messages.append({"role": "assistant", "content": bot2_msg})
|
||||||
|
bot1_messages.append({"role": "user", "content": bot2_msg})
|
||||||
|
|
||||||
all_audio = bytearray()
|
all_audio = bytearray()
|
||||||
async for audio in tts2.run_tts(bot2_msg):
|
async for audio in tts2.run_tts(bot2_msg):
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import requests
|
|
||||||
import time
|
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
from dailyai.services.daily_transport_service import DailyTransportService
|
from dailyai.services.daily_transport_service import DailyTransportService
|
||||||
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
|
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
|
||||||
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
||||||
from dailyai.services.fal_ai_services import FalImageGenService
|
from dailyai.services.fal_ai_services import FalImageGenService
|
||||||
from dailyai.services.open_ai_services import OpenAIImageGenService
|
from dailyai.queue_frame import AudioQueueFrame, ImageQueueFrame
|
||||||
from dailyai.queue_frame import QueueFrame, AudioQueueFrame, ImageQueueFrame
|
|
||||||
|
|
||||||
async def main(room_url:str):
|
async def main(room_url:str):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@@ -39,7 +35,7 @@ async def main(room_url:str):
|
|||||||
topic = "Are pokemon edible?"
|
topic = "Are pokemon edible?"
|
||||||
affirmative = "A woman dressed as a cowboy, outside on a ranch"
|
affirmative = "A woman dressed as a cowboy, outside on a ranch"
|
||||||
negative = "Pikachu in a business suit"
|
negative = "Pikachu in a business suit"
|
||||||
|
|
||||||
topic = "Is a hot dog a sandwich?"
|
topic = "Is a hot dog a sandwich?"
|
||||||
affirmative = "A woman conservatively dressed as a librarian in a library surrounded by books"
|
affirmative = "A woman conservatively dressed as a librarian in a library surrounded by books"
|
||||||
negative = "A cat dressed in a hot dog costume"
|
negative = "A cat dressed in a hot dog costume"
|
||||||
@@ -52,26 +48,28 @@ async def main(room_url:str):
|
|||||||
bot2_messages = [
|
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."},
|
{"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():
|
async def get_bot1_statement():
|
||||||
# Run the LLMs synchronously for the back-and-forth
|
# Run the LLMs synchronously for the back-and-forth
|
||||||
bot1_msg = await llm.run_llm(bot1_messages)
|
bot1_msg = await llm.run_llm(bot1_messages)
|
||||||
print(f"bot1_msg: {bot1_msg}")
|
print(f"bot1_msg: {bot1_msg}")
|
||||||
bot1_messages.append({"role": "assistant", "content": bot1_msg})
|
if bot1_msg:
|
||||||
bot2_messages.append({"role": "user", "content": bot1_msg})
|
bot1_messages.append({"role": "assistant", "content": bot1_msg})
|
||||||
|
bot2_messages.append({"role": "user", "content": bot1_msg})
|
||||||
|
|
||||||
all_audio = bytearray()
|
all_audio = bytearray()
|
||||||
async for audio in tts1.run_tts(bot1_msg):
|
async for audio in tts1.run_tts(bot1_msg):
|
||||||
all_audio.extend(audio)
|
all_audio.extend(audio)
|
||||||
|
|
||||||
return all_audio
|
return all_audio
|
||||||
|
|
||||||
async def get_bot2_statement():
|
async def get_bot2_statement():
|
||||||
# Run the LLMs synchronously for the back-and-forth
|
# Run the LLMs synchronously for the back-and-forth
|
||||||
bot2_msg = await llm.run_llm(bot2_messages)
|
bot2_msg = await llm.run_llm(bot2_messages)
|
||||||
print(f"bot2_msg: {bot2_msg}")
|
print(f"bot2_msg: {bot2_msg}")
|
||||||
bot2_messages.append({"role": "assistant", "content": bot2_msg})
|
if bot2_msg:
|
||||||
bot1_messages.append({"role": "user", "content": bot2_msg})
|
bot2_messages.append({"role": "assistant", "content": bot2_msg})
|
||||||
|
bot1_messages.append({"role": "user", "content": bot2_msg})
|
||||||
|
|
||||||
all_audio = bytearray()
|
all_audio = bytearray()
|
||||||
async for audio in tts2.run_tts(bot2_msg):
|
async for audio in tts2.run_tts(bot2_msg):
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class TranscriptFilter(AIService):
|
|||||||
|
|
||||||
|
|
||||||
class NameCheckFilter(AIService):
|
class NameCheckFilter(AIService):
|
||||||
def __init__(self, names=None):
|
def __init__(self, names:list[str]):
|
||||||
self.names = names
|
self.names = names
|
||||||
self.sentence = ""
|
self.sentence = ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user