forked from snowby666/poe-api-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
177 lines (148 loc) · 9.93 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from poe_api_wrapper import PoeApi
import unittest, random, string, loguru
loguru.logger.disable('poe_api_wrapper')
TOKEN = input("Enter your token: ")
def testObjectGenerator(length):
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
class PoeApiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.botName = testObjectGenerator(20)
cls.botName2 = testObjectGenerator(20)
print("Initializing tests")
def test_get_subscription_info(self):
client = PoeApi(cookie=TOKEN)
client.get_channel_settings()
client.subscribe()
def test_get_available_bots(self):
client = PoeApi(cookie=TOKEN)
client.get_available_bots()
def test_get_available_categories(self):
client = PoeApi(cookie=TOKEN)
client.get_available_categories()
def test_get_user_bots(self):
client = PoeApi(cookie=TOKEN)
client.get_user_bots(user='poe')
def test_explore(self):
client = PoeApi(cookie=TOKEN)
client.explore(count=10)
client.explore(search="Midjourney", count=30)
client.explore(categoryName="Popular", count=30)
client.explore(search="Poe", entity_type='user', count=30)
def test_get_chat_history(self):
client = PoeApi(cookie=TOKEN)
client.get_chat_history(count=200)
def test_send_message(self):
client = PoeApi(cookie=TOKEN)
for _ in client.send_message(bot='a2', message='Nice to meet you. Write a 100 word essay about the moon', suggest_replies=True):
pass
def test_upload_file(self):
client = PoeApi(cookie=TOKEN)
file_urls = ["https://sweet.ua.pt/jpbarraca/course/er-2122/slides/er-1-intro_to_re.pdf",
"https://www.kcl.ac.uk/warstudies/assets/automation-and-artificial-intelligence.pdf"]
for _ in client.send_message(bot="a2", message="Compare 2 files and describe them in 100 words", file_path=file_urls):
pass
def test_get_threadData(self):
client = PoeApi(cookie=TOKEN)
client.get_threadData(bot="a2")
def test_cancel_message(self):
client = PoeApi(cookie=TOKEN)
i = 0
for chunk in client.send_message(bot="a2", message="What is the meaning of life (100 words)?"):
i += 1
if i >= 2:
client.cancel_message(chunk)
break
def test_retry_message(self):
client = PoeApi(cookie=TOKEN)
for _ in client.send_message(bot="capybara", message="Explain Quantaum Mechanics in 50 words"):
pass
chatCode = client.get_chat_history("capybara")['data']['capybara'][0]['chatCode']
for _ in client.retry_message(chatCode=chatCode):
pass
def test_clear_conversation(self):
client = PoeApi(cookie=TOKEN)
chatCode = client.get_chat_history("a2")['data']['a2'][0]['chatCode']
client.chat_break(bot="a2", chatCode=chatCode)
def test_purge_conversation(self):
client = PoeApi(cookie=TOKEN)
chatCode = client.get_chat_history("a2")['data']['a2'][0]['chatCode']
client.purge_conversation(bot="a2", chatCode=chatCode)
def test_get_previous_messages(self):
client = PoeApi(cookie=TOKEN)
chatCode = client.get_chat_history("a2")['data']['a2'][0]['chatCode']
client.get_previous_messages('a2', chatCode=chatCode, count=2)
def test_upload_knowledge(self):
client = PoeApi(cookie=TOKEN)
# Web urls
file_urls = ["https://sweet.ua.pt/jpbarraca/course/er-2122/slides/er-1-intro_to_re.pdf",
"https://www.kcl.ac.uk/warstudies/assets/automation-and-artificial-intelligence.pdf"]
client.upload_knowledge(file_path=file_urls)
# Text knowledge
knowledges = [
{
"title": "What is Quora?",
"content": "Quora is a popular online platform that enables users to ask questions on various topics and receive answers from a diverse community. It covers a wide range of subjects, from academic and professional queries to personal experiences and opinions, fostering knowledge-sharing and meaningful discussions among its users worldwide."
},
{
"title": "Founders of Quora",
"content": "Quora was founded by two individuals, Adam D'Angelo and Charlie Cheever. Adam D'Angelo, who previously served as the Chief Technology Officer (CTO) at Facebook, and Charlie Cheever, a former Facebook employee as well, launched Quora in June 2009. They aimed to create a platform that would enable users to ask questions and receive high-quality answers from knowledgeable individuals. Since its inception, Quora has grown into a widely used question-and-answer platform with a large user base and a diverse range of topics covered."
},
]
client.upload_knowledge(text_knowledge=knowledges)
def test_edit_knowledge(self):
client = PoeApi(cookie=TOKEN)
knowledges = [
{
"title": "What is Quora?",
"content": "Quora is a popular online platform that enables users to ask questions on various topics and receive answers from a diverse community. It covers a wide range of subjects, from academic and professional queries to personal experiences and opinions, fostering knowledge-sharing and meaningful discussions among its users worldwide."
},
{
"title": "Founders of Quora",
"content": "Quora was founded by two individuals, Adam D'Angelo and Charlie Cheever. Adam D'Angelo, who previously served as the Chief Technology Officer (CTO) at Facebook, and Charlie Cheever, a former Facebook employee as well, launched Quora in June 2009. They aimed to create a platform that would enable users to ask questions and receive high-quality answers from knowledgeable individuals. Since its inception, Quora has grown into a widely used question-and-answer platform with a large user base and a diverse range of topics covered."
},
]
source_ids = client.upload_knowledge(text_knowledge=knowledges)
client.edit_knowledge(knowledgeSourceId=source_ids['What is Quora?'][-1], title='What is Quora?', content='Quora is a question-and-answer platform where users can ask questions, provide answers, and engage in discussions on various topics.')
def test_create_bot(self):
client = PoeApi(cookie=TOKEN)
knowledges = [
{
"title": "What is Quora?",
"content": "Quora is a popular online platform that enables users to ask questions on various topics and receive answers from a diverse community. It covers a wide range of subjects, from academic and professional queries to personal experiences and opinions, fostering knowledge-sharing and meaningful discussions among its users worldwide."
},
{
"title": "Founders of Quora",
"content": "Quora was founded by two individuals, Adam D'Angelo and Charlie Cheever. Adam D'Angelo, who previously served as the Chief Technology Officer (CTO) at Facebook, and Charlie Cheever, a former Facebook employee as well, launched Quora in June 2009. They aimed to create a platform that would enable users to ask questions and receive high-quality answers from knowledgeable individuals. Since its inception, Quora has grown into a widely used question-and-answer platform with a large user base and a diverse range of topics covered."
},
]
source_ids = client.upload_knowledge(text_knowledge=knowledges)
client.create_bot(handle=self.botName, prompt='You are a helpful assitant', base_model='a2', knowledgeSourceIds=source_ids)
def test_get_available_knowledge(self):
client = PoeApi(cookie=TOKEN)
client.get_available_knowledge(botName=self.botName)
def test_delete_bot(self):
client = PoeApi(cookie=TOKEN)
client.delete_bot(handle=self.botName)
def test_edit_bot(self):
client = PoeApi(cookie=TOKEN)
knowledges = [
{
"title": "What is Quora?",
"content": "Quora is a popular online platform that enables users to ask questions on various topics and receive answers from a diverse community. It covers a wide range of subjects, from academic and professional queries to personal experiences and opinions, fostering knowledge-sharing and meaningful discussions among its users worldwide."
},
{
"title": "Founders of Quora",
"content": "Quora was founded by two individuals, Adam D'Angelo and Charlie Cheever. Adam D'Angelo, who previously served as the Chief Technology Officer (CTO) at Facebook, and Charlie Cheever, a former Facebook employee as well, launched Quora in June 2009. They aimed to create a platform that would enable users to ask questions and receive high-quality answers from knowledgeable individuals. Since its inception, Quora has grown into a widely used question-and-answer platform with a large user base and a diverse range of topics covered."
},
]
source_ids = client.upload_knowledge(text_knowledge=knowledges)
client.create_bot(handle=self.botName2, prompt='You are a helpful assitant', base_model='a2', knowledgeSourceIds=source_ids)
client.edit_bot(handle=self.botName2, prompt='You are a helpful assitant', base_model='chinchilla', knowledgeSourceIdsToRemove=source_ids)
client.delete_bot(handle=self.botName2)
def test_shareCode(self):
client = PoeApi(cookie=TOKEN)
chatCode = client.get_chat_history("capybara")['data']['capybara'][0]['chatCode']
shareCode = client.share_chat("capybara", chatCode=chatCode, count=2)
client.import_chat("capybara", shareCode=shareCode)
unittest.main(verbosity=2)