Skip to content

Instantly share code, notes, and snippets.

@ShayneP
Last active October 8, 2024 02:39
Show Gist options
  • Save ShayneP/c0e89cb9070ee79b864bf32e50af1042 to your computer and use it in GitHub Desktop.
Save ShayneP/c0e89cb9070ee79b864bf32e50af1042 to your computer and use it in GitHub Desktop.
A simple implementation of a Realtime Agent using LiveKit.
from __future__ import annotations
import logging
from livekit import rtc
from livekit.agents import (
AutoSubscribe,
JobContext,
WorkerOptions,
cli,
llm,
)
from livekit.agents.multimodal import MultimodalAgent
from livekit.plugins import openai
logger = logging.getLogger("myagent")
logger.setLevel(logging.INFO)
async def entrypoint(ctx: JobContext):
logger.info("starting entrypoint")
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
participant = await ctx.wait_for_participant()
model = openai.realtime.RealtimeModel(
instructions="You are a helpful assistant and you love kittens",
voice="shimmer",
temperature=0.8,
modalities=["audio", "text"],
)
assistant = MultimodalAgent(model=model)
assistant.start(ctx.room)
logger.info("starting agent")
session = model.sessions[0]
session.conversation.item.create(
llm.ChatMessage(
role="user",
content="Please begin the interaction with the user in a manner consistent with your instructions.",
)
)
session.response.create()
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment