-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathmain.py
50 lines (39 loc) · 1.37 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import asyncio
from livekit.agents import JobContext, WorkerOptions, cli, JobProcess
from livekit.agents.llm import (
ChatContext,
ChatMessage,
)
from livekit.agents.voice_assistant import VoiceAssistant
from livekit.plugins import deepgram, silero, cartesia, openai
from dotenv import load_dotenv
load_dotenv()
def prewarm(proc: JobProcess):
proc.userdata["vad"] = silero.VAD.load()
async def entrypoint(ctx: JobContext):
initial_ctx = ChatContext(
messages=[
ChatMessage(
role="system",
content="You are a voice assistant. Pretend we're having a human conversation, no special formatting or headings, just natural speech.",
)
]
)
assistant = VoiceAssistant(
vad=ctx.proc.userdata["vad"],
stt=deepgram.STT(),
llm=openai.LLM(
base_url="https://api.cerebras.ai/v1",
api_key=os.environ.get("CEREBRAS_API_KEY"),
model="llama3.1-8b",
),
tts=cartesia.TTS(voice="248be419-c632-4f23-adf1-5324ed7dbf1d"),
chat_ctx=initial_ctx,
)
await ctx.connect()
assistant.start(ctx.room)
await asyncio.sleep(1)
await assistant.say("Hi there, how are you doing today?", allow_interruptions=True)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))