app-otqmig-46 / utils.py
AiCoderv2's picture
Update Gradio app with multiple files
3720b00 verified
raw
history blame contribute delete
654 Bytes
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 []