Skip to content

Commit 56b28e3

Browse files
committed
Updates per feedback; prewarm_fnc updates
1 parent e397f1d commit 56b28e3

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ description = "Simple voice AI assistant built with LiveKit Agents for Python"
99
requires-python = ">=3.9"
1010

1111
dependencies = [
12-
"livekit-agents[silero,turn-detector]~=1.3.0rc1",
12+
"livekit-agents[turn-detector]~=1.3.0rc2",
13+
"livekit-plugins-silero~=1.3.0rc1",
1314
"livekit-plugins-noise-cancellation~=0.2",
1415
"python-dotenv",
1516
]

src/agent.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
AgentSession,
88
JobContext,
99
JobProcess,
10-
MetricsCollectedEvent,
11-
RoomInputOptions,
12-
WorkerOptions,
1310
cli,
1411
inference,
15-
metrics,
12+
room_io,
1613
)
1714
from livekit.plugins import noise_cancellation, silero
1815
from livekit.plugins.turn_detector.multilingual import MultilingualModel
@@ -49,14 +46,15 @@ def __init__(self) -> None:
4946
# return "sunny with a temperature of 70 degrees."
5047

5148

52-
server = AgentServer()
53-
54-
55-
@server.setup()
5649
def prewarm(proc: JobProcess):
5750
proc.userdata["vad"] = silero.VAD.load()
5851

5952

53+
server = AgentServer(
54+
setup_fnc = prewarm,
55+
)
56+
57+
6058
@server.rtc_session()
6159
async def my_agent(ctx: JobContext):
6260
# Logging setup
@@ -97,21 +95,6 @@ async def my_agent(ctx: JobContext):
9795
# llm=openai.realtime.RealtimeModel(voice="marin")
9896
# )
9997

100-
# Metrics collection, to measure pipeline performance
101-
# For more information, see https://docs.livekit.io/agents/build/metrics/
102-
usage_collector = metrics.UsageCollector()
103-
104-
@session.on("metrics_collected")
105-
def _on_metrics_collected(ev: MetricsCollectedEvent):
106-
metrics.log_metrics(ev.metrics)
107-
usage_collector.collect(ev.metrics)
108-
109-
async def log_usage():
110-
summary = usage_collector.get_summary()
111-
logger.info(f"Usage: {summary}")
112-
113-
ctx.add_shutdown_callback(log_usage)
114-
11598
# # Add a virtual avatar to the session, if desired
11699
# # For other providers, see https://docs.livekit.io/agents/models/avatar/
117100
# avatar = hedra.AvatarSession(
@@ -124,9 +107,11 @@ async def log_usage():
124107
await session.start(
125108
agent=Assistant(),
126109
room=ctx.room,
127-
room_input_options=RoomInputOptions(
128-
# For telephony applications, use `BVCTelephony` for best results
129-
noise_cancellation=noise_cancellation.BVC(),
110+
room_options=room_io.RoomOptions(
111+
audio_input=room_io.AudioInputOptions(
112+
# For telephony applications, use `BVCTelephony` for best results
113+
noise_cancellation=noise_cancellation.BVC(),
114+
),
130115
),
131116
)
132117

0 commit comments

Comments
 (0)