Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ You can also self-host LiveKit instead of using LiveKit Cloud. See the [self-hos

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Simple voice AI assistant built with LiveKit Agents for Python"
requires-python = ">=3.9"

dependencies = [
"livekit-agents[silero,turn-detector]~=1.2",
"livekit-agents[silero,turn-detector]~=1.3.2",
"livekit-plugins-noise-cancellation~=0.2",
"python-dotenv",
]
Expand Down
39 changes: 15 additions & 24 deletions src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
from dotenv import load_dotenv
from livekit.agents import (
Agent,
AgentServer,
AgentSession,
JobContext,
JobProcess,
MetricsCollectedEvent,
RoomInputOptions,
WorkerOptions,
cli,
inference,
metrics,
room_io,
)
from livekit.plugins import noise_cancellation, silero
from livekit.plugins.turn_detector.multilingual import MultilingualModel
Expand Down Expand Up @@ -52,7 +50,13 @@
proc.userdata["vad"] = silero.VAD.load()


async def entrypoint(ctx: JobContext):
server = AgentServer(
setup_fnc = prewarm,

Check failure on line 54 in src/agent.py

View workflow job for this annotation

GitHub Actions / ruff-check

Ruff (W291)

src/agent.py:54:24: W291 Trailing whitespace
)


@server.rtc_session()
async def my_agent(ctx: JobContext):
# Logging setup
# Add any other context you want in all log entries here
ctx.log_context_fields = {
Expand Down Expand Up @@ -91,21 +95,6 @@
# llm=openai.realtime.RealtimeModel(voice="marin")
# )

# Metrics collection, to measure pipeline performance
# For more information, see https://docs.livekit.io/agents/build/metrics/
usage_collector = metrics.UsageCollector()

@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics.log_metrics(ev.metrics)
usage_collector.collect(ev.metrics)

async def log_usage():
summary = usage_collector.get_summary()
logger.info(f"Usage: {summary}")

ctx.add_shutdown_callback(log_usage)

# # Add a virtual avatar to the session, if desired
# # For other providers, see https://docs.livekit.io/agents/models/avatar/
# avatar = hedra.AvatarSession(
Expand All @@ -118,9 +107,11 @@
await session.start(
agent=Assistant(),
room=ctx.room,
room_input_options=RoomInputOptions(
# For telephony applications, use `BVCTelephony` for best results
noise_cancellation=noise_cancellation.BVC(),
room_options=room_io.RoomOptions(
audio_input=room_io.AudioInputOptions(
# For telephony applications, use `BVCTelephony` for best results
noise_cancellation=noise_cancellation.BVC(),
),
),
)

Expand All @@ -129,4 +120,4 @@


if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))
cli.run_app(server)
Loading