-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(example): add basic agent and task definitions
- Loading branch information
1 parent
8a53ea1
commit 0078b84
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
.env.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LIVEKIT_URL=<your LiveKit server URL> | ||
LIVEKIT_API_KEY=<your API Key> | ||
LIVEKIT_API_SECRET=<your API Secret> | ||
ELEVEN_API_KEY=<your ElevenLabs API key> | ||
DEEPGRAM_API_KEY=<your Deepgram API key> | ||
OPENAI_API_KEY=<your OpenAI API key> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env.local | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import asyncio | ||
|
||
from dotenv import load_dotenv | ||
from livekit import rtc | ||
from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli, llm | ||
from livekit.agents.voice_assistant import VoiceAssistant | ||
from livekit.plugins import deepgram, openai, silero | ||
|
||
load_dotenv(dotenv_path=".env.local") | ||
|
||
|
||
async def entrypoint(ctx: JobContext): | ||
initial_ctx = llm.ChatContext().append( | ||
role="system", | ||
text=( | ||
"You are a voice assistant created by LiveKit. Your interface with users will be voice. " | ||
"You should use short and concise responses, and avoiding usage of unpronouncable punctuation. " | ||
"You were created as a demo to showcase the capabilities of LiveKit's agents framework, " | ||
"as well as the ease of development of realtime AI prototypes. You are currently running in a " | ||
"LiveKit Sandbox, which is an environment that allows developers to instantly deploy prototypes " | ||
"of their realtime AI applications to share with others." | ||
), | ||
) | ||
|
||
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY) | ||
|
||
assistant = VoiceAssistant( | ||
vad=silero.VAD.load(), | ||
stt=deepgram.STT(), | ||
llm=openai.LLM(), | ||
tts=openai.TTS(), | ||
chat_ctx=initial_ctx, | ||
) | ||
assistant.start(ctx.room) | ||
|
||
# listen to incoming chat messages, only required if you'd like the agent to | ||
# answer incoming messages from Chat | ||
chat = rtc.ChatManager(ctx.room) | ||
|
||
async def answer_from_text(txt: str): | ||
chat_ctx = assistant.chat_ctx.copy() | ||
chat_ctx.append(role="user", text=txt) | ||
stream = assistant.llm.chat(chat_ctx=chat_ctx) | ||
await assistant.say(stream) | ||
|
||
@chat.on("message_received") | ||
def on_chat_received(msg: rtc.ChatMessage): | ||
if msg.message: | ||
asyncio.create_task(answer_from_text(msg.message)) | ||
|
||
await asyncio.sleep(1) | ||
await assistant.say("Hey, how can I help you today?", allow_interruptions=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
livekit-agents>=0.8.5 | ||
livekit-plugins-openai>=0.8.0 | ||
livekit-plugins-deepgram>=0.6.4 | ||
livekit-plugins-silero>=0.6.3 | ||
python-dotenv~=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
version: "3" | ||
|
||
output: prefixed | ||
|
||
dotenv: | ||
- "ui/.env.local" | ||
- "agent/.env.local" | ||
|
||
tasks: | ||
install: | ||
desc: "Bootstrap application for local development" | ||
deps: | ||
- install_ui | ||
- install_agent | ||
|
||
install_sandbox: | ||
desc: "Bootstrap application for sandbox environment" | ||
deps: | ||
- install_agent | ||
|
||
install_ui: | ||
dir: "frontend" | ||
interactive: true | ||
cmds: | ||
- "pnpm install" | ||
|
||
install_agent: | ||
dir: "agent" | ||
cmds: | ||
- "python3 -m venv venv" | ||
- cmd: "source venv/bin/activate" | ||
platforms: | ||
- darwin | ||
- linux | ||
- cmd: "powershell venv/Scripts/Activate.ps1" | ||
platforms: | ||
- windows | ||
- cmd: "venv/bin/python3 -m pip install -r requirements.txt" | ||
platforms: | ||
- darwin | ||
- linux | ||
- cmd: "venv/Scripts/python -m pip install -r requirements.txt" | ||
platforms: | ||
- windows | ||
|
||
dev: | ||
interactive: true | ||
deps: | ||
- dev_ui | ||
- dev_agent | ||
|
||
dev_ui: | ||
dir: "frontend" | ||
cmds: | ||
- "pnpm dev" | ||
|
||
dev_agent: | ||
dir: "agent" | ||
cmds: | ||
- cmd: "source venv/bin/activate" | ||
platforms: | ||
- darwin | ||
- linux | ||
- cmd: "powershell venv/Scripts/Activate.ps1" | ||
platforms: | ||
- windows | ||
- cmd: "venv/bin/python3 agent.py start" | ||
platforms: | ||
- darwin | ||
- linux | ||
- cmd: "venv/Scripts/python agent.py start" | ||
platforms: | ||
- windows |