File size: 1,067 Bytes
4107d17
15b1979
4107d17
a2d5bfd
4107d17
 
15b1979
4107d17
 
15b1979
4107d17
 
 
15b1979
 
4107d17
 
 
15b1979
 
 
4107d17
15b1979
 
 
4107d17
 
 
 
15b1979
4107d17
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
# application/utils/convs_handler.py
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": [], "memory": ""}  # Initialize
        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]