-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (43 loc) · 1.57 KB
/
main.py
File metadata and controls
58 lines (43 loc) · 1.57 KB
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
51
52
53
54
55
56
57
58
import asyncio
from dotenv import load_dotenv
import logging
load_dotenv()
from livekit.agents import Agent, AgentSession, cli, WorkerOptions, JobContext
from livekit.plugins import groq, elevenlabs, deepgram, silero
from metrics_logger import setup_metrics_logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%H:%M:%S'
)
logging.getLogger("livekit").setLevel(logging.WARNING)
async def entrypoint(ctx: JobContext):
"""The main entrypoint for the voice agent."""
logging.info("Agent job starting...")
await ctx.connect()
logging.info("Connected to the room.")
# 1. Initialize all the services for the agent
stt = deepgram.STT()
llm = groq.LLM()
tts = elevenlabs.TTS()
vad = silero.VAD.load()
# 2. Set up the metrics logging by passing the services to our logger module
# This single call replaces all the individual .on() calls here.
setup_metrics_logging(llm=llm, stt=stt, tts=tts)
# 3. Create the agent session
session = AgentSession(
stt=stt,
llm=llm,
tts=tts,
vad=vad,
)
# 4. Define the agent's identity and behavior
agent = Agent(
instructions="You are a helpful AI voice assistant. Keep responses short and conversational."
)
# 5. Start the agent session
logging.info("Starting agent session...")
await session.start(room=ctx.room, agent=agent)
logging.info("Agent session finished.")
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))