1
0
Fork 0

Reformat code using PyCharm

This commit is contained in:
Aymane Hrouch 2023-04-27 15:43:59 +01:00
parent 86e0fbe556
commit f1594cfdde
33 changed files with 675 additions and 666 deletions

View file

@ -1,51 +1,54 @@
from tls_client import Session
from forefront.mail import Mail
from time import time, sleep
from re import match
from forefront.typing import ForeFrontResponse
from uuid import uuid4
from requests import post
from json import loads from json import loads
from re import match
from time import time, sleep
from uuid import uuid4
from requests import post
from tls_client import Session
from forefront.mail import Mail
from forefront.typing import ForeFrontResponse
class Account: class Account:
@staticmethod @staticmethod
def create(proxy = None, logging = False): def create(proxy=None, logging=False):
proxies = { proxies = {
'http': 'http://' + proxy, 'http': 'http://' + proxy,
'https': 'http://' + proxy } if proxy else False 'https': 'http://' + proxy} if proxy else False
start = time() start = time()
mail = Mail(proxies) mail = Mail(proxies)
mail_token = None mail_token = None
mail_adress = mail.get_mail() mail_adress = mail.get_mail()
#print(mail_adress) # print(mail_adress)
client = Session(client_identifier='chrome110') client = Session(client_identifier='chrome110')
client.proxies = proxies client.proxies = proxies
client.headers = { client.headers = {
"origin": "https://accounts.forefront.ai", "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', response = client.post('https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
data = { data={
"email_address": mail_adress "email_address": mail_adress
} }
) )
trace_token = response.json()['response']['id'] trace_token = response.json()['response']['id']
if logging: print(trace_token) 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", response = client.post(
data = { f"https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6",
"strategy" : "email_code", data={
"strategy": "email_code",
} }
) )
if logging: print(response.text) if logging: print(response.text)
if not 'sign_up_attempt' in response.text: if not 'sign_up_attempt' in response.text:
@ -59,89 +62,91 @@ class Account:
if mail_token: if mail_token:
break break
if logging: print(mail_token) 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 = { response = client.post(
'code': mail_token, f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/attempt_verification?_clerk_js_version=4.38.4',
'strategy': 'email_code' data={
}) 'code': mail_token,
'strategy': 'email_code'
})
if logging: print(response.json()) 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: with open('accounts.txt', 'a') as f:
f.write(f'{mail_adress}:{token}\n') f.write(f'{mail_adress}:{token}\n')
if logging: print(time() - start) if logging: print(time() - start)
return token return token
class StreamingCompletion: class StreamingCompletion:
@staticmethod @staticmethod
def create( def create(
token = None, token=None,
chatId = None, chatId=None,
prompt = '', prompt='',
actionType = 'new', actionType='new',
defaultPersona = '607e41fe-95be-497e-8e97-010a59b2e2c0', # default defaultPersona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
model = 'gpt-4') -> ForeFrontResponse: model='gpt-4') -> ForeFrontResponse:
if not token: raise Exception('Token is required!') if not token: raise Exception('Token is required!')
if not chatId: chatId = str(uuid4()) if not chatId: chatId = str(uuid4())
headers = { headers = {
'authority' : 'chat-server.tenant-forefront-default.knative.chi.coreweave.com', 'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
'accept' : '*/*', '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', '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, 'authorization': 'Bearer ' + token,
'cache-control' : 'no-cache', 'cache-control': 'no-cache',
'content-type' : 'application/json', 'content-type': 'application/json',
'origin' : 'https://chat.forefront.ai', 'origin': 'https://chat.forefront.ai',
'pragma' : 'no-cache', 'pragma': 'no-cache',
'referer' : 'https://chat.forefront.ai/', 'referer': 'https://chat.forefront.ai/',
'sec-ch-ua' : '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"', 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
'sec-ch-ua-mobile' : '?0', 'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"', 'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest' : 'empty', 'sec-fetch-dest': 'empty',
'sec-fetch-mode' : 'cors', 'sec-fetch-mode': 'cors',
'sec-fetch-site' : 'cross-site', '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', '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 = { json_data = {
'text' : prompt, 'text': prompt,
'action' : actionType, 'action': actionType,
'parentId' : chatId, 'parentId': chatId,
'workspaceId' : chatId, 'workspaceId': chatId,
'messagePersona' : defaultPersona, 'messagePersona': defaultPersona,
'model' : model 'model': model
} }
for chunk in post('https://chat-server.tenant-forefront-default.knative.chi.coreweave.com/chat', 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: 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') token = data['choices'][0]['delta'].get('content')
if token != None: if token != None:
yield ForeFrontResponse({ yield ForeFrontResponse({
'id' : chatId, 'id': chatId,
'object' : 'text_completion', 'object': 'text_completion',
'created': int(time()), 'created': int(time()),
'model' : model, 'model': model,
'choices': [{ 'choices': [{
'text' : token, 'text': token,
'index' : 0, 'index': 0,
'logprobs' : None, 'logprobs': None,
'finish_reason' : 'stop' 'finish_reason': 'stop'
}], }],
'usage': { 'usage': {
'prompt_tokens' : len(prompt), 'prompt_tokens': len(prompt),
'completion_tokens' : len(token), 'completion_tokens': len(token),
'total_tokens' : len(prompt) + len(token) 'total_tokens': len(prompt) + len(token)
} }
}) })

View file

@ -1,6 +1,8 @@
from requests import Session
from string import ascii_letters
from random import choices from random import choices
from string import ascii_letters
from requests import Session
class Mail: class Mail:
def __init__(self, proxies: dict = None) -> None: def __init__(self, proxies: dict = None) -> None:
@ -23,27 +25,27 @@ class Mail:
"accept-encoding": "gzip, deflate, br", "accept-encoding": "gzip, deflate, br",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8" "accept-language": "en-GB,en-US;q=0.9,en;q=0.8"
} }
def get_mail(self) -> str: def get_mail(self) -> str:
token = ''.join(choices(ascii_letters, k=14)).lower() token = ''.join(choices(ascii_letters, k=14)).lower()
init = self.client.post("https://api.mail.tm/accounts", json={ init = self.client.post("https://api.mail.tm/accounts", json={
"address" : f"{token}@bugfoo.com", "address": f"{token}@bugfoo.com",
"password": token "password": token
}) })
if init.status_code == 201: 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(), **init.json(),
"password": token "password": token
}) })
self.client.headers['authorization'] = 'Bearer ' + resp.json()['token'] self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
return f"{token}@bugfoo.com" return f"{token}@bugfoo.com"
else: else:
raise Exception("Failed to create email") raise Exception("Failed to create email")
def fetch_inbox(self): def fetch_inbox(self):
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"] 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): def get_message_content(self, message_id: str):
return self.get_message(message_id)["text"] return self.get_message(message_id)["text"]

View file

@ -2,12 +2,12 @@ class ForeFrontResponse:
class Completion: class Completion:
class Choices: class Choices:
def __init__(self, choice: dict) -> None: def __init__(self, choice: dict) -> None:
self.text = choice['text'] self.text = choice['text']
self.content = self.text.encode() self.content = self.text.encode()
self.index = choice['index'] self.index = choice['index']
self.logprobs = choice['logprobs'] self.logprobs = choice['logprobs']
self.finish_reason = choice['finish_reason'] self.finish_reason = choice['finish_reason']
def __repr__(self) -> str: 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>''' 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: class Usage:
def __init__(self, usage_dict: dict) -> None: def __init__(self, usage_dict: dict) -> None:
self.prompt_tokens = usage_dict['prompt_tokens'] self.prompt_tokens = usage_dict['prompt_tokens']
self.completion_tokens = usage_dict['completion_tokens'] self.completion_tokens = usage_dict['completion_tokens']
self.total_tokens = usage_dict['total_tokens'] self.total_tokens = usage_dict['total_tokens']
def __repr__(self): 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>''' 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: def __init__(self, response_dict: dict) -> None:
self.response_dict = response_dict
self.response_dict = response_dict self.id = response_dict['id']
self.id = response_dict['id'] self.object = response_dict['object']
self.object = response_dict['object'] self.created = response_dict['created']
self.created = response_dict['created'] self.model = response_dict['model']
self.model = response_dict['model'] self.completion = self.Completion(response_dict['choices'])
self.completion = self.Completion(response_dict['choices']) self.usage = self.Usage(response_dict['usage'])
self.usage = self.Usage(response_dict['usage'])
def json(self) -> dict: def json(self) -> dict:
return self.response_dict return self.response_dict

View file

@ -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 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 from curl_cffi.requests import post
cf_clearance = '' 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 PhindResponse:
class Completion: class Completion:
class Choices: class Choices:
def __init__(self, choice: dict) -> None: def __init__(self, choice: dict) -> None:
self.text = choice['text'] self.text = choice['text']
self.content = self.text.encode() self.content = self.text.encode()
self.index = choice['index'] self.index = choice['index']
self.logprobs = choice['logprobs'] self.logprobs = choice['logprobs']
self.finish_reason = choice['finish_reason'] self.finish_reason = choice['finish_reason']
def __repr__(self) -> str: 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>''' 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: class Usage:
def __init__(self, usage_dict: dict) -> None: def __init__(self, usage_dict: dict) -> None:
self.prompt_tokens = usage_dict['prompt_tokens'] self.prompt_tokens = usage_dict['prompt_tokens']
self.completion_tokens = usage_dict['completion_tokens'] self.completion_tokens = usage_dict['completion_tokens']
self.total_tokens = usage_dict['total_tokens'] self.total_tokens = usage_dict['total_tokens']
def __repr__(self): 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>''' 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: def __init__(self, response_dict: dict) -> None:
self.response_dict = response_dict
self.response_dict = response_dict self.id = response_dict['id']
self.id = response_dict['id'] self.object = response_dict['object']
self.object = response_dict['object'] self.created = response_dict['created']
self.created = response_dict['created'] self.model = response_dict['model']
self.model = response_dict['model'] self.completion = self.Completion(response_dict['choices'])
self.completion = self.Completion(response_dict['choices']) self.usage = self.Usage(response_dict['usage'])
self.usage = self.Usage(response_dict['usage'])
def json(self) -> dict: def json(self) -> dict:
return self.response_dict return self.response_dict
class Search: 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 == '': if user_agent == '':
raise ValueError('user_agent must be set, refer to documentation') 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') raise ValueError('cf_clearance must be set, refer to documentation')
if not actualSearch: if not actualSearch:
return { return {
'_type': 'SearchResponse', '_type': 'SearchResponse',
@ -75,7 +72,7 @@ class Search:
} }
} }
} }
headers = { headers = {
'authority': 'www.phind.com', 'authority': 'www.phind.com',
'accept': '*/*', 'accept': '*/*',
@ -91,8 +88,8 @@ class Search:
'sec-fetch-site': 'same-origin', 'sec-fetch-site': 'same-origin',
'user-agent': user_agent '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, 'q': prompt,
'userRankList': {}, 'userRankList': {},
'browserLanguage': language}).json()['rawBingResults'] 'browserLanguage': language}).json()['rawBingResults']
@ -100,45 +97,45 @@ class Search:
class Completion: class Completion:
def create( def create(
model = 'gpt-4', model='gpt-4',
prompt: str = '', prompt: str = '',
results: dict = None, results: dict = None,
creative: bool = False, creative: bool = False,
detailed: bool = False, detailed: bool = False,
codeContext: str = '', codeContext: str = '',
language: str = 'en') -> PhindResponse: language: str = 'en') -> PhindResponse:
if user_agent == '' : if user_agent == '':
raise ValueError('user_agent must be set, refer to documentation') 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') raise ValueError('cf_clearance must be set, refer to documentation')
if results is None: if results is None:
results = Search.create(prompt, actualSearch = True) results = Search.create(prompt, actualSearch=True)
if len(codeContext) > 2999: if len(codeContext) > 2999:
raise ValueError('codeContext must be less than 3000 characters') raise ValueError('codeContext must be less than 3000 characters')
models = { models = {
'gpt-4' : 'expert', 'gpt-4': 'expert',
'gpt-3.5-turbo' : 'intermediate', 'gpt-3.5-turbo': 'intermediate',
'gpt-3.5': 'intermediate', 'gpt-3.5': 'intermediate',
} }
json_data = { json_data = {
'question' : prompt, 'question': prompt,
'bingResults' : results, #response.json()['rawBingResults'], 'bingResults': results, # response.json()['rawBingResults'],
'codeContext' : codeContext, 'codeContext': codeContext,
'options': { 'options': {
'skill' : models[model], 'skill': models[model],
'date' : datetime.now().strftime("%d/%m/%Y"), 'date': datetime.now().strftime("%d/%m/%Y"),
'language': language, 'language': language,
'detailed': detailed, 'detailed': detailed,
'creative': creative 'creative': creative
} }
} }
headers = { headers = {
'authority': 'www.phind.com', 'authority': 'www.phind.com',
'accept': '*/*', 'accept': '*/*',
@ -155,50 +152,51 @@ class Completion:
'sec-fetch-site': 'same-origin', 'sec-fetch-site': 'same-origin',
'user-agent': user_agent 'user-agent': user_agent
} }
completion = '' 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'): for line in response.text.split('\r\n\r\n'):
completion += (line.replace('data: ', '')) completion += (line.replace('data: ', ''))
return PhindResponse({ return PhindResponse({
'id' : f'cmpl-1337-{int(time())}', 'id': f'cmpl-1337-{int(time())}',
'object' : 'text_completion', 'object': 'text_completion',
'created': int(time()), 'created': int(time()),
'model' : models[model], 'model': models[model],
'choices': [{ 'choices': [{
'text' : completion, 'text': completion,
'index' : 0, 'index': 0,
'logprobs' : None, 'logprobs': None,
'finish_reason' : 'stop' 'finish_reason': 'stop'
}], }],
'usage': { 'usage': {
'prompt_tokens' : len(prompt), 'prompt_tokens': len(prompt),
'completion_tokens' : len(completion), 'completion_tokens': len(completion),
'total_tokens' : len(prompt) + len(completion) 'total_tokens': len(prompt) + len(completion)
} }
}) })
class StreamingCompletion: class StreamingCompletion:
message_queue = Queue() message_queue = Queue()
stream_completed = False stream_completed = False
def request(model, prompt, results, creative, detailed, codeContext, language) -> None: def request(model, prompt, results, creative, detailed, codeContext, language) -> None:
models = { models = {
'gpt-4' : 'expert', 'gpt-4': 'expert',
'gpt-3.5-turbo' : 'intermediate', 'gpt-3.5-turbo': 'intermediate',
'gpt-3.5': 'intermediate', 'gpt-3.5': 'intermediate',
} }
json_data = { json_data = {
'question' : prompt, 'question': prompt,
'bingResults' : results, 'bingResults': results,
'codeContext' : codeContext, 'codeContext': codeContext,
'options': { 'options': {
'skill' : models[model], 'skill': models[model],
'date' : datetime.now().strftime("%d/%m/%Y"), 'date': datetime.now().strftime("%d/%m/%Y"),
'language': language, 'language': language,
'detailed': detailed, 'detailed': detailed,
'creative': creative 'creative': creative
@ -221,65 +219,65 @@ class StreamingCompletion:
'sec-fetch-site': 'same-origin', 'sec-fetch-site': 'same-origin',
'user-agent': user_agent '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 StreamingCompletion.stream_completed = True
@staticmethod @staticmethod
def create( def create(
model : str = 'gpt-4', model: str = 'gpt-4',
prompt : str = '', prompt: str = '',
results : dict = None, results: dict = None,
creative : bool = False, creative: bool = False,
detailed : bool = False, detailed: bool = False,
codeContext : str = '', codeContext: str = '',
language : str = 'en'): language: str = 'en'):
if user_agent == '': if user_agent == '':
raise ValueError('user_agent must be set, refer to documentation') 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') raise ValueError('cf_clearance must be set, refer to documentation')
if results is None: if results is None:
results = Search.create(prompt, actualSearch = True) results = Search.create(prompt, actualSearch=True)
if len(codeContext) > 2999: if len(codeContext) > 2999:
raise ValueError('codeContext must be less than 3000 characters') 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() model, prompt, results, creative, detailed, codeContext, language]).start()
while StreamingCompletion.stream_completed != True or not StreamingCompletion.message_queue.empty(): while StreamingCompletion.stream_completed != True or not StreamingCompletion.message_queue.empty():
try: try:
chunk = StreamingCompletion.message_queue.get(timeout=0) chunk = StreamingCompletion.message_queue.get(timeout=0)
if chunk == b'data: \r\ndata: \r\ndata: \r\n\r\n': if chunk == b'data: \r\ndata: \r\ndata: \r\n\r\n':
chunk = b'data: \n\n\r\n\r\n' chunk = b'data: \n\n\r\n\r\n'
chunk = chunk.decode() chunk = chunk.decode()
chunk = chunk.replace('data: \r\n\r\ndata: ', 'data: \n') 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('\r\ndata: \r\ndata: \r\n\r\n', '\n\n\r\n\r\n')
chunk = chunk.replace('data: ', '').replace('\r\n\r\n', '') chunk = chunk.replace('data: ', '').replace('\r\n\r\n', '')
yield PhindResponse({ yield PhindResponse({
'id' : f'cmpl-1337-{int(time())}', 'id': f'cmpl-1337-{int(time())}',
'object' : 'text_completion', 'object': 'text_completion',
'created': int(time()), 'created': int(time()),
'model' : model, 'model': model,
'choices': [{ 'choices': [{
'text' : chunk, 'text': chunk,
'index' : 0, 'index': 0,
'logprobs' : None, 'logprobs': None,
'finish_reason' : 'stop' 'finish_reason': 'stop'
}], }],
'usage': { 'usage': {
'prompt_tokens' : len(prompt), 'prompt_tokens': len(prompt),
'completion_tokens' : len(chunk), 'completion_tokens': len(chunk),
'total_tokens' : len(prompt) + len(chunk) 'total_tokens': len(prompt) + len(chunk)
} }
}) })

View file

@ -116,11 +116,11 @@ class ModelResponse:
class Model: class Model:
@staticmethod @staticmethod
def create( def create(
token: str, token: str,
model: str = 'gpt-3.5-turbo', # claude-instant 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', 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', description: str = 'gpt-3.5 language model from openai, skidded by poe.com',
handle: str = None, handle: str = None,
) -> ModelResponse: ) -> ModelResponse:
models = { models = {
'gpt-3.5-turbo': 'chinchilla', 'gpt-3.5-turbo': 'chinchilla',
@ -202,9 +202,9 @@ class Model:
class Account: class Account:
@staticmethod @staticmethod
def create( def create(
proxy: Optional[str] = None, proxy: Optional[str] = None,
logging: bool = False, logging: bool = False,
enable_bot_creation: 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 client.proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} if proxy else None
@ -309,10 +309,10 @@ class Account:
class StreamingCompletion: class StreamingCompletion:
@staticmethod @staticmethod
def create( def create(
model: str = 'gpt-4', model: str = 'gpt-4',
custom_model: bool = None, custom_model: bool = None,
prompt: str = 'hello world', prompt: str = 'hello world',
token: str = '', token: str = '',
): ):
_model = MODELS[model] if not custom_model else custom_model _model = MODELS[model] if not custom_model else custom_model
@ -344,10 +344,10 @@ class StreamingCompletion:
class Completion: class Completion:
def create( def create(
model: str = 'gpt-4', model: str = 'gpt-4',
custom_model: str = None, custom_model: str = None,
prompt: str = 'hello world', prompt: str = 'hello world',
token: str = '', token: str = '',
): ):
models = { models = {
'sage': 'capybara', 'sage': 'capybara',
@ -389,12 +389,12 @@ class Completion:
class Poe: class Poe:
def __init__( def __init__(
self, self,
model: str = 'ChatGPT', model: str = 'ChatGPT',
driver: str = 'firefox', driver: str = 'firefox',
download_driver: bool = False, download_driver: bool = False,
driver_path: Optional[str] = None, driver_path: Optional[str] = None,
cookie_path: str = './quora/cookie.json', cookie_path: str = './quora/cookie.json',
): ):
# validating the model # validating the model
if model and model not in MODELS: if model and model not in MODELS:
@ -473,12 +473,12 @@ class Poe:
return response return response
def create_bot( def create_bot(
self, self,
name: str, name: str,
/, /,
prompt: str = '', prompt: str = '',
base_model: str = 'ChatGPT', base_model: str = 'ChatGPT',
description: str = '', description: str = '',
) -> None: ) -> None:
if base_model not in MODELS: if base_model not in MODELS:
raise RuntimeError('Sorry, the base_model you provided does not exist. Please check and try again.') raise RuntimeError('Sorry, the base_model you provided does not exist. Please check and try again.')

View file

@ -384,7 +384,7 @@ class Client:
continue continue
# update info about response # update info about response
message["text_new"] = message["text"][len(last_text) :] message["text_new"] = message["text"][len(last_text):]
last_text = message["text"] last_text = message["text"]
message_id = message["messageId"] message_id = message["messageId"]
@ -456,21 +456,21 @@ class Client:
logger.info(f"No more messages left to delete.") logger.info(f"No more messages left to delete.")
def create_bot( def create_bot(
self, self,
handle, handle,
prompt="", prompt="",
base_model="chinchilla", base_model="chinchilla",
description="", description="",
intro_message="", intro_message="",
api_key=None, api_key=None,
api_bot=False, api_bot=False,
api_url=None, api_url=None,
prompt_public=True, prompt_public=True,
pfp_url=None, pfp_url=None,
linkification=False, linkification=False,
markdown_rendering=True, markdown_rendering=True,
suggested_replies=False, suggested_replies=False,
private=False, private=False,
): ):
result = self.send_query( result = self.send_query(
"PoeBotCreateMutation", "PoeBotCreateMutation",
@ -499,21 +499,21 @@ class Client:
return data return data
def edit_bot( def edit_bot(
self, self,
bot_id, bot_id,
handle, handle,
prompt="", prompt="",
base_model="chinchilla", base_model="chinchilla",
description="", description="",
intro_message="", intro_message="",
api_key=None, api_key=None,
api_url=None, api_url=None,
private=False, private=False,
prompt_public=True, prompt_public=True,
pfp_url=None, pfp_url=None,
linkification=False, linkification=False,
markdown_rendering=True, markdown_rendering=True,
suggested_replies=False, suggested_replies=False,
): ):
result = self.send_query( result = self.send_query(
"PoeBotEditMutation", "PoeBotEditMutation",

View file

@ -5,7 +5,6 @@ token = forefront.Account.create(logging=True)
print(token) print(token)
# get a response # get a response
for response in forefront.StreamingCompletion.create(token = token, for response in forefront.StreamingCompletion.create(token=token,
prompt = 'hello world', model='gpt-4'): prompt='hello world', model='gpt-4'):
print(response.completion.choices[0].text, end='')
print(response.completion.choices[0].text, end = '')

View file

@ -2,18 +2,19 @@ import phind
# set cf_clearance cookie ( not needed at the moment) # set cf_clearance cookie ( not needed at the moment)
phind.cf_clearance = 'MDzwnr3ZWk_ap8u.iwwMR5F3WccfOkhUy_zGNDpcF3s-1682497341-0-160' 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' prompt = 'hello world'
# normal completion # normal completion
result = phind.Completion.create( result = phind.Completion.create(
model = 'gpt-4', model='gpt-4',
prompt = prompt, prompt=prompt,
results = phind.Search.create(prompt, actualSearch = False), # create search (set actualSearch to False to disable internet) results=phind.Search.create(prompt, actualSearch=False),
creative = False, # create search (set actualSearch to False to disable internet)
detailed = False, creative=False,
codeContext = '') # up to 3000 chars of code detailed=False,
codeContext='') # up to 3000 chars of code
print(result.completion.choices[0].text) 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 # help needed: not getting newlines from the stream, please submit a PR if you know how to fix this
# stream completion # stream completion
for result in phind.StreamingCompletion.create( for result in phind.StreamingCompletion.create(
model = 'gpt-4', model='gpt-4',
prompt = prompt, prompt=prompt,
results = phind.Search.create(prompt, actualSearch = True), # create search (set actualSearch to False to disable internet) results=phind.Search.create(prompt, actualSearch=True),
creative = False, # create search (set actualSearch to False to disable internet)
detailed = False, creative=False,
codeContext = ''): # up to 3000 chars of code detailed=False,
codeContext=''): # up to 3000 chars of code
print(result.completion.choices[0].text, end='', flush=True) print(result.completion.choices[0].text, end='', flush=True)

View file

@ -1,90 +1,90 @@
from requests import Session
from tls_client import Session as TLS
from json import dumps
from hashlib import md5 from hashlib import md5
from time import sleep from json import dumps
from re import findall 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 import extract_formkey
from quora.mail import Emailnator from quora.mail import Emailnator
from twocaptcha import TwoCaptcha
solver = TwoCaptcha('72747bf24a9d89b4dcc1b24875efd358') solver = TwoCaptcha('72747bf24a9d89b4dcc1b24875efd358')
class Account: class Account:
def create(proxy: None or str = None, logging: bool = False, enable_bot_creation: bool = False): 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 = { client.proxies = {
'http': f'http://{proxy}', 'http': f'http://{proxy}',
'https': f'http://{proxy}'} if proxy else None 'https': f'http://{proxy}'} if proxy else None
mail_client = Emailnator() mail_client = Emailnator()
mail_address = mail_client.get_mail() mail_address = mail_client.get_mail()
if logging: print('email', mail_address) if logging: print('email', mail_address)
client.headers = { client.headers = {
'authority' : 'poe.com', 'authority': 'poe.com',
'accept' : '*/*', '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', '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', 'content-type': 'application/json',
'origin' : 'https://poe.com', 'origin': 'https://poe.com',
'poe-formkey' : 'null', 'poe-formkey': 'null',
'poe-tag-id' : 'null', 'poe-tag-id': 'null',
'poe-tchannel' : 'null', 'poe-tchannel': 'null',
'referer' : 'https://poe.com/login', 'referer': 'https://poe.com/login',
'sec-ch-ua' : '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"', 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
'sec-ch-ua-mobile' : '?0', 'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"', 'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest': 'empty', 'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors', 'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin', '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'] 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', token = solver.recaptcha(sitekey='6LflhEElAAAAAI_ewVwRWI9hsyV4mbZnYAslSvlG',
url = 'https://poe.com/login?redirect_url=%2F', url='https://poe.com/login?redirect_url=%2F',
version = 'v3', version='v3',
enterprise = 1, enterprise=1,
invisible = 1, invisible=1,
action = 'login',)['code'] action='login', )['code']
payload = dumps(separators = (',', ':'), obj = { payload = dumps(separators=(',', ':'), obj={
'queryName': 'MainSignupLoginSection_sendVerificationCodeMutation_Mutation', 'queryName': 'MainSignupLoginSection_sendVerificationCodeMutation_Mutation',
'variables': { 'variables': {
'emailAddress' : mail_address, 'emailAddress': mail_address,
'phoneNumber' : None, 'phoneNumber': None,
'recaptchaToken': token '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', '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' 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)) print(dumps(client.headers, indent=4))
response = client.post('https://poe.com/api/gql_POST', data=payload) response = client.post('https://poe.com/api/gql_POST', data=payload)
if 'automated_request_detected' in response.text: if 'automated_request_detected' in response.text:
print('please try using a proxy / wait for fix') print('please try using a proxy / wait for fix')
if 'Bad Request' in response.text: if 'Bad Request' in response.text:
if logging: print('bad request, retrying...' , response.json()) if logging: print('bad request, retrying...', response.json())
quit() quit()
if logging: print('send_code' ,response.json()) if logging: print('send_code', response.json())
mail_content = mail_client.get_message() 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) if logging: print('code', mail_token)
payload = dumps(separators = (',', ':'), obj={ payload = dumps(separators=(',', ':'), obj={
"queryName": "SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation", "queryName": "SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation",
"variables": { "variables": {
"verificationCode": str(mail_token), "verificationCode": str(mail_token),
@ -95,10 +95,10 @@ class Account:
}) })
base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k' 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()) if logging: print('verify_code', response.json())
Account.create(proxy = 'xtekky:wegwgwegwed_streaming-1@geo.iproyal.com:12321', logging = True)
Account.create(proxy='xtekky:wegwgwegwed_streaming-1@geo.iproyal.com:12321', logging=True)

View file

@ -1,13 +1,13 @@
import quora
from time import sleep 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) print('token', token)
sleep(2) sleep(2)
for response in quora.StreamingCompletion.create(model = 'gpt-3.5-turbo', for response in quora.StreamingCompletion.create(model='gpt-3.5-turbo',
prompt = 'hello world', prompt='hello world',
token = token): token=token):
print(response.completion.choices[0].text, end="", flush=True)
print(response.completion.choices[0].text, end="", flush=True)

View file

@ -1,18 +1,17 @@
import quora 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( model = quora.Model.create(
token = token, token=token,
model = 'gpt-3.5-turbo', # or claude-instant-v1.0 model='gpt-3.5-turbo', # or claude-instant-v1.0
system_prompt = 'you are ChatGPT a large language model ...' system_prompt='you are ChatGPT a large language model ...'
) )
print(model.name) print(model.name)
for response in quora.StreamingCompletion.create( for response in quora.StreamingCompletion.create(
custom_model = model.name, custom_model=model.name,
prompt ='hello world', prompt='hello world',
token = token): token=token):
print(response.completion.choices[0].text)
print(response.completion.choices[0].text)

View file

@ -1,7 +1,6 @@
import sqlchat import sqlchat
for response in sqlchat.StreamCompletion.create( for response in sqlchat.StreamCompletion.create(
prompt = 'write python code to reverse a string', prompt='write python code to reverse a string',
messages = []): messages=[]):
print(response.completion.choices[0].text, end='')
print(response.completion.choices[0].text, end='')

View file

@ -1,7 +1,6 @@
import t3nsor import t3nsor
for response in t3nsor.StreamCompletion.create( for response in t3nsor.StreamCompletion.create(
prompt = 'write python code to reverse a string', prompt='write python code to reverse a string',
messages = []): messages=[]):
print(response.completion.choices[0].text) print(response.completion.choices[0].text)

View file

@ -2,29 +2,29 @@
import writesonic import writesonic
# create account (3-4s) # create account (3-4s)
account = writesonic.Account.create(logging = True) account = writesonic.Account.create(logging=True)
# with loging: # 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__ -> 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__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
# 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...' # 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:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
# simple completion # simple completion
response = writesonic.Completion.create( response = writesonic.Completion.create(
api_key = account.key, api_key=account.key,
prompt = 'hello world' 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 # conversation
response = writesonic.Completion.create( response = writesonic.Completion.create(
api_key = account.key, api_key=account.key,
prompt = 'what is my name ?', prompt='what is my name ?',
enable_memory = True, enable_memory=True,
history_data = [ history_data=[
{ {
'is_sent': True, 'is_sent': True,
'message': 'my name is Tekky' '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 # enable internet
response = writesonic.Completion.create( response = writesonic.Completion.create(
api_key = account.key, api_key=account.key,
prompt = 'who won the quatar world cup ?', prompt='who won the quatar world cup ?',
enable_google_results = True enable_google_results=True
) )
print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ... print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...

View file

@ -1,12 +1,12 @@
from requests import Session
from re import search
from random import randint
from json import dumps, loads from json import dumps, loads
from urllib.parse import urlencode
from dotenv import load_dotenv
from os import getenv from os import getenv
from random import randint
from re import search
from urllib.parse import urlencode
from bard.typings import BardResponse from bard.typings import BardResponse
from dotenv import load_dotenv
from requests import Session
load_dotenv() load_dotenv()
token = getenv('1psid') token = getenv('1psid')
@ -62,16 +62,17 @@ class Completion:
'rt': 'c', 'rt': 'c',
}) })
response = client.post(f'https://bard.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate?{params}', response = client.post(
data={ f'https://bard.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate?{params}',
'at': snlm0e, data={
'f.req': dumps([None, dumps([ 'at': snlm0e,
[prompt], 'f.req': dumps([None, dumps([
None, [prompt],
[conversation_id, response_id, choice_id], None,
])]) [conversation_id, response_id, choice_id],
} ])])
) }
)
chat_data = loads(response.content.splitlines()[3])[0][2] chat_data = loads(response.content.splitlines()[3])[0][2]
if not chat_data: if not chat_data:

View file

@ -1,4 +1,4 @@
from typing import Dict, List, Optional, Union from typing import Dict, List, Union
class BardResponse: class BardResponse:

View file

@ -1,14 +1,12 @@
# Import necessary libraries # 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
from json import dumps, loads
import asyncio import asyncio
from json import dumps, loads
from ssl import create_default_context
import websockets import websockets
from browser_cookie3 import edge
from certifi import where
from requests import get
# Set up SSL context # Set up SSL context
ssl_context = create_default_context() ssl_context = create_default_context()
@ -28,14 +26,14 @@ def get_token():
class AsyncCompletion: class AsyncCompletion:
async def create( async def create(
prompt: str = 'hello world', prompt: str = 'hello world',
optionSets: list = [ optionSets: list = [
'deepleo', 'deepleo',
'enable_debug_commands', 'enable_debug_commands',
'disable_emoji_spoken_text', 'disable_emoji_spoken_text',
'enablemm', 'enablemm',
'h3relaxedimg' 'h3relaxedimg'
], ],
token: str = get_token()): token: str = get_token()):
"""Create a connection to Bing AI and send the prompt.""" """Create a connection to Bing AI and send the prompt."""
@ -83,7 +81,7 @@ class AsyncCompletion:
continue continue
response = loads(obj) 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( response_text = response['arguments'][0]['messages'][0]['adaptiveCards'][0]['body'][0].get(
'text') 'text')
@ -99,11 +97,12 @@ class AsyncCompletion:
async def run(): async def run():
"""Run the async completion and print the result.""" """Run the async completion and print the result."""
async for value in AsyncCompletion.create( async for value in AsyncCompletion.create(
prompt='summarize cinderella with each word beginning with a consecutive letter of the alphabet, a-z', prompt='summarize cinderella with each word beginning with a consecutive letter of the alphabet, a-z',
optionSets=[ optionSets=[
"galileo", "galileo",
] ]
): ):
print(value, end='', flush=True) print(value, end='', flush=True)
asyncio.run(run()) asyncio.run(run())

View file

@ -6,7 +6,6 @@ class Completion:
system_prompt=("ASSUME I HAVE FULL ACCESS TO COCALC. ENCLOSE MATH IN $. " system_prompt=("ASSUME I HAVE FULL ACCESS TO COCALC. ENCLOSE MATH IN $. "
"INCLUDE THE LANGUAGE DIRECTLY AFTER THE TRIPLE BACKTICKS " "INCLUDE THE LANGUAGE DIRECTLY AFTER THE TRIPLE BACKTICKS "
"IN ALL MARKDOWN CODE BLOCKS. How can I do the following using CoCalc?")) -> str: "IN ALL MARKDOWN CODE BLOCKS. How can I do the following using CoCalc?")) -> str:
# Initialize a session with custom headers # Initialize a session with custom headers
session = self._initialize_session() session = self._initialize_session()

View file

@ -1,8 +1,7 @@
import cocalc import cocalc
response = cocalc.Completion.create( response = cocalc.Completion.create(
prompt = 'hello world' prompt='hello world'
) )
print(response) print(response)

View file

@ -1,7 +1,8 @@
# Import necessary libraries # Import necessary libraries
from requests import get
from os import urandom
from json import loads from json import loads
from os import urandom
from requests import get
# Generate a random session ID # Generate a random session ID
sessionId = urandom(10).hex() sessionId = urandom(10).hex()

View file

@ -1,6 +1,8 @@
import websockets
from json import dumps, loads from json import dumps, loads
import websockets
# Define the asynchronous function to test the WebSocket connection # Define the asynchronous function to test the WebSocket connection

View file

@ -1,7 +1,8 @@
# Import required libraries # Import required libraries
from tls_client import Session
from uuid import uuid4 from uuid import uuid4
from browser_cookie3 import chrome from browser_cookie3 import chrome
from tls_client import Session
class OpenAIChat: class OpenAIChat:

View file

@ -1,7 +1,8 @@
import requests
import json import json
import re import re
import requests
headers = { headers = {
'authority': 'openai.a2hosted.com', 'authority': 'openai.a2hosted.com',
'accept': 'text/event-stream', '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', '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): def create_query_param(conversation):
encoded_conversation = json.dumps(conversation) encoded_conversation = json.dumps(conversation)
return encoded_conversation.replace(" ", "%20").replace('"', '%22').replace("'", "%27") return encoded_conversation.replace(" ", "%20").replace('"', '%22').replace("'", "%27")
user_input = input("Enter your message: ") user_input = input("Enter your message: ")
data = [ data = [

View file

@ -1,9 +1,9 @@
from requests import post, get
from json import dumps from json import dumps
#from mail import MailClient # from mail import MailClient
from time import sleep
from re import findall from re import findall
from requests import post, get
html = get('https://developermail.com/mail/') html = get('https://developermail.com/mail/')
print(html.cookies.get('mailboxId')) print(html.cookies.get('mailboxId'))
email = findall(r'mailto:(.*)">', html.text)[0] email = findall(r'mailto:(.*)">', html.text)[0]
@ -15,9 +15,9 @@ headers = {
} }
json_data = { json_data = {
'email' : email, 'email': email,
'password': 'T4xyt4Yn6WWQ4NC', 'password': 'T4xyt4Yn6WWQ4NC',
'data' : {}, 'data': {},
'gotrue_meta_security': {}, 'gotrue_meta_security': {},
} }
@ -27,20 +27,20 @@ print(response.json())
# email_link = None # email_link = None
# while not email_link: # while not email_link:
# sleep(1) # sleep(1)
# mails = mailbox.getmails() # mails = mailbox.getmails()
# print(mails) # print(mails)
quit() quit()
url = input("Enter the url: ") url = input("Enter the url: ")
response = get(url, allow_redirects=False) 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 # https://openprompt.co/#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV8&expires_in=604800&refresh_token=_Zp8uXIA2InTDKYgo8TCqA&token_type=bearer&type=signup
redirect = response.headers.get('location') redirect = response.headers.get('location')
access_token = redirect.split('&')[0].split('=')[1] access_token = redirect.split('&')[0].split('=')[1]
refresh_token = redirect.split('&')[2].split('=')[1] refresh_token = redirect.split('&')[2].split('=')[1]
supabase_auth_token = dumps([access_token, refresh_token, None, None, None], separators=(',', ':')) 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) response = post('https://openprompt.co/api/chat2', cookies=cookies, json=json_data, stream=True)
for chunk in response.iter_content(chunk_size=1024): for chunk in response.iter_content(chunk_size=1024):
print(chunk) print(chunk)

View file

@ -1,6 +1,8 @@
import requests
import email import email
import requests
class MailClient: class MailClient:
def __init__(self): def __init__(self):
@ -106,4 +108,4 @@ class MailClient:
client = MailClient() client = MailClient()
client.newtoken() client.newtoken()
print(client.getmails()) print(client.getmails())

View file

@ -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): for chunk in response.iter_content(chunk_size=1024):
print(chunk) print(chunk)

View file

@ -1,7 +1,6 @@
access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV' access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDI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y1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV8", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyMjk0ODcxLCJzdWIiOiI4NWNkNTNiNC1lZTUwLTRiMDQtOGJhNS0wNTUyNjk4ODliZDIiLCJlbWFpbCI6ImNsc2J5emdqcGhiQGJ1Z2Zvby5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODE2OTAwNzF9XSwic2Vzc2lvbl9pZCI6ImY4MTg1YTM5LTkxYzgtNGFmMy1iNzAxLTdhY2MwY2MwMGNlNSJ9.UvcTfpyIM1TdzM8ZV6UAPWfa0rgNq4AiqeD0INy6zV8",
"_Zp8uXIA2InTDKYgo8TCqA",None,None,None] "_Zp8uXIA2InTDKYgo8TCqA", None, None, None]

View file

@ -1,5 +1,6 @@
from time import time
from requests import post from requests import post
from time import time
headers = { headers = {
'authority': 'www.t3nsor.tech', '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', '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 T3nsorResponse:
class Completion: class Completion:
class Choices: class Choices:
def __init__(self, choice: dict) -> None: def __init__(self, choice: dict) -> None:
self.text = choice['text'] self.text = choice['text']
self.content = self.text.encode() self.content = self.text.encode()
self.index = choice['index'] self.index = choice['index']
self.logprobs = choice['logprobs'] self.logprobs = choice['logprobs']
self.finish_reason = choice['finish_reason'] self.finish_reason = choice['finish_reason']
def __repr__(self) -> str: 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>''' 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: class Usage:
def __init__(self, usage_dict: dict) -> None: def __init__(self, usage_dict: dict) -> None:
self.prompt_tokens = usage_dict['prompt_chars'] self.prompt_tokens = usage_dict['prompt_chars']
self.completion_tokens = usage_dict['completion_chars'] self.completion_tokens = usage_dict['completion_chars']
self.total_tokens = usage_dict['total_chars'] self.total_tokens = usage_dict['total_chars']
def __repr__(self): 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>''' 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: def __init__(self, response_dict: dict) -> None:
self.response_dict = response_dict
self.response_dict = response_dict self.id = response_dict['id']
self.id = response_dict['id'] self.object = response_dict['object']
self.object = response_dict['object'] self.created = response_dict['created']
self.created = response_dict['created'] self.model = response_dict['model']
self.model = response_dict['model'] self.completion = self.Completion(response_dict['choices'])
self.completion = self.Completion(response_dict['choices']) self.usage = self.Usage(response_dict['usage'])
self.usage = self.Usage(response_dict['usage'])
def json(self) -> dict: def json(self) -> dict:
return self.response_dict return self.response_dict
class Completion: class Completion:
model = { model = {
'model': { 'model': {
'id' : 'gpt-3.5-turbo', 'id': 'gpt-3.5-turbo',
'name' : 'Default (GPT-3.5)' 'name': 'Default (GPT-3.5)'
} }
} }
def create( def create(
prompt: str = 'hello world', prompt: str = 'hello world',
messages: list = []) -> T3nsorResponse: messages: list = []) -> T3nsorResponse:
response = post('https://www.t3nsor.tech/api/chat', headers=headers, json=Completion.model | {
response = post('https://www.t3nsor.tech/api/chat', headers = headers, json = Completion.model | { 'messages': messages,
'messages' : messages, 'key': '',
'key' : '', 'prompt': prompt
'prompt' : prompt
}) })
return T3nsorResponse({ return T3nsorResponse({
'id' : f'cmpl-1337-{int(time())}', 'id': f'cmpl-1337-{int(time())}',
'object' : 'text_completion', 'object': 'text_completion',
'created': int(time()), 'created': int(time()),
'model' : Completion.model, 'model': Completion.model,
'choices': [{ 'choices': [{
'text' : response.text, 'text': response.text,
'index' : 0, 'index': 0,
'logprobs' : None, 'logprobs': None,
'finish_reason' : 'stop' 'finish_reason': 'stop'
}], }],
'usage': { 'usage': {
'prompt_chars' : len(prompt), 'prompt_chars': len(prompt),
'completion_chars' : len(response.text), 'completion_chars': len(response.text),
'total_chars' : len(prompt) + len(response.text) 'total_chars': len(prompt) + len(response.text)
} }
}) })
class StreamCompletion: class StreamCompletion:
model = { model = {
'model': { 'model': {
'id' : 'gpt-3.5-turbo', 'id': 'gpt-3.5-turbo',
'name' : 'Default (GPT-3.5)' 'name': 'Default (GPT-3.5)'
} }
} }
def create( def create(
prompt: str = 'hello world', prompt: str = 'hello world',
messages: list = []) -> T3nsorResponse: messages: list = []) -> T3nsorResponse:
print('t3nsor api is down, this may not work, refer to another module') 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 | { response = post('https://www.t3nsor.tech/api/chat', headers=headers, stream=True, json=Completion.model | {
'messages' : messages, 'messages': messages,
'key' : '', 'key': '',
'prompt' : prompt 'prompt': prompt
}) })
for chunk in response.iter_content(chunk_size = 2046): for chunk in response.iter_content(chunk_size=2046):
yield T3nsorResponse({ yield T3nsorResponse({
'id' : f'cmpl-1337-{int(time())}', 'id': f'cmpl-1337-{int(time())}',
'object' : 'text_completion', 'object': 'text_completion',
'created': int(time()), 'created': int(time()),
'model' : Completion.model, 'model': Completion.model,
'choices': [{ 'choices': [{
'text' : chunk.decode(), 'text': chunk.decode(),
'index' : 0, 'index': 0,
'logprobs' : None, 'logprobs': None,
'finish_reason' : 'stop' 'finish_reason': 'stop'
}], }],
'usage': { 'usage': {
'prompt_chars' : len(prompt), 'prompt_chars': len(prompt),
'completion_chars' : len(chunk.decode()), 'completion_chars': len(chunk.decode()),
'total_chars' : len(prompt) + len(chunk.decode()) 'total_chars': len(prompt) + len(chunk.decode())
} }
}) })

View file

@ -1,12 +1,8 @@
import gptbz
import asyncio
# asyncio.run(gptbz.test()) # asyncio.run(gptbz.test())
import requests import requests
image = '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAoALQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAA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y4mtUkNqJPKuBJ5ewuEBYx8gbiBxz+FFFS3ZM1p01OdNN/wBaFfVtU0qHxHplx9qsSkEl2853SvIjxwjdtCZXIX7wbt05q7YJdS6nc6vYxWEtpfi2KS+bKsjQhCSWBBG4bhtAAyCcmiinF3k0RWgqdKMl1VvxZfM2s+VkWFh5nl5x9tfG/djGfK6bec468Y/irN1CeUCeHXbrTItPc3O6GN5PNltxHx0I+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]) response = requests.get('https://ocr.holey.cc/ncku?base64_str=%s' % image) # .split('base64,')[1])
print(response.content) print(response.content)

View file

@ -1,46 +1,49 @@
from curl_cffi import requests from json import loads
from json import loads from queue import Queue, Empty
from re import findall from re import findall
from threading import Thread from threading import Thread
from queue import Queue, Empty
from curl_cffi import requests
class Completion: class Completion:
# experimental # experimental
part1 = '{"role":"assistant","id":"chatcmpl' part1 = '{"role":"assistant","id":"chatcmpl'
part2 = '"},"index":0,"finish_reason":null}]}}' part2 = '"},"index":0,"finish_reason":null}]}}'
regex = rf'{part1}(.*){part2}' regex = rf'{part1}(.*){part2}'
timer = None timer = None
message_queue = Queue() message_queue = Queue()
stream_completed = False stream_completed = False
def request(): def request():
headers = { headers = {
'authority' : 'chatbot.theb.ai', 'authority': 'chatbot.theb.ai',
'content-type': 'application/json', 'content-type': 'application/json',
'origin' : 'https://chatbot.theb.ai', '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', '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, requests.post('https://chatbot.theb.ai/api/chat-process', headers=headers,
json = { content_callback=Completion.handle_stream_response,
'prompt' : 'hello world', json={
'options': {} 'prompt': 'hello world',
} 'options': {}
) }
)
Completion.stream_completed = True Completion.stream_completed = True
@staticmethod @staticmethod
def create(): def create():
Thread(target=Completion.request).start() Thread(target=Completion.request).start()
while Completion.stream_completed != True or not Completion.message_queue.empty(): while Completion.stream_completed != True or not Completion.message_queue.empty():
try: try:
message = Completion.message_queue.get(timeout=0.01) message = Completion.message_queue.get(timeout=0.01)
for message in findall(Completion.regex, message): for message in findall(Completion.regex, message):
yield loads(Completion.part1 + message + Completion.part2) yield loads(Completion.part1 + message + Completion.part2)
except Empty: except Empty:
pass pass
@ -48,10 +51,12 @@ class Completion:
def handle_stream_response(response): def handle_stream_response(response):
Completion.message_queue.put(response.decode()) Completion.message_queue.put(response.decode())
def start(): def start():
for message in Completion.create(): for message in Completion.create():
yield message['delta'] yield message['delta']
if __name__ == '__main__': if __name__ == '__main__':
for message in start(): for message in start():
print(message) print(message)

View file

@ -1,6 +1,5 @@
import requests import requests
token = requests.get('https://play.vercel.ai/openai.jpeg', headers={ token = requests.get('https://play.vercel.ai/openai.jpeg', headers={
'authority': 'play.vercel.ai', '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', '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' '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', 'prompt': 'hi',
'model': 'openai:gpt-3.5-turbo', 'model': 'openai:gpt-3.5-turbo',
'temperature': 0.7, 'temperature': 0.7,
@ -25,5 +24,4 @@ for chunk in requests.post('https://play.vercel.ai/api/generate', headers=header
'frequencyPenalty': 1, 'frequencyPenalty': 1,
'presencePenalty': 1, 'presencePenalty': 1,
'stopSequences': []}).iter_lines(): 'stopSequences': []}).iter_lines():
print(chunk)
print(chunk)

View file

@ -1,29 +1,33 @@
from requests import Session from random import choice
from names import get_first_name, get_last_name from time import time
from random import choice
from requests import post from colorama import Fore, init;
from time import time from names import get_first_name, get_last_name
from colorama import Fore, init; init() from requests import Session
from requests import post
init()
class logger: class logger:
@staticmethod @staticmethod
def info(string) -> print: def info(string) -> print:
import datetime import datetime
now = datetime.datetime.now() 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 SonicResponse:
class Completion: class Completion:
class Choices: class Choices:
def __init__(self, choice: dict) -> None: def __init__(self, choice: dict) -> None:
self.text = choice['text'] self.text = choice['text']
self.content = self.text.encode() self.content = self.text.encode()
self.index = choice['index'] self.index = choice['index']
self.logprobs = choice['logprobs'] self.logprobs = choice['logprobs']
self.finish_reason = choice['finish_reason'] self.finish_reason = choice['finish_reason']
def __repr__(self) -> str: 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>''' 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: class Usage:
def __init__(self, usage_dict: dict) -> None: def __init__(self, usage_dict: dict) -> None:
self.prompt_tokens = usage_dict['prompt_chars'] self.prompt_tokens = usage_dict['prompt_chars']
self.completion_tokens = usage_dict['completion_chars'] self.completion_tokens = usage_dict['completion_chars']
self.total_tokens = usage_dict['total_chars'] self.total_tokens = usage_dict['total_chars']
def __repr__(self): 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>''' 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: def __init__(self, response_dict: dict) -> None:
self.response_dict = response_dict
self.response_dict = response_dict self.id = response_dict['id']
self.id = response_dict['id'] self.object = response_dict['object']
self.object = response_dict['object'] self.created = response_dict['created']
self.created = response_dict['created'] self.model = response_dict['model']
self.model = response_dict['model'] self.completion = self.Completion(response_dict['choices'])
self.completion = self.Completion(response_dict['choices']) self.usage = self.Usage(response_dict['usage'])
self.usage = self.Usage(response_dict['usage'])
def json(self) -> dict: def json(self) -> dict:
return self.response_dict return self.response_dict
class Account: class Account:
session = Session() session = Session()
session.headers = { session.headers = {
"connection" : "keep-alive", "connection": "keep-alive",
"sec-ch-ua" : "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"", "sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
"accept" : "application/json, text/plain, */*", "accept": "application/json, text/plain, */*",
"content-type" : "application/json", "content-type": "application/json",
"sec-ch-ua-mobile" : "?0", "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", "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-ch-ua-platform": "\"Windows\"",
"sec-fetch-site" : "same-origin", "sec-fetch-site": "same-origin",
"sec-fetch-mode" : "cors", "sec-fetch-mode": "cors",
"sec-fetch-dest" : "empty", "sec-fetch-dest": "empty",
# "accept-encoding" : "gzip, deflate, br", # "accept-encoding" : "gzip, deflate, br",
"accept-language" : "en-GB,en-US;q=0.9,en;q=0.8", "accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"cookie" : "" "cookie": ""
} }
@staticmethod @staticmethod
def get_user(): def get_user():
password = f'0opsYouGoTme@1234' password = f'0opsYouGoTme@1234'
f_name = get_first_name() f_name = get_first_name()
l_name = get_last_name() l_name = get_last_name()
hosts = ['gmail.com', 'protonmail.com', 'proton.me', 'outlook.com'] hosts = ['gmail.com', 'protonmail.com', 'proton.me', 'outlook.com']
return { return {
"email" : f"{f_name.lower()}.{l_name.lower()}@{choice(hosts)}", "email": f"{f_name.lower()}.{l_name.lower()}@{choice(hosts)}",
"password" : password, "password": password,
"confirm_password" : password, "confirm_password": password,
"full_name" : f'{f_name} {l_name}' "full_name": f'{f_name} {l_name}'
} }
@staticmethod @staticmethod
def create(logging: bool = False): def create(logging: bool = False):
while True: while True:
try: try:
user = Account.get_user() user = Account.get_user()
start = time() start = time()
response = Account.session.post("https://app.writesonic.com/api/session-login", json = user | { response = Account.session.post("https://app.writesonic.com/api/session-login", json=user | {
"utmParams" : "{}", "utmParams": "{}",
"visitorId" : "0", "visitorId": "0",
"locale" : "en", "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", "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", "signInWith": "password",
"request_type" : "signup", "request_type": "signup",
}) })
if logging: if logging:
logger.info(f"\x1b[31mregister success\x1b[0m : '{response.text[:30]}...' ({int(time() - start)}s)") 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[31mid\x1b[0m : '{response.json()['id']}'")
logger.info(f"\x1b[31mtoken\x1b[0m : '{response.json()['token'][:30]}...'") logger.info(f"\x1b[31mtoken\x1b[0m : '{response.json()['token'][:30]}...'")
start = time() 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"] key = response.json()["business"]["api_key"]
if logging: logger.info(f"\x1b[31mgot key\x1b[0m : '{key}' ({int(time() - start)}s)") if logging: logger.info(f"\x1b[31mgot key\x1b[0m : '{key}' ({int(time() - start)}s)")
return Account.AccountResponse(user['email'], user['password'], key) return Account.AccountResponse(user['email'], user['password'], key)
except Exception as e: except Exception as e:
if logging: logger.info(f"\x1b[31merror\x1b[0m : '{e}'") if logging: logger.info(f"\x1b[31merror\x1b[0m : '{e}'")
continue continue
class AccountResponse: class AccountResponse:
def __init__(self, email, password, key): def __init__(self, email, password, key):
self.email = email self.email = email
self.password = password self.password = password
self.key = key self.key = key
class Completion: class Completion:
def create( def create(
api_key: str, api_key: str,
prompt: str, prompt: str,
enable_memory: bool = False, enable_memory: bool = False,
enable_google_results: bool = False, enable_google_results: bool = False,
history_data: list = []) -> SonicResponse: history_data: list = []) -> SonicResponse:
response = post('https://api.writesonic.com/v2/business/content/chatsonic?engine=premium',
response = post('https://api.writesonic.com/v2/business/content/chatsonic?engine=premium', headers = {"X-API-KEY": api_key}, headers={"X-API-KEY": api_key},
json = { json={
"enable_memory" : enable_memory, "enable_memory": enable_memory,
"enable_google_results" : enable_google_results, "enable_google_results": enable_google_results,
"input_text" : prompt, "input_text": prompt,
"history_data" : history_data}).json() "history_data": history_data}).json()
return SonicResponse({ return SonicResponse({
'id' : f'cmpl-premium-{int(time())}', 'id': f'cmpl-premium-{int(time())}',
'object' : 'text_completion', 'object': 'text_completion',
'created': int(time()), 'created': int(time()),
'model' : 'premium', 'model': 'premium',
'choices': [{ 'choices': [{
'text' : response['message'], 'text': response['message'],
'index' : 0, 'index': 0,
'logprobs' : None, 'logprobs': None,
'finish_reason' : 'stop' 'finish_reason': 'stop'
}], }],
'usage': { 'usage': {
'prompt_chars' : len(prompt), 'prompt_chars': len(prompt),
'completion_chars' : len(response['message']), 'completion_chars': len(response['message']),
'total_chars' : len(prompt) + len(response['message']) 'total_chars': len(prompt) + len(response['message'])
} }
}) })

View file

@ -9,19 +9,19 @@ from tls_client import Session
class Completion: class Completion:
@staticmethod @staticmethod
def create( def create(
prompt: str, prompt: str,
page: int = 1, page: int = 1,
count: int = 10, count: int = 10,
safe_search: str = 'Moderate', safe_search: str = 'Moderate',
on_shopping_page: bool = False, on_shopping_page: bool = False,
mkt: str = '', mkt: str = '',
response_filter: str = 'WebPages,Translations,TimeZone,Computation,RelatedSearches', response_filter: str = 'WebPages,Translations,TimeZone,Computation,RelatedSearches',
domain: str = 'youchat', domain: str = 'youchat',
query_trace_id: str = None, query_trace_id: str = None,
chat: list = None, chat: list = None,
include_links: bool = False, include_links: bool = False,
detailed: bool = False, detailed: bool = False,
debug: bool = False, debug: bool = False,
) -> dict: ) -> dict:
if chat is None: if chat is None:
chat = [] chat = []