how to clear a conversation history/context during...
# ask-ai
s
how to clear a conversation history/context during a live openairealtime conversation
t
Thanks for reaching out, MBMBMB. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To clear conversation history or context during a live OpenAIRealtime conversation, you can use the following methods depending on your requirements: • Clearing Individual Conversation Items: ◦ JavaScript/TypeScript:
Copy code
// Delete a specific conversation item by ID
session.conversation.item.delete(itemId);
◦ Python:
Copy code
# Update chat context (this can include removing items)
await session.update_chat_ctx(new_chat_ctx)
• Clearing Input Audio Buffer: ◦ JavaScript/TypeScript:
Copy code
// Clear the input audio buffer
session.inputAudioBuffer.clear();
◦ Python:
Copy code
# Clear the input audio buffer
session.clear_audio()
• Truncating Conversation Items: ◦ JavaScript/TypeScript:
Copy code
// Truncate a conversation item
session.conversation.item.truncate(itemId, contentIndex, audioEnd);
◦ Python:
Copy code
# Truncate a conversation item
session.truncate(message_id=message_id, audio_end_ms=audio_end_ms)
• Complete Context Reset: ◦ To completely reset the conversation context, delete all existing conversation items and optionally provide a new chat context. In Python, this can be achieved by calling
update_chat_ctx
with an empty or new
ChatContext
. Let me know if you need further details on any of these methods! Sources: plugins/openai/src/realtime/api_proto.ts | ConversationItemDeleteEvent | LiveKit Agents | examples/voice_agents/realtime_load_chat_history.py | InputAudioBufferClearEvent | LiveKit Agents | ConversationItemTruncateEvent | LiveKit Agents
s
ok give more detail about complete context reset using python
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!