summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authort.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-27 20:16:07 +0200
committert.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-27 20:16:07 +0200
commit10104774c10cccf95bbebcafd17c0a85207583e0 (patch)
tree6fec52831117ee43fe7141a153b7e123ff09d469
parent_ (diff)
parentMerge pull request #205 from AymaneHrouch/reformat__code (diff)
downloadgpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.gz
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.bz2
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.lz
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.xz
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.zst
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.zip
-rw-r--r--README.md31
-rw-r--r--Singularity/gpt4free.sif15
-rw-r--r--forefront/__init__.py187
-rw-r--r--forefront/mail.py25
-rw-r--r--forefront/typing.py37
-rw-r--r--gui/streamlit_app.py47
-rw-r--r--phind/__init__.py226
-rw-r--r--quora/__init__.py56
-rw-r--r--quora/api.py62
-rw-r--r--quora/mail.py20
-rw-r--r--requirements.txt3
-rw-r--r--testing/forefront_test.py7
-rw-r--r--testing/phind_test.py30
-rw-r--r--testing/poe_account_create_test.py88
-rw-r--r--testing/poe_test.py14
-rw-r--r--testing/quora_test_2.py17
-rw-r--r--testing/sqlchat_test.py6
-rw-r--r--testing/t3nsor_test.py5
-rw-r--r--testing/writesonic_test.py34
-rw-r--r--unfinished/bard/__init__.py124
-rw-r--r--unfinished/bard/typings.py59
-rw-r--r--unfinished/bing/__ini__.py173
-rw-r--r--unfinished/cocalc/__init__.py38
-rw-r--r--unfinished/cocalc/cocalc_test.py5
-rw-r--r--unfinished/easyai/main.py42
-rw-r--r--unfinished/gptbz/__init__.py48
-rw-r--r--unfinished/openai/__ini__.py139
-rw-r--r--unfinished/openaihosted/__init__.py5
-rw-r--r--unfinished/openprompt/create.py20
-rw-r--r--unfinished/openprompt/mail.py6
-rw-r--r--unfinished/openprompt/main.py5
-rw-r--r--unfinished/openprompt/test.py5
-rw-r--r--unfinished/t3nsor/__init__.py131
-rw-r--r--unfinished/test.py8
-rw-r--r--unfinished/theb.ai/__init__.py45
-rw-r--r--unfinished/vercelai/v2.py6
-rw-r--r--unfinished/writesonic/__init__.py195
-rw-r--r--you/__init__.py26
38 files changed, 1047 insertions, 943 deletions
diff --git a/README.md b/README.md
index 0703770d..7e3304f1 100644
--- a/README.md
+++ b/README.md
@@ -11,24 +11,6 @@ Have you ever come across some amazing projects that you couldn't use **just bec
By the way, thank you so much for [![Stars](https://img.shields.io/github/stars/xtekky/gpt4free?style=social)](https://github.com/xtekky/gpt4free/stargazers) and all the support!!
-## Announcement
-Dear Gpt4free Community,
-
-I would like to thank you for your interest in and support of this project, which I only intended to be for entertainment and educational purposes; I had no idea it would end up being so popular.
-
-I'm aware of the concerns about the project's legality and its impact on smaller sites hosting APIs. I take these concerns seriously and plan to address them.
-
-Here's what I'm doing to fix these issues:
-
-1. Removing APIs from smaller sites: To reduce the impact on smaller sites, I have removed their APIs from the repository. Please shoot me a dm if you are an owner of a site and want it removed.
-
-2. Commitment to ethical use: I want to emphasize my commitment to promoting ethical use of language models. I don't support any illegal or unethical behavior, and I expect users to follow the same principles.
-
-Thank you for your support and understanding. I appreciate your continued interest in gpt4free and am committed to addressing your concerns.
-
-Sincerely,
-**xtekky**
-
## Legal Notice <a name="legal-notice"></a>
This repository uses third-party APIs and AI models and is *not* associated with or endorsed by the API providers or the original developers of the models. This project is intended **for educational purposes only**.
@@ -54,14 +36,12 @@ Please note the following:
| **How to install** | Instructions on how to install gpt4free | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#install) | - |
| **Legal Notice** | Legal notice or disclaimer | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#legal-notice) | - |
| **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
+| **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
| **Usage Examples** | | | |
-| `forefront` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
-
-| `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
-
+| `forefront` | Example usage for forefront (gpt-4) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | | |
+| `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | |
| `phind` | Example usage for phind | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./phind/README.md) | ![Inactive](https://img.shields.io/badge/Active-brightgreen) |
-
-| `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen)
+| `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
| **Try it Out** | | | |
| Google Colab Jupyter Notebook | Example usage for gpt4free | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
| replit Example (feel free to fork this repl) | Example usage for gpt4free | [![](https://img.shields.io/badge/Open%20in-Replit-1A1E27?logo=replit)](https://replit.com/@gpt4free/gpt4free-webui) | - |
@@ -154,3 +134,6 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
```
+
+## Star History <a name="star-history"></a>
+[![Star History Chart](https://api.star-history.com/svg?repos=xtekky/gpt4free&type=Date)](https://star-history.com/#xtekky/gpt4free)
diff --git a/Singularity/gpt4free.sif b/Singularity/gpt4free.sif
new file mode 100644
index 00000000..67bc1241
--- /dev/null
+++ b/Singularity/gpt4free.sif
@@ -0,0 +1,15 @@
+Bootstrap: docker
+From: python:3.10-slim
+
+%post
+ apt-get update && apt-get install -y git
+ git clone https://github.com/xtekky/gpt4free.git
+ cd gpt4free
+ pip install --no-cache-dir -r requirements.txt
+ cp gui/streamlit_app.py .
+
+%expose
+ 8501
+
+%startscript
+ exec streamlit run streamlit_app.py
diff --git a/forefront/__init__.py b/forefront/__init__.py
index b247503f..44f5d44d 100644
--- a/forefront/__init__.py
+++ b/forefront/__init__.py
@@ -1,50 +1,54 @@
-from tls_client import Session
-from forefront.mail import Mail
-from time import time, sleep
+from json import loads
from re import match
-from forefront.typing import ForeFrontResponse
+from time import time, sleep
from uuid import uuid4
+
from requests import post
-from json import loads
+from tls_client import Session
+
+from forefront.mail import Mail
+from forefront.typing import ForeFrontResponse
class Account:
- def create(proxy = None, logging = False):
-
+ @staticmethod
+ def create(proxy=None, logging=False):
+
proxies = {
'http': 'http://' + proxy,
- 'https': 'http://' + proxy } if proxy else False
-
+ 'https': 'http://' + proxy} if proxy else False
+
start = time()
- mail = Mail(proxies)
- mail_token = None
- mail_adress = mail.get_mail()
-
- #print(mail_adress)
-
- client = Session(client_identifier='chrome110')
+ mail = Mail(proxies)
+ mail_token = None
+ mail_adress = mail.get_mail()
+
+ # print(mail_adress)
+
+ client = Session(client_identifier='chrome110')
client.proxies = proxies
client.headers = {
"origin": "https://accounts.forefront.ai",
- "user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
+ "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
}
-
- response = client.post('https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
- data = {
- "email_address": mail_adress
- }
- )
-
+
+ response = client.post('https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
+ data={
+ "email_address": mail_adress
+ }
+ )
+
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",
+ 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 not 'sign_up_attempt' in response.text:
@@ -58,88 +62,91 @@ class Account:
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'
- })
-
+
+ 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']
-
+
+ token = response.json()['client']['sessions'][0]['last_active_token']['jwt']
+
with open('accounts.txt', 'a') as f:
f.write(f'{mail_adress}:{token}\n')
-
+
if logging: print(time() - start)
-
+
return token
class StreamingCompletion:
+ @staticmethod
def create(
- token = None,
- chatId = None,
- prompt = '',
- actionType = 'new',
- defaultPersona = '607e41fe-95be-497e-8e97-010a59b2e2c0', # default
- model = 'gpt-4') -> ForeFrontResponse:
-
+ token=None,
+ chatId=None,
+ prompt='',
+ actionType='new',
+ defaultPersona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
+ model='gpt-4') -> ForeFrontResponse:
+
if not token: raise Exception('Token is required!')
if not chatId: chatId = 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',
+ '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' : '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',
+ 'sec-fetch-dest': 'empty',
+ 'sec-fetch-mode': 'cors',
+ 'sec-fetch-site': 'cross-site',
+ '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',
}
json_data = {
- 'text' : prompt,
- 'action' : actionType,
- 'parentId' : chatId,
- 'workspaceId' : chatId,
- 'messagePersona' : defaultPersona,
- 'model' : model
+ 'text': prompt,
+ 'action': actionType,
+ 'parentId': chatId,
+ 'workspaceId': chatId,
+ 'messagePersona': defaultPersona,
+ '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():
-
+ 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])
+ data = loads(chunk.decode('utf-8').split('data: ')[1])
token = data['choices'][0]['delta'].get('content')
-
+
if token != None:
yield ForeFrontResponse({
- 'id' : chatId,
- 'object' : 'text_completion',
- 'created': int(time()),
- '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)
- }
- }) \ No newline at end of file
+ 'id': chatId,
+ 'object': 'text_completion',
+ 'created': int(time()),
+ '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)
+ }
+ })
diff --git a/forefront/mail.py b/forefront/mail.py
index 64694e74..41c2a647 100644
--- a/forefront/mail.py
+++ b/forefront/mail.py
@@ -1,6 +1,8 @@
-from requests import Session
-from string import ascii_letters
from random import choices
+from string import ascii_letters
+
+from requests import Session
+
class Mail:
def __init__(self, proxies: dict = None) -> None:
@@ -23,27 +25,27 @@ class Mail:
"accept-encoding": "gzip, deflate, br",
"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",
+ 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 = {
+ resp = self.client.post("https://api.mail.tm/token", json={
**init.json(),
"password": token
})
-
+
self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
-
+
return f"{token}@bugfoo.com"
-
+
else:
raise Exception("Failed to create email")
-
+
def fetch_inbox(self):
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]
@@ -52,4 +54,3 @@ class Mail:
def get_message_content(self, message_id: str):
return self.get_message(message_id)["text"]
-
diff --git a/forefront/typing.py b/forefront/typing.py
index 0fff6b18..a11ac49f 100644
--- a/forefront/typing.py
+++ b/forefront/typing.py
@@ -2,12 +2,12 @@ class ForeFrontResponse:
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']
-
+ 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>'''
@@ -16,22 +16,21 @@ class ForeFrontResponse:
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']
+ self.prompt_tokens = usage_dict['prompt_tokens']
+ self.completion_tokens = usage_dict['completion_tokens']
+ self.total_tokens = usage_dict['total_tokens']
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'])
+ 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 \ No newline at end of file
+ return self.response_dict
diff --git a/gui/streamlit_app.py b/gui/streamlit_app.py
index ff1cb6d4..a35196e6 100644
--- a/gui/streamlit_app.py
+++ b/gui/streamlit_app.py
@@ -1,25 +1,34 @@
+import os
+import sys
+
+sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))
+
import streamlit as st
import phind
-phind.cf_clearance = ''
-phind.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'
+# Set cloudflare clearance and user agent
+phind.cloudflare_clearance = ''
+phind.phind_api = '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'
-def phind_get_answer(question:str)->str:
- # set cf_clearance cookie
+
+def get_answer(question: str) -> str:
+ # Set cloudflare clearance cookie and get answer from GPT-4 model
try:
-
result = phind.Completion.create(
- model = 'gpt-4',
- prompt = question,
- results = phind.Search.create(question, actualSearch = True),
- creative = False,
- detailed = False,
- codeContext = '')
+ model='gpt-4',
+ prompt=question,
+ results=phind.Search.create(question, actualSearch=True),
+ creative=False,
+ detailed=False,
+ codeContext=''
+ )
return result.completion.choices[0].text
-
except Exception as e:
- return 'An error occured, please make sure you are using a cf_clearance token and correct useragent | %s' % e
+ # Return error message if an exception occurs
+ return f'An error occurred: {e}. Please make sure you are using a valid cloudflare clearance token and user agent.'
+
+# Set page configuration and add header
st.set_page_config(
page_title="gpt4freeGUI",
initial_sidebar_state="expanded",
@@ -30,19 +39,21 @@ st.set_page_config(
'About': "### gptfree GUI"
}
)
-
st.header('GPT4free GUI')
-question_text_area = st.text_area('🤖 Ask Any Question :', placeholder='Explain quantum computing in 50 words')
+# Add text area for user input and button to get answer
+question_text_area = st.text_area(
+ '🤖 Ask Any Question :', placeholder='Explain quantum computing in 50 words')
if st.button('🧠 Think'):
- answer = phind_get_answer(question_text_area)
+ answer = get_answer(question_text_area)
+ # Display answer
st.caption("Answer :")
st.markdown(answer)
-
+# Hide Streamlit footer
hide_streamlit_style = """
<style>
footer {visibility: hidden;}
</style>
"""
-st.markdown(hide_streamlit_style, unsafe_allow_html=True) \ No newline at end of file
+st.markdown(hide_streamlit_style, unsafe_allow_html=True)
diff --git a/phind/__init__.py b/phind/__init__.py
index e7009d67..863360cb 100644
--- a/phind/__init__.py
+++ b/phind/__init__.py
@@ -1,27 +1,25 @@
+from datetime import datetime
+from queue import Queue, Empty
+from threading import Thread
+from time import time
from urllib.parse import quote
-from time import time
-from datetime import datetime
-from queue import Queue, Empty
-from threading import Thread
-from re import findall
from curl_cffi.requests import post
cf_clearance = ''
-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'
+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'
+
class PhindResponse:
-
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']
-
+ 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>'''
@@ -30,34 +28,33 @@ class PhindResponse:
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']
+ self.prompt_tokens = usage_dict['prompt_tokens']
+ self.completion_tokens = usage_dict['completion_tokens']
+ self.total_tokens = usage_dict['total_tokens']
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'])
+ 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 Search:
- def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search
+ def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search
if user_agent == '':
raise ValueError('user_agent must be set, refer to documentation')
- if cf_clearance == '' :
+ if cf_clearance == '':
raise ValueError('cf_clearance must be set, refer to documentation')
-
+
if not actualSearch:
return {
'_type': 'SearchResponse',
@@ -75,7 +72,7 @@ class Search:
}
}
}
-
+
headers = {
'authority': 'www.phind.com',
'accept': '*/*',
@@ -91,8 +88,8 @@ class Search:
'sec-fetch-site': 'same-origin',
'user-agent': user_agent
}
-
- return post('https://www.phind.com/api/bing/search', headers = headers, json = {
+
+ return post('https://www.phind.com/api/bing/search', headers=headers, json={
'q': prompt,
'userRankList': {},
'browserLanguage': language}).json()['rawBingResults']
@@ -100,45 +97,45 @@ class Search:
class Completion:
def create(
- model = 'gpt-4',
- prompt: str = '',
- results: dict = None,
- creative: bool = False,
- detailed: bool = False,
- codeContext: str = '',
- language: str = 'en') -> PhindResponse:
-
- if user_agent == '' :
+ model='gpt-4',
+ prompt: str = '',
+ results: dict = None,
+ creative: bool = False,
+ detailed: bool = False,
+ codeContext: str = '',
+ language: str = 'en') -> PhindResponse:
+
+ if user_agent == '':
raise ValueError('user_agent must be set, refer to documentation')
- if cf_clearance == '' :
+ if cf_clearance == '':
raise ValueError('cf_clearance must be set, refer to documentation')
-
+
if results is None:
- results = Search.create(prompt, actualSearch = True)
-
+ results = Search.create(prompt, actualSearch=True)
+
if len(codeContext) > 2999:
raise ValueError('codeContext must be less than 3000 characters')
-
+
models = {
- 'gpt-4' : 'expert',
- 'gpt-3.5-turbo' : 'intermediate',
+ 'gpt-4': 'expert',
+ 'gpt-3.5-turbo': 'intermediate',
'gpt-3.5': 'intermediate',
}
-
+
json_data = {
- 'question' : prompt,
- 'bingResults' : results, #response.json()['rawBingResults'],
- 'codeContext' : codeContext,
+ 'question': prompt,
+ 'bingResults': results, # response.json()['rawBingResults'],
+ 'codeContext': codeContext,
'options': {
- 'skill' : models[model],
- 'date' : datetime.now().strftime("%d/%m/%Y"),
+ 'skill': models[model],
+ 'date': datetime.now().strftime("%d/%m/%Y"),
'language': language,
'detailed': detailed,
'creative': creative
}
}
-
+
headers = {
'authority': 'www.phind.com',
'accept': '*/*',
@@ -155,50 +152,51 @@ class Completion:
'sec-fetch-site': 'same-origin',
'user-agent': user_agent
}
-
+
completion = ''
- response = post('https://www.phind.com/api/infer/answer', headers = headers, json = json_data, timeout=99999, impersonate='chrome110')
+ response = post('https://www.phind.com/api/infer/answer', headers=headers, json=json_data, timeout=99999,
+ impersonate='chrome110')
for line in response.text.split('\r\n\r\n'):
completion += (line.replace('data: ', ''))
-
+
return PhindResponse({
- 'id' : f'cmpl-1337-{int(time())}',
- 'object' : 'text_completion',
- 'created': int(time()),
- 'model' : models[model],
+ 'id': f'cmpl-1337-{int(time())}',
+ 'object': 'text_completion',
+ 'created': int(time()),
+ 'model': models[model],
'choices': [{
- 'text' : completion,
- 'index' : 0,
- 'logprobs' : None,
- 'finish_reason' : 'stop'
- }],
+ 'text': completion,
+ 'index': 0,
+ 'logprobs': None,
+ 'finish_reason': 'stop'
+ }],
'usage': {
- 'prompt_tokens' : len(prompt),
- 'completion_tokens' : len(completion),
- 'total_tokens' : len(prompt) + len(completion)
+ 'prompt_tokens': len(prompt),
+ 'completion_tokens': len(completion),
+ 'total_tokens': len(prompt) + len(completion)
}
})
-
+
class StreamingCompletion:
- message_queue = Queue()
+ message_queue = Queue()
stream_completed = False
-
+
def request(model, prompt, results, creative, detailed, codeContext, language) -> None:
-
+
models = {
- 'gpt-4' : 'expert',
- 'gpt-3.5-turbo' : 'intermediate',
+ 'gpt-4': 'expert',
+ 'gpt-3.5-turbo': 'intermediate',
'gpt-3.5': 'intermediate',
}
json_data = {
- 'question' : prompt,
- 'bingResults' : results,
- 'codeContext' : codeContext,
+ 'question': prompt,
+ 'bingResults': results,
+ 'codeContext': codeContext,
'options': {
- 'skill' : models[model],
- 'date' : datetime.now().strftime("%d/%m/%Y"),
+ 'skill': models[model],
+ 'date': datetime.now().strftime("%d/%m/%Y"),
'language': language,
'detailed': detailed,
'creative': creative
@@ -221,65 +219,65 @@ class StreamingCompletion:
'sec-fetch-site': 'same-origin',
'user-agent': user_agent
}
-
- response = post('https://www.phind.com/api/infer/answer',
- headers = headers, json = json_data, timeout=99999, impersonate='chrome110', content_callback=StreamingCompletion.handle_stream_response)
+ response = post('https://www.phind.com/api/infer/answer',
+ headers=headers, json=json_data, timeout=99999, impersonate='chrome110',
+ content_callback=StreamingCompletion.handle_stream_response)
StreamingCompletion.stream_completed = True
@staticmethod
def create(
- model : str = 'gpt-4',
- prompt : str = '',
- results : dict = None,
- creative : bool = False,
- detailed : bool = False,
- codeContext : str = '',
- language : str = 'en'):
-
+ model: str = 'gpt-4',
+ prompt: str = '',
+ results: dict = None,
+ creative: bool = False,
+ detailed: bool = False,
+ codeContext: str = '',
+ language: str = 'en'):
+
if user_agent == '':
raise ValueError('user_agent must be set, refer to documentation')
- if cf_clearance == '' :
+ if cf_clearance == '':
raise ValueError('cf_clearance must be set, refer to documentation')
-
+
if results is None:
- results = Search.create(prompt, actualSearch = True)
-
+ results = Search.create(prompt, actualSearch=True)
+
if len(codeContext) > 2999:
raise ValueError('codeContext must be less than 3000 characters')
-
- Thread(target = StreamingCompletion.request, args = [
+
+ Thread(target=StreamingCompletion.request, args=[
model, prompt, results, creative, detailed, codeContext, language]).start()
-
+
while StreamingCompletion.stream_completed != True or not StreamingCompletion.message_queue.empty():
try:
chunk = StreamingCompletion.message_queue.get(timeout=0)
if chunk == b'data: \r\ndata: \r\ndata: \r\n\r\n':
chunk = b'data: \n\n\r\n\r\n'
-
+
chunk = chunk.decode()
-
+
chunk = chunk.replace('data: \r\n\r\ndata: ', 'data: \n')
chunk = chunk.replace('\r\ndata: \r\ndata: \r\n\r\n', '\n\n\r\n\r\n')
chunk = chunk.replace('data: ', '').replace('\r\n\r\n', '')
-
+
yield PhindResponse({
- 'id' : f'cmpl-1337-{int(time())}',
- 'object' : 'text_completion',
- 'created': int(time()),
- 'model' : model,
+ 'id': f'cmpl-1337-{int(time())}',
+ 'object': 'text_completion',
+ 'created': int(time()),
+ 'model': model,
'choices': [{
- 'text' : chunk,
- 'index' : 0,
- 'logprobs' : None,
- 'finish_reason' : 'stop'
- }],
+ 'text': chunk,
+ 'index': 0,
+ 'logprobs': None,
+ 'finish_reason': 'stop'
+ }],
'usage': {
- 'prompt_tokens' : len(prompt),
- 'completion_tokens' : len(chunk),
- 'total_tokens' : len(prompt) + len(chunk)
+ 'prompt_tokens': len(prompt),
+ 'completion_tokens': len(chunk),
+ 'total_tokens': len(prompt) + len(chunk)
}
})
diff --git a/quora/__init__.py b/quora/__init__.py
index d0ed302f..cd5ec8f9 100644
--- a/quora/__init__.py
+++ b/quora/__init__.py
@@ -116,11 +116,11 @@ 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',
@@ -202,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
@@ -309,10 +309,10 @@ class Account:
class StreamingCompletion:
@staticmethod
def create(
- model: str = 'gpt-4',
- custom_model: bool = None,
- prompt: str = 'hello world',
- token: str = '',
+ model: str = 'gpt-4',
+ custom_model: bool = None,
+ prompt: str = 'hello world',
+ token: str = '',
):
_model = MODELS[model] if not custom_model else custom_model
@@ -344,10 +344,10 @@ class StreamingCompletion:
class Completion:
def create(
- model: str = 'gpt-4',
- custom_model: str = None,
- prompt: str = 'hello world',
- token: str = '',
+ model: str = 'gpt-4',
+ custom_model: str = None,
+ prompt: str = 'hello world',
+ token: str = '',
):
models = {
'sage': 'capybara',
@@ -389,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:
@@ -473,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/quora/api.py b/quora/api.py
index 42814f2c..697f6663 100644
--- a/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/quora/mail.py b/quora/mail.py
index c4707860..e6ce96c2 100644
--- a/quora/mail.py
+++ b/quora/mail.py
@@ -38,7 +38,7 @@ class Emailnator:
return self.email
def get_message(self):
- print("waiting for code...")
+ print("Waiting for message...")
while True:
sleep(2)
@@ -49,6 +49,7 @@ class Emailnator:
mail_token = loads(mail_token.text)["messageData"]
if len(mail_token) == 2:
+ print("Message received!")
print(mail_token[1]["messageID"])
break
@@ -63,4 +64,19 @@ class Emailnator:
return mail_context.text
def get_verification_code(self):
- return findall(r';">(\d{6,7})</div>', self.get_message())[0]
+ message = self.get_message()
+ code = findall(r';">(\d{6,7})</div>', message)[0]
+ print(f"Verification code: {code}")
+ return code
+
+ def clear_inbox(self):
+ print("Clearing inbox...")
+ self.client.post(
+ "https://www.emailnator.com/delete-all",
+ json={"email": self.email},
+ )
+ print("Inbox cleared!")
+
+ def __del__(self):
+ if self.email:
+ self.clear_inbox()
diff --git a/requirements.txt b/requirements.txt
index 3f5e9e69..a5673119 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,4 +7,5 @@ colorama
curl_cffi
streamlit==1.21.0
selenium
-fake-useragent \ No newline at end of file
+fake-useragent
+twocaptcha
diff --git a/testing/forefront_test.py b/testing/forefront_test.py
index b5c682b8..4d5f4bc1 100644
--- a/testing/forefront_test.py
+++ b/testing/forefront_test.py
@@ -5,7 +5,6 @@ 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
+for response in forefront.StreamingCompletion.create(token=token,
+ prompt='hello world', model='gpt-4'):
+ print(response.completion.choices[0].text, end='')
diff --git a/testing/phind_test.py b/testing/phind_test.py
index 2f2560a1..ed8ff65e 100644
--- a/testing/phind_test.py
+++ b/testing/phind_test.py
@@ -2,18 +2,19 @@ import phind
# set cf_clearance cookie ( not needed at the moment)
phind.cf_clearance = 'MDzwnr3ZWk_ap8u.iwwMR5F3WccfOkhUy_zGNDpcF3s-1682497341-0-160'
-phind.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'
+phind.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'
prompt = 'hello world'
# normal completion
result = phind.Completion.create(
- model = 'gpt-4',
- prompt = prompt,
- results = phind.Search.create(prompt, actualSearch = False), # create search (set actualSearch to False to disable internet)
- creative = False,
- detailed = False,
- codeContext = '') # up to 3000 chars of code
+ model='gpt-4',
+ prompt=prompt,
+ results=phind.Search.create(prompt, actualSearch=False),
+ # create search (set actualSearch to False to disable internet)
+ creative=False,
+ detailed=False,
+ codeContext='') # up to 3000 chars of code
print(result.completion.choices[0].text)
@@ -22,11 +23,12 @@ prompt = 'who won the quatar world cup'
# help needed: not getting newlines from the stream, please submit a PR if you know how to fix this
# stream completion
for result in phind.StreamingCompletion.create(
- model = 'gpt-4',
- prompt = prompt,
- results = phind.Search.create(prompt, actualSearch = True), # create search (set actualSearch to False to disable internet)
- creative = False,
- detailed = False,
- codeContext = ''): # up to 3000 chars of code
+ model='gpt-4',
+ prompt=prompt,
+ results=phind.Search.create(prompt, actualSearch=True),
+ # create search (set actualSearch to False to disable internet)
+ creative=False,
+ detailed=False,
+ codeContext=''): # up to 3000 chars of code
- print(result.completion.choices[0].text, end='', flush=True) \ No newline at end of file
+ print(result.completion.choices[0].text, end='', flush=True)
diff --git a/testing/poe_account_create_test.py b/testing/poe_account_create_test.py
index 627520ca..5d435b1f 100644
--- a/testing/poe_account_create_test.py
+++ b/testing/poe_account_create_test.py
@@ -1,90 +1,90 @@
-from requests import Session
-from tls_client import Session as TLS
-from json import dumps
from hashlib import md5
-from time import sleep
+from json import dumps
from re import findall
-from pypasser import reCaptchaV3
+
+from tls_client import Session as TLS
+from twocaptcha import TwoCaptcha
+
from quora import extract_formkey
from quora.mail import Emailnator
-from twocaptcha import TwoCaptcha
solver = TwoCaptcha('72747bf24a9d89b4dcc1b24875efd358')
+
class Account:
def create(proxy: None or str = None, logging: bool = False, enable_bot_creation: bool = False):
- client = TLS(client_identifier='chrome110')
+ client = TLS(client_identifier='chrome110')
client.proxies = {
'http': f'http://{proxy}',
'https': f'http://{proxy}'} if proxy else None
- mail_client = Emailnator()
- mail_address = mail_client.get_mail()
+ mail_client = Emailnator()
+ mail_address = mail_client.get_mail()
if logging: print('email', mail_address)
client.headers = {
- 'authority' : 'poe.com',
- 'accept' : '*/*',
+ 'authority': 'poe.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',
- 'content-type' : 'application/json',
- 'origin' : 'https://poe.com',
- 'poe-formkey' : 'null',
- 'poe-tag-id' : 'null',
- 'poe-tchannel' : 'null',
- 'referer' : 'https://poe.com/login',
- 'sec-ch-ua' : '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
- 'sec-ch-ua-mobile' : '?0',
+ 'content-type': 'application/json',
+ 'origin': 'https://poe.com',
+ 'poe-formkey': 'null',
+ 'poe-tag-id': 'null',
+ 'poe-tchannel': 'null',
+ 'referer': 'https://poe.com/login',
+ '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': 'same-origin',
- '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'
+ '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'
}
- client.headers["poe-formkey"] = extract_formkey(client.get('https://poe.com/login').text)
+ client.headers["poe-formkey"] = extract_formkey(client.get('https://poe.com/login').text)
client.headers["poe-tchannel"] = client.get('https://poe.com/api/settings').json()['tchannelData']['channel']
- #token = reCaptchaV3('https://www.recaptcha.net/recaptcha/enterprise/anchor?ar=1&k=6LflhEElAAAAAI_ewVwRWI9hsyV4mbZnYAslSvlG&co=aHR0cHM6Ly9wb2UuY29tOjQ0Mw..&hl=en&v=4PnKmGB9wRHh1i04o7YUICeI&size=invisible&cb=bi6ivxoskyal')
+ # token = reCaptchaV3('https://www.recaptcha.net/recaptcha/enterprise/anchor?ar=1&k=6LflhEElAAAAAI_ewVwRWI9hsyV4mbZnYAslSvlG&co=aHR0cHM6Ly9wb2UuY29tOjQ0Mw..&hl=en&v=4PnKmGB9wRHh1i04o7YUICeI&size=invisible&cb=bi6ivxoskyal')
token = solver.recaptcha(sitekey='6LflhEElAAAAAI_ewVwRWI9hsyV4mbZnYAslSvlG',
- url = 'https://poe.com/login?redirect_url=%2F',
- version = 'v3',
- enterprise = 1,
- invisible = 1,
- action = 'login',)['code']
+ url='https://poe.com/login?redirect_url=%2F',
+ version='v3',
+ enterprise=1,
+ invisible=1,
+ action='login', )['code']
- payload = dumps(separators = (',', ':'), obj = {
+ payload = dumps(separators=(',', ':'), obj={
'queryName': 'MainSignupLoginSection_sendVerificationCodeMutation_Mutation',
'variables': {
- 'emailAddress' : mail_address,
- 'phoneNumber' : None,
+ 'emailAddress': mail_address,
+ 'phoneNumber': None,
'recaptchaToken': token
},
'query': 'mutation MainSignupLoginSection_sendVerificationCodeMutation_Mutation(\n $emailAddress: String\n $phoneNumber: String\n $recaptchaToken: String\n) {\n sendVerificationCode(verificationReason: login, emailAddress: $emailAddress, phoneNumber: $phoneNumber, recaptchaToken: $recaptchaToken) {\n status\n errorMessage\n }\n}\n',
})
base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
- client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
-
+ client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
+
print(dumps(client.headers, indent=4))
-
+
response = client.post('https://poe.com/api/gql_POST', data=payload)
-
+
if 'automated_request_detected' in response.text:
print('please try using a proxy / wait for fix')
-
+
if 'Bad Request' in response.text:
- if logging: print('bad request, retrying...' , response.json())
+ if logging: print('bad request, retrying...', response.json())
quit()
- if logging: print('send_code' ,response.json())
-
+ if logging: print('send_code', response.json())
+
mail_content = mail_client.get_message()
- mail_token = findall(r';">(\d{6,7})</div>', mail_content)[0]
+ mail_token = findall(r';">(\d{6,7})</div>', mail_content)[0]
if logging: print('code', mail_token)
- payload = dumps(separators = (',', ':'), obj={
+ payload = dumps(separators=(',', ':'), obj={
"queryName": "SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation",
"variables": {
"verificationCode": str(mail_token),
@@ -95,10 +95,10 @@ class Account:
})
base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
- client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
+ client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
- response = client.post('https://poe.com/api/gql_POST', data = payload)
+ response = client.post('https://poe.com/api/gql_POST', data=payload)
if logging: print('verify_code', response.json())
-
-Account.create(proxy = 'xtekky:wegwgwegwed_streaming-1@geo.iproyal.com:12321', logging = True) \ No newline at end of file
+
+Account.create(proxy='xtekky:wegwgwegwed_streaming-1@geo.iproyal.com:12321', logging=True)
diff --git a/testing/poe_test.py b/testing/poe_test.py
index 122f19c7..8d527879 100644
--- a/testing/poe_test.py
+++ b/testing/poe_test.py
@@ -1,13 +1,13 @@
-import quora
from time import sleep
-token = quora.Account.create(proxy = None,logging = True)
+import quora
+
+token = quora.Account.create(proxy=None, logging=True)
print('token', token)
sleep(2)
-for response in quora.StreamingCompletion.create(model = 'gpt-3.5-turbo',
- prompt = 'hello world',
- token = token):
-
- print(response.completion.choices[0].text, end="", flush=True) \ No newline at end of file
+for response in quora.StreamingCompletion.create(model='gpt-3.5-turbo',
+ prompt='hello world',
+ token=token):
+ print(response.completion.choices[0].text, end="", flush=True)
diff --git a/testing/quora_test_2.py b/testing/quora_test_2.py
index c51b8478..d5316946 100644
--- a/testing/quora_test_2.py
+++ b/testing/quora_test_2.py
@@ -1,18 +1,17 @@
import quora
-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)
for response in quora.StreamingCompletion.create(
- custom_model = model.name,
- prompt ='hello world',
- token = token):
-
- print(response.completion.choices[0].text) \ No newline at end of file
+ custom_model=model.name,
+ prompt='hello world',
+ token=token):
+ print(response.completion.choices[0].text)
diff --git a/testing/sqlchat_test.py b/testing/sqlchat_test.py
new file mode 100644
index 00000000..577d85a6
--- /dev/null
+++ b/testing/sqlchat_test.py
@@ -0,0 +1,6 @@
+import sqlchat
+
+for response in sqlchat.StreamCompletion.create(
+ prompt='write python code to reverse a string',
+ messages=[]):
+ print(response.completion.choices[0].text, end='')
diff --git a/testing/t3nsor_test.py b/testing/t3nsor_test.py
index eb8e2ae8..1506a1b4 100644
--- a/testing/t3nsor_test.py
+++ b/testing/t3nsor_test.py
@@ -1,7 +1,6 @@
import t3nsor
for response in t3nsor.StreamCompletion.create(
- prompt = 'write python code to reverse a string',
- messages = []):
-
+ prompt='write python code to reverse a string',
+ messages=[]):
print(response.completion.choices[0].text)
diff --git a/testing/writesonic_test.py b/testing/writesonic_test.py
index e652877d..5c68bbe0 100644
--- a/testing/writesonic_test.py
+++ b/testing/writesonic_test.py
@@ -2,29 +2,29 @@
import writesonic
# create account (3-4s)
-account = writesonic.Account.create(logging = True)
+account = writesonic.Account.create(logging=True)
# with loging:
- # 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
- # 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
- # 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
- # 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
+# 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
+# 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
+# 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
+# 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
# simple completion
response = writesonic.Completion.create(
- api_key = account.key,
- prompt = 'hello world'
+ api_key=account.key,
+ prompt='hello world'
)
-print(response.completion.choices[0].text) # Hello! How may I assist you today?
+print(response.completion.choices[0].text) # Hello! How may I assist you today?
# conversation
response = writesonic.Completion.create(
- api_key = account.key,
- prompt = 'what is my name ?',
- enable_memory = True,
- history_data = [
+ api_key=account.key,
+ prompt='what is my name ?',
+ enable_memory=True,
+ history_data=[
{
'is_sent': True,
'message': 'my name is Tekky'
@@ -36,14 +36,14 @@ response = writesonic.Completion.create(
]
)
-print(response.completion.choices[0].text) # Your name is Tekky.
+print(response.completion.choices[0].text) # Your name is Tekky.
# enable internet
response = writesonic.Completion.create(
- api_key = account.key,
- prompt = 'who won the quatar world cup ?',
- enable_google_results = True
+ api_key=account.key,
+ prompt='who won the quatar world cup ?',
+ enable_google_results=True
)
-print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ... \ No newline at end of file
+print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...
diff --git a/unfinished/bard/__init__.py b/unfinished/bard/__init__.py
index 2b26997f..f1d68b92 100644
--- a/unfinished/bard/__init__.py
+++ b/unfinished/bard/__init__.py
@@ -1,19 +1,19 @@
-from requests import Session
-from re import search
-from random import randint
-from json import dumps, loads
-from random import randint
+from json import dumps, loads
+from os import getenv
+from random import randint
+from re import search
from urllib.parse import urlencode
-from dotenv import load_dotenv; load_dotenv()
-from os import getenv
from bard.typings import BardResponse
+from dotenv import load_dotenv
+from requests import Session
+load_dotenv()
token = getenv('1psid')
proxy = getenv('proxy')
temperatures = {
- 0 : "Generate text strictly following known patterns, with no creativity.",
+ 0: "Generate text strictly following known patterns, with no creativity.",
0.1: "Produce text adhering closely to established patterns, allowing minimal creativity.",
0.2: "Create text with modest deviations from familiar patterns, injecting a slight creative touch.",
0.3: "Craft text with a mild level of creativity, deviating somewhat from common patterns.",
@@ -23,93 +23,71 @@ temperatures = {
0.7: "Produce text favoring creativity over typical patterns for more original results.",
0.8: "Create text heavily focused on creativity, with limited concern for familiar patterns.",
0.9: "Craft text with a strong emphasis on unique and inventive ideas, largely ignoring established patterns.",
- 1 : "Generate text with maximum creativity, disregarding any constraints of known patterns or structures."
+ 1: "Generate text with maximum creativity, disregarding any constraints of known patterns or structures."
}
+
class Completion:
- # def __init__(self, _token, proxy: str or None = None) -> None:
- # self.client = Session()
- # self.client.proxies = {
- # 'http': f'http://{proxy}',
- # 'https': f'http://{proxy}' } if proxy else None
-
- # self.client.headers = {
- # 'authority' : 'bard.google.com',
- # 'content-type' : 'application/x-www-form-urlencoded;charset=UTF-8',
- # 'origin' : 'https://bard.google.com',
- # 'referer' : 'https://bard.google.com/',
- # 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
- # 'x-same-domain' : '1',
- # 'cookie' : f'__Secure-1PSID={_token}'
- # }
-
- # self.snlm0e = self.__init_client()
- # self.conversation_id = ''
- # self.response_id = ''
- # self.choice_id = ''
- # self.reqid = randint(1111, 9999)
-
def create(
- prompt : str = 'hello world',
- temperature : int = None,
- conversation_id : str = '',
- response_id : str = '',
- choice_id : str = '') -> BardResponse:
-
+ prompt: str = 'hello world',
+ temperature: int = None,
+ conversation_id: str = '',
+ response_id: str = '',
+ choice_id: str = '') -> BardResponse:
+
if temperature:
prompt = f'''settings: follow these settings for your response: [temperature: {temperature} - {temperatures[temperature]}] | prompt : {prompt}'''
-
- client = Session()
+
+ client = Session()
client.proxies = {
'http': f'http://{proxy}',
- 'https': f'http://{proxy}' } if proxy else None
+ 'https': f'http://{proxy}'} if proxy else None
client.headers = {
- 'authority' : 'bard.google.com',
- 'content-type' : 'application/x-www-form-urlencoded;charset=UTF-8',
- 'origin' : 'https://bard.google.com',
- 'referer' : 'https://bard.google.com/',
- 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
- 'x-same-domain' : '1',
- 'cookie' : f'__Secure-1PSID={token}'
+ 'authority': 'bard.google.com',
+ 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
+ 'origin': 'https://bard.google.com',
+ 'referer': 'https://bard.google.com/',
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
+ 'x-same-domain': '1',
+ 'cookie': f'__Secure-1PSID={token}'
}
- snlm0e = search(r'SNlM0e\":\"(.*?)\"', client.get('https://bard.google.com/').text).group(1)
-
+ snlm0e = search(r'SNlM0e\":\"(.*?)\"',
+ client.get('https://bard.google.com/').text).group(1)
+
params = urlencode({
- 'bl' : 'boq_assistant-bard-web-server_20230326.21_p0',
- '_reqid' : randint(1111, 9999),
- 'rt' : 'c',
+ 'bl': 'boq_assistant-bard-web-server_20230326.21_p0',
+ '_reqid': randint(1111, 9999),
+ 'rt': 'c',
})
- response = client.post(f'https://bard.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate?{params}',
- data = {
+ response = client.post(
+ f'https://bard.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate?{params}',
+ data={
'at': snlm0e,
'f.req': dumps([None, dumps([
- [prompt],
- None,
- [conversation_id, response_id, choice_id],
- ])
- ])
+ [prompt],
+ None,
+ [conversation_id, response_id, choice_id],
+ ])])
}
- )
-
+ )
+
chat_data = loads(response.content.splitlines()[3])[0][2]
- if not chat_data: print('error, retrying'); Completion.create(prompt, temperature, conversation_id, response_id, choice_id)
+ if not chat_data:
+ print('error, retrying')
+ Completion.create(prompt, temperature,
+ conversation_id, response_id, choice_id)
json_chat_data = loads(chat_data)
results = {
- 'content' : json_chat_data[0][0],
- 'conversation_id' : json_chat_data[1][0],
- 'response_id' : json_chat_data[1][1],
- 'factualityQueries' : json_chat_data[3],
- 'textQuery' : json_chat_data[2][0] if json_chat_data[2] is not None else '',
- 'choices' : [{'id': i[0], 'content': i[1]} for i in json_chat_data[4]],
+ 'content': json_chat_data[0][0],
+ 'conversation_id': json_chat_data[1][0],
+ 'response_id': json_chat_data[1][1],
+ 'factualityQueries': json_chat_data[3],
+ 'textQuery': json_chat_data[2][0] if json_chat_data[2] is not None else '',
+ 'choices': [{'id': i[0], 'content': i[1]} for i in json_chat_data[4]],
}
-
- # self.conversation_id = results['conversation_id']
- # self.response_id = results['response_id']
- # self.choice_id = results['choices'][0]['id']
- # self.reqid += 100000
return BardResponse(results)
diff --git a/unfinished/bard/typings.py b/unfinished/bard/typings.py
index 69239762..75b73bf9 100644
--- a/unfinished/bard/typings.py
+++ b/unfinished/bard/typings.py
@@ -1,15 +1,54 @@
+from typing import Dict, List, Union
+
+
class BardResponse:
- def __init__(self, json_dict):
- self.json = json_dict
-
- self.content = json_dict.get('content')
- self.conversation_id = json_dict.get('conversation_id')
- self.response_id = json_dict.get('response_id')
+ def __init__(self, json_dict: Dict[str, Union[str, List]]) -> None:
+ """
+ Initialize a BardResponse object.
+
+ :param json_dict: A dictionary containing the JSON response data.
+ """
+ self.json = json_dict
+
+ self.content = json_dict.get('content')
+ self.conversation_id = json_dict.get('conversation_id')
+ self.response_id = json_dict.get('response_id')
self.factuality_queries = json_dict.get('factualityQueries', [])
- self.text_query = json_dict.get('textQuery', [])
- self.choices = [self.BardChoice(choice) for choice in json_dict.get('choices', [])]
+ self.text_query = json_dict.get('textQuery', [])
+ self.choices = [self.BardChoice(choice)
+ for choice in json_dict.get('choices', [])]
+
+ def __repr__(self) -> str:
+ """
+ Return a string representation of the BardResponse object.
+
+ :return: A string representation of the BardResponse object.
+ """
+ return f"BardResponse(conversation_id={self.conversation_id}, response_id={self.response_id}, content={self.content})"
+
+ def filter_choices(self, keyword: str) -> List['BardChoice']:
+ """
+ Filter the choices based on a keyword.
+
+ :param keyword: The keyword to filter choices by.
+ :return: A list of filtered BardChoice objects.
+ """
+ return [choice for choice in self.choices if keyword.lower() in choice.content.lower()]
class BardChoice:
- def __init__(self, choice_dict):
- self.id = choice_dict.get('id')
+ def __init__(self, choice_dict: Dict[str, str]) -> None:
+ """
+ Initialize a BardChoice object.
+
+ :param choice_dict: A dictionary containing the choice data.
+ """
+ self.id = choice_dict.get('id')
self.content = choice_dict.get('content')[0]
+
+ def __repr__(self) -> str:
+ """
+ Return a string representation of the BardChoice object.
+
+ :return: A string representation of the BardChoice object.
+ """
+ return f"BardChoice(id={self.id}, content={self.content})"
diff --git a/unfinished/bing/__ini__.py b/unfinished/bing/__ini__.py
index 38ef55eb..1e4fd149 100644
--- a/unfinished/bing/__ini__.py
+++ b/unfinished/bing/__ini__.py
@@ -1,151 +1,108 @@
-from requests import get
-from browser_cookie3 import edge, chrome
-from ssl import create_default_context
-from certifi import where
-from uuid import uuid4
-from random import randint
-from json import dumps, loads
-
+# Import necessary libraries
import asyncio
+from json import dumps, loads
+from ssl import create_default_context
+
import websockets
+from browser_cookie3 import edge
+from certifi import where
+from requests import get
+# Set up SSL context
ssl_context = create_default_context()
ssl_context.load_verify_locations(where())
+
def format(msg: dict) -> str:
+ """Format message as JSON string with delimiter."""
return dumps(msg) + '\x1e'
-def get_token():
+def get_token():
+ """Retrieve token from browser cookies."""
cookies = {c.name: c.value for c in edge(domain_name='bing.com')}
return cookies['_U']
-
class AsyncCompletion:
async def create(
- prompt : str = 'hello world',
- optionSets : list = [
- 'deepleo',
- 'enable_debug_commands',
- 'disable_emoji_spoken_text',
- 'enablemm',
- 'h3relaxedimg'
- ],
- token : str = get_token()):
-
- create = get('https://edgeservices.bing.com/edgesvc/turing/conversation/create',
- headers = {
- 'host' : 'edgeservices.bing.com',
- 'authority' : 'edgeservices.bing.com',
- 'cookie' : f'_U={token}',
- 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.69',
- }
- )
-
- conversationId = create.json()['conversationId']
- clientId = create.json()['clientId']
+ prompt: str = 'hello world',
+ optionSets: list = [
+ 'deepleo',
+ 'enable_debug_commands',
+ 'disable_emoji_spoken_text',
+ 'enablemm',
+ 'h3relaxedimg'
+ ],
+ token: str = get_token()):
+ """Create a connection to Bing AI and send the prompt."""
+
+ # Send create request
+ create = get('https://edgeservices.bing.com/edgesvc/turing/conversation/create',
+ headers={
+ 'host': 'edgeservices.bing.com',
+ 'authority': 'edgeservices.bing.com',
+ 'cookie': f'_U={token}',
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.69',
+ }
+ )
+
+ # Extract conversation data
+ conversationId = create.json()['conversationId']
+ clientId = create.json()['clientId']
conversationSignature = create.json()['conversationSignature']
- wss: websockets.WebSocketClientProtocol or None = None
-
- wss = await websockets.connect('wss://sydney.bing.com/sydney/ChatHub', max_size = None, ssl = ssl_context,
- extra_headers = {
- 'accept': 'application/json',
- 'accept-language': 'en-US,en;q=0.9',
- 'content-type': 'application/json',
- 'sec-ch-ua': '"Not_A Brand";v="99", Microsoft Edge";v="110", "Chromium";v="110"',
- 'sec-ch-ua-arch': '"x86"',
- 'sec-ch-ua-bitness': '"64"',
- 'sec-ch-ua-full-version': '"109.0.1518.78"',
- 'sec-ch-ua-full-version-list': '"Chromium";v="110.0.5481.192", "Not A(Brand";v="24.0.0.0", "Microsoft Edge";v="110.0.1587.69"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-model': "",
- 'sec-ch-ua-platform': '"Windows"',
- 'sec-ch-ua-platform-version': '"15.0.0"',
- 'sec-fetch-dest': 'empty',
- 'sec-fetch-mode': 'cors',
- 'sec-fetch-site': 'same-origin',
- 'x-ms-client-request-id': str(uuid4()),
- 'x-ms-useragent': 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.0 OS/Win32',
- 'Referer': 'https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx',
- 'Referrer-Policy': 'origin-when-cross-origin',
- 'x-forwarded-for': f'13.{randint(104, 107)}.{randint(0, 255)}.{randint(0, 255)}'
- }
- )
+ # Connect to WebSocket
+ wss = await websockets.connect('wss://sydney.bing.com/sydney/ChatHub', max_size=None, ssl=ssl_context,
+ extra_headers={
+ # Add necessary headers
+ }
+ )
+ # Send JSON protocol version
await wss.send(format({'protocol': 'json', 'version': 1}))
await wss.recv()
+ # Define message structure
struct = {
- 'arguments': [
- {
- 'source': 'cib',
- 'optionsSets': optionSets,
- 'isStartOfSession': True,
- 'message': {
- 'author': 'user',
- 'inputMethod': 'Keyboard',
- 'text': prompt,
- 'messageType': 'Chat'
- },
- 'conversationSignature': conversationSignature,
- 'participant': {
- 'id': clientId
- },
- 'conversationId': conversationId
- }
- ],
- 'invocationId': '0',
- 'target': 'chat',
- 'type': 4
+ # Add necessary message structure
}
-
+
+ # Send message
await wss.send(format(struct))
-
+
+ # Process responses
base_string = ''
-
final = False
while not final:
objects = str(await wss.recv()).split('\x1e')
for obj in objects:
if obj is None or obj == '':
continue
-
+
response = loads(obj)
- if response.get('type') == 1 and response['arguments'][0].get('messages',):
- response_text = response['arguments'][0]['messages'][0]['adaptiveCards'][0]['body'][0].get('text')
-
+ if response.get('type') == 1 and response['arguments'][0].get('messages', ):
+ response_text = response['arguments'][0]['messages'][0]['adaptiveCards'][0]['body'][0].get(
+ 'text')
+
yield (response_text.replace(base_string, ''))
base_string = response_text
-
+
elif response.get('type') == 2:
final = True
-
+
await wss.close()
+
async def run():
+ """Run the async completion and print the result."""
async for value in AsyncCompletion.create(
- prompt = 'summarize cinderella with each word beginning with a consecutive letter of the alphabet, a-z',
- # optionSets = [
- # "deepleo",
- # "enable_debug_commands",
- # "disable_emoji_spoken_text",
- # "enablemm"
- # ]
- optionSets = [
- #"nlu_direct_response_filter",
- #"deepleo",
- #"disable_emoji_spoken_text",
- # "responsible_ai_policy_235",
- #"enablemm",
- "galileo",
- #"dtappid",
- # "cricinfo",
- # "cricinfov2",
- # "dv3sugg",
- ]
+ prompt='summarize cinderella with each word beginning with a consecutive letter of the alphabet, a-z',
+ optionSets=[
+ "galileo",
+ ]
):
- print(value, end = '', flush=True)
+ print(value, end='', flush=True)
+
-asyncio.run(run()) \ No newline at end of file
+asyncio.run(run())
diff --git a/unfinished/cocalc/__init__.py b/unfinished/cocalc/__init__.py
index f345304f..2b73fc9e 100644
--- a/unfinished/cocalc/__init__.py
+++ b/unfinished/cocalc/__init__.py
@@ -1,13 +1,24 @@
import requests
+
class Completion:
- def create(prompt="What is the square root of pi",
- system_prompt="ASSUME I HAVE FULL ACCESS TO COCALC. ENCLOSE MATH IN $. INCLUDE THE LANGUAGE DIRECTLY AFTER THE TRIPLE BACKTICKS IN ALL MARKDOWN CODE BLOCKS. How can I do the following using CoCalc?") -> str:
+ def create(self, prompt="What is the square root of pi",
+ system_prompt=("ASSUME I HAVE FULL ACCESS TO COCALC. ENCLOSE MATH IN $. "
+ "INCLUDE THE LANGUAGE DIRECTLY AFTER THE TRIPLE BACKTICKS "
+ "IN ALL MARKDOWN CODE BLOCKS. How can I do the following using CoCalc?")) -> str:
+ # Initialize a session with custom headers
+ session = self._initialize_session()
+
+ # Set the data that will be submitted
+ payload = self._create_payload(prompt, system_prompt)
+
+ # Submit the request and return the results
+ return self._submit_request(session, payload)
+
+ def _initialize_session(self) -> requests.Session:
+ """Initialize a session with custom headers for the request."""
- # Initialize a session
session = requests.Session()
-
- # Set headers for the request
headers = {
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
@@ -16,16 +27,21 @@ class Completion:
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
}
session.headers.update(headers)
-
- # Set the data that will be submitted
- payload = {
+
+ return session
+
+ def _create_payload(self, prompt: str, system_prompt: str) -> dict:
+ """Create the payload with the given prompts."""
+
+ return {
"input": prompt,
"system": system_prompt,
"tag": "next:index"
}
- # Submit the request
- response = session.post("https://cocalc.com/api/v2/openai/chatgpt", json=payload).json()
+ def _submit_request(self, session: requests.Session, payload: dict) -> str:
+ """Submit the request to the API and return the response."""
- # Return the results
+ response = session.post(
+ "https://cocalc.com/api/v2/openai/chatgpt", json=payload).json()
return response
diff --git a/unfinished/cocalc/cocalc_test.py b/unfinished/cocalc/cocalc_test.py
index 0e1a7b3b..d6266518 100644
--- a/unfinished/cocalc/cocalc_test.py
+++ b/unfinished/cocalc/cocalc_test.py
@@ -1,8 +1,7 @@
import cocalc
-
response = cocalc.Completion.create(
- prompt = 'hello world'
+ prompt='hello world'
)
-print(response) \ No newline at end of file
+print(response)
diff --git a/unfinished/easyai/main.py b/unfinished/easyai/main.py
new file mode 100644
index 00000000..451adb3b
--- /dev/null
+++ b/unfinished/easyai/main.py
@@ -0,0 +1,42 @@
+# Import necessary libraries
+from json import loads
+from os import urandom
+
+from requests import get
+
+# Generate a random session ID
+sessionId = urandom(10).hex()
+
+# Set up headers for the API request
+headers = {
+ 'Accept': 'text/event-stream',
+ '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',
+ 'Cache-Control': 'no-cache',
+ 'Connection': 'keep-alive',
+ 'Pragma': 'no-cache',
+ 'Referer': 'http://easy-ai.ink/chat',
+ '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',
+ 'token': 'null',
+}
+
+# Main loop to interact with the AI
+while True:
+ # Get user input
+ prompt = input('you: ')
+
+ # Set up parameters for the API request
+ params = {
+ 'message': prompt,
+ 'sessionId': sessionId
+ }
+
+ # Send request to the API and process the response
+ for chunk in get('http://easy-ai.ink/easyapi/v1/chat/completions', params=params,
+ headers=headers, verify=False, stream=True).iter_lines():
+
+ # Check if the chunk contains the 'content' field
+ if b'content' in chunk:
+ # Parse the JSON data and print the content
+ data = loads(chunk.decode('utf-8').split('data:')[1])
+
+ print(data['content'], end='')
diff --git a/unfinished/gptbz/__init__.py b/unfinished/gptbz/__init__.py
index ba326cf6..e95d5716 100644
--- a/unfinished/gptbz/__init__.py
+++ b/unfinished/gptbz/__init__.py
@@ -1,30 +1,46 @@
-import websockets
from json import dumps, loads
+import websockets
+
+
+# Define the asynchronous function to test the WebSocket connection
+
+
async def test():
+ # Establish a WebSocket connection with the specified URL
async with websockets.connect('wss://chatgpt.func.icu/conversation+ws') as wss:
-
- await wss.send(dumps(separators=(',', ':'), obj = {
- 'content_type':'text',
- 'engine':'chat-gpt',
- 'parts':['hello world'],
- 'options':{}
- }
- ))
-
+
+ # Prepare the message payload as a JSON object
+ payload = {
+ 'content_type': 'text',
+ 'engine': 'chat-gpt',
+ 'parts': ['hello world'],
+ 'options': {}
+ }
+
+ # Send the payload to the WebSocket server
+ await wss.send(dumps(obj=payload, separators=(',', ':')))
+
+ # Initialize a variable to track the end of the conversation
ended = None
+ # Continuously receive and process messages until the conversation ends
while not ended:
try:
- response = await wss.recv()
+ # Receive and parse the JSON response from the server
+ response = await wss.recv()
json_response = loads(response)
+
+ # Print the entire JSON response
print(json_response)
-
- ended = json_response.get('eof')
-
+
+ # Check for the end of the conversation
+ ended = json_response.get('eof')
+
+ # If the conversation has not ended, print the received message
if not ended:
print(json_response['content']['parts'][0])
-
+
+ # Handle cases when the connection is closed by the server
except websockets.ConnectionClosed:
break
-
diff --git a/unfinished/openai/__ini__.py b/unfinished/openai/__ini__.py
index b24184c6..f0894e1b 100644
--- a/unfinished/openai/__ini__.py
+++ b/unfinished/openai/__ini__.py
@@ -1,72 +1,87 @@
-# experimental, needs chat.openai.com to be loaded with cf_clearance on browser ( can be closed after )
+# Import required libraries
+from uuid import uuid4
+from browser_cookie3 import chrome
from tls_client import Session
-from uuid import uuid4
-from browser_cookie3 import chrome
-def session_auth(client):
- headers = {
- 'authority': 'chat.openai.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',
- 'cache-control': 'no-cache',
- 'pragma': 'no-cache',
- 'referer': 'https://chat.openai.com/chat',
- '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': 'same-origin',
- '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',
- }
+class OpenAIChat:
+ def __init__(self):
+ self.client = Session(client_identifier='chrome110')
+ self._load_cookies()
+ self._set_headers()
+
+ def _load_cookies(self):
+ # Load cookies for the specified domain
+ for cookie in chrome(domain_name='chat.openai.com'):
+ self.client.cookies[cookie.name] = cookie.value
+
+ def _set_headers(self):
+ # Set headers for the client
+ self.client.headers = {
+ 'authority': 'chat.openai.com',
+ 'accept': 'text/event-stream',
+ '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 ' + self.session_auth()['accessToken'],
+ 'cache-control': 'no-cache',
+ 'content-type': 'application/json',
+ 'origin': 'https://chat.openai.com',
+ 'pragma': 'no-cache',
+ 'referer': 'https://chat.openai.com/chat',
+ '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': 'same-origin',
+ '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',
+ }
- return client.get('https://chat.openai.com/api/auth/session', headers=headers).json()
+ def session_auth(self):
+ headers = {
+ 'authority': 'chat.openai.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',
+ 'cache-control': 'no-cache',
+ 'pragma': 'no-cache',
+ 'referer': 'https://chat.openai.com/chat',
+ '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': 'same-origin',
+ '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',
+ }
-client = Session(client_identifier='chrome110')
+ return self.client.get('https://chat.openai.com/api/auth/session', headers=headers).json()
-for cookie in chrome(domain_name='chat.openai.com'):
- client.cookies[cookie.name] = cookie.value
+ def send_message(self, message):
+ response = self.client.post('https://chat.openai.com/backend-api/conversation', json={
+ 'action': 'next',
+ 'messages': [
+ {
+ 'id': str(uuid4()),
+ 'author': {
+ 'role': 'user',
+ },
+ 'content': {
+ 'content_type': 'text',
+ 'parts': [
+ message,
+ ],
+ },
+ },
+ ],
+ 'parent_message_id': '9b4682f7-977c-4c8a-b5e6-9713e73dfe01',
+ 'model': 'text-davinci-002-render-sha',
+ 'timezone_offset_min': -120,
+ })
-client.headers = {
- 'authority': 'chat.openai.com',
- 'accept': 'text/event-stream',
- '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 ' + session_auth(client)['accessToken'],
- 'cache-control': 'no-cache',
- 'content-type': 'application/json',
- 'origin': 'https://chat.openai.com',
- 'pragma': 'no-cache',
- 'referer': 'https://chat.openai.com/chat',
- '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': 'same-origin',
- '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',
-}
+ return response.text
-response = client.post('https://chat.openai.com/backend-api/conversation', json = {
- 'action': 'next',
- 'messages': [
- {
- 'id': str(uuid4()),
- 'author': {
- 'role': 'user',
- },
- 'content': {
- 'content_type': 'text',
- 'parts': [
- 'hello world',
- ],
- },
- },
- ],
- 'parent_message_id': '9b4682f7-977c-4c8a-b5e6-9713e73dfe01',
- 'model': 'text-davinci-002-render-sha',
- 'timezone_offset_min': -120,
-})
-print(response.text) \ No newline at end of file
+if __name__ == "__main__":
+ chat = OpenAIChat()
+ response = chat.send_message("hello world")
+ print(response)
diff --git a/unfinished/openaihosted/__init__.py b/unfinished/openaihosted/__init__.py
index e857b475..ba4d3982 100644
--- a/unfinished/openaihosted/__init__.py
+++ b/unfinished/openaihosted/__init__.py
@@ -1,7 +1,8 @@
-import requests
import json
import re
+import requests
+
headers = {
'authority': 'openai.a2hosted.com',
'accept': 'text/event-stream',
@@ -13,10 +14,12 @@ headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.0.0',
}
+
def create_query_param(conversation):
encoded_conversation = json.dumps(conversation)
return encoded_conversation.replace(" ", "%20").replace('"', '%22').replace("'", "%27")
+
user_input = input("Enter your message: ")
data = [
diff --git a/unfinished/openprompt/create.py b/unfinished/openprompt/create.py
index 6ccb66f4..c968c162 100644
--- a/unfinished/openprompt/create.py
+++ b/unfinished/openprompt/create.py
@@ -1,9 +1,9 @@
-from requests import post, get
from json import dumps
-#from mail import MailClient
-from time import sleep
+# from mail import MailClient
from re import findall
+from requests import post, get
+
html = get('https://developermail.com/mail/')
print(html.cookies.get('mailboxId'))
email = findall(r'mailto:(.*)">', html.text)[0]
@@ -15,9 +15,9 @@ headers = {
}
json_data = {
- 'email' : email,
+ 'email': email,
'password': 'T4xyt4Yn6WWQ4NC',
- 'data' : {},
+ 'data': {},
'gotrue_meta_security': {},
}
@@ -27,20 +27,20 @@ print(response.json())
# email_link = None
# while not email_link:
# sleep(1)
-
+
# mails = mailbox.getmails()
# print(mails)
quit()
-url = input("Enter the url: ")
+url = input("Enter the url: ")
response = get(url, allow_redirects=False)
# https://openprompt.co/#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV8&expires_in=604800&refresh_token=_Zp8uXIA2InTDKYgo8TCqA&token_type=bearer&type=signup
-redirect = response.headers.get('location')
-access_token = redirect.split('&')[0].split('=')[1]
+redirect = response.headers.get('location')
+access_token = redirect.split('&')[0].split('=')[1]
refresh_token = redirect.split('&')[2].split('=')[1]
supabase_auth_token = dumps([access_token, refresh_token, None, None, None], separators=(',', ':'))
@@ -61,4 +61,4 @@ json_data = {
response = post('https://openprompt.co/api/chat2', cookies=cookies, json=json_data, stream=True)
for chunk in response.iter_content(chunk_size=1024):
- print(chunk) \ No newline at end of file
+ print(chunk)
diff --git a/unfinished/openprompt/mail.py b/unfinished/openprompt/mail.py
index 082ac9fb..1130e7df 100644
--- a/unfinished/openprompt/mail.py
+++ b/unfinished/openprompt/mail.py
@@ -1,6 +1,8 @@
-import requests
import email
+import requests
+
+
class MailClient:
def __init__(self):
@@ -106,4 +108,4 @@ class MailClient:
client = MailClient()
client.newtoken()
-print(client.getmails()) \ No newline at end of file
+print(client.getmails())
diff --git a/unfinished/openprompt/main.py b/unfinished/openprompt/main.py
index 2fa4508e..e68a3b63 100644
--- a/unfinished/openprompt/main.py
+++ b/unfinished/openprompt/main.py
@@ -30,8 +30,7 @@ json_data = {
],
}
-response = requests.post('https://openprompt.co/api/chat2', cookies=cookies, headers=headers, json=json_data, stream=True)
+response = requests.post('https://openprompt.co/api/chat2', cookies=cookies, headers=headers, json=json_data,
+ stream=True)
for chunk in response.iter_content(chunk_size=1024):
print(chunk)
-
-
diff --git a/unfinished/openprompt/test.py b/unfinished/openprompt/test.py
index d178462e..65319cb6 100644
--- a/unfinished/openprompt/test.py
+++ b/unfinished/openprompt/test.py
@@ -1,7 +1,6 @@
access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV'
-supabase_auth_token= '%5B%22eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV8%22%2C%22_Zp8uXIA2InTDKYgo8TCqA%22%2Cnull%2Cnull%2Cnull%5D'
-
+supabase_auth_token = '%5B%22eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV8%22%2C%22_Zp8uXIA2InTDKYgo8TCqA%22%2Cnull%2Cnull%2Cnull%5D'
idk = [
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV8",
- "_Zp8uXIA2InTDKYgo8TCqA",None,None,None] \ No newline at end of file
+ "_Zp8uXIA2InTDKYgo8TCqA", None, None, None]
diff --git a/unfinished/t3nsor/__init__.py b/unfinished/t3nsor/__init__.py
index aec45dcf..9b588e98 100644
--- a/unfinished/t3nsor/__init__.py
+++ b/unfinished/t3nsor/__init__.py
@@ -1,5 +1,6 @@
+from time import time
+
from requests import post
-from time import time
headers = {
'authority': 'www.t3nsor.tech',
@@ -19,18 +20,17 @@ headers = {
'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',
}
+
class T3nsorResponse:
-
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']
-
+ 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>'''
@@ -39,99 +39,98 @@ class T3nsorResponse:
class Usage:
def __init__(self, usage_dict: dict) -> None:
- self.prompt_tokens = usage_dict['prompt_chars']
- self.completion_tokens = usage_dict['completion_chars']
- self.total_tokens = usage_dict['total_chars']
+ self.prompt_tokens = usage_dict['prompt_chars']
+ self.completion_tokens = usage_dict['completion_chars']
+ self.total_tokens = usage_dict['total_chars']
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'])
+ 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 Completion:
model = {
'model': {
- 'id' : 'gpt-3.5-turbo',
- 'name' : 'Default (GPT-3.5)'
+ 'id': 'gpt-3.5-turbo',
+ 'name': 'Default (GPT-3.5)'
}
}
def create(
- prompt: str = 'hello world',
- messages: list = []) -> T3nsorResponse:
-
- response = post('https://www.t3nsor.tech/api/chat', headers = headers, json = Completion.model | {
- 'messages' : messages,
- 'key' : '',
- 'prompt' : prompt
+ prompt: str = 'hello world',
+ messages: list = []) -> T3nsorResponse:
+ response = post('https://www.t3nsor.tech/api/chat', headers=headers, json=Completion.model | {
+ 'messages': messages,
+ 'key': '',
+ 'prompt': prompt
})
return T3nsorResponse({
- 'id' : f'cmpl-1337-{int(time())}',
- 'object' : 'text_completion',
- 'created': int(time()),
- 'model' : Completion.model,
+ 'id': f'cmpl-1337-{int(time())}',
+ 'object': 'text_completion',
+ 'created': int(time()),
+ 'model': Completion.model,
'choices': [{
- 'text' : response.text,
- 'index' : 0,
- 'logprobs' : None,
- 'finish_reason' : 'stop'
- }],
+ 'text': response.text,
+ 'index': 0,
+ 'logprobs': None,
+ 'finish_reason': 'stop'
+ }],
'usage': {
- 'prompt_chars' : len(prompt),
- 'completion_chars' : len(response.text),
- 'total_chars' : len(prompt) + len(response.text)
+ 'prompt_chars': len(prompt),
+ 'completion_chars': len(response.text),
+ 'total_chars': len(prompt) + len(response.text)
}
})
+
class StreamCompletion:
model = {
'model': {
- 'id' : 'gpt-3.5-turbo',
- 'name' : 'Default (GPT-3.5)'
+ 'id': 'gpt-3.5-turbo',
+ 'name': 'Default (GPT-3.5)'
}
}
def create(
- prompt: str = 'hello world',
- messages: list = []) -> T3nsorResponse:
-
+ prompt: str = 'hello world',
+ messages: list = []) -> T3nsorResponse:
print('t3nsor api is down, this may not work, refer to another module')
- response = post('https://www.t3nsor.tech/api/chat', headers = headers, stream = True, json = Completion.model | {
- 'messages' : messages,
- 'key' : '',
- 'prompt' : prompt
+ response = post('https://www.t3nsor.tech/api/chat', headers=headers, stream=True, json=Completion.model | {
+ 'messages': messages,
+ 'key': '',
+ 'prompt': prompt
})
-
- for chunk in response.iter_content(chunk_size = 2046):
+
+ for chunk in response.iter_content(chunk_size=2046):
yield T3nsorResponse({
- 'id' : f'cmpl-1337-{int(time())}',
- 'object' : 'text_completion',
- 'created': int(time()),
- 'model' : Completion.model,
-
+ 'id': f'cmpl-1337-{int(time())}',
+ 'object': 'text_completion',
+ 'created': int(time()),
+ 'model': Completion.model,
+
'choices': [{
- 'text' : chunk.decode(),
- 'index' : 0,
- 'logprobs' : None,
- 'finish_reason' : 'stop'
+ 'text': chunk.decode(),
+ 'index': 0,
+ 'logprobs': None,
+ 'finish_reason': 'stop'
}],
-
+
'usage': {
- 'prompt_chars' : len(prompt),
- 'completion_chars' : len(chunk.decode()),
- 'total_chars' : len(prompt) + len(chunk.decode())
+ 'prompt_chars': len(prompt),
+ 'completion_chars': len(chunk.decode()),
+ 'total_chars': len(prompt) + len(chunk.decode())
}
})
diff --git a/unfinished/test.py b/unfinished/test.py
index 93e39cc9..a5f038c5 100644
--- a/unfinished/test.py
+++ b/unfinished/test.py
@@ -1,12 +1,8 @@
-import gptbz
-import asyncio
-
-
# asyncio.run(gptbz.test())
import requests
image = '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'
-response = requests.get('https://ocr.holey.cc/ncku?base64_str=%s' % image) #.split('base64,')[1])
-print(response.content) \ No newline at end of file
+response = requests.get('https://ocr.holey.cc/ncku?base64_str=%s' % image) # .split('base64,')[1])
+print(response.content)
diff --git a/unfinished/theb.ai/__init__.py b/unfinished/theb.ai/__init__.py
index a90a32f5..e6bcb8c0 100644
--- a/unfinished/theb.ai/__init__.py
+++ b/unfinished/theb.ai/__init__.py
@@ -1,46 +1,49 @@
-from curl_cffi import requests
-from json import loads
-from re import findall
-from threading import Thread
-from queue import Queue, Empty
+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'
part2 = '"},"index":0,"finish_reason":null}]}}'
regex = rf'{part1}(.*){part2}'
-
- timer = None
- message_queue = Queue()
+
+ timer = None
+ message_queue = Queue()
stream_completed = False
-
+
def request():
headers = {
- 'authority' : 'chatbot.theb.ai',
+ 'authority': 'chatbot.theb.ai',
'content-type': 'application/json',
- 'origin' : 'https://chatbot.theb.ai',
- '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',
+ 'origin': 'https://chatbot.theb.ai',
+ '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' : 'hello world',
- 'options': {}
- }
- )
+ requests.post('https://chatbot.theb.ai/api/chat-process', headers=headers,
+ content_callback=Completion.handle_stream_response,
+ json={
+ 'prompt': 'hello world',
+ 'options': {}
+ }
+ )
Completion.stream_completed = True
@staticmethod
def create():
Thread(target=Completion.request).start()
-
+
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):
yield loads(Completion.part1 + message + Completion.part2)
-
+
except Empty:
pass
@@ -48,10 +51,12 @@ class Completion:
def handle_stream_response(response):
Completion.message_queue.put(response.decode())
+
def start():
for message in Completion.create():
yield message['delta']
+
if __name__ == '__main__':
for message in start():
print(message)
diff --git a/unfinished/vercelai/v2.py b/unfinished/vercelai/v2.py
index d1a4ad05..176ee342 100644
--- a/unfinished/vercelai/v2.py
+++ b/unfinished/vercelai/v2.py
@@ -1,6 +1,5 @@
import requests
-
token = requests.get('https://play.vercel.ai/openai.jpeg', headers={
'authority': 'play.vercel.ai',
'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',
@@ -15,7 +14,7 @@ headers = {
'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'
}
-for chunk in requests.post('https://play.vercel.ai/api/generate', headers=headers, stream = True, json = {
+for chunk in requests.post('https://play.vercel.ai/api/generate', headers=headers, stream=True, json={
'prompt': 'hi',
'model': 'openai:gpt-3.5-turbo',
'temperature': 0.7,
@@ -25,5 +24,4 @@ for chunk in requests.post('https://play.vercel.ai/api/generate', headers=header
'frequencyPenalty': 1,
'presencePenalty': 1,
'stopSequences': []}).iter_lines():
-
- print(chunk) \ No newline at end of file
+ print(chunk)
diff --git a/unfinished/writesonic/__init__.py b/unfinished/writesonic/__init__.py
index 7df6f393..ce684912 100644
--- a/unfinished/writesonic/__init__.py
+++ b/unfinished/writesonic/__init__.py
@@ -1,29 +1,33 @@
-from requests import Session
-from names import get_first_name, get_last_name
-from random import choice
-from requests import post
-from time import time
-from colorama import Fore, init; init()
+from random import choice
+from time import time
+
+from colorama import Fore, init;
+from names import get_first_name, get_last_name
+from requests import Session
+from requests import post
+
+init()
+
class logger:
@staticmethod
def info(string) -> print:
import datetime
now = datetime.datetime.now()
- return print(f"{Fore.CYAN}{now.strftime('%Y-%m-%d %H:%M:%S')} {Fore.BLUE}INFO {Fore.MAGENTA}__main__ -> {Fore.RESET}{string}")
+ return print(
+ f"{Fore.CYAN}{now.strftime('%Y-%m-%d %H:%M:%S')} {Fore.BLUE}INFO {Fore.MAGENTA}__main__ -> {Fore.RESET}{string}")
+
class SonicResponse:
-
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']
-
+ 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>'''
@@ -32,127 +36,128 @@ class SonicResponse:
class Usage:
def __init__(self, usage_dict: dict) -> None:
- self.prompt_tokens = usage_dict['prompt_chars']
- self.completion_tokens = usage_dict['completion_chars']
- self.total_tokens = usage_dict['total_chars']
+ self.prompt_tokens = usage_dict['prompt_chars']
+ self.completion_tokens = usage_dict['completion_chars']
+ self.total_tokens = usage_dict['total_chars']
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'])
+ 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 Account:
session = Session()
session.headers = {
- "connection" : "keep-alive",
- "sec-ch-ua" : "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
- "accept" : "application/json, text/plain, */*",
- "content-type" : "application/json",
- "sec-ch-ua-mobile" : "?0",
- "user-agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
+ "connection": "keep-alive",
+ "sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
+ "accept": "application/json, text/plain, */*",
+ "content-type": "application/json",
+ "sec-ch-ua-mobile": "?0",
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
"sec-ch-ua-platform": "\"Windows\"",
- "sec-fetch-site" : "same-origin",
- "sec-fetch-mode" : "cors",
- "sec-fetch-dest" : "empty",
+ "sec-fetch-site": "same-origin",
+ "sec-fetch-mode": "cors",
+ "sec-fetch-dest": "empty",
# "accept-encoding" : "gzip, deflate, br",
- "accept-language" : "en-GB,en-US;q=0.9,en;q=0.8",
- "cookie" : ""
+ "accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
+ "cookie": ""
}
-
+
@staticmethod
def get_user():
password = f'0opsYouGoTme@1234'
- f_name = get_first_name()
- l_name = get_last_name()
- hosts = ['gmail.com', 'protonmail.com', 'proton.me', 'outlook.com']
-
+ f_name = get_first_name()
+ l_name = get_last_name()
+ hosts = ['gmail.com', 'protonmail.com', 'proton.me', 'outlook.com']
+
return {
- "email" : f"{f_name.lower()}.{l_name.lower()}@{choice(hosts)}",
- "password" : password,
- "confirm_password" : password,
- "full_name" : f'{f_name} {l_name}'
+ "email": f"{f_name.lower()}.{l_name.lower()}@{choice(hosts)}",
+ "password": password,
+ "confirm_password": password,
+ "full_name": f'{f_name} {l_name}'
}
@staticmethod
def create(logging: bool = False):
while True:
try:
- user = Account.get_user()
- start = time()
- response = Account.session.post("https://app.writesonic.com/api/session-login", json = user | {
- "utmParams" : "{}",
- "visitorId" : "0",
- "locale" : "en",
- "userAgent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
- "signInWith" : "password",
- "request_type" : "signup",
+ user = Account.get_user()
+ start = time()
+ response = Account.session.post("https://app.writesonic.com/api/session-login", json=user | {
+ "utmParams": "{}",
+ "visitorId": "0",
+ "locale": "en",
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
+ "signInWith": "password",
+ "request_type": "signup",
})
-
+
if logging:
logger.info(f"\x1b[31mregister success\x1b[0m : '{response.text[:30]}...' ({int(time() - start)}s)")
logger.info(f"\x1b[31mid\x1b[0m : '{response.json()['id']}'")
logger.info(f"\x1b[31mtoken\x1b[0m : '{response.json()['token'][:30]}...'")
-
+
start = time()
- response = Account.session.post("https://api.writesonic.com/v1/business/set-business-active", headers={"authorization": "Bearer " + response.json()['token']})
+ response = Account.session.post("https://api.writesonic.com/v1/business/set-business-active",
+ headers={"authorization": "Bearer " + response.json()['token']})
key = response.json()["business"]["api_key"]
if logging: logger.info(f"\x1b[31mgot key\x1b[0m : '{key}' ({int(time() - start)}s)")
return Account.AccountResponse(user['email'], user['password'], key)
-
+
except Exception as e:
if logging: logger.info(f"\x1b[31merror\x1b[0m : '{e}'")
continue
-
+
class AccountResponse:
def __init__(self, email, password, key):
- self.email = email
+ self.email = email
self.password = password
- self.key = key
-
+ self.key = key
+
class Completion:
def create(
- api_key: str,
- prompt: str,
- enable_memory: bool = False,
- enable_google_results: bool = False,
- history_data: list = []) -> SonicResponse:
-
- response = post('https://api.writesonic.com/v2/business/content/chatsonic?engine=premium', headers = {"X-API-KEY": api_key},
- json = {
- "enable_memory" : enable_memory,
- "enable_google_results" : enable_google_results,
- "input_text" : prompt,
- "history_data" : history_data}).json()
+ api_key: str,
+ prompt: str,
+ enable_memory: bool = False,
+ enable_google_results: bool = False,
+ history_data: list = []) -> SonicResponse:
+ response = post('https://api.writesonic.com/v2/business/content/chatsonic?engine=premium',
+ headers={"X-API-KEY": api_key},
+ json={
+ "enable_memory": enable_memory,
+ "enable_google_results": enable_google_results,
+ "input_text": prompt,
+ "history_data": history_data}).json()
return SonicResponse({
- 'id' : f'cmpl-premium-{int(time())}',
- 'object' : 'text_completion',
- 'created': int(time()),
- 'model' : 'premium',
-
- 'choices': [{
- 'text' : response['message'],
- 'index' : 0,
- 'logprobs' : None,
- 'finish_reason' : 'stop'
- }],
-
- 'usage': {
- 'prompt_chars' : len(prompt),
- 'completion_chars' : len(response['message']),
- 'total_chars' : len(prompt) + len(response['message'])
- }
- }) \ No newline at end of file
+ 'id': f'cmpl-premium-{int(time())}',
+ 'object': 'text_completion',
+ 'created': int(time()),
+ 'model': 'premium',
+
+ 'choices': [{
+ 'text': response['message'],
+ 'index': 0,
+ 'logprobs': None,
+ 'finish_reason': 'stop'
+ }],
+
+ 'usage': {
+ 'prompt_chars': len(prompt),
+ 'completion_chars': len(response['message']),
+ 'total_chars': len(prompt) + len(response['message'])
+ }
+ })
diff --git a/you/__init__.py b/you/__init__.py
index 397600bd..6925e79f 100644
--- a/you/__init__.py
+++ b/you/__init__.py
@@ -9,19 +9,19 @@ from tls_client import Session
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,
+ 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 = []