forked from TheAurder/Private-LLM-for-Data-Integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
18 lines (14 loc) · 629 Bytes
/
utils.py
File metadata and controls
18 lines (14 loc) · 629 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import json
from langchain.schema.messages import HumanMessage, AIMessage
from datetime import datetime
def save_chat_history_json(chat_history, file_path):
with open(file_path, "w") as f:
json_data = [message.dict() for message in chat_history]
json.dump(json_data, f)
def load_chat_history_json(file_path):
with open(file_path, "r") as f:
json_data = json.load(f)
messages = [HumanMessage(**message) if message["type"] == "human" else AIMessage(**message) for message in json_data]
return messages
def get_timestamp():
return datetime.now().strftime("%Y_%m_%d_%H_%M_%S")