steep-balloon-41261
06/25/2025, 7:35 AMtall-airline-16756
06/25/2025, 7:35 AMtall-airline-16756
06/25/2025, 7:35 AMsession.history
property. This provides the entire conversation data, which you can process or summarize as needed.
For example, you can use the following approach to save the conversation history:
async def write_transcript():
current_date = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"/tmp/transcript_{ctx.room.name}_{current_date}.json"
with open(filename, 'w') as f:
json.dump(session.history.to_dict(), f, indent=2)
print(f"Transcript for {ctx.room.name} saved to {filename}")
ctx.add_shutdown_callback(write_transcript)
This will save the complete conversation history to a JSON file when the session ends. You can modify this process to generate a summary before saving if needed.
Sources: Session recording and transcripts | LiveKit Docsmost-vr-18651
06/25/2025, 7:38 AMtall-airline-16756
06/25/2025, 7:38 AMsession.history
- it's super easy!
2. Then, you'll want to pull out those messages and send them to a cool summarization tool. OpenAI's GPT models or other NLP libraries work great for this.
3. Generate your summary and save it - you can keep it alongside the full conversation or replace it entirely.
Here's a practical example to help you out:
from openai import ChatCompletion
async def summarize_conversation(history):
messages = [item.text_content for item in history.items]
conversation_text = "\n".join(messages)
response = ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "Summarize the following conversation."},
{"role": "user", "content": conversation_text}
]
)
summary = response["choices"][0]["message"]["content"]
return summary
# Example usage
summary = await summarize_conversation(session.history)
print("Summary:", summary)
Pretty cool, right? This approach uses a smart language model to whip up a neat, concise summary of your conversation. Once you've got it, you can easily save the summary to your database or file system. It's like having a helpful assistant that can capture the essence of any chat in just a few words!