77 AgentSession ,
88 JobContext ,
99 JobProcess ,
10- MetricsCollectedEvent ,
11- RoomInputOptions ,
12- WorkerOptions ,
1310 cli ,
1411 inference ,
15- metrics ,
12+ room_io ,
1613)
1714from livekit .plugins import noise_cancellation , silero
1815from 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 ()
5649def 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 ()
6159async 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