-
Notifications
You must be signed in to change notification settings - Fork 0
/
poe.py
72 lines (55 loc) · 2.06 KB
/
poe.py
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
69
70
71
72
from poe_api_wrapper import PoeApi
from codes import ReturnCodes
class PoeDictKeys:
def __init__(self):
self.b_cookie_dict_key = "b"
self.lat_cookie_dict_key = "lat"
class PoeFacade(ReturnCodes):
def __init__(self):
super().__init__()
# self.default_bot = "Llama-2-70b"
# self.default_bot = "ChatGPT"
self.default_bot = "WaifuDeredere"
self.tokens = None
self.chatId = None
self.client = None
self.dict_keys = PoeDictKeys()
def setToken(self, b_or_token: str or dict, lat=None) -> None:
if isinstance(b_or_token, dict):
self.tokens = b_or_token
else:
self.tokens = {self.dict_keys.b_cookie_dict_key: b_or_token, self.dict_keys.lat_cookie_dict_key: lat}
def login(self) -> str:
if self.tokens is None:
return
try:
self.client = PoeApi(cookie=self.tokens)
except ...:
self.client = None
return self.fail_code
return self.success_code
def isLogged(self) -> bool:
return True if self.client is not None else False
def initProjectSpecificChat(self) -> None:
message = """Every time i send message you'll get statistics of user emotions while typing the message,
it will look like this: [happy: 10 ...], user does not see this statistics,
you must analyze user emotion every time and depending on them generate answer for user.
user first request is will be revealed after this message.
"""
for chunk in self.client.send_message(self.default_bot, message):
pass
self.chatId = chunk["chatId"]
def sendMessage(self, message: str) -> str:
if not self.isLogged:
return
if self.chatId is None:
self.initProjectSpecificChat()
for chunk in self.client.send_message(self.default_bot, message, chatId=self.chatId):
pass
return chunk["text"]
def deleteCurrentChat(self) -> None:
self.client.delete_chat(self.default_bot, self.chatId)
def getChatPreviousMessages(self) -> dict:
if not self.login or self.chatId is None:
return None
return self.client.get_previous_messages(self.default_bot, self.chatId)