Fix 06- demo and also fix bugs where dangling sentences wouldn't be spoken

This commit is contained in:
Moishe Lettvin
2024-02-01 12:54:23 -05:00
parent 0d96f91cde
commit 9d5ad5675c
2 changed files with 10 additions and 7 deletions

View File

@@ -70,6 +70,13 @@ class LLMContextAggregator(AIService):
self.messages.append({"role": self.role, "content": frame.text}) # type: ignore -- the linter thinks this isn't a TextQueueFrame, even though we check it above
yield LLMMessagesQueueFrame(self.messages)
async def finalize(self) -> AsyncGenerator[QueueFrame, None]:
# Send any dangling words that weren't finished with punctuation.
if self.complete_sentences and self.sentence:
self.messages.append({"role": self.role, "content": self.sentence})
yield LLMMessagesQueueFrame(self.messages)
class LLMUserContextAggregator(LLMContextAggregator):
def __init__(self,
messages: list[dict],

View File

@@ -6,7 +6,7 @@ import urllib.parse
from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
from dailyai.queue_aggregators import LLMContextAggregator
from dailyai.queue_aggregators import LLMAssistantContextAggregator, LLMContextAggregator, LLMUserContextAggregator
async def main(room_url: str, token):
@@ -36,12 +36,8 @@ async def main(room_url: str, token):
{"role": "system", "content": "You are a helpful LLM in a WebRTC call. Your goal is to demonstrate your capabilities in a succinct way. Your output will be converted to audio. Respond to what the user said in a creative and helpful way."},
]
tma_in = LLMContextAggregator(
messages, "user", transport.my_participant_id
)
tma_out = LLMContextAggregator(
messages, "assistant", transport.my_participant_id
)
tma_in = LLMUserContextAggregator(messages, transport.my_participant_id)
tma_out = LLMAssistantContextAggregator(messages, transport.my_participant_id)
await tts.run_to_queue(
transport.send_queue,
tma_out.run(