返回提交历史
Modified
README.md
+29
-21
Modified
quora/__init__.py
+106
-12
Modified
quora/cookies.txt
+5
-0
Modified
requirements.txt
+1
-1
Added
testing/quora_test_2.py
+18
-0
XFEstudio/gpt4free
quora (poe) [gpt-4/3.5] create bot feature
added create bot feature quora.Model.create new model names: { 'sage' : 'capybara', 'gpt-4' : 'beaver', 'claude-v1.2' : 'a2_2', 'claude-instant-v1.0' : 'a2', 'gpt-3.5-turbo' : 'chinchilla' }
081dfff8
代码差异
5 个文件
+159
-34
@@ -6,7 +6,7 @@ This repository provides reverse-engineered language models from various sources
6
6
7
7
## To-Do List
8
8
9
- [ ] implement poe.com create bot feature (4)
9
- [x] implement poe.com create bot feature (4) AVAILABLE NOW
10
10
- [ ] poe.com chat history management (3)
11
11
- [x] renaming the 'poe' module to 'quora' (2)
12
12
- [x] add you.com api (1)
@@ -47,31 +47,41 @@ These sites will be reverse engineered but need account access:
47
47
### Example: `quora (poe)` (use like openai pypi package) - GPT-4 <a name="example-poe"></a>
48
48
49
49
```python
50
# Import quora (poe)
51
import quora
50
# quora model names: (use left key as argument)
51
models = {
52
'sage' : 'capybara',
53
'gpt-4' : 'beaver',
54
'claude-v1.2' : 'a2_2',
55
'claude-instant-v1.0' : 'a2',
56
'gpt-3.5-turbo' : 'chinchilla'
57
}
58
```
52
59
53
# quora.Account.create
54
# quora.Completion.create
55
# quora.StreamCompletion.create
60
#### !! new: bot creation
56
61
57
[...]
62
```python
63
# import quora (poe) package
64
import quora
58
65
59
```
66
# create account
67
# make shure to set enable_bot_creation to True
68
token = quora.Account.create(logging = True, enable_bot_creation=True)
60
69
61
#### Create Token (3-6s)
62
```python
63
token = quora.Account.create(logging = True)
64
print('token', token)
65
```
70
model = quora.Model.create(
71
token = token,
72
model = 'gpt-3.5-turbo', # or claude-instant-v1.0
73
system_prompt = 'you are ChatGPT a large language model ...'
74
)
66
75
67
#### Streaming Response
68
```python
76
print(model.name) # gptx....
69
77
70
for response in quora.StreamingCompletion.create(model = 'gpt-4',
71
prompt = 'hello world',
72
token = token):
78
# streaming response
79
for response in quora.StreamingCompletion.create(
80
custom_model = model.name,
81
prompt ='hello world',
82
token = token):
73
83
74
print(response.completion.choices[0].text, end="", flush=True)
84
print(response.completion.choices[0].text)
75
85
```
76
86
77
87
#### Normal Response:
@@ -84,8 +94,6 @@ response = quora.Completion.create(model = 'gpt-4',
84
94
print(response.completion.choices[0].text)
85
95
```
86
96
87
88
89
97
### Example: `t3nsor` (use like openai pypi package) <a name="example-t3nsor"></a>
90
98
91
99
```python
@@ -3,11 +3,12 @@ from quora.mail import Mail
3
3
from requests import Session
4
4
from re import search, findall
5
5
from json import loads
6
from time import sleep, time
6
from time import sleep
7
7
from pathlib import Path
8
from random import choice
8
from random import choice, choices, randint
9
from string import ascii_letters, digits
9
10
from urllib import parse
10
11
11
12
class PoeResponse:
12
13
13
14
class Completion:
@@ -48,8 +49,88 @@ class PoeResponse:
48
49
def json(self) -> dict:
49
50
return self.response_dict
50
51
52
53
class ModelResponse:
54
def __init__(self, json_response: dict) -> None:
55
self.id = json_response['data']['poeBotCreate']['bot']['id']
56
self.name = json_response['data']['poeBotCreate']['bot']['displayName']
57
self.limit = json_response['data']['poeBotCreate']['bot']['messageLimit']['dailyLimit']
58
self.deleted = json_response['data']['poeBotCreate']['bot']['deletionState']
59
60
class Model:
61
def create(
62
token: str,
63
model: str = 'gpt-3.5-turbo', # claude-instant
64
system_prompt: str = 'You are ChatGPT a large language model developed by Openai. Answer as consisely as possible',
65
description: str = 'gpt-3.5 language model from openai, skidded by poe.com',
66
handle: str = None) -> ModelResponse:
67
68
models = {
69
'gpt-3.5-turbo' : 'chinchilla',
70
'claude-instant-v1.0': 'a2'
71
}
72
73
if not handle:
74
handle = f'gptx{randint(1111111, 9999999)}'
75
76
client = Session()
77
client.cookies['p-b'] = token
78
79
settings = client.get('https://poe.com/api/settings').json()
80
81
client.headers = {
82
"host" : "poe.com",
83
"origin" : "https://poe.com",
84
"referer" : "https://poe.com/",
85
"content-type" : "application/json",
86
"poe-formkey" : settings['formkey'],
87
"poe-tchannel" : settings['tchannelData']['channel'],
88
"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
89
"connection" : "keep-alive",
90
"sec-ch-ua" : "\"Chromium\";v=\"112\", \"Google Chrome\";v=\"112\", \"Not:A-Brand\";v=\"99\"",
91
"sec-ch-ua-mobile" : "?0",
92
"sec-ch-ua-platform": "\"macOS\"",
93
"sec-fetch-site" : "same-origin",
94
"sec-fetch-mode" : "cors",
95
"sec-fetch-dest" : "empty",
96
"accept" : "*/*",
97
"accept-encoding" : "gzip, deflate, br",
98
"accept-language" : "en-GB,en-US;q=0.9,en;q=0.8",
99
}
100
101
response = client.post("https://poe.com/api/gql_POST", json = {
102
'queryName': 'CreateBotMain_poeBotCreate_Mutation',
103
'variables': {
104
'model' : models[model],
105
'handle' : handle,
106
'prompt' : system_prompt,
107
'isPromptPublic' : True,
108
'introduction' : '',
109
'description' : description,
110
'profilePictureUrl' : 'https://qph.fs.quoracdn.net/main-qimg-24e0b480dcd946e1cc6728802c5128b6',
111
'apiUrl' : None,
112
'apiKey' : ''.join(choices(ascii_letters + digits, k = 32)),
113
'isApiBot' : False,
114
'hasLinkification' : False,
115
'hasMarkdownRendering' : False,
116
'hasSuggestedReplies' : False,
117
'isPrivateBot' : False
118
},
119
'query': 'mutation CreateBotMain_poeBotCreate_Mutation(\n $model: String!\n $handle: String!\n $prompt: String!\n $isPromptPublic: Boolean!\n $introduction: String!\n $description: String!\n $profilePictureUrl: String\n $apiUrl: String\n $apiKey: String\n $isApiBot: Boolean\n $hasLinkification: Boolean\n $hasMarkdownRendering: Boolean\n $hasSuggestedReplies: Boolean\n $isPrivateBot: Boolean\n) {\n poeBotCreate(model: $model, handle: $handle, promptPlaintext: $prompt, isPromptPublic: $isPromptPublic, introduction: $introduction, description: $description, profilePicture: $profilePictureUrl, apiUrl: $apiUrl, apiKey: $apiKey, isApiBot: $isApiBot, hasLinkification: $hasLinkification, hasMarkdownRendering: $hasMarkdownRendering, hasSuggestedReplies: $hasSuggestedReplies, isPrivateBot: $isPrivateBot) {\n status\n bot {\n id\n ...BotHeader_bot\n }\n }\n}\n\nfragment BotHeader_bot on Bot {\n displayName\n messageLimit {\n dailyLimit\n }\n ...BotImage_bot\n ...BotLink_bot\n ...IdAnnotation_node\n ...botHelpers_useViewerCanAccessPrivateBot\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotImage_bot on Bot {\n displayName\n ...botHelpers_useDeletion_bot\n ...BotImage_useProfileImage_bot\n}\n\nfragment BotImage_useProfileImage_bot on Bot {\n image {\n __typename\n ... on LocalBotImage {\n localName\n }\n ... on UrlBotImage {\n url\n }\n }\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotLink_bot on Bot {\n displayName\n}\n\nfragment IdAnnotation_node on Node {\n __isNode: __typename\n id\n}\n\nfragment botHelpers_useDeletion_bot on Bot {\n deletionState\n}\n\nfragment botHelpers_useViewerCanAccessPrivateBot on Bot {\n isPrivateBot\n viewerIsCreator\n}\n',
120
})
121
122
if not 'success' in response.text:
123
raise Exception('''
124
Bot creation Failed
125
!! Important !!
126
Bot creation was not enabled on this account
127
please use: quora.Account.create with enable_bot_creation set to True
128
''')
129
130
return ModelResponse(response.json())
131
51
132
class Account:
52
def create(proxy: None or str = None, logging: bool = False):
133
def create(proxy: None or str = None, logging: bool = False, enable_bot_creation: bool = False):
53
134
54
135
client = Session()
55
136
client.proxies = {
@@ -133,6 +214,13 @@ class Account:
133
214
with open(Path(__file__).resolve().parent / 'cookies.txt', 'a') as f:
134
215
f.write(f'{token}\n')
135
216
217
if enable_bot_creation:
218
client.post("https://poe.com/api/gql_POST", json = {
219
"queryName": "UserProfileConfigurePreviewModal_markMultiplayerNuxCompleted_Mutation",
220
"variables": {},
221
"query": "mutation UserProfileConfigurePreviewModal_markMultiplayerNuxCompleted_Mutation {\n markMultiplayerNuxCompleted {\n viewer {\n hasCompletedMultiplayerNux\n id\n }\n }\n}\n"
222
})
223
136
224
return token
137
225
138
226
def get():
@@ -142,17 +230,20 @@ class Account:
142
230
class StreamingCompletion:
143
231
def create(
144
232
model : str = 'gpt-4',
233
custom_model : str = None,
145
234
prompt: str = 'hello world',
146
235
token : str = ''):
147
236
148
237
models = {
149
238
'sage' : 'capybara',
150
239
'gpt-4' : 'beaver',
151
'claude+': 'a2_2',
152
'claude' : 'a2',
153
'gpt-3.5': 'chinchilla'
240
'claude-v1.2' : 'a2_2',
241
'claude-instant-v1.0' : 'a2',
242
'gpt-3.5-turbo' : 'chinchilla'
154
243
}
155
244
245
_model = models[model] if not custom_model else custom_model
246
156
247
client = PoeClient(token)
157
248
158
249
for chunk in client.send_message(models[model], prompt):
@@ -161,7 +252,7 @@ class StreamingCompletion:
161
252
'id' : chunk["messageId"],
162
253
'object' : 'text_completion',
163
254
'created': chunk['creationTime'],
164
'model' : models[model],
255
'model' : _model,
165
256
'choices': [{
166
257
'text' : chunk["text_new"],
167
258
'index' : 0,
@@ -178,17 +269,20 @@ class StreamingCompletion:
178
269
class Completion:
179
270
def create(
180
271
model : str = 'gpt-4',
272
custom_model : str = None,
181
273
prompt: str = 'hello world',
182
274
token : str = ''):
183
275
184
276
models = {
185
277
'sage' : 'capybara',
186
278
'gpt-4' : 'beaver',
187
'claude+': 'a2_2',
188
'claude' : 'a2',
189
'gpt-3.5': 'chinchilla'
279
'claude-v1.2' : 'a2_2',
280
'claude-instant-v1.0' : 'a2',
281
'gpt-3.5-turbo' : 'chinchilla'
190
282
}
191
283
284
_model = models[model] if not custom_model else custom_model
285
192
286
client = PoeClient(token)
193
287
194
288
for chunk in client.send_message(models[model], prompt):
@@ -198,7 +292,7 @@ class Completion:
198
292
'id' : chunk["messageId"],
199
293
'object' : 'text_completion',
200
294
'created': chunk['creationTime'],
201
'model' : models[model],
295
'model' : _model,
202
296
'choices': [{
203
297
'text' : chunk["text"],
204
298
'index' : 0,
@@ -8,3 +8,8 @@ pUEbtxobN_QUSpLIR8RGww==
8
8
9_dUWxKkHHhpQRSvCvBk2Q==
9
9
UV45rvGwUwi2qV9QdIbMcw==
10
10
cVIN0pK1Wx-F7zCdUxlYqA==
11
UP2wQVds17VFHh6IfCQFrA==
12
18eKr0ME2Tzifdfqat38Aw==
13
FNgKEpc2r-XqWe0rHBfYpg==
14
juCAh6kB0sUpXHvKik2woA==
15
nBvuNYRLaE4xE4HuzBPiIQ==
@@ -1,3 +1,3 @@
1
1
websocket-client
2
2
requests
3
tls-client
3
tls-client
@@ -0,0 +1,18 @@
1
import quora
2
3
token = quora.Account.create(logging = True, enable_bot_creation=True)
4
5
model = quora.Model.create(
6
token = token,
7
model = 'gpt-3.5-turbo', # or claude-instant-v1.0
8
system_prompt = 'you are ChatGPT a large language model ...'
9
)
10
11
print(model.name)
12
13
for response in quora.StreamingCompletion.create(
14
custom_model = model.name,
15
prompt ='hello world',
16
token = token):
17
18
print(response.completion.choices[0].text)