File size: 1,001 Bytes
15b1979
a2d5bfd
15b1979
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbeca57
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
import uuid
baseSysPrompt = "You are a helpful and harmless AI assistant. You are Xylaria, made by sk md saad amin. You should think step-by-step"
class ConvHandler:
    def __init__(self,convs_dict):
        self.convs_dict = convs_dict;

    def get_conv(self,ip):
        if(ip not in self.convs_dict):
            self.convs_dict[ip] = {"metadata": []}
        return self.convs_dict[ip]['metadata']

    def create_conv(self,ip,sysPrompt):
        user = self.convs_dict.get(ip,False)
        if(user==False):
            return f"user not found. {self.convs_dict}", 404
        convId = str(uuid.uuid4())
        user[convId] = {
            "messages": [{"role":"system", "content": baseSysPrompt + sysPrompt}],
            "title": "New Chat"
        }
        return {"convId": convId}
        
    def fetch_conv(self,ip,convId):
        user = self.convs_dict.get(ip,False)
        if(user==False):
            return f"user not found. {self.convs_dict}", 404
        return user[convId]