Spaces:
Sleeping
Sleeping
File size: 654 Bytes
3720b00 be9534f 3720b00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import json
import os
def format_conversation(message, history):
"""Format conversation for the model."""
conversation = []
for msg in history:
conversation.append(f"{msg['role']}: {msg['content']}")
conversation.append(f"user: {message}")
return "\n".join(conversation)
def save_chat_history(history):
"""Save chat history to a file."""
with open("chat_history.json", "w") as f:
json.dump(history, f)
def load_chat_history():
"""Load chat history from a file."""
if os.path.exists("chat_history.json"):
with open("chat_history.json", "r") as f:
return json.load(f)
return [] |