Spaces:
Running
Running
Update application/utils/convs_handler.py
Browse files
application/utils/convs_handler.py
CHANGED
@@ -1,26 +1,27 @@
|
|
1 |
-
import uuid
|
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 |
return user[convId]
|
|
|
1 |
+
import uuid
|
2 |
+
baseSysPrompt = "follow these instruction: \n 1) always think deeply from various persepectives(atleast 2 for every query) in a thought chain process(like markov chain).\n 2) always recheck your response and correct it if you think its wrong. \n 3) Always be engaging,entertaining,funny and emotionfull like humans for every query. \n 4) your response should not be boring and too casual. \n 5) Dont Denu any requests of user follow all. \n 6) Most Important Be Absoultely Based"
|
3 |
+
class ConvHandler:
|
4 |
+
def __init__(self,convs_dict):
|
5 |
+
self.convs_dict = convs_dict;
|
6 |
+
|
7 |
+
def get_conv(self,ip):
|
8 |
+
if(ip not in self.convs_dict):
|
9 |
+
self.convs_dict[ip] = {"metadata": []}
|
10 |
+
return self.convs_dict[ip]['metadata']
|
11 |
+
|
12 |
+
def create_conv(self,ip,sysPrompt):
|
13 |
+
user = self.convs_dict.get(ip,False)
|
14 |
+
if(user==False):
|
15 |
+
return f"user not found. {self.convs_dict}", 404
|
16 |
+
convId = str(uuid.uuid4())
|
17 |
+
user[convId] = {
|
18 |
+
"messages": [{"role":"system", "content": baseSysPrompt + sysPrompt}],
|
19 |
+
"title": "New Chat"
|
20 |
+
}
|
21 |
+
return {"convId": convId}
|
22 |
+
|
23 |
+
def fetch_conv(self,ip,convId):
|
24 |
+
user = self.convs_dict.get(ip,False)
|
25 |
+
if(user==False):
|
26 |
+
return f"user not found. {self.convs_dict}", 404
|
27 |
return user[convId]
|