summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxtekky <98614666+xtekky@users.noreply.github.com>2023-05-21 19:48:10 +0200
committerGitHub <noreply@github.com>2023-05-21 19:48:10 +0200
commit9b6848766d42a48bae86815dcdc9052abda1d27d (patch)
tree4cd1e4eea73cb963046bab903448058558ea513a
parentMerge pull request #578 from ezerinz/main (diff)
parentUpdate readme (diff)
downloadgpt4free-9b6848766d42a48bae86815dcdc9052abda1d27d.tar
gpt4free-9b6848766d42a48bae86815dcdc9052abda1d27d.tar.gz
gpt4free-9b6848766d42a48bae86815dcdc9052abda1d27d.tar.bz2
gpt4free-9b6848766d42a48bae86815dcdc9052abda1d27d.tar.lz
gpt4free-9b6848766d42a48bae86815dcdc9052abda1d27d.tar.xz
gpt4free-9b6848766d42a48bae86815dcdc9052abda1d27d.tar.zst
gpt4free-9b6848766d42a48bae86815dcdc9052abda1d27d.zip
-rw-r--r--gpt4free/usesless/README.md18
-rw-r--r--gpt4free/usesless/__init__.py105
-rw-r--r--gpt4free/usesless/account_creation.py3
3 files changed, 106 insertions, 20 deletions
diff --git a/gpt4free/usesless/README.md b/gpt4free/usesless/README.md
index 13e9df8c..426314cb 100644
--- a/gpt4free/usesless/README.md
+++ b/gpt4free/usesless/README.md
@@ -1,22 +1,30 @@
ai.usesless.com
-to do:
+### Example: `usesless` <a name="example-usesless"></a>
-- use random user agent in header
-- make the code better I guess (?)
+### token generation
+<p>this will create account.txt that contains mail and token</p>
-### Example: `usesless` <a name="example-usesless"></a>
+```python
+import usesless
+
+usesless.Account.create(logging=True)
+```
+
+### completion
+<p>insert token from account.txt</p>
```python
import usesless
message_id = ""
+token = <TOKENHERE> # usesless.Account.create(logging=True)
while True:
prompt = input("Question: ")
if prompt == "!stop":
break
- req = usesless.Completion.create(prompt=prompt, parentMessageId=message_id)
+ req = usesless.Completion.create(prompt=prompt, parentMessageId=message_id, token=token)
print(f"Answer: {req['text']}")
message_id = req["id"]
diff --git a/gpt4free/usesless/__init__.py b/gpt4free/usesless/__init__.py
index 40e99938..7c61936e 100644
--- a/gpt4free/usesless/__init__.py
+++ b/gpt4free/usesless/__init__.py
@@ -1,22 +1,87 @@
+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 Completion:
- 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": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0",
- }
+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:
+ time.sleep(5)
+ 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 = "",
@@ -24,7 +89,17 @@ class Completion:
temperature: float = 1,
model: str = "gpt-3.5-turbo",
):
- print(parentMessageId, prompt)
+ 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": "",
@@ -41,14 +116,14 @@ class Completion:
}
url = "https://ai.usesless.com/api/chat-process"
- request = requests.post(url, headers=Completion.headers, json=json_data)
+ request = requests.post(url, headers=headers, json=json_data)
content = request.content
response = Completion.__response_to_json(content)
return response
@classmethod
- def __response_to_json(cls, text) -> dict:
+ def __response_to_json(cls, text) -> str:
text = str(text.decode("utf-8"))
split_text = text.rsplit("\n", 1)[1]
diff --git a/gpt4free/usesless/account_creation.py b/gpt4free/usesless/account_creation.py
new file mode 100644
index 00000000..05819453
--- /dev/null
+++ b/gpt4free/usesless/account_creation.py
@@ -0,0 +1,3 @@
+import usesless
+
+usesless.Account.create(logging=True)