Spaces:
Sleeping
Sleeping
Download utils.py from AiCoderv2/app-otqmig-46: direct link, hf CLI and curl.
- Browser
- Download file 654 Bytes
-
https://huggingface.co/spaces/AiCoderv2/app-otqmig-46/resolve/main/utils.py
- Command line
-
hf download hf://spaces/AiCoderv2/app-otqmig-46/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/AiCoderv2/app-otqmig-46/resolve/main/utils.py
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 [] |