diff options
Diffstat (limited to 'gpt4free')
-rw-r--r-- | gpt4free/__init__.py | 7 | ||||
-rw-r--r-- | gpt4free/forefront/README.md | 9 | ||||
-rw-r--r-- | gpt4free/forefront/__init__.py | 31 | ||||
-rw-r--r-- | gpt4free/forefront/typing.py | 3 | ||||
-rw-r--r-- | gpt4free/quora/README.md | 9 | ||||
-rw-r--r-- | gpt4free/quora/__init__.py | 27 | ||||
-rw-r--r-- | gpt4free/quora/api.py | 6 | ||||
-rw-r--r-- | gpt4free/quora/backup-mail.py | 30 | ||||
-rw-r--r-- | gpt4free/quora/graphql/SettingsDeleteAccountButton_deleteAccountMutation_Mutation.graphql | 1 | ||||
-rw-r--r-- | gpt4free/test.py | 4 | ||||
-rw-r--r-- | gpt4free/theb/README.md | 9 | ||||
-rw-r--r-- | gpt4free/theb/__init__.py | 29 | ||||
-rw-r--r-- | gpt4free/usesless/__init__.py | 9 | ||||
-rw-r--r-- | gpt4free/you/__init__.py | 4 |
14 files changed, 115 insertions, 63 deletions
diff --git a/gpt4free/__init__.py b/gpt4free/__init__.py index b4742b64..6df778e3 100644 --- a/gpt4free/__init__.py +++ b/gpt4free/__init__.py @@ -4,8 +4,8 @@ from gpt4free import cocalc from gpt4free import forefront from gpt4free import quora from gpt4free import theb -from gpt4free import you from gpt4free import usesless +from gpt4free import you class Provider(Enum): @@ -24,7 +24,6 @@ class Completion: @staticmethod def create(provider: Provider, prompt: str, **kwargs) -> str: - """ Invokes the given provider with given prompt and addition arguments and returns the string response @@ -47,10 +46,10 @@ class Completion: return Completion.__useless_service(prompt, **kwargs) else: raise Exception('Provider not exist, Please try again') - + @staticmethod def __useless_service(prompt: str, **kwargs) -> str: - return usesless.Completion.create(prompt = prompt, **kwargs) + return usesless.Completion.create(prompt=prompt, **kwargs) @staticmethod def __you_service(prompt: str, **kwargs) -> str: diff --git a/gpt4free/forefront/README.md b/gpt4free/forefront/README.md index 35ba9897..887097ec 100644 --- a/gpt4free/forefront/README.md +++ b/gpt4free/forefront/README.md @@ -6,8 +6,11 @@ from gpt4free import forefront token = forefront.Account.create(logging=False) print(token) # get a response -for response in forefront.StreamingCompletion.create(token=token, - prompt='hello world', model='gpt-4'): - print(response.completion.choices[0].text, end='') +for response in forefront.StreamingCompletion.create( + token=token, + prompt='hello world', + model='gpt-4' +): + print(response.choices[0].text, end='') print("") ```
\ No newline at end of file diff --git a/gpt4free/forefront/__init__.py b/gpt4free/forefront/__init__.py index 969b33b8..dbf1730b 100644 --- a/gpt4free/forefront/__init__.py +++ b/gpt4free/forefront/__init__.py @@ -1,14 +1,13 @@ from json import loads +from xtempmail import Email from re import findall +from typing import Optional, Generator +from faker import Faker from time import time, sleep -from typing import Generator, Optional from uuid import uuid4 - from fake_useragent import UserAgent from requests import post -from pymailtm import MailTm, Message from tls_client import Session - from .typing import ForeFrontResponse @@ -16,11 +15,13 @@ class Account: @staticmethod def create(proxy: Optional[str] = None, logging: bool = False): proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False + faker = Faker() + name = (faker.name().replace(' ', '_')).lower() start = time() - mail_client = MailTm().get_account() - mail_address = mail_client.address + mail_client = Email(name=name) + mail_address = mail_client.email client = Session(client_identifier='chrome110') client.proxies = proxies @@ -54,21 +55,17 @@ class Account: if 'sign_up_attempt' not in response.text: return 'Failed to create account!' - - while True: - sleep(1) - new_message: Message = mail_client.wait_for_message() - if logging: - print(new_message.data['id']) - - verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', new_message.text)[0] - + verification_url = None + new_message = mail_client.get_new_message(5) + for msg in new_message: + verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', msg.text)[0] if verification_url: break - + + if verification_url is None or not verification_url: + raise RuntimeError('Error while obtaining verfication URL!') if logging: print(verification_url) - response = client.get(verification_url) response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4') diff --git a/gpt4free/forefront/typing.py b/gpt4free/forefront/typing.py index a9025419..23e90903 100644 --- a/gpt4free/forefront/typing.py +++ b/gpt4free/forefront/typing.py @@ -1,4 +1,5 @@ from typing import Any, List + from pydantic import BaseModel @@ -22,4 +23,4 @@ class ForeFrontResponse(BaseModel): model: str choices: List[Choice] usage: Usage - text: str
\ No newline at end of file + text: str diff --git a/gpt4free/quora/README.md b/gpt4free/quora/README.md index 9c652c59..88fd0093 100644 --- a/gpt4free/quora/README.md +++ b/gpt4free/quora/README.md @@ -65,4 +65,13 @@ poe.chat('who won the football world cup most?') # new bot creation poe.create_bot('new_bot_name', prompt='You are new test bot', base_model='gpt-3.5-turbo') +# delete account +poe.delete_account() +``` + +### Deleting the Poe Account +```python +from gpt4free import quora + +quora.Account.delete(token='') ``` diff --git a/gpt4free/quora/__init__.py b/gpt4free/quora/__init__.py index afbfb68d..5d9e80c1 100644 --- a/gpt4free/quora/__init__.py +++ b/gpt4free/quora/__init__.py @@ -104,8 +104,8 @@ class Model: def create( token: str, model: str = 'gpt-3.5-turbo', # claude-instant - system_prompt: str = 'You are ChatGPT a large language model developed by Openai. Answer as consisely as possible', - description: str = 'gpt-3.5 language model from openai, skidded by poe.com', + system_prompt: str = 'You are ChatGPT a large language model. Answer as consisely as possible', + description: str = 'gpt-3.5 language model', handle: str = None, ) -> ModelResponse: if not handle: @@ -285,6 +285,11 @@ class Account: cookies = open(Path(__file__).resolve().parent / 'cookies.txt', 'r').read().splitlines() return choice(cookies) + @staticmethod + def delete(token: str, proxy: Optional[str] = None): + client = PoeClient(token, proxy=proxy) + client.delete_account() + class StreamingCompletion: @staticmethod @@ -293,11 +298,11 @@ class StreamingCompletion: custom_model: bool = None, prompt: str = 'hello world', token: str = '', - proxy: Optional[str] = None + proxy: Optional[str] = None, ) -> Generator[PoeResponse, None, None]: _model = MODELS[model] if not custom_model else custom_model - proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else False + proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False client = PoeClient(token) client.proxy = proxies @@ -333,7 +338,7 @@ class Completion: custom_model: str = None, prompt: str = 'hello world', token: str = '', - proxy: Optional[str] = None + proxy: Optional[str] = None, ) -> PoeResponse: _model = MODELS[model] if not custom_model else custom_model @@ -454,14 +459,7 @@ class Poe: response = chunk['text'] return response - def create_bot( - self, - name: str, - /, - prompt: str = '', - base_model: str = 'ChatGPT', - description: str = '', - ) -> None: + def create_bot(self, name: str, /, prompt: str = '', base_model: str = 'ChatGPT', description: str = '') -> None: if base_model not in MODELS: raise RuntimeError('Sorry, the base_model you provided does not exist. Please check and try again.') @@ -475,3 +473,6 @@ class Poe: def list_bots(self) -> list: return list(self.client.bot_names.values()) + + def delete_account(self) -> None: + self.client.delete_account() diff --git a/gpt4free/quora/api.py b/gpt4free/quora/api.py index d19172ce..9e3c0b91 100644 --- a/gpt4free/quora/api.py +++ b/gpt4free/quora/api.py @@ -548,5 +548,11 @@ class Client: self.get_bots() return data + def delete_account(self) -> None: + response = self.send_query('SettingsDeleteAccountButton_deleteAccountMutation_Mutation', {}) + data = response['data']['deleteAccount'] + if 'viewer' not in data: + raise RuntimeError(f'Error occurred while deleting the account, Please try again!') + load_queries() diff --git a/gpt4free/quora/backup-mail.py b/gpt4free/quora/backup-mail.py index 0a2a5e94..25d526d7 100644 --- a/gpt4free/quora/backup-mail.py +++ b/gpt4free/quora/backup-mail.py @@ -1,7 +1,10 @@ -from requests import Session
-from time import sleep
from json import loads
from re import findall
+from time import sleep
+
+from requests import Session
+
+
class Mail:
def __init__(self) -> None:
self.client = Session()
@@ -9,29 +12,34 @@ class Mail: self.cookies = {'acceptcookie': 'true'}
self.cookies["ci_session"] = self.client.cookies.get_dict()["ci_session"]
self.email = None
+
def get_mail(self):
- respone=self.client.post("https://etempmail.com/getEmailAddress")
- #cookies
+ respone = self.client.post("https://etempmail.com/getEmailAddress")
+ # cookies
self.cookies["lisansimo"] = eval(respone.text)["recover_key"]
self.email = eval(respone.text)["address"]
return self.email
+
def get_message(self):
print("Waiting for message...")
while True:
sleep(5)
- respone=self.client.post("https://etempmail.com/getInbox")
- mail_token=loads(respone.text)
+ respone = self.client.post("https://etempmail.com/getInbox")
+ mail_token = loads(respone.text)
print(self.client.cookies.get_dict())
if len(mail_token) == 1:
break
-
- params = {'id': '1',}
- self.mail_context = self.client.post("https://etempmail.com/getInbox",params=params)
+
+ params = {
+ 'id': '1',
+ }
+ self.mail_context = self.client.post("https://etempmail.com/getInbox", params=params)
self.mail_context = eval(self.mail_context.text)[0]["body"]
return self.mail_context
- #,cookies=self.cookies
+
+ # ,cookies=self.cookies
def get_verification_code(self):
message = self.mail_context
code = findall(r';">(\d{6,7})</div>', message)[0]
print(f"Verification code: {code}")
- return code
\ No newline at end of file + return code
diff --git a/gpt4free/quora/graphql/SettingsDeleteAccountButton_deleteAccountMutation_Mutation.graphql b/gpt4free/quora/graphql/SettingsDeleteAccountButton_deleteAccountMutation_Mutation.graphql new file mode 100644 index 00000000..0af50950 --- /dev/null +++ b/gpt4free/quora/graphql/SettingsDeleteAccountButton_deleteAccountMutation_Mutation.graphql @@ -0,0 +1 @@ +mutation SettingsDeleteAccountButton_deleteAccountMutation_Mutation{ deleteAccount { viewer { uid id } }}
\ No newline at end of file diff --git a/gpt4free/test.py b/gpt4free/test.py new file mode 100644 index 00000000..b2516748 --- /dev/null +++ b/gpt4free/test.py @@ -0,0 +1,4 @@ +import forefront +token = forefront.Account.create() +response = forefront.Completion.create(token=token, prompt='Hello!') +print(response)
\ No newline at end of file diff --git a/gpt4free/theb/README.md b/gpt4free/theb/README.md index a4abdf62..a7af9dd8 100644 --- a/gpt4free/theb/README.md +++ b/gpt4free/theb/README.md @@ -5,7 +5,10 @@ from gpt4free import theb # simple streaming completion -for token in theb.Completion.create('hello world'): - print(token, end='', flush=True) -print("") + +while True: + x = input() + for token in theb.Completion.create(x): + print(token, end='', flush=True) + print("") ``` diff --git a/gpt4free/theb/__init__.py b/gpt4free/theb/__init__.py index 75a15068..0177194e 100644 --- a/gpt4free/theb/__init__.py +++ b/gpt4free/theb/__init__.py @@ -17,9 +17,10 @@ class Completion: timer = None message_queue = Queue() stream_completed = False + last_msg_id = None @staticmethod - def request(prompt: str, proxy: Optional[str]=None): + def request(prompt: str, proxy: Optional[str] = None): headers = { 'authority': 'chatbot.theb.ai', 'content-type': 'application/json', @@ -28,26 +29,35 @@ class Completion: } proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else None - + + options = {} + if Completion.last_msg_id: + options['parentMessageId'] = Completion.last_msg_id + requests.post( 'https://chatbot.theb.ai/api/chat-process', headers=headers, proxies=proxies, content_callback=Completion.handle_stream_response, - json={'prompt': prompt, 'options': {}}, + json={'prompt': prompt, 'options': options}, + timeout=100000 ) Completion.stream_completed = True @staticmethod - def create(prompt: str, proxy: Optional[str]=None) -> Generator[str, None, None]: + def create(prompt: str, proxy: Optional[str] = None) -> Generator[str, None, None]: + Completion.stream_completed = False + Thread(target=Completion.request, args=[prompt, proxy]).start() while not Completion.stream_completed or not Completion.message_queue.empty(): try: message = Completion.message_queue.get(timeout=0.01) for message in findall(Completion.regex, message): - yield loads(Completion.part1 + message + Completion.part2)['delta'] + message_json = loads(Completion.part1 + message + Completion.part2) + Completion.last_msg_id = message_json['id'] + yield message_json['delta'] except Empty: pass @@ -55,3 +65,12 @@ class Completion: @staticmethod def handle_stream_response(response): Completion.message_queue.put(response.decode()) + + @staticmethod + def get_response(prompt: str, proxy: Optional[str] = None) -> str: + response_list = [] + for message in Completion.create(prompt, proxy): + response_list.append(message) + return ''.join(response_list) + + Completion.message_queue.put(response.decode(errors='replace')) diff --git a/gpt4free/usesless/__init__.py b/gpt4free/usesless/__init__.py index 6029009d..40e99938 100644 --- a/gpt4free/usesless/__init__.py +++ b/gpt4free/usesless/__init__.py @@ -1,6 +1,7 @@ -import requests import json +import requests + class Completion: headers = { @@ -24,7 +25,7 @@ class Completion: model: str = "gpt-3.5-turbo", ): print(parentMessageId, prompt) - + json_data = { "openaiKey": "", "prompt": prompt, @@ -42,14 +43,14 @@ class Completion: url = "https://ai.usesless.com/api/chat-process" request = requests.post(url, headers=Completion.headers, json=json_data) content = request.content - + response = Completion.__response_to_json(content) return response @classmethod def __response_to_json(cls, text) -> dict: text = str(text.decode("utf-8")) - + split_text = text.rsplit("\n", 1)[1] to_json = json.loads(split_text) return to_json diff --git a/gpt4free/you/__init__.py b/gpt4free/you/__init__.py index d084a842..da22d05e 100644 --- a/gpt4free/you/__init__.py +++ b/gpt4free/you/__init__.py @@ -30,12 +30,12 @@ class Completion: include_links: bool = False, detailed: bool = False, debug: bool = False, - proxy: Optional[str] = None + proxy: Optional[str] = None, ) -> PoeResponse: if chat is None: chat = [] - proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else {} + proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else {} client = Session(client_identifier='chrome_108') client.headers = Completion.__get_headers() |