返回提交历史
Modified
gpt4free/usesless/README.md
+15
-6
Modified
gpt4free/usesless/__init__.py
+90
-15
Added
gpt4free/usesless/account_creation.py
+3
-0
XFEstudio/gpt4free
update usesless, add function to retrieve token
7f4322e1
代码差异
3 个文件
+108
-21
@@ -1,23 +1,32 @@
1
1
ai.usesless.com
2
2
3
to do:
3
### Example: `usesless` <a name="example-usesless"></a>
4
4
5
- use random user agent in header
6
- make the code better I guess (?)
5
### create account
7
6
8
### Example: `usesless` <a name="example-usesless"></a>
7
<p>create account first, this will create account.txt that contains mail and token</p>
8
```python
9
import usesless
10
11
usesless.Account.create(logging=True)
12
13
````
14
15
### completion
16
<p>insert token from account.txt</p>
9
17
10
18
```python
11
19
import usesless
12
20
13
21
message_id = ""
22
token = <TOKENHERE> # usesless.Account.create(logging=True)
14
23
while True:
15
24
prompt = input("Question: ")
16
25
if prompt == "!stop":
17
26
break
18
27
19
req = usesless.Completion.create(prompt=prompt, parentMessageId=message_id)
28
req = usesless.Completion.create(prompt=prompt, parentMessageId=message_id, token=token)
20
29
21
30
print(f"Answer: {req['text']}")
22
31
message_id = req["id"]
23
```
32
````
@@ -1,22 +1,87 @@
1
import time
2
import re
1
3
import json
2
3
4
import requests
5
import fake_useragent
6
import names
4
7
8
from mailgw_temporary_email import Email
9
from password_generator import PasswordGenerator
5
10
6
class Completion:
7
headers = {
8
"authority": "ai.usesless.com",
9
"accept": "application/json, text/plain, */*",
10
"accept-language": "en-US,en;q=0.5",
11
"cache-control": "no-cache",
12
"sec-fetch-dest": "empty",
13
"sec-fetch-mode": "cors",
14
"sec-fetch-site": "same-origin",
15
"user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0",
16
}
17
11
12
class Account:
13
@staticmethod
14
def create(logging: bool = False):
15
mail_client = Email()
16
mail_client.register()
17
mail_address = mail_client.address
18
19
pwo = PasswordGenerator()
20
pwo.minlen = 8
21
password = pwo.generate()
22
23
session = requests.Session()
24
25
if logging:
26
print(f"email: {mail_address}")
27
28
register_url = "https://ai.usesless.com/api/cms/auth/local/register"
29
register_json = {
30
"username": names.get_first_name(),
31
"password": password,
32
"email": mail_address,
33
}
34
headers = {
35
"authority": "ai.usesless.com",
36
"accept": "application/json, text/plain, */*",
37
"accept-language": "en-US,en;q=0.5",
38
"cache-control": "no-cache",
39
"sec-fetch-dest": "empty",
40
"sec-fetch-mode": "cors",
41
"sec-fetch-site": "same-origin",
42
"user-agent": fake_useragent.UserAgent().random,
43
}
44
register = session.post(register_url, json=register_json, headers=headers)
45
if logging:
46
if register.status_code == 200:
47
print("register success")
48
else:
49
print("there's a problem with account creation, try again")
50
51
if register.status_code != 200:
52
quit()
53
54
while True:
55
time.sleep(5)
56
message_id = mail_client.message_list()[0]["id"]
57
message = mail_client.message(message_id)
58
verification_url = re.findall(
59
r"http:\/\/ai\.usesless\.com\/api\/cms\/auth\/email-confirmation\?confirmation=\w.+\w\w",
60
message["text"],
61
)[0]
62
if verification_url:
63
break
64
65
session.get(verification_url)
66
login_json = {"identifier": mail_address, "password": password}
67
login_request = session.post(
68
url="https://ai.usesless.com/api/cms/auth/local", json=login_json
69
)
70
token = login_request.json()["jwt"]
71
if logging:
72
print(f"token: {token}")
73
74
with open("accounts.txt", "w") as f:
75
f.write(f"{mail_address}\n")
76
f.write(f"{token}")
77
78
return token
79
80
81
class Completion:
18
82
@staticmethod
19
83
def create(
84
token: str,
20
85
systemMessage: str = "You are a helpful assistant",
21
86
prompt: str = "",
22
87
parentMessageId: str = "",
@@ -24,7 +89,17 @@ class Completion:
24
89
temperature: float = 1,
25
90
model: str = "gpt-3.5-turbo",
26
91
):
27
print(parentMessageId, prompt)
92
headers = {
93
"authority": "ai.usesless.com",
94
"accept": "application/json, text/plain, */*",
95
"accept-language": "en-US,en;q=0.5",
96
"cache-control": "no-cache",
97
"sec-fetch-dest": "empty",
98
"sec-fetch-mode": "cors",
99
"sec-fetch-site": "same-origin",
100
"user-agent": fake_useragent.UserAgent().random,
101
"Authorization": f"Bearer {token}",
102
}
28
103
29
104
json_data = {
30
105
"openaiKey": "",
@@ -41,14 +116,14 @@ class Completion:
41
116
}
42
117
43
118
url = "https://ai.usesless.com/api/chat-process"
44
request = requests.post(url, headers=Completion.headers, json=json_data)
119
request = requests.post(url, headers=headers, json=json_data)
45
120
content = request.content
46
121
47
122
response = Completion.__response_to_json(content)
48
123
return response
49
124
50
125
@classmethod
51
def __response_to_json(cls, text) -> dict:
126
def __response_to_json(cls, text) -> str:
52
127
text = str(text.decode("utf-8"))
53
128
54
129
split_text = text.rsplit("\n", 1)[1]
@@ -0,0 +1,3 @@
1
import usesless
2
3
usesless.Account.create(logging=True)