diff options
author | Aymane Hrouch <jo.aymane@gmail.com> | 2023-04-27 16:43:59 +0200 |
---|---|---|
committer | Aymane Hrouch <jo.aymane@gmail.com> | 2023-04-27 16:43:59 +0200 |
commit | f1594cfddecf2bd47a25d54852834b392eaa4efd (patch) | |
tree | 6fec52831117ee43fe7141a153b7e123ff09d469 /unfinished | |
parent | Merge pull request #201 from DanielShemesh/patch-4 (diff) | |
download | gpt4free-f1594cfddecf2bd47a25d54852834b392eaa4efd.tar gpt4free-f1594cfddecf2bd47a25d54852834b392eaa4efd.tar.gz gpt4free-f1594cfddecf2bd47a25d54852834b392eaa4efd.tar.bz2 gpt4free-f1594cfddecf2bd47a25d54852834b392eaa4efd.tar.lz gpt4free-f1594cfddecf2bd47a25d54852834b392eaa4efd.tar.xz gpt4free-f1594cfddecf2bd47a25d54852834b392eaa4efd.tar.zst gpt4free-f1594cfddecf2bd47a25d54852834b392eaa4efd.zip |
Diffstat (limited to '')
-rw-r--r-- | unfinished/bard/__init__.py | 31 | ||||
-rw-r--r-- | unfinished/bard/typings.py | 2 | ||||
-rw-r--r-- | unfinished/bing/__ini__.py | 39 | ||||
-rw-r--r-- | unfinished/cocalc/__init__.py | 1 | ||||
-rw-r--r-- | unfinished/cocalc/cocalc_test.py | 5 | ||||
-rw-r--r-- | unfinished/easyai/main.py | 5 | ||||
-rw-r--r-- | unfinished/gptbz/__init__.py | 4 | ||||
-rw-r--r-- | unfinished/openai/__ini__.py | 3 | ||||
-rw-r--r-- | unfinished/openaihosted/__init__.py | 5 | ||||
-rw-r--r-- | unfinished/openprompt/create.py | 20 | ||||
-rw-r--r-- | unfinished/openprompt/mail.py | 6 | ||||
-rw-r--r-- | unfinished/openprompt/main.py | 5 | ||||
-rw-r--r-- | unfinished/openprompt/test.py | 5 | ||||
-rw-r--r-- | unfinished/t3nsor/__init__.py | 131 | ||||
-rw-r--r-- | unfinished/test.py | 8 | ||||
-rw-r--r-- | unfinished/theb.ai/__init__.py | 45 | ||||
-rw-r--r-- | unfinished/vercelai/v2.py | 6 | ||||
-rw-r--r-- | unfinished/writesonic/__init__.py | 195 |
18 files changed, 262 insertions, 254 deletions
diff --git a/unfinished/bard/__init__.py b/unfinished/bard/__init__.py index ef8980d7..f1d68b92 100644 --- a/unfinished/bard/__init__.py +++ b/unfinished/bard/__init__.py @@ -1,12 +1,12 @@ -from requests import Session -from re import search -from random import randint from json import dumps, loads -from urllib.parse import urlencode -from dotenv import load_dotenv from os import getenv +from random import randint +from re import search +from urllib.parse import urlencode from bard.typings import BardResponse +from dotenv import load_dotenv +from requests import Session load_dotenv() token = getenv('1psid') @@ -62,16 +62,17 @@ class Completion: 'rt': 'c', }) - 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], - ])]) - } - ) + 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], + ])]) + } + ) chat_data = loads(response.content.splitlines()[3])[0][2] if not chat_data: diff --git a/unfinished/bard/typings.py b/unfinished/bard/typings.py index ddf803b6..75b73bf9 100644 --- a/unfinished/bard/typings.py +++ b/unfinished/bard/typings.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Optional, Union +from typing import Dict, List, Union class BardResponse: diff --git a/unfinished/bing/__ini__.py b/unfinished/bing/__ini__.py index 508b1067..1e4fd149 100644 --- a/unfinished/bing/__ini__.py +++ b/unfinished/bing/__ini__.py @@ -1,14 +1,12 @@ # Import necessary libraries -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 +import asyncio from json import dumps, loads +from ssl import create_default_context -import asyncio import websockets +from browser_cookie3 import edge +from certifi import where +from requests import get # Set up SSL context ssl_context = create_default_context() @@ -28,14 +26,14 @@ def get_token(): class AsyncCompletion: async def create( - prompt: str = 'hello world', - optionSets: list = [ - 'deepleo', - 'enable_debug_commands', - 'disable_emoji_spoken_text', - 'enablemm', - 'h3relaxedimg' - ], + 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.""" @@ -83,7 +81,7 @@ class AsyncCompletion: continue response = loads(obj) - if response.get('type') == 1 and response['arguments'][0].get('messages',): + if response.get('type') == 1 and response['arguments'][0].get('messages', ): response_text = response['arguments'][0]['messages'][0]['adaptiveCards'][0]['body'][0].get( 'text') @@ -99,11 +97,12 @@ class AsyncCompletion: 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=[ - "galileo", - ] + prompt='summarize cinderella with each word beginning with a consecutive letter of the alphabet, a-z', + optionSets=[ + "galileo", + ] ): print(value, end='', flush=True) + asyncio.run(run()) diff --git a/unfinished/cocalc/__init__.py b/unfinished/cocalc/__init__.py index 3ad9937a..2b73fc9e 100644 --- a/unfinished/cocalc/__init__.py +++ b/unfinished/cocalc/__init__.py @@ -6,7 +6,6 @@ class Completion: 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() 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 index 07adfd72..451adb3b 100644 --- a/unfinished/easyai/main.py +++ b/unfinished/easyai/main.py @@ -1,7 +1,8 @@ # Import necessary libraries -from requests import get -from os import urandom from json import loads +from os import urandom + +from requests import get # Generate a random session ID sessionId = urandom(10).hex() diff --git a/unfinished/gptbz/__init__.py b/unfinished/gptbz/__init__.py index 44bfcd19..e95d5716 100644 --- a/unfinished/gptbz/__init__.py +++ b/unfinished/gptbz/__init__.py @@ -1,6 +1,8 @@ -import websockets from json import dumps, loads +import websockets + + # Define the asynchronous function to test the WebSocket connection diff --git a/unfinished/openai/__ini__.py b/unfinished/openai/__ini__.py index 71ec4623..f0894e1b 100644 --- a/unfinished/openai/__ini__.py +++ b/unfinished/openai/__ini__.py @@ -1,7 +1,8 @@ # Import required libraries -from tls_client import Session from uuid import uuid4 + from browser_cookie3 import chrome +from tls_client import Session class OpenAIChat: 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.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgt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LCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.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 = '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAoALQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldY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brTItPc3O6GN5PNltxHx0I+YKXLYB42455ooqpaIwo2lO1rE1rZjUYrcCO2Giw/Zp7BYzKrkKu4bh8oAB2EA56HIz0u3uxL+1kbygQpQFt2fmki4GOOuOvfHbNFFPpcTu6nKFpsTU75V8oNJKXIXduOI4hk54zjHTjGO+a0KKKaM59PQxLqNNBMuoQpDFYJEfPQLISp8zcWAXIxh5CcLnOMnHQaFNKkkvtOFoli0k9xqP32Zn24LIFyM7kwRg98c5yUVL3No6xTfV2/IrxyW0vh21kQ2phaexKn97s5aErj+LPTbnj7u7+KujoopxZNZW+9/oQXdpBfWk1rcxiSGVGjdSSMhgQeRyOCRxWOtvbXU0Ol6mIHksJbea0IMoJYISGy3U5ST+JuB83uUUMVJuz121JnaL/AITOBSYPOGnyEA7/ADdvmJnH8G3IHX5s4xxmtmiihdRVFZR9AoooqjI//9k=' -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']) + } + }) |