-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
68 lines (58 loc) · 1.97 KB
/
agent.py
File metadata and controls
68 lines (58 loc) · 1.97 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
59
60
61
62
63
64
65
66
67
68
from livekit import agents
from livekit.agents import AgentSession, Agent, RoomInputOptions
from livekit.plugins import (
openai,
rime,
assemblyai,
noise_cancellation,
silero,
)
from livekit.plugins.rime import TTS as RimeTTS
from dotenv import load_dotenv
import os
load_dotenv()
class LoggingRimeTTS(RimeTTS):
def synthesize(self, text, *args, **kwargs):
print("🔊 [Rime TTS] Outgoing Audio:", text)
return super().synthesize(text, *args, **kwargs)
class Assistant(Agent):
def __init__(self) -> None:
super().__init__(instructions="You are a helpful voice AI assistant.")
async def on_user_turn_completed(self, chat_ctx, new_message):
if new_message.text_content:
print(f"👶 [User] User Transcript: {new_message.text_content}")
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(
stt=assemblyai.STT(
end_of_turn_confidence_threshold=0.7,
min_end_of_turn_silence_when_confident=160,
max_turn_silence=2400,
format_turns=True,
),
llm=openai.LLM.with_cerebras(
model="llama-3.3-70b",
),
tts=LoggingRimeTTS(model="mist",
speaker="rainforest",
speed_alpha=0.9,
reduce_latency=True,
),
vad=silero.VAD.load(),
turn_detection="stt"
)
await session.start(
room=ctx.room,
agent=Assistant(),
room_input_options=RoomInputOptions(
# LiveKit Cloud enhanced noise cancellation
# - If self-hosting, omit this parameter
# - For telephony applications, use `BVCTelephony` for best results
# noise_cancellation=noise_cancellation.BVC(),
),
)
await ctx.connect()
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))