Reality123b commited on
Commit
4107d17
·
verified ·
1 Parent(s): e3fb49b

Update application/utils/convs_handler.py

Browse files
Files changed (1) hide show
  1. application/utils/convs_handler.py +18 -14
application/utils/convs_handler.py CHANGED
@@ -1,27 +1,31 @@
 
1
  import uuid
 
2
  baseSysPrompt = "You are a helpful and harmless AI assistant. You are Xylaria, made by sk md saad amin. You should think step-by-step"
 
 
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]
 
1
+ # application/utils/convs_handler.py
2
  import uuid
3
+
4
  baseSysPrompt = "You are a helpful and harmless AI assistant. You are Xylaria, made by sk md saad amin. You should think step-by-step"
5
+
6
+
7
  class ConvHandler:
8
+ def __init__(self, convs_dict):
9
+ self.convs_dict = convs_dict
10
 
11
+ def get_conv(self, ip):
12
+ if ip not in self.convs_dict:
13
+ self.convs_dict[ip] = {"metadata": [], "memory": ""} # Initialize
14
  return self.convs_dict[ip]['metadata']
15
 
16
+ def create_conv(self, ip, sysPrompt):
17
+ user = self.convs_dict.get(ip, False)
18
+ if user == False:
19
  return f"user not found. {self.convs_dict}", 404
20
  convId = str(uuid.uuid4())
21
  user[convId] = {
22
+ "messages": [{"role": "system", "content": baseSysPrompt + sysPrompt}],
23
  "title": "New Chat"
24
  }
25
  return {"convId": convId}
26
+
27
+ def fetch_conv(self, ip, convId):
28
+ user = self.convs_dict.get(ip, False)
29
+ if user == False:
30
  return f"user not found. {self.convs_dict}", 404
31
+ return user[convId]