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
|
import time
import re
import json
import requests
import fake_useragent
import names
from mailgw_temporary_email import Email
from password_generator import PasswordGenerator
class Account:
@staticmethod
def create(logging: bool = False):
mail_client = Email()
mail_client.register()
mail_address = mail_client.address
pwo = PasswordGenerator()
pwo.minlen = 8
password = pwo.generate()
session = requests.Session()
if logging:
print(f"email: {mail_address}")
register_url = "https://ai.usesless.com/api/cms/auth/local/register"
register_json = {
"username": names.get_first_name(),
"password": password,
"email": mail_address,
}
headers = {
"authority": "ai.usesless.com",
"accept": "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.5",
"cache-control": "no-cache",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": fake_useragent.UserAgent().random,
}
register = session.post(register_url, json=register_json, headers=headers)
if logging:
if register.status_code == 200:
print("register success")
else:
print("there's a problem with account creation, try again")
if register.status_code != 200:
quit()
while True:
messages = mail_client.message_list()
# Check if method `message_list()` didn't return None or empty list.
if not messages or len(messages) == 0:
# If it returned None or empty list sleep for 5 seconds to wait for new message.
time.sleep(5)
continue
message_id = mail_client.message_list()[0]["id"]
message = mail_client.message(message_id)
verification_url = re.findall(
r"http:\/\/ai\.usesless\.com\/api\/cms\/auth\/email-confirmation\?confirmation=\w.+\w\w",
message["text"],
)[0]
if verification_url:
break
session.get(verification_url)
login_json = {"identifier": mail_address, "password": password}
login_request = session.post(
url="https://ai.usesless.com/api/cms/auth/local", json=login_json
)
token = login_request.json()["jwt"]
if logging:
print(f"token: {token}")
with open("accounts.txt", "w") as f:
f.write(f"{mail_address}\n")
f.write(f"{token}")
return token
class Completion:
@staticmethod
def create(
token: str,
systemMessage: str = "You are a helpful assistant",
prompt: str = "",
parentMessageId: str = "",
presence_penalty: float = 1,
temperature: float = 1,
model: str = "gpt-3.5-turbo",
):
headers = {
"authority": "ai.usesless.com",
"accept": "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.5",
"cache-control": "no-cache",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": fake_useragent.UserAgent().random,
"Authorization": f"Bearer {token}",
}
json_data = {
"openaiKey": "",
"prompt": prompt,
"options": {
"parentMessageId": parentMessageId,
"systemMessage": systemMessage,
"completionParams": {
"presence_penalty": presence_penalty,
"temperature": temperature,
"model": model,
},
},
}
url = "https://ai.usesless.com/api/chat-process"
request = requests.post(url, headers=headers, json=json_data)
request.encoding = request.apparent_encoding
content = request.content
response = Completion.__response_to_json(content)
return response
@classmethod
def __response_to_json(cls, text) -> str:
text = str(text.decode("utf-8"))
split_text = text.rsplit("\n", 1)[1]
to_json = json.loads(split_text)
return to_json
|