Skip to content

Commit

Permalink
wip proposal: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aconchillo committed Apr 27, 2024
1 parent e60b6a8 commit 420bb2c
Show file tree
Hide file tree
Showing 70 changed files with 3,301 additions and 1,839 deletions.
35 changes: 18 additions & 17 deletions examples/foundational/01-say-one-thing.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#
# Copyright (c) 2024, Daily
#
# SPDX-License-Identifier: BSD 2-Clause License
#

import asyncio
import aiohttp
import logging
import os
from dailyai.pipeline.frames import EndFrame, TextFrame
from dailyai.pipeline.pipeline import Pipeline

from dailyai.frames.frames import TextFrame
from dailyai.pipeline.pipeline import Pipeline
from dailyai.services.live_stream import LiveStream
from dailyai.services.elevenlabs import ElevenLabsTTSService
from dailyai.transports.daily_transport import DailyTransport
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService

from runner import configure

from dotenv import load_dotenv
load_dotenv(override=True)

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,26 +29,25 @@ async def main(room_url):
mic_enabled=True,
)

livestream = LiveStream(transport, mic_enabled=True)

tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
)

pipeline = Pipeline([tts])
pipeline = Pipeline([tts, livestream])

# Register an event handler so we can play the audio when the
# participant joins.
@transport.event_handler("on_participant_joined")
async def on_participant_joined(transport, participant):
if participant["info"]["isLocal"]:
return

@livestream.event_handler("on_participant_joined")
async def on_participant_joined(livestream, participant):
participant_name = participant["info"]["userName"] or ''
await pipeline.queue_frames([TextFrame("Hello there, " + participant_name + "!"), EndFrame()])
await pipeline.queue_frames([TextFrame("Hello there, " + participant_name + "!")])
await pipeline.stop()

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


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/01a-local-transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import os

from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.elevenlabs_ai_services import ElevenLabsTTSService
from dailyai.transports.local_transport import LocalTransport

from dotenv import load_dotenv
Expand Down
31 changes: 18 additions & 13 deletions examples/foundational/02-llm-say-one-thing.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#
# Copyright (c) 2024, Daily
#
# SPDX-License-Identifier: BSD 2-Clause License
#

import asyncio
import os
import logging

import aiohttp

from dailyai.pipeline.frames import EndFrame, LLMMessagesFrame
from dailyai.frames.frames import LLMMessagesFrame
from dailyai.pipeline.pipeline import Pipeline
from dailyai.services.live_stream import LiveStream
from dailyai.services.elevenlabs import ElevenLabsTTSService
from dailyai.services.openai import OpenAILLMService
from dailyai.transports.daily_transport import DailyTransport
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.open_ai_services import OpenAILLMService

from runner import configure

from dotenv import load_dotenv
load_dotenv(override=True)

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 @@ -29,6 +31,8 @@ async def main(room_url):
mic_enabled=True,
)

livestream = LiveStream(transport, mic_enabled=True)

tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
Expand All @@ -45,13 +49,14 @@ async def main(room_url):
"content": "You are an LLM in a WebRTC session, and this is a 'hello world' demo. Say hello to the world.",
}]

pipeline = Pipeline([llm, tts])
pipeline = Pipeline([llm, tts, livestream])

@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport, participant):
await pipeline.queue_frames([LLMMessagesFrame(messages), EndFrame()])
@livestream.event_handler("on_first_participant_joined")
async def on_first_participant_joined(livestream, participant):
await pipeline.queue_frames([LLMMessagesFrame(messages)])
await pipeline.stop()

await transport.run(pipeline)
await pipeline.run()


if __name__ == "__main__":
Expand Down
23 changes: 15 additions & 8 deletions examples/foundational/03-still-frame.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#
# Copyright (c) 2024, Daily
#
# SPDX-License-Identifier: BSD 2-Clause License
#

import asyncio
import aiohttp
import logging
import os

from dailyai.pipeline.frames import TextFrame
from dailyai.frames.frames import TextFrame
from dailyai.pipeline.pipeline import Pipeline
from dailyai.services.live_stream import LiveStream
from dailyai.services.fal import FalImageGenService
from dailyai.transports.daily_transport import DailyTransport
from dailyai.services.fal_ai_services import FalImageGenService

from runner import configure

Expand All @@ -30,6 +37,8 @@ async def main(room_url):
duration_minutes=1
)

livestream = LiveStream(transport, camera_enabled=True)

imagegen = FalImageGenService(
params=FalImageGenService.InputParams(
image_size="square_hd"
Expand All @@ -38,19 +47,17 @@ async def main(room_url):
key=os.getenv("FAL_KEY"),
)

pipeline = Pipeline([imagegen])
pipeline = Pipeline([imagegen, livestream])

@transport.event_handler("on_first_other_participant_joined")
@livestream.event_handler("on_first_participant_joined")
async def on_first_other_participant_joined(transport, participant):
# Note that we do not put an EndFrame() item in the pipeline for this demo.
# This means that the bot will stay in the channel until it times out.
# An EndFrame() in the pipeline would cause the transport to shut
# down.
await pipeline.queue_frames(
[TextFrame("a cat in the style of picasso")]
)
await pipeline.queue_frames([TextFrame("a cat in the style of picasso")])

await transport.run(pipeline)
await pipeline.run()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/04-utterance-and-speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
from dailyai.services.deepgram_ai_services import DeepgramTTSService
from dailyai.pipeline.frames import EndPipeFrame, LLMMessagesFrame, TextFrame
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.elevenlabs_ai_services import ElevenLabsTTSService

from runner import configure

Expand Down
Loading

0 comments on commit 420bb2c

Please sign in to comment.