-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_history.py
More file actions
37 lines (33 loc) · 1.13 KB
/
chat_history.py
File metadata and controls
37 lines (33 loc) · 1.13 KB
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
29
30
31
32
33
34
35
36
37
from haystack.dataclasses import ChatMessage, ChatRole
from typing import List
chat_history = {
"Metta": {
"linkedin": {
"event": [],
"blog": [],
"experience": [],
"contribution": [],
"certificate": [],
"hackathon": [],
"project": []
},
"twitter": {
"event": [],
"blog": [],
"experience": [],
"contribution": [],
"certificate": [],
"hackathon": [],
"project": []
}
}
}
def get_chat_history(user_name:str, media_type:str, history_type:str) -> List[ChatMessage]:
return chat_history[user_name][media_type][history_type]
def update_chat_history(user_name:str, media_type:str,history_type:str, data:str, response:str):
global chat_history
chat_history[user_name][media_type][history_type].append(ChatMessage.from_user(data))
chat_history[user_name][media_type][history_type].append(ChatMessage.from_assistant(response))
def add_chat_history(user_name:str, media_type:str,history_type:str, data: List[ChatMessage]):
global chat_history
chat_history[user_name][media_type][history_type] = chat_history[user_name][media_type][history_type] + data