Skip to content

Commit

Permalink
cleaned up example logging (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadbailey59 authored Mar 8, 2024
1 parent 95a1efb commit 8241dc0
Show file tree
Hide file tree
Showing 20 changed files with 409 additions and 273 deletions.
20 changes: 7 additions & 13 deletions src/examples/foundational/01-say-one-thing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import aiohttp
import logging
import os

from dailyai.services.daily_transport_service import DailyTransportService
Expand All @@ -8,6 +9,9 @@

from examples.support.runner import configure

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)

async def main(room_url):
async with aiohttp.ClientSession() as session:
Expand All @@ -21,24 +25,14 @@ async def main(room_url):
# to the daily-python basic API
meeting_duration_minutes = 5
transport = DailyTransportService(
room_url,
None,
"Say One Thing",
meeting_duration_minutes,
mic_enabled=True
room_url, None, "Say One Thing", meeting_duration_minutes, mic_enabled=True
)

tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"))
"""
tts = PlayHTAIService(
api_key=os.getenv("PLAY_HT_API_KEY"),
user_id=os.getenv("PLAY_HT_USER_ID"),
voice_url=os.getenv("PLAY_HT_VOICE_URL"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
)
"""

# Register an event handler so we can play the audio when the participant joins.
@transport.event_handler("on_participant_joined")
Expand All @@ -56,7 +50,7 @@ async def on_participant_joined(transport, participant):
await transport.stop_when_done()

await transport.run()
del(tts)
del tts


if __name__ == "__main__":
Expand Down
7 changes: 5 additions & 2 deletions src/examples/foundational/01a-local-transport.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import asyncio
import aiohttp
import logging
import os

from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.local_transport_service import LocalTransportService

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)

async def main():
async with aiohttp.ClientSession() as session:
meeting_duration_minutes = 1
transport = LocalTransportService(
duration_minutes=meeting_duration_minutes,
mic_enabled=True
duration_minutes=meeting_duration_minutes, mic_enabled=True
)
tts = ElevenLabsTTSService(
aiohttp_session=session,
Expand Down
30 changes: 16 additions & 14 deletions src/examples/foundational/02-llm-say-one-thing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import os
import logging

import aiohttp

Expand All @@ -11,6 +12,9 @@
from dailyai.services.open_ai_services import OpenAILLMService
from examples.support.runner import configure

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)

async def main(room_url):
async with aiohttp.ClientSession() as session:
Expand All @@ -20,25 +24,23 @@ async def main(room_url):
None,
"Say One Thing From an LLM",
duration_minutes=meeting_duration_minutes,
mic_enabled=True
mic_enabled=True,
)

tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"))
# tts = AzureTTSService(api_key=os.getenv("AZURE_SPEECH_API_KEY"), region=os.getenv("AZURE_SPEECH_REGION"))
# tts = DeepgramTTSService(aiohttp_session=session, api_key=os.getenv("DEEPGRAM_API_KEY"), voice=os.getenv("DEEPGRAM_VOICE"))

llm = AzureLLMService(
api_key=os.getenv("AZURE_CHATGPT_API_KEY"),
endpoint=os.getenv("AZURE_CHATGPT_ENDPOINT"),
model=os.getenv("AZURE_CHATGPT_MODEL"))
# llm = OpenAILLMService(api_key=os.getenv("OPENAI_CHATGPT_API_KEY"))
messages = [{
"role": "system",
"content": "You are an LLM in a WebRTC session, and this is a 'hello world' demo. Say hello to the world."
}]
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
)
llm = OpenAILLMService(
api_key=os.getenv("OPENAI_CHATGPT_API_KEY"), model="gpt-4-turbo-preview"
)
messages = [
{
"role": "system",
"content": "You are an LLM in a WebRTC session, and this is a 'hello world' demo. Say hello to the world.",
}
]
tts_task = asyncio.create_task(
tts.run_to_queue(
transport.send_queue,
Expand Down
14 changes: 10 additions & 4 deletions src/examples/foundational/03-still-frame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import aiohttp
import logging
import os

from dailyai.pipeline.frames import TextFrame
Expand All @@ -10,6 +11,9 @@

from examples.support.runner import configure

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)
local_joined = False
participant_joined = False

Expand All @@ -25,21 +29,23 @@ async def main(room_url):
mic_enabled=False,
camera_enabled=True,
camera_width=1024,
camera_height=1024
camera_height=1024,
)

imagegen = FalImageGenService(
image_size="1024x1024",
aiohttp_session=session,
key_id=os.getenv("FAL_KEY_ID"),
key_secret=os.getenv("FAL_KEY_SECRET"))
key_secret=os.getenv("FAL_KEY_SECRET"),
)
# imagegen = OpenAIImageGenService(aiohttp_session=session, api_key=os.getenv("OPENAI_DALLE_API_KEY"), image_size="1024x1024")
# imagegen = AzureImageGenServiceREST(image_size="1024x1024", aiohttp_session=session, api_key=os.getenv("AZURE_DALLE_API_KEY"), endpoint=os.getenv("AZURE_DALLE_ENDPOINT"), model=os.getenv("AZURE_DALLE_MODEL"))

image_task = asyncio.create_task(
imagegen.run_to_queue(
transport.send_queue, [
TextFrame("a cat in the style of picasso")]))
transport.send_queue, [TextFrame("a cat in the style of picasso")]
)
)

@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport):
Expand Down
6 changes: 6 additions & 0 deletions src/examples/foundational/03a-image-local.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import aiohttp
import logging
import os

import tkinter as tk
Expand All @@ -8,6 +9,10 @@
from dailyai.services.fal_ai_services import FalImageGenService
from dailyai.services.local_transport_service import LocalTransportService

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)

local_joined = False
participant_joined = False

Expand Down Expand Up @@ -46,5 +51,6 @@ async def run_tk():

await asyncio.gather(transport.run(), image_task, run_tk())


if __name__ == "__main__":
asyncio.run(main())
26 changes: 19 additions & 7 deletions src/examples/foundational/04-utterance-and-speech.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import logging
import os

import aiohttp
Expand All @@ -8,9 +9,12 @@
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
from dailyai.pipeline.frames import EndFrame, LLMMessagesQueueFrame
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService

from examples.support.runner import configure

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)


async def main(room_url: str):
async with aiohttp.ClientSession() as session:
Expand All @@ -21,20 +25,23 @@ async def main(room_url: str):
duration_minutes=1,
mic_enabled=True,
mic_sample_rate=16000,
camera_enabled=False
camera_enabled=False,
)

llm = AzureLLMService(
api_key=os.getenv("AZURE_CHATGPT_API_KEY"),
endpoint=os.getenv("AZURE_CHATGPT_ENDPOINT"),
model=os.getenv("AZURE_CHATGPT_MODEL"))
model=os.getenv("AZURE_CHATGPT_MODEL"),
)
azure_tts = AzureTTSService(
api_key=os.getenv("AZURE_SPEECH_API_KEY"),
region=os.getenv("AZURE_SPEECH_REGION"))
region=os.getenv("AZURE_SPEECH_REGION"),
)
elevenlabs_tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"))
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
)

messages = [{"role": "system", "content": "tell the user a joke about llamas"}]

Expand All @@ -43,14 +50,19 @@ async def main(room_url: str):
# speak the LLM response.
buffer_queue = asyncio.Queue()
source_queue = asyncio.Queue()
pipeline = Pipeline(source = source_queue, sink=buffer_queue, processors=[llm, elevenlabs_tts])
pipeline = Pipeline(
source=source_queue, sink=buffer_queue, processors=[llm, elevenlabs_tts]
)
await source_queue.put(LLMMessagesQueueFrame(messages))
await source_queue.put(EndFrame())
pipeline_run_task = pipeline.run_pipeline()

@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport):
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():
while True:
Expand Down
40 changes: 32 additions & 8 deletions src/examples/foundational/05-sync-speech-and-image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,38 @@
from re import S
import aiohttp
import os
from dailyai.pipeline.aggregators import GatedAggregator, LLMFullResponseAggregator, ParallelPipeline, SentenceAggregator

from dailyai.pipeline.frames import AudioFrame, EndFrame, ImageFrame, LLMMessagesQueueFrame, LLMResponseStartFrame
import logging

from dailyai.pipeline.aggregators import (
GatedAggregator,
LLMFullResponseAggregator,
ParallelPipeline,
SentenceAggregator,
)
from dailyai.pipeline.frames import (
AudioFrame,
EndFrame,
ImageFrame,
LLMMessagesQueueFrame,
LLMResponseStartFrame,
)
from dailyai.pipeline.pipeline import Pipeline
from dailyai.services.azure_ai_services import AzureLLMService, AzureImageGenServiceREST, AzureTTSService
from dailyai.services.azure_ai_services import (
AzureLLMService,
AzureImageGenServiceREST,
AzureTTSService,
)
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.fal_ai_services import FalImageGenService
from dailyai.services.open_ai_services import OpenAIImageGenService

from examples.support.runner import configure

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)


async def main(room_url):
async with aiohttp.ClientSession() as session:
Expand All @@ -27,23 +47,26 @@ async def main(room_url):
camera_enabled=True,
mic_sample_rate=16000,
camera_width=1024,
camera_height=1024
camera_height=1024,
)

llm = AzureLLMService(
api_key=os.getenv("AZURE_CHATGPT_API_KEY"),
endpoint=os.getenv("AZURE_CHATGPT_ENDPOINT"),
model=os.getenv("AZURE_CHATGPT_MODEL"))
model=os.getenv("AZURE_CHATGPT_MODEL"),
)
tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id="ErXwobaYiN019PkySvjV")
voice_id="ErXwobaYiN019PkySvjV",
)

dalle = FalImageGenService(
image_size="1024x1024",
aiohttp_session=session,
key_id=os.getenv("FAL_KEY_ID"),
key_secret=os.getenv("FAL_KEY_SECRET"))
key_secret=os.getenv("FAL_KEY_SECRET"),
)

source_queue = asyncio.Queue()

Expand Down Expand Up @@ -101,6 +124,7 @@ async def on_first_other_participant_joined(transport):

await transport.run()


if __name__ == "__main__":
(url, token) = configure()
asyncio.run(main(url))
10 changes: 7 additions & 3 deletions src/examples/foundational/05a-local-sync-speech-and-text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import aiohttp
import argparse
import asyncio
import logging
import tkinter as tk
import os

Expand All @@ -10,6 +11,10 @@
from dailyai.services.fal_ai_services import FalImageGenService
from dailyai.services.local_transport_service import LocalTransportService

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)


async def main(room_url):
async with aiohttp.ClientSession() as session:
Expand Down Expand Up @@ -67,9 +72,7 @@ async def get_month_data(month):
to_speak = f"{month}: {image_description}"
audio_task = asyncio.create_task(get_all_audio(to_speak))
image_task = asyncio.create_task(dalle.run_image_gen(image_description))
(audio, image_data) = await asyncio.gather(
audio_task, image_task
)
(audio, image_data) = await asyncio.gather(audio_task, image_task)

return {
"month": month,
Expand Down Expand Up @@ -123,6 +126,7 @@ async def run_tk():

await asyncio.gather(transport.run(), show_images(), run_tk())


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Simple Daily Bot Sample")
parser.add_argument(
Expand Down
Loading

0 comments on commit 8241dc0

Please sign in to comment.