forked from Leon-Sander/Local-Multimodal-AI-Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
28 lines (23 loc) · 891 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json
from langchain.schema.messages import HumanMessage, AIMessage
from datetime import datetime
import yaml
def load_config():
with open("config.yaml", "r") as f:
return yaml.safe_load(f)
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")
def get_avatar(sender_type):
if sender_type == "human":
return "chat_icons/user_image.png"
else:
return "chat_icons/bot_image.png"