Skip to content

Instantly share code, notes, and snippets.

@ShayneP
Created January 15, 2025 20:08
Show Gist options
  • Save ShayneP/2c1ea3239bfa3f76384e2f118b2cecb2 to your computer and use it in GitHub Desktop.
Save ShayneP/2c1ea3239bfa3f76384e2f118b2cecb2 to your computer and use it in GitHub Desktop.
Basic LiveKit Agent
from dotenv import load_dotenv
from livekit.agents import (
AutoSubscribe,
JobContext,
JobProcess,
WorkerOptions,
cli,
llm,
)
from livekit.agents.pipeline import VoicePipelineAgent
from livekit.plugins import deepgram, openai, silero, turn_detector, cartesia
load_dotenv()
def prewarm(proc: JobProcess):
proc.userdata["vad"] = silero.VAD.load()
async def entrypoint(ctx: JobContext):
initial_ctx = llm.ChatContext().append(
role="system",
text=(
""),
)
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
participant = await ctx.wait_for_participant()
agent = VoicePipelineAgent(
vad=ctx.proc.userdata["vad"],
stt=openai.STT(),
llm=openai.LLM(),
tts=openai.TTS(),
chat_ctx=initial_ctx,
)
agent.start(ctx.room, participant)
await agent.say("Hi there! What can I help with?")
if __name__ == "__main__":
cli.run_app(
WorkerOptions(
entrypoint_fnc=entrypoint,
prewarm_fnc=prewarm
),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment