How do I add a prompt to my realtime API gpt-realt...
# ask-ai
m
How do I add a prompt to my realtime API gpt-realtime session?
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to add a prompt to your realtime API
gpt-realtime
session, you can use the instructions parameter. Think of it as the system message that helps guide how the model behaves. Here are a couple of easy ways to set or update your prompt: 1. Set the Prompt When You Start the Session Just pass the
instructions
parameter when you create a new session. For example:
Copy code
const session = llm.session();
await session.updateInstructions("You are a helpful and concise assistant.");
2. Change the Prompt On the Fly During a Session If you want to switch things up while the session is running, just use the
updateInstructions
method like this:
Copy code
await session.updateInstructions("You are now a pirate, speak like one!");
Feel free to reach out if you have any questions or need a hand with this! Sources: examples/src/realtime_turn_detector.ts | Live Conversations with AI using ChatGPT and WebRTC | livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime...
m
swift ex
t
Hey there! It looks like you’re interested in a Swift example for adding a prompt to a gpt-realtime session. Just to make sure I’m on the right track, are you asking about: • Adding a system prompt to help guide how the assistant responds? • Using a prompt specifically for speech-to-text transcription? Just let me know, and I’ll be happy to help you out! Sources: Groq STT integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime...
m
Sorry, meant Python on the backend. Give me a python ex of updating the nistructions
t
If you want to update the instructions on the fly in a gpt-realtime session using Python, you can use the
update_instructions
method. Here’s a little example to show you how:
Copy code
async def on_enter(self):
    if self.session.participant.name.startswith("sip"):
        await self.update_instructions("You are a helpful agent speaking on the phone.")
    self.session.generate_reply()
This method lets you change the system prompt while the session is still going. If you have any questions or want me to walk you through it, just let me know—I’m here to help! Sources: livekit-agents/livekit/agents/llm/realtime.py | basics/change_agent_instructions.py