diff options
author | noptuno <repollo.marrero@gmail.com> | 2023-04-28 12:33:51 +0200 |
---|---|---|
committer | noptuno <repollo.marrero@gmail.com> | 2023-04-28 12:33:51 +0200 |
commit | 396d7e11b2623cf05c3b0fd4ff9b6cce667835fd (patch) | |
tree | 4d7f4531e082deba4fb6bac7e5b221d887e066d9 /openai_rev | |
parent | Remove ignored files from repository (diff) | |
parent | Merge pull request #241 from ethanx40/main (diff) | |
download | gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.gz gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.bz2 gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.lz gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.xz gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.zst gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.zip |
Diffstat (limited to '')
-rw-r--r-- | forefront/mail.py (renamed from openai_rev/forefront/mail.py) | 14 | ||||
-rw-r--r-- | openai_rev/__init__.py | 1 | ||||
-rw-r--r-- | openai_rev/forefront/README.md | 15 | ||||
-rw-r--r-- | openai_rev/forefront/__init__.py | 189 | ||||
-rw-r--r-- | openai_rev/forefront/models.py | 26 | ||||
-rw-r--r-- | openai_rev/openai_rev.py | 42 | ||||
-rw-r--r-- | quora/README.md (renamed from openai_rev/quora/README.md) | 35 | ||||
-rw-r--r-- | quora/__init__.py (renamed from openai_rev/quora/__init__.py) | 145 | ||||
-rw-r--r-- | quora/api.py (renamed from openai_rev/quora/api.py) | 62 | ||||
-rw-r--r-- | quora/cookies.txt (renamed from openai_rev/quora/cookies.txt) | 0 | ||||
-rw-r--r-- | quora/graphql/AddHumanMessageMutation.graphql (renamed from openai_rev/quora/graphql/AddHumanMessageMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/AddMessageBreakMutation.graphql (renamed from openai_rev/quora/graphql/AddMessageBreakMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/AutoSubscriptionMutation.graphql (renamed from openai_rev/quora/graphql/AutoSubscriptionMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/BioFragment.graphql (renamed from openai_rev/quora/graphql/BioFragment.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ChatAddedSubscription.graphql (renamed from openai_rev/quora/graphql/ChatAddedSubscription.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ChatFragment.graphql (renamed from openai_rev/quora/graphql/ChatFragment.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ChatListPaginationQuery.graphql (renamed from openai_rev/quora/graphql/ChatListPaginationQuery.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ChatPaginationQuery.graphql (renamed from openai_rev/quora/graphql/ChatPaginationQuery.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ChatViewQuery.graphql (renamed from openai_rev/quora/graphql/ChatViewQuery.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/DeleteHumanMessagesMutation.graphql (renamed from openai_rev/quora/graphql/DeleteHumanMessagesMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/DeleteMessageMutation.graphql (renamed from openai_rev/quora/graphql/DeleteMessageMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/HandleFragment.graphql (renamed from openai_rev/quora/graphql/HandleFragment.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/LoginWithVerificationCodeMutation.graphql (renamed from openai_rev/quora/graphql/LoginWithVerificationCodeMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/MessageAddedSubscription.graphql (renamed from openai_rev/quora/graphql/MessageAddedSubscription.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/MessageDeletedSubscription.graphql (renamed from openai_rev/quora/graphql/MessageDeletedSubscription.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/MessageFragment.graphql (renamed from openai_rev/quora/graphql/MessageFragment.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/MessageRemoveVoteMutation.graphql (renamed from openai_rev/quora/graphql/MessageRemoveVoteMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/MessageSetVoteMutation.graphql (renamed from openai_rev/quora/graphql/MessageSetVoteMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/PoeBotCreateMutation.graphql (renamed from openai_rev/quora/graphql/PoeBotCreateMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/PoeBotEditMutation.graphql (renamed from openai_rev/quora/graphql/PoeBotEditMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/SendMessageMutation.graphql (renamed from openai_rev/quora/graphql/SendMessageMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/SendVerificationCodeForLoginMutation.graphql (renamed from openai_rev/quora/graphql/SendVerificationCodeForLoginMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ShareMessagesMutation.graphql (renamed from openai_rev/quora/graphql/ShareMessagesMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/SignupWithVerificationCodeMutation.graphql (renamed from openai_rev/quora/graphql/SignupWithVerificationCodeMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/StaleChatUpdateMutation.graphql (renamed from openai_rev/quora/graphql/StaleChatUpdateMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/SubscriptionsMutation.graphql (renamed from openai_rev/quora/graphql/SubscriptionsMutation.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/SummarizePlainPostQuery.graphql (renamed from openai_rev/quora/graphql/SummarizePlainPostQuery.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/SummarizeQuotePostQuery.graphql (renamed from openai_rev/quora/graphql/SummarizeQuotePostQuery.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/SummarizeSharePostQuery.graphql (renamed from openai_rev/quora/graphql/SummarizeSharePostQuery.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/UserSnippetFragment.graphql (renamed from openai_rev/quora/graphql/UserSnippetFragment.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ViewerInfoQuery.graphql (renamed from openai_rev/quora/graphql/ViewerInfoQuery.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ViewerStateFragment.graphql (renamed from openai_rev/quora/graphql/ViewerStateFragment.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/ViewerStateUpdatedSubscription.graphql (renamed from openai_rev/quora/graphql/ViewerStateUpdatedSubscription.graphql) | 0 | ||||
-rw-r--r-- | quora/graphql/__init__.py (renamed from openai_rev/quora/graphql/__init__.py) | 0 | ||||
-rw-r--r-- | quora/mail.py (renamed from openai_rev/quora/mail.py) | 4 | ||||
-rw-r--r-- | test.py (renamed from openai_rev/theb/theb_test.py) | 3 | ||||
-rw-r--r-- | theb/README.md (renamed from openai_rev/theb/README.md) | 6 | ||||
-rw-r--r-- | theb/__init__.py (renamed from openai_rev/theb/__init__.py) | 20 | ||||
-rw-r--r-- | you/README.md (renamed from openai_rev/you/README.md) | 8 | ||||
-rw-r--r-- | you/__init__.py (renamed from openai_rev/you/__init__.py) | 62 |
50 files changed, 190 insertions, 442 deletions
diff --git a/openai_rev/forefront/mail.py b/forefront/mail.py index 2c00051c..41c2a647 100644 --- a/openai_rev/forefront/mail.py +++ b/forefront/mail.py @@ -23,17 +23,21 @@ class Mail: "sec-fetch-dest": "empty", "referer": "https://mail.tm/", "accept-encoding": "gzip, deflate, br", - "accept-language": "en-GB,en-US;q=0.9,en;q=0.8", + "accept-language": "en-GB,en-US;q=0.9,en;q=0.8" } def get_mail(self) -> str: token = ''.join(choices(ascii_letters, k=14)).lower() - init = self.client.post( - "https://api.mail.tm/accounts", json={"address": f"{token}@bugfoo.com", "password": token} - ) + init = self.client.post("https://api.mail.tm/accounts", json={ + "address": f"{token}@bugfoo.com", + "password": token + }) if init.status_code == 201: - resp = self.client.post("https://api.mail.tm/token", json={**init.json(), "password": token}) + resp = self.client.post("https://api.mail.tm/token", json={ + **init.json(), + "password": token + }) self.client.headers['authorization'] = 'Bearer ' + resp.json()['token'] diff --git a/openai_rev/__init__.py b/openai_rev/__init__.py deleted file mode 100644 index 9076abe9..00000000 --- a/openai_rev/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .openai_rev import Provider diff --git a/openai_rev/forefront/README.md b/openai_rev/forefront/README.md deleted file mode 100644 index 94089faa..00000000 --- a/openai_rev/forefront/README.md +++ /dev/null @@ -1,15 +0,0 @@ -### Example: `forefront` (use like openai pypi package) <a name="example-forefront"></a> - -```python - -from openai_rev import forefront - -# create an account -token = forefront.Account.create(logging=True) -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='') -```
\ No newline at end of file diff --git a/openai_rev/forefront/__init__.py b/openai_rev/forefront/__init__.py deleted file mode 100644 index 6fece65a..00000000 --- a/openai_rev/forefront/__init__.py +++ /dev/null @@ -1,189 +0,0 @@ -from json import loads -from re import match -from time import time, sleep -from typing import Generator, Optional -from uuid import uuid4 - -from fake_useragent import UserAgent -from requests import post -from tls_client import Session - -from .mail import Mail -from .models import ForeFrontResponse - - -class Account: - @staticmethod - def create(proxy: Optional[str] = None, logging: bool = False): - proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False - - start = time() - - mail_client = Mail(proxies) - mail_token = None - mail_address = mail_client.get_mail() - - # print(mail_address) - - client = Session(client_identifier='chrome110') - client.proxies = proxies - client.headers = { - 'origin': 'https://accounts.forefront.ai', - 'user-agent': UserAgent().random, - } - - response = client.post( - 'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6', - data={'email_address': mail_address}, - ) - - trace_token = response.json()['response']['id'] - if logging: - print(trace_token) - - response = client.post( - f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6', - data={ - 'strategy': 'email_code', - }, - ) - - if logging: - print(response.text) - - if 'sign_up_attempt' not in response.text: - return 'Failed to create account!' - - while True: - sleep(1) - for _ in mail_client.fetch_inbox(): - if logging: - print(mail_client.get_message_content(_['id'])) - mail_token = match(r'(\d){5,6}', mail_client.get_message_content(_['id'])).group(0) - - if mail_token: - break - - if logging: - print(mail_token) - - response = client.post( - f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/attempt_verification?_clerk_js_version=4.38.4', - data={'code': mail_token, 'strategy': 'email_code'}, - ) - - if logging: - print(response.json()) - - token = response.json()['client']['sessions'][0]['last_active_token']['jwt'] - - with open('accounts.txt', 'a') as f: - f.write(f'{mail_address}:{token}\n') - - if logging: - print(time() - start) - - return token - - -class StreamingCompletion: - @staticmethod - def create( - token=None, - chat_id=None, - prompt='', - action_type='new', - default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default - model='gpt-4', - ) -> Generator[ForeFrontResponse, None, None]: - if not token: - raise Exception('Token is required!') - if not chat_id: - chat_id = str(uuid4()) - - headers = { - 'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com', - 'accept': '*/*', - 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', - 'authorization': 'Bearer ' + token, - 'cache-control': 'no-cache', - 'content-type': 'application/json', - 'origin': 'https://chat.forefront.ai', - 'pragma': 'no-cache', - 'referer': 'https://chat.forefront.ai/', - 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"macOS"', - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'cross-site', - 'user-agent': UserAgent().random, - } - - json_data = { - 'text': prompt, - 'action': action_type, - 'parentId': chat_id, - 'workspaceId': chat_id, - 'messagePersona': default_persona, - 'model': model, - } - - for chunk in post( - 'https://chat-server.tenant-forefront-default.knative.chi.coreweave.com/chat', - headers=headers, - json=json_data, - stream=True, - ).iter_lines(): - if b'finish_reason":null' in chunk: - data = loads(chunk.decode('utf-8').split('data: ')[1]) - token = data['choices'][0]['delta'].get('content') - - if token is not None: - yield ForeFrontResponse( - **{ - 'id': chat_id, - 'object': 'text_completion', - 'created': int(time()), - 'text': token, - 'model': model, - 'choices': [{'text': token, 'index': 0, 'logprobs': None, 'finish_reason': 'stop'}], - 'usage': { - 'prompt_tokens': len(prompt), - 'completion_tokens': len(token), - 'total_tokens': len(prompt) + len(token), - }, - } - ) - - -class Completion: - @staticmethod - def create( - token=None, - chat_id=None, - prompt='', - action_type='new', - default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default - model='gpt-4', - ) -> ForeFrontResponse: - text = '' - final_response = None - for response in StreamingCompletion.create( - token=token, - chat_id=chat_id, - prompt=prompt, - action_type=action_type, - default_persona=default_persona, - model=model, - ): - if response: - final_response = response - text += response.text - - if final_response: - final_response.text = text - else: - raise Exception('Unable to get the response, Please try again') - - return final_response diff --git a/openai_rev/forefront/models.py b/openai_rev/forefront/models.py deleted file mode 100644 index 23e90903..00000000 --- a/openai_rev/forefront/models.py +++ /dev/null @@ -1,26 +0,0 @@ -from typing import Any, List - -from pydantic import BaseModel - - -class Choice(BaseModel): - text: str - index: int - logprobs: Any - finish_reason: str - - -class Usage(BaseModel): - prompt_tokens: int - completion_tokens: int - total_tokens: int - - -class ForeFrontResponse(BaseModel): - id: str - object: str - created: int - model: str - choices: List[Choice] - usage: Usage - text: str diff --git a/openai_rev/openai_rev.py b/openai_rev/openai_rev.py deleted file mode 100644 index 6b88298b..00000000 --- a/openai_rev/openai_rev.py +++ /dev/null @@ -1,42 +0,0 @@ -from enum import Enum - -from openai_rev import forefront -from openai_rev import quora -from openai_rev import theb -from openai_rev import you - - -class Provider(Enum): - You = 'you' - Poe = 'poe' - ForeFront = 'fore_front' - Theb = 'theb' - - -class Completion: - @staticmethod - def create(provider: Provider, prompt: str, **kwargs): - if provider == Provider.Poe: - return Completion.__poe_service(prompt, **kwargs) - elif provider == Provider.You: - return Completion.__you_service(prompt, **kwargs) - elif provider == Provider.ForeFront: - return Completion.__fore_front_service(prompt, **kwargs) - elif provider == Provider.Theb: - return Completion.__theb_service(prompt, **kwargs) - - @classmethod - def __you_service(cls, prompt: str, **kwargs) -> str: - return you.Completion.create(prompt, **kwargs).text - - @classmethod - def __poe_service(cls, prompt: str, **kwargs) -> str: - return quora.Completion.create(prompt=prompt, **kwargs).text - - @classmethod - def __fore_front_service(cls, prompt: str, **kwargs) -> str: - return forefront.Completion.create(prompt=prompt, **kwargs).text - - @classmethod - def __theb_service(cls, prompt: str, **kwargs): - return ''.join(theb.Completion.create(prompt=prompt)) diff --git a/openai_rev/quora/README.md b/quora/README.md index dc2bb32d..24679277 100644 --- a/openai_rev/quora/README.md +++ b/quora/README.md @@ -1,4 +1,5 @@ -#### warning !!! + +> ⚠ Warning !!! poe.com added security and can detect if you are making automated requests. You may get your account banned if you are using this api. The normal non-driver api is also currently not very stable @@ -16,44 +17,44 @@ models = { } ``` -#### !! new: bot creation +### New: bot creation ```python # import quora (poe) package -from openai_rev import quora +import quora # create account # make sure to set enable_bot_creation to True -token = quora.Account.create(logging=True, enable_bot_creation=True) +token = quora.Account.create(logging = True, enable_bot_creation=True) model = quora.Model.create( - token=token, - model='gpt-3.5-turbo', # or claude-instant-v1.0 - system_prompt='you are ChatGPT a large language model ...' + token = token, + model = 'gpt-3.5-turbo', # or claude-instant-v1.0 + system_prompt = 'you are ChatGPT a large language model ...' ) -print(model.name) # gptx.... +print(model.name) # gptx.... # streaming response for response in quora.StreamingCompletion.create( - custom_model=model.name, - prompt='hello world', - token=token): - print(response.text) + custom_model = model.name, + prompt ='hello world', + token = token): + + print(response.completion.choices[0].text) ``` -#### Normal Response: +### Normal Response: ```python -import quora response = quora.Completion.create(model = 'gpt-4', prompt = 'hello world', - token = 'token') + token = token) -print(response.text) +print(response.completion.choices[0].text) ``` -#### Update Use This For Poe +### Update Use This For Poe ```python from quora import Poe diff --git a/openai_rev/quora/__init__.py b/quora/__init__.py index 5303f206..cd5ec8f9 100644 --- a/openai_rev/quora/__init__.py +++ b/quora/__init__.py @@ -6,12 +6,11 @@ from pathlib import Path from random import choice, choices, randint from re import search, findall from string import ascii_letters, digits -from typing import Optional, Union, List, Any, Generator +from typing import Optional, Union from urllib.parse import unquote import selenium.webdriver.support.expected_conditions as EC from fake_useragent import UserAgent -from pydantic import BaseModel from pypasser import reCaptchaV3 from requests import Session from selenium.webdriver import Firefox, Chrome, FirefoxOptions, ChromeOptions @@ -19,8 +18,8 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from tls_client import Session as TLS -from .api import Client as PoeClient -from .mail import Emailnator +from quora.api import Client as PoeClient +from quora.mail import Emailnator SELENIUM_WEB_DRIVER_ERROR_MSG = b'''The error message you are receiving is due to the `geckodriver` executable not being found in your system\'s PATH. To resolve this issue, you need to download the geckodriver and add its location @@ -68,27 +67,42 @@ def extract_formkey(html): return formkey -class Choice(BaseModel): - text: str - index: int - logprobs: Any - finish_reason: str +class PoeResponse: + class Completion: + class Choices: + def __init__(self, choice: dict) -> None: + self.text = choice['text'] + self.content = self.text.encode() + self.index = choice['index'] + self.logprobs = choice['logprobs'] + self.finish_reason = choice['finish_reason'] + def __repr__(self) -> str: + return f'''<__main__.APIResponse.Completion.Choices(\n text = {self.text.encode()},\n index = {self.index},\n logprobs = {self.logprobs},\n finish_reason = {self.finish_reason})object at 0x1337>''' -class Usage(BaseModel): - prompt_tokens: int - completion_tokens: int - total_tokens: int + def __init__(self, choices: dict) -> None: + self.choices = [self.Choices(choice) for choice in choices] + class Usage: + def __init__(self, usage_dict: dict) -> None: + self.prompt_tokens = usage_dict['prompt_tokens'] + self.completion_tokens = usage_dict['completion_tokens'] + self.total_tokens = usage_dict['total_tokens'] -class PoeResponse(BaseModel): - id: int - object: str - created: int - model: str - choices: List[Choice] - usage: Usage - text: str + def __repr__(self): + return f'''<__main__.APIResponse.Usage(\n prompt_tokens = {self.prompt_tokens},\n completion_tokens = {self.completion_tokens},\n total_tokens = {self.total_tokens})object at 0x1337>''' + + def __init__(self, response_dict: dict) -> None: + self.response_dict = response_dict + self.id = response_dict['id'] + self.object = response_dict['object'] + self.created = response_dict['created'] + self.model = response_dict['model'] + self.completion = self.Completion(response_dict['choices']) + self.usage = self.Usage(response_dict['usage']) + + def json(self) -> dict: + return self.response_dict class ModelResponse: @@ -102,12 +116,17 @@ class ModelResponse: class Model: @staticmethod 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', - handle: str = None, + 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', + handle: str = None, ) -> ModelResponse: + models = { + 'gpt-3.5-turbo': 'chinchilla', + 'claude-instant-v1.0': 'a2', + 'gpt-4': 'beaver', + } if not handle: handle = f'gptx{randint(1111111, 9999999)}' @@ -143,7 +162,7 @@ class Model: obj={ 'queryName': 'CreateBotMain_poeBotCreate_Mutation', 'variables': { - 'model': MODELS[model], + 'model': models[model], 'handle': handle, 'prompt': system_prompt, 'isPromptPublic': True, @@ -183,9 +202,9 @@ class Model: class Account: @staticmethod def create( - proxy: Optional[str] = None, - logging: bool = False, - enable_bot_creation: bool = False, + proxy: Optional[str] = None, + logging: bool = False, + enable_bot_creation: bool = False, ): client = TLS(client_identifier='chrome110') client.proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} if proxy else None @@ -290,23 +309,22 @@ class Account: class StreamingCompletion: @staticmethod def create( - model: str = 'gpt-4', - custom_model: bool = None, - prompt: str = 'hello world', - token: str = '', - ) -> Generator[PoeResponse, None, None]: + model: str = 'gpt-4', + custom_model: bool = None, + prompt: str = 'hello world', + token: str = '', + ): _model = MODELS[model] if not custom_model else custom_model client = PoeClient(token) for chunk in client.send_message(_model, prompt): yield PoeResponse( - **{ + { 'id': chunk['messageId'], 'object': 'text_completion', 'created': chunk['creationTime'], 'model': _model, - 'text': chunk['text_new'], 'choices': [ { 'text': chunk['text_new'], @@ -325,28 +343,33 @@ class StreamingCompletion: class Completion: - @staticmethod def create( - model: str = 'gpt-4', - custom_model: str = None, - prompt: str = 'hello world', - token: str = '', - ) -> PoeResponse: - _model = MODELS[model] if not custom_model else custom_model + model: str = 'gpt-4', + custom_model: str = None, + prompt: str = 'hello world', + token: str = '', + ): + models = { + 'sage': 'capybara', + 'gpt-4': 'beaver', + 'claude-v1.2': 'a2_2', + 'claude-instant-v1.0': 'a2', + 'gpt-3.5-turbo': 'chinchilla', + } + + _model = models[model] if not custom_model else custom_model client = PoeClient(token) - chunk = None - for response in client.send_message(_model, prompt): - chunk = response + for chunk in client.send_message(_model, prompt): + pass return PoeResponse( - **{ + { 'id': chunk['messageId'], 'object': 'text_completion', 'created': chunk['creationTime'], 'model': _model, - 'text': chunk['text'], 'choices': [ { 'text': chunk['text'], @@ -366,12 +389,12 @@ class Completion: class Poe: def __init__( - self, - model: str = 'ChatGPT', - driver: str = 'firefox', - download_driver: bool = False, - driver_path: Optional[str] = None, - cookie_path: str = './quora/cookie.json', + self, + model: str = 'ChatGPT', + driver: str = 'firefox', + download_driver: bool = False, + driver_path: Optional[str] = None, + cookie_path: str = './quora/cookie.json', ): # validating the model if model and model not in MODELS: @@ -450,12 +473,12 @@ class Poe: return response def create_bot( - self, - name: str, - /, - prompt: str = '', - base_model: str = 'ChatGPT', - description: str = '', + 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.') diff --git a/openai_rev/quora/api.py b/quora/api.py index 42814f2c..697f6663 100644 --- a/openai_rev/quora/api.py +++ b/quora/api.py @@ -384,7 +384,7 @@ class Client: continue # update info about response - message["text_new"] = message["text"][len(last_text) :] + message["text_new"] = message["text"][len(last_text):] last_text = message["text"] message_id = message["messageId"] @@ -456,21 +456,21 @@ class Client: logger.info(f"No more messages left to delete.") def create_bot( - self, - handle, - prompt="", - base_model="chinchilla", - description="", - intro_message="", - api_key=None, - api_bot=False, - api_url=None, - prompt_public=True, - pfp_url=None, - linkification=False, - markdown_rendering=True, - suggested_replies=False, - private=False, + self, + handle, + prompt="", + base_model="chinchilla", + description="", + intro_message="", + api_key=None, + api_bot=False, + api_url=None, + prompt_public=True, + pfp_url=None, + linkification=False, + markdown_rendering=True, + suggested_replies=False, + private=False, ): result = self.send_query( "PoeBotCreateMutation", @@ -499,21 +499,21 @@ class Client: return data def edit_bot( - self, - bot_id, - handle, - prompt="", - base_model="chinchilla", - description="", - intro_message="", - api_key=None, - api_url=None, - private=False, - prompt_public=True, - pfp_url=None, - linkification=False, - markdown_rendering=True, - suggested_replies=False, + self, + bot_id, + handle, + prompt="", + base_model="chinchilla", + description="", + intro_message="", + api_key=None, + api_url=None, + private=False, + prompt_public=True, + pfp_url=None, + linkification=False, + markdown_rendering=True, + suggested_replies=False, ): result = self.send_query( "PoeBotEditMutation", diff --git a/openai_rev/quora/cookies.txt b/quora/cookies.txt index 9cccf6ba..9cccf6ba 100644 --- a/openai_rev/quora/cookies.txt +++ b/quora/cookies.txt diff --git a/openai_rev/quora/graphql/AddHumanMessageMutation.graphql b/quora/graphql/AddHumanMessageMutation.graphql index 01e6bc8c..01e6bc8c 100644 --- a/openai_rev/quora/graphql/AddHumanMessageMutation.graphql +++ b/quora/graphql/AddHumanMessageMutation.graphql diff --git a/openai_rev/quora/graphql/AddMessageBreakMutation.graphql b/quora/graphql/AddMessageBreakMutation.graphql index b28d9903..b28d9903 100644 --- a/openai_rev/quora/graphql/AddMessageBreakMutation.graphql +++ b/quora/graphql/AddMessageBreakMutation.graphql diff --git a/openai_rev/quora/graphql/AutoSubscriptionMutation.graphql b/quora/graphql/AutoSubscriptionMutation.graphql index 6cf7bf74..6cf7bf74 100644 --- a/openai_rev/quora/graphql/AutoSubscriptionMutation.graphql +++ b/quora/graphql/AutoSubscriptionMutation.graphql diff --git a/openai_rev/quora/graphql/BioFragment.graphql b/quora/graphql/BioFragment.graphql index c4218030..c4218030 100644 --- a/openai_rev/quora/graphql/BioFragment.graphql +++ b/quora/graphql/BioFragment.graphql diff --git a/openai_rev/quora/graphql/ChatAddedSubscription.graphql b/quora/graphql/ChatAddedSubscription.graphql index 664b107f..664b107f 100644 --- a/openai_rev/quora/graphql/ChatAddedSubscription.graphql +++ b/quora/graphql/ChatAddedSubscription.graphql diff --git a/openai_rev/quora/graphql/ChatFragment.graphql b/quora/graphql/ChatFragment.graphql index 605645ff..605645ff 100644 --- a/openai_rev/quora/graphql/ChatFragment.graphql +++ b/quora/graphql/ChatFragment.graphql diff --git a/openai_rev/quora/graphql/ChatListPaginationQuery.graphql b/quora/graphql/ChatListPaginationQuery.graphql index 6d9ae884..6d9ae884 100644 --- a/openai_rev/quora/graphql/ChatListPaginationQuery.graphql +++ b/quora/graphql/ChatListPaginationQuery.graphql diff --git a/openai_rev/quora/graphql/ChatPaginationQuery.graphql b/quora/graphql/ChatPaginationQuery.graphql index f2452cd6..f2452cd6 100644 --- a/openai_rev/quora/graphql/ChatPaginationQuery.graphql +++ b/quora/graphql/ChatPaginationQuery.graphql diff --git a/openai_rev/quora/graphql/ChatViewQuery.graphql b/quora/graphql/ChatViewQuery.graphql index c330107d..c330107d 100644 --- a/openai_rev/quora/graphql/ChatViewQuery.graphql +++ b/quora/graphql/ChatViewQuery.graphql diff --git a/openai_rev/quora/graphql/DeleteHumanMessagesMutation.graphql b/quora/graphql/DeleteHumanMessagesMutation.graphql index 42692c6e..42692c6e 100644 --- a/openai_rev/quora/graphql/DeleteHumanMessagesMutation.graphql +++ b/quora/graphql/DeleteHumanMessagesMutation.graphql diff --git a/openai_rev/quora/graphql/DeleteMessageMutation.graphql b/quora/graphql/DeleteMessageMutation.graphql index 7b9e36d4..7b9e36d4 100644 --- a/openai_rev/quora/graphql/DeleteMessageMutation.graphql +++ b/quora/graphql/DeleteMessageMutation.graphql diff --git a/openai_rev/quora/graphql/HandleFragment.graphql b/quora/graphql/HandleFragment.graphql index f53c484b..f53c484b 100644 --- a/openai_rev/quora/graphql/HandleFragment.graphql +++ b/quora/graphql/HandleFragment.graphql diff --git a/openai_rev/quora/graphql/LoginWithVerificationCodeMutation.graphql b/quora/graphql/LoginWithVerificationCodeMutation.graphql index 723b1f44..723b1f44 100644 --- a/openai_rev/quora/graphql/LoginWithVerificationCodeMutation.graphql +++ b/quora/graphql/LoginWithVerificationCodeMutation.graphql diff --git a/openai_rev/quora/graphql/MessageAddedSubscription.graphql b/quora/graphql/MessageAddedSubscription.graphql index 8dc9499c..8dc9499c 100644 --- a/openai_rev/quora/graphql/MessageAddedSubscription.graphql +++ b/quora/graphql/MessageAddedSubscription.graphql diff --git a/openai_rev/quora/graphql/MessageDeletedSubscription.graphql b/quora/graphql/MessageDeletedSubscription.graphql index 54c1c164..54c1c164 100644 --- a/openai_rev/quora/graphql/MessageDeletedSubscription.graphql +++ b/quora/graphql/MessageDeletedSubscription.graphql diff --git a/openai_rev/quora/graphql/MessageFragment.graphql b/quora/graphql/MessageFragment.graphql index cc860811..cc860811 100644 --- a/openai_rev/quora/graphql/MessageFragment.graphql +++ b/quora/graphql/MessageFragment.graphql diff --git a/openai_rev/quora/graphql/MessageRemoveVoteMutation.graphql b/quora/graphql/MessageRemoveVoteMutation.graphql index d5e6e610..d5e6e610 100644 --- a/openai_rev/quora/graphql/MessageRemoveVoteMutation.graphql +++ b/quora/graphql/MessageRemoveVoteMutation.graphql diff --git a/openai_rev/quora/graphql/MessageSetVoteMutation.graphql b/quora/graphql/MessageSetVoteMutation.graphql index 76000df0..76000df0 100644 --- a/openai_rev/quora/graphql/MessageSetVoteMutation.graphql +++ b/quora/graphql/MessageSetVoteMutation.graphql diff --git a/openai_rev/quora/graphql/PoeBotCreateMutation.graphql b/quora/graphql/PoeBotCreateMutation.graphql index 971b4248..971b4248 100644 --- a/openai_rev/quora/graphql/PoeBotCreateMutation.graphql +++ b/quora/graphql/PoeBotCreateMutation.graphql diff --git a/openai_rev/quora/graphql/PoeBotEditMutation.graphql b/quora/graphql/PoeBotEditMutation.graphql index fdd309ef..fdd309ef 100644 --- a/openai_rev/quora/graphql/PoeBotEditMutation.graphql +++ b/quora/graphql/PoeBotEditMutation.graphql diff --git a/openai_rev/quora/graphql/SendMessageMutation.graphql b/quora/graphql/SendMessageMutation.graphql index 4b0a4383..4b0a4383 100644 --- a/openai_rev/quora/graphql/SendMessageMutation.graphql +++ b/quora/graphql/SendMessageMutation.graphql diff --git a/openai_rev/quora/graphql/SendVerificationCodeForLoginMutation.graphql b/quora/graphql/SendVerificationCodeForLoginMutation.graphql index 45af4799..45af4799 100644 --- a/openai_rev/quora/graphql/SendVerificationCodeForLoginMutation.graphql +++ b/quora/graphql/SendVerificationCodeForLoginMutation.graphql diff --git a/openai_rev/quora/graphql/ShareMessagesMutation.graphql b/quora/graphql/ShareMessagesMutation.graphql index 92e80db5..92e80db5 100644 --- a/openai_rev/quora/graphql/ShareMessagesMutation.graphql +++ b/quora/graphql/ShareMessagesMutation.graphql diff --git a/openai_rev/quora/graphql/SignupWithVerificationCodeMutation.graphql b/quora/graphql/SignupWithVerificationCodeMutation.graphql index 06b2826f..06b2826f 100644 --- a/openai_rev/quora/graphql/SignupWithVerificationCodeMutation.graphql +++ b/quora/graphql/SignupWithVerificationCodeMutation.graphql diff --git a/openai_rev/quora/graphql/StaleChatUpdateMutation.graphql b/quora/graphql/StaleChatUpdateMutation.graphql index de203d47..de203d47 100644 --- a/openai_rev/quora/graphql/StaleChatUpdateMutation.graphql +++ b/quora/graphql/StaleChatUpdateMutation.graphql diff --git a/openai_rev/quora/graphql/SubscriptionsMutation.graphql b/quora/graphql/SubscriptionsMutation.graphql index b864bd60..b864bd60 100644 --- a/openai_rev/quora/graphql/SubscriptionsMutation.graphql +++ b/quora/graphql/SubscriptionsMutation.graphql diff --git a/openai_rev/quora/graphql/SummarizePlainPostQuery.graphql b/quora/graphql/SummarizePlainPostQuery.graphql index afa2a84c..afa2a84c 100644 --- a/openai_rev/quora/graphql/SummarizePlainPostQuery.graphql +++ b/quora/graphql/SummarizePlainPostQuery.graphql diff --git a/openai_rev/quora/graphql/SummarizeQuotePostQuery.graphql b/quora/graphql/SummarizeQuotePostQuery.graphql index 5147c3c5..5147c3c5 100644 --- a/openai_rev/quora/graphql/SummarizeQuotePostQuery.graphql +++ b/quora/graphql/SummarizeQuotePostQuery.graphql diff --git a/openai_rev/quora/graphql/SummarizeSharePostQuery.graphql b/quora/graphql/SummarizeSharePostQuery.graphql index cb4a623c..cb4a623c 100644 --- a/openai_rev/quora/graphql/SummarizeSharePostQuery.graphql +++ b/quora/graphql/SummarizeSharePostQuery.graphql diff --git a/openai_rev/quora/graphql/UserSnippetFragment.graphql b/quora/graphql/UserSnippetFragment.graphql index 17fc8426..17fc8426 100644 --- a/openai_rev/quora/graphql/UserSnippetFragment.graphql +++ b/quora/graphql/UserSnippetFragment.graphql diff --git a/openai_rev/quora/graphql/ViewerInfoQuery.graphql b/quora/graphql/ViewerInfoQuery.graphql index 1ecaf9e8..1ecaf9e8 100644 --- a/openai_rev/quora/graphql/ViewerInfoQuery.graphql +++ b/quora/graphql/ViewerInfoQuery.graphql diff --git a/openai_rev/quora/graphql/ViewerStateFragment.graphql b/quora/graphql/ViewerStateFragment.graphql index 3cd83e9c..3cd83e9c 100644 --- a/openai_rev/quora/graphql/ViewerStateFragment.graphql +++ b/quora/graphql/ViewerStateFragment.graphql diff --git a/openai_rev/quora/graphql/ViewerStateUpdatedSubscription.graphql b/quora/graphql/ViewerStateUpdatedSubscription.graphql index 03fc73d1..03fc73d1 100644 --- a/openai_rev/quora/graphql/ViewerStateUpdatedSubscription.graphql +++ b/quora/graphql/ViewerStateUpdatedSubscription.graphql diff --git a/openai_rev/quora/graphql/__init__.py b/quora/graphql/__init__.py index e69de29b..e69de29b 100644 --- a/openai_rev/quora/graphql/__init__.py +++ b/quora/graphql/__init__.py diff --git a/openai_rev/quora/mail.py b/quora/mail.py index 864d9568..e6ce96c2 100644 --- a/openai_rev/quora/mail.py +++ b/quora/mail.py @@ -42,7 +42,9 @@ class Emailnator: while True: sleep(2) - mail_token = self.client.post("https://www.emailnator.com/message-list", json={"email": self.email}) + mail_token = self.client.post( + "https://www.emailnator.com/message-list", json={"email": self.email} + ) mail_token = loads(mail_token.text)["messageData"] diff --git a/openai_rev/theb/theb_test.py b/test.py index 805ef094..4b39bd0a 100644 --- a/openai_rev/theb/theb_test.py +++ b/test.py @@ -1,4 +1,5 @@ -from openai_rev import theb +import theb for token in theb.Completion.create('hello world'): print(token, end='', flush=True) + print('asdsos')
\ No newline at end of file diff --git a/openai_rev/theb/README.md b/theb/README.md index bd37ba3f..ca978fce 100644 --- a/openai_rev/theb/README.md +++ b/theb/README.md @@ -1,10 +1,12 @@ ### Example: `theb` (use like openai pypi package) <a name="example-theb"></a> + ```python # import library -from openai_rev import theb +import theb # simple streaming completion for token in theb.Completion.create('hello world'): print(token, end='', flush=True) -```
\ No newline at end of file +print("") +``` diff --git a/openai_rev/theb/__init__.py b/theb/__init__.py index fa79fdd9..726e025e 100644 --- a/openai_rev/theb/__init__.py +++ b/theb/__init__.py @@ -1,11 +1,9 @@ +from re import findall from json import loads from queue import Queue, Empty -from re import findall from threading import Thread - from curl_cffi import requests - class Completion: # experimental part1 = '{"role":"assistant","id":"chatcmpl' @@ -16,8 +14,7 @@ class Completion: message_queue = Queue() stream_completed = False - @classmethod - def request(cls, prompt: str): + def request(prompt: str): headers = { 'authority': 'chatbot.theb.ai', 'content-type': 'application/json', @@ -25,11 +22,12 @@ class Completion: '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', } - requests.post( - 'https://chatbot.theb.ai/api/chat-process', - headers=headers, - content_callback=Completion.handle_stream_response, - json={'prompt': prompt, 'options': {}}, + requests.post('https://chatbot.theb.ai/api/chat-process', headers=headers, + content_callback = Completion.handle_stream_response, + json = { + 'prompt': prompt, + 'options': {} + } ) Completion.stream_completed = True @@ -38,7 +36,7 @@ class Completion: def create(prompt: str): Thread(target=Completion.request, args=[prompt]).start() - while not Completion.stream_completed or not Completion.message_queue.empty(): + while Completion.stream_completed != True or not Completion.message_queue.empty(): try: message = Completion.message_queue.get(timeout=0.01) for message in findall(Completion.regex, message): diff --git a/openai_rev/you/README.md b/you/README.md index f759c27c..25c20085 100644 --- a/openai_rev/you/README.md +++ b/you/README.md @@ -1,8 +1,7 @@ ### Example: `you` (use like openai pypi package) <a name="example-you"></a> ```python - -from openai_rev import you +import you # simple request with links and details response = you.Completion.create( @@ -26,7 +25,8 @@ chat = [] while True: prompt = input("You: ") - + if prompt == 'q': + break response = you.Completion.create( prompt=prompt, chat=chat) @@ -34,4 +34,4 @@ while True: print("Bot:", response["response"]) chat.append({"question": prompt, "answer": response["response"]}) -```
\ No newline at end of file +``` diff --git a/openai_rev/you/__init__.py b/you/__init__.py index 50d74152..8bf31f0d 100644 --- a/openai_rev/you/__init__.py +++ b/you/__init__.py @@ -1,36 +1,28 @@ -import json import re -from typing import Optional, List, Dict, Any +from json import loads from uuid import uuid4 from fake_useragent import UserAgent -from pydantic import BaseModel from tls_client import Session -class PoeResponse(BaseModel): - text: Optional[str] = None - links: List[str] = [] - extra: Dict[str, Any] = {} - - class Completion: @staticmethod def create( - prompt: str, - page: int = 1, - count: int = 10, - safe_search: str = 'Moderate', - on_shopping_page: bool = False, - mkt: str = '', - response_filter: str = 'WebPages,Translations,TimeZone,Computation,RelatedSearches', - domain: str = 'youchat', - query_trace_id: str = None, - chat: list = None, - include_links: bool = False, - detailed: bool = False, - debug: bool = False, - ) -> PoeResponse: + prompt: str, + page: int = 1, + count: int = 10, + safe_search: str = 'Moderate', + on_shopping_page: bool = False, + mkt: str = '', + response_filter: str = 'WebPages,Translations,TimeZone,Computation,RelatedSearches', + domain: str = 'youchat', + query_trace_id: str = None, + chat: list = None, + include_links: bool = False, + detailed: bool = False, + debug: bool = False, + ) -> dict: if chat is None: chat = [] @@ -65,25 +57,23 @@ class Completion: r'(?<=event: youChatSerpResults\ndata:)(.*\n)*?(?=event: )', response.text ).group() third_party_search_results = re.search( - r'(?<=event: thirdPartySearchResults\ndata:)(.*\n)*?(?=event: )', response.text - ).group() + r'(?<=event: thirdPartySearchResults\ndata:)(.*\n)*?(?=event: )', response.text).group() # slots = findall(r"slots\ndata: (.*)\n\nevent", response.text)[0] text = ''.join(re.findall(r'{\"youChatToken\": \"(.*?)\"}', response.text)) extra = { - 'youChatSerpResults': json.loads(you_chat_serp_results), + 'youChatSerpResults': loads(you_chat_serp_results), # 'slots' : loads(slots) } - response = PoeResponse(text=text.replace('\\n', '\n').replace('\\\\', '\\').replace('\\"', '"')) - if include_links: - response.links = json.loads(third_party_search_results)['search']['third_party_search_results'] - - if detailed: - response.extra = extra - - return response + return { + 'response': text.replace('\\n', '\n').replace('\\\\', '\\').replace('\\"', '"'), + 'links': loads(third_party_search_results)['search']['third_party_search_results'] + if include_links + else None, + 'extra': extra if detailed else None, + } @classmethod def __get_headers(cls) -> dict: @@ -104,5 +94,5 @@ class Completion: } @classmethod - def __get_failure_response(cls) -> PoeResponse: - return PoeResponse(text='Unable to fetch the response, Please try again.') + def __get_failure_response(cls) -> dict: + return dict(response='Unable to fetch the response, Please try again.', links=[], extra={}) |