File size: 2,161 Bytes
3164c55
 
70629ed
3164c55
 
70629ed
3164c55
 
 
 
ab1d89e
70629ed
3164c55
 
 
c477d00
 
 
 
 
 
b705433
c477d00
 
 
 
 
b705433
c477d00
 
3164c55
c477d00
 
 
 
 
 
 
 
70629ed
 
 
 
 
 
 
 
 
b705433
70629ed
 
 
 
 
b705433
70629ed
 
 
 
 
 
 
 
 
 
ab1d89e
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from poe_api_wrapper import PoeApi
from App.Chat.Schemas import BotRequest
import re

# import pprint
pattern = r"\!\[.*?\]\((.*?)\)"


client = PoeApi("sXvCnfYy8CHnXNTRlxhmVg==")
CHAT_CODE = ""
# print(client.get_chat_history()["data"])
GEN_CODE = ""


async def SendMessage(req: BotRequest):
    global CHAT_CODE, client
    counter = 0
    while True:
        try:
            if CHAT_CODE == "":
                for chunk in client.send_message(
                    req.bot, req.message, chatCode="2rx4w5jt6zf96tn7dr1", file_path=req.file_upload
                ):
                    pass
                CHAT_CODE = chunk["chatCode"]
            else:
                for chunk in client.send_message(
                    req.bot, req.message, chatCode=CHAT_CODE, file_path=req.file_upload
                ):
                    pass

            return {"response": chunk["text"], "code": 200}
        except:
            if counter > 4:
                return {"response": "Try again later", "code": 500}
            client = PoeApi("sXvCnfYy8CHnXNTRlxhmVg==")
            CHAT_CODE = ""
            counter += 1
            print(client.get_chat_history()["data"])


async def GenerateImage(req: BotRequest):
    global GEN_CODE, client
    counter = 0
    while True:
        try:
            if GEN_CODE == "":
                for chunk in client.send_message(
                    req.bot, req.message, chatCode="2rx4w5jt6zf96tn7dr1", file_path=req.file_upload
                ):
                    pass
                GEN_CODE = chunk["chatCode"]
            else:
                for chunk in client.send_message(
                    req.bot, req.message, chatCode=GEN_CODE, file_path=req.file_upload
                ):
                    pass

            return {"response": re.findall(pattern, chunk["response"])[0], "code": 200}
        except:
            if counter > 4:
                return {"response": "Try again later", "code": 500}
            client = PoeApi("sXvCnfYy8CHnXNTRlxhmVg==")
            GEN_CODE = ""
            counter += 1
            client.get_chat_history()
            # print(client.get_chat_history()["data"])