Spaces:
Sleeping
Sleeping
| 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 [] |