Merge branch 'main' into main
This commit is contained in:
commit
d8ec09cebb
13 changed files with 549 additions and 305 deletions
30
README.md
30
README.md
|
@ -1,7 +1,7 @@
|
||||||
# GPT4free - use ChatGPT, for free!!
|
# GPT4free - use ChatGPT, for free!!
|
||||||
|
|
||||||
##### You may join our discord server for updates and support ; )
|
##### You may join our discord server for updates and support ; )
|
||||||
- https://discord.gg/gpt4free
|
- [Discord Link](https://discord.gg/gpt4free)
|
||||||
|
|
||||||
<img width="1383" alt="image" src="https://user-images.githubusercontent.com/98614666/233799515-1a7cb6a3-b17f-42c4-956d-8d2a0664466f.png">
|
<img width="1383" alt="image" src="https://user-images.githubusercontent.com/98614666/233799515-1a7cb6a3-b17f-42c4-956d-8d2a0664466f.png">
|
||||||
|
|
||||||
|
@ -9,25 +9,7 @@ Have you ever come across some amazing projects that you couldn't use **just bec
|
||||||
|
|
||||||
**We've got you covered!** This repository offers **reverse-engineered** third-party APIs for `GPT-4/3.5`, sourced from various websites. You can simply **download** this repository, and use the available modules, which are designed to be used **just like OpenAI's official package**. **Unleash ChatGPT's potential for your projects, now!** You are welcome ; ).
|
**We've got you covered!** This repository offers **reverse-engineered** third-party APIs for `GPT-4/3.5`, sourced from various websites. You can simply **download** this repository, and use the available modules, which are designed to be used **just like OpenAI's official package**. **Unleash ChatGPT's potential for your projects, now!** You are welcome ; ).
|
||||||
|
|
||||||
By the way, thank you so much for [![Stars](https://img.shields.io/github/stars/xtekky/gpt4free?style=social)](https://github.com/xtekky/gpt4free/stargazers) and all the support!!
|
By the way, thank you so much for `11k` stars and all the support!!
|
||||||
|
|
||||||
## Announcement
|
|
||||||
Dear Gpt4free Community,
|
|
||||||
|
|
||||||
I want to thank you for your interest in and support of this project, which I only intended to be for entertainment and educational purposes; I had no idea it would end up being so popular.
|
|
||||||
|
|
||||||
I'm aware of the concerns about the project's legality and its impact on smaller sites hosting APIs. I take these concerns seriously and plan to address them.
|
|
||||||
|
|
||||||
Here's what I'm doing to fix these issues:
|
|
||||||
|
|
||||||
1. Removing APIs from smaller sites: To reduce the impact on smaller sites, I have removed their APIs from the repository. Please shoot me a dm if you are an owner of a site and want it removed.
|
|
||||||
|
|
||||||
2. Commitment to ethical use: I want to emphasize my commitment to promoting ethical use of language models. I don't support any illegal or unethical behavior, and I expect users to follow the same principles.
|
|
||||||
|
|
||||||
Thank you for your support and understanding. I appreciate your continued interest in gpt4free and am committed to addressing your concerns.
|
|
||||||
|
|
||||||
Sincerely,
|
|
||||||
xtekky
|
|
||||||
|
|
||||||
## Legal Notice <a name="legal-notice"></a>
|
## Legal Notice <a name="legal-notice"></a>
|
||||||
|
|
||||||
|
@ -55,9 +37,10 @@ Please note the following:
|
||||||
| **Legal Notice** | Legal notice or disclaimer | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#legal-notice) | - |
|
| **Legal Notice** | Legal notice or disclaimer | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#legal-notice) | - |
|
||||||
| **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
|
| **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
|
||||||
| **Usage Examples** | | | |
|
| **Usage Examples** | | | |
|
||||||
| `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
|
| `forefront` | Example usage for forefront (gpt-4) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | | |
|
||||||
|
| `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | |
|
||||||
| `phind` | Example usage for phind | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./phind/README.md) | ![Inactive](https://img.shields.io/badge/Active-brightgreen) |
|
| `phind` | Example usage for phind | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./phind/README.md) | ![Inactive](https://img.shields.io/badge/Active-brightgreen) |
|
||||||
| `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen)
|
| `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
|
||||||
| **Try it Out** | | | |
|
| **Try it Out** | | | |
|
||||||
| Google Colab Jupyter Notebook | Example usage for gpt4free | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
|
| Google Colab Jupyter Notebook | Example usage for gpt4free | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
|
||||||
| replit Example (feel free to fork this repl) | Example usage for gpt4free | [![](https://img.shields.io/badge/Open%20in-Replit-1A1E27?logo=replit)](https://replit.com/@gpt4free/gpt4free-webui) | - |
|
| replit Example (feel free to fork this repl) | Example usage for gpt4free | [![](https://img.shields.io/badge/Open%20in-Replit-1A1E27?logo=replit)](https://replit.com/@gpt4free/gpt4free-webui) | - |
|
||||||
|
@ -74,8 +57,9 @@ Please note the following:
|
||||||
|
|
||||||
## Current Sites <a name="current-sites"></a>
|
## Current Sites <a name="current-sites"></a>
|
||||||
|
|
||||||
| Website | Model(s) |
|
| Website s | Model(s) |
|
||||||
| ---------------------------------------------------- | ------------------------------- |
|
| ---------------------------------------------------- | ------------------------------- |
|
||||||
|
| [forefront.ai](https://chat.forefront.ai) | GPT-4/3.5 |
|
||||||
| [poe.com](https://poe.com) | GPT-4/3.5 |
|
| [poe.com](https://poe.com) | GPT-4/3.5 |
|
||||||
| [writesonic.com](https://writesonic.com) | GPT-3.5 / Internet |
|
| [writesonic.com](https://writesonic.com) | GPT-3.5 / Internet |
|
||||||
| [t3nsor.com](https://t3nsor.com) | GPT-3.5 |
|
| [t3nsor.com](https://t3nsor.com) | GPT-3.5 |
|
||||||
|
|
15
Singularity/gpt4free.sif
Normal file
15
Singularity/gpt4free.sif
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Bootstrap: docker
|
||||||
|
From: python:3.10-slim
|
||||||
|
|
||||||
|
%post
|
||||||
|
apt-get update && apt-get install -y git
|
||||||
|
git clone https://github.com/xtekky/gpt4free.git
|
||||||
|
cd gpt4free
|
||||||
|
pip install --no-cache-dir -r requirements.txt
|
||||||
|
cp gui/streamlit_app.py .
|
||||||
|
|
||||||
|
%expose
|
||||||
|
8501
|
||||||
|
|
||||||
|
%startscript
|
||||||
|
exec streamlit run streamlit_app.py
|
15
forefront/README.md
Normal file
15
forefront/README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
### Example: `forefront` (use like openai pypi package) <a name="example-forefront"></a>
|
||||||
|
|
||||||
|
```python
|
||||||
|
import forefront
|
||||||
|
|
||||||
|
# create an account
|
||||||
|
token = forefront.Account.create(logging=True)
|
||||||
|
print(token)
|
||||||
|
|
||||||
|
# get a response
|
||||||
|
for response in forefront.StreamingCompletion.create(token = token,
|
||||||
|
prompt = 'hello world', model='gpt-4'):
|
||||||
|
|
||||||
|
print(response.completion.choices[0].text, end = '')
|
||||||
|
```
|
145
forefront/__init__.py
Normal file
145
forefront/__init__.py
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
class Account:
|
||||||
|
def create(proxy = None, logging = False):
|
||||||
|
|
||||||
|
proxies = {
|
||||||
|
'http': 'http://' + proxy,
|
||||||
|
'https': 'http://' + proxy } if proxy else False
|
||||||
|
|
||||||
|
start = time()
|
||||||
|
|
||||||
|
mail = Mail(proxies)
|
||||||
|
mail_token = None
|
||||||
|
mail_adress = mail.get_mail()
|
||||||
|
|
||||||
|
#print(mail_adress)
|
||||||
|
|
||||||
|
client = Session(client_identifier='chrome110')
|
||||||
|
client.proxies = proxies
|
||||||
|
client.headers = {
|
||||||
|
"origin": "https://accounts.forefront.ai",
|
||||||
|
"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
|
||||||
|
}
|
||||||
|
|
||||||
|
response = client.post('https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
|
||||||
|
data = {
|
||||||
|
"email_address": mail_adress
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
trace_token = response.json()['response']['id']
|
||||||
|
if logging: print(trace_token)
|
||||||
|
|
||||||
|
response = client.post(f"https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6",
|
||||||
|
data = {
|
||||||
|
"strategy" : "email_code",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if logging: print(response.text)
|
||||||
|
|
||||||
|
if not 'sign_up_attempt' in response.text:
|
||||||
|
return 'Failed to create account!'
|
||||||
|
|
||||||
|
while True:
|
||||||
|
sleep(1)
|
||||||
|
for _ in mail.fetch_inbox():
|
||||||
|
print(mail.get_message_content(_["id"]))
|
||||||
|
mail_token = match(r"(\d){5,6}", mail.get_message_content(_["id"])).group(0)
|
||||||
|
|
||||||
|
if mail_token:
|
||||||
|
break
|
||||||
|
|
||||||
|
if logging: print(mail_token)
|
||||||
|
|
||||||
|
response = client.post(f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/attempt_verification?_clerk_js_version=4.38.4', data = {
|
||||||
|
'code': mail_token,
|
||||||
|
'strategy': 'email_code'
|
||||||
|
})
|
||||||
|
|
||||||
|
if logging: print(response.json())
|
||||||
|
|
||||||
|
token = response.json()['client']['sessions'][0]['last_active_token']['jwt']
|
||||||
|
|
||||||
|
with open('accounts.txt', 'a') as f:
|
||||||
|
f.write(f'{mail_adress}:{token}\n')
|
||||||
|
|
||||||
|
if logging: print(time() - start)
|
||||||
|
|
||||||
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
class StreamingCompletion:
|
||||||
|
def create(
|
||||||
|
token = None,
|
||||||
|
chatId = None,
|
||||||
|
prompt = '',
|
||||||
|
actionType = 'new',
|
||||||
|
defaultPersona = '607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
||||||
|
model = 'gpt-4') -> ForeFrontResponse:
|
||||||
|
|
||||||
|
if not token: raise Exception('Token is required!')
|
||||||
|
if not chatId: chatId = str(uuid4())
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'authority' : 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
|
||||||
|
'accept' : '*/*',
|
||||||
|
'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
|
||||||
|
'authorization' : 'Bearer ' + token,
|
||||||
|
'cache-control' : 'no-cache',
|
||||||
|
'content-type' : 'application/json',
|
||||||
|
'origin' : 'https://chat.forefront.ai',
|
||||||
|
'pragma' : 'no-cache',
|
||||||
|
'referer' : 'https://chat.forefront.ai/',
|
||||||
|
'sec-ch-ua' : '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
|
||||||
|
'sec-ch-ua-mobile' : '?0',
|
||||||
|
'sec-ch-ua-platform': '"macOS"',
|
||||||
|
'sec-fetch-dest' : 'empty',
|
||||||
|
'sec-fetch-mode' : 'cors',
|
||||||
|
'sec-fetch-site' : 'cross-site',
|
||||||
|
'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
|
||||||
|
}
|
||||||
|
|
||||||
|
json_data = {
|
||||||
|
'text' : prompt,
|
||||||
|
'action' : actionType,
|
||||||
|
'parentId' : chatId,
|
||||||
|
'workspaceId' : chatId,
|
||||||
|
'messagePersona' : defaultPersona,
|
||||||
|
'model' : model
|
||||||
|
}
|
||||||
|
|
||||||
|
for chunk in post('https://chat-server.tenant-forefront-default.knative.chi.coreweave.com/chat',
|
||||||
|
headers=headers, json=json_data, stream=True).iter_lines():
|
||||||
|
|
||||||
|
if b'finish_reason":null' in chunk:
|
||||||
|
data = loads(chunk.decode('utf-8').split('data: ')[1])
|
||||||
|
token = data['choices'][0]['delta'].get('content')
|
||||||
|
|
||||||
|
if token != None:
|
||||||
|
yield ForeFrontResponse({
|
||||||
|
'id' : chatId,
|
||||||
|
'object' : 'text_completion',
|
||||||
|
'created': int(time()),
|
||||||
|
'model' : model,
|
||||||
|
'choices': [{
|
||||||
|
'text' : token,
|
||||||
|
'index' : 0,
|
||||||
|
'logprobs' : None,
|
||||||
|
'finish_reason' : 'stop'
|
||||||
|
}],
|
||||||
|
'usage': {
|
||||||
|
'prompt_tokens' : len(prompt),
|
||||||
|
'completion_tokens' : len(token),
|
||||||
|
'total_tokens' : len(prompt) + len(token)
|
||||||
|
}
|
||||||
|
})
|
55
forefront/mail.py
Normal file
55
forefront/mail.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
from requests import Session
|
||||||
|
from string import ascii_letters
|
||||||
|
from random import choices
|
||||||
|
|
||||||
|
class Mail:
|
||||||
|
def __init__(self, proxies: dict = None) -> None:
|
||||||
|
self.client = Session()
|
||||||
|
self.client.proxies = proxies
|
||||||
|
self.client.headers = {
|
||||||
|
"host": "api.mail.tm",
|
||||||
|
"connection": "keep-alive",
|
||||||
|
"sec-ch-ua": "\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
|
||||||
|
"accept": "application/json, text/plain, */*",
|
||||||
|
"content-type": "application/json",
|
||||||
|
"sec-ch-ua-mobile": "?0",
|
||||||
|
"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",
|
||||||
|
"sec-ch-ua-platform": "\"macOS\"",
|
||||||
|
"origin": "https://mail.tm",
|
||||||
|
"sec-fetch-site": "same-site",
|
||||||
|
"sec-fetch-mode": "cors",
|
||||||
|
"sec-fetch-dest": "empty",
|
||||||
|
"referer": "https://mail.tm/",
|
||||||
|
"accept-encoding": "gzip, deflate, br",
|
||||||
|
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8"
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_mail(self) -> str:
|
||||||
|
token = ''.join(choices(ascii_letters, k=14)).lower()
|
||||||
|
init = self.client.post("https://api.mail.tm/accounts", json={
|
||||||
|
"address" : f"{token}@bugfoo.com",
|
||||||
|
"password": token
|
||||||
|
})
|
||||||
|
|
||||||
|
if init.status_code == 201:
|
||||||
|
resp = self.client.post("https://api.mail.tm/token", json = {
|
||||||
|
**init.json(),
|
||||||
|
"password": token
|
||||||
|
})
|
||||||
|
|
||||||
|
self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
|
||||||
|
|
||||||
|
return f"{token}@bugfoo.com"
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise Exception("Failed to create email")
|
||||||
|
|
||||||
|
def fetch_inbox(self):
|
||||||
|
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]
|
||||||
|
|
||||||
|
def get_message(self, message_id: str):
|
||||||
|
return self.client.get(f"https://api.mail.tm/messages/{message_id}").json()
|
||||||
|
|
||||||
|
def get_message_content(self, message_id: str):
|
||||||
|
return self.get_message(message_id)["text"]
|
||||||
|
|
37
forefront/typing.py
Normal file
37
forefront/typing.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
class ForeFrontResponse:
|
||||||
|
class Completion:
|
||||||
|
class Choices:
|
||||||
|
def __init__(self, choice: dict) -> None:
|
||||||
|
self.text = choice['text']
|
||||||
|
self.content = self.text.encode()
|
||||||
|
self.index = choice['index']
|
||||||
|
self.logprobs = choice['logprobs']
|
||||||
|
self.finish_reason = choice['finish_reason']
|
||||||
|
|
||||||
|
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>'''
|
||||||
|
|
||||||
|
def __init__(self, choices: dict) -> None:
|
||||||
|
self.choices = [self.Choices(choice) for choice in choices]
|
||||||
|
|
||||||
|
class Usage:
|
||||||
|
def __init__(self, usage_dict: dict) -> None:
|
||||||
|
self.prompt_tokens = usage_dict['prompt_tokens']
|
||||||
|
self.completion_tokens = usage_dict['completion_tokens']
|
||||||
|
self.total_tokens = usage_dict['total_tokens']
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'''<__main__.APIResponse.Usage(\n prompt_tokens = {self.prompt_tokens},\n completion_tokens = {self.completion_tokens},\n total_tokens = {self.total_tokens})object at 0x1337>'''
|
||||||
|
|
||||||
|
def __init__(self, response_dict: dict) -> None:
|
||||||
|
|
||||||
|
self.response_dict = response_dict
|
||||||
|
self.id = response_dict['id']
|
||||||
|
self.object = response_dict['object']
|
||||||
|
self.created = response_dict['created']
|
||||||
|
self.model = response_dict['model']
|
||||||
|
self.completion = self.Completion(response_dict['choices'])
|
||||||
|
self.usage = self.Usage(response_dict['usage'])
|
||||||
|
|
||||||
|
def json(self) -> dict:
|
||||||
|
return self.response_dict
|
|
@ -1,3 +1,8 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
||||||
|
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
import phind
|
import phind
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ from quora import Poe
|
||||||
|
|
||||||
# available models: ['Sage', 'GPT-4', 'Claude+', 'Claude-instant', 'ChatGPT', 'Dragonfly', 'NeevaAI']
|
# available models: ['Sage', 'GPT-4', 'Claude+', 'Claude-instant', 'ChatGPT', 'Dragonfly', 'NeevaAI']
|
||||||
|
|
||||||
poe = Poe(model='ChatGPT')
|
poe = Poe(model='ChatGPT', driver='firefox', cookie_path='cookie.json', driver_path='path_of_driver')
|
||||||
poe.chat('who won the football world cup most?')
|
poe.chat('who won the football world cup most?')
|
||||||
|
|
||||||
# new bot creation
|
# new bot creation
|
||||||
|
|
|
@ -6,13 +6,14 @@ from pathlib import Path
|
||||||
from random import choice, choices, randint
|
from random import choice, choices, randint
|
||||||
from re import search, findall
|
from re import search, findall
|
||||||
from string import ascii_letters, digits
|
from string import ascii_letters, digits
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
import selenium.webdriver.support.expected_conditions as EC
|
import selenium.webdriver.support.expected_conditions as EC
|
||||||
|
from fake_useragent import UserAgent
|
||||||
from pypasser import reCaptchaV3
|
from pypasser import reCaptchaV3
|
||||||
from requests import Session
|
from requests import Session
|
||||||
from selenium import webdriver
|
from selenium.webdriver import Firefox, Chrome, FirefoxOptions, ChromeOptions
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
from selenium.webdriver.support.wait import WebDriverWait
|
||||||
from tls_client import Session as TLS
|
from tls_client import Session as TLS
|
||||||
|
@ -20,33 +21,48 @@ from tls_client import Session as TLS
|
||||||
from quora.api import Client as PoeClient
|
from quora.api import Client as PoeClient
|
||||||
from quora.mail import Emailnator
|
from quora.mail import Emailnator
|
||||||
|
|
||||||
|
SELENIUM_WEB_DRIVER_ERROR_MSG = b'''The error message you are receiving is due to the `geckodriver` executable not
|
||||||
|
being found in your system\'s PATH. To resolve this issue, you need to download the geckodriver and add its location
|
||||||
|
to your system\'s PATH.\n\nHere are the steps to resolve the issue:\n\n1. Download the geckodriver for your platform
|
||||||
|
(Windows, macOS, or Linux) from the following link: https://github.com/mozilla/geckodriver/releases\n\n2. Extract the
|
||||||
|
downloaded archive and locate the geckodriver executable.\n\n3. Add the geckodriver executable to your system\'s
|
||||||
|
PATH.\n\nFor macOS and Linux:\n\n- Open a terminal window.\n- Move the geckodriver executable to a directory that is
|
||||||
|
already in your PATH, or create a new directory and add it to your PATH:\n\n```bash\n# Example: Move geckodriver to
|
||||||
|
/usr/local/bin\nmv /path/to/your/geckodriver /usr/local/bin\n```\n\n- If you created a new directory, add it to your
|
||||||
|
PATH:\n\n```bash\n# Example: Add a new directory to PATH\nexport PATH=$PATH:/path/to/your/directory\n```\n\nFor
|
||||||
|
Windows:\n\n- Right-click on "My Computer" or "This PC" and select "Properties".\n- Click on "Advanced system
|
||||||
|
settings".\n- Click on the "Environment Variables" button.\n- In the "System variables" section, find the "Path"
|
||||||
|
variable, select it, and click "Edit".\n- Click "New" and add the path to the directory containing the geckodriver
|
||||||
|
executable.\n\nAfter adding the geckodriver to your PATH, restart your terminal or command prompt and try running
|
||||||
|
your script again. The error should be resolved.'''
|
||||||
|
|
||||||
# from twocaptcha import TwoCaptcha
|
# from twocaptcha import TwoCaptcha
|
||||||
# solver = TwoCaptcha('72747bf24a9d89b4dcc1b24875efd358')
|
# solver = TwoCaptcha('72747bf24a9d89b4dcc1b24875efd358')
|
||||||
|
|
||||||
MODELS = {
|
MODELS = {
|
||||||
"Sage": "capybara",
|
'Sage': 'capybara',
|
||||||
"GPT-4": "beaver",
|
'GPT-4': 'beaver',
|
||||||
"Claude+": "a2_2",
|
'Claude+': 'a2_2',
|
||||||
"Claude-instant": "a2",
|
'Claude-instant': 'a2',
|
||||||
"ChatGPT": "chinchilla",
|
'ChatGPT': 'chinchilla',
|
||||||
"Dragonfly": "nutria",
|
'Dragonfly': 'nutria',
|
||||||
"NeevaAI": "hutia",
|
'NeevaAI': 'hutia',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def extract_formkey(html):
|
def extract_formkey(html):
|
||||||
script_regex = r"<script>if\(.+\)throw new Error;(.+)</script>"
|
script_regex = r'<script>if\(.+\)throw new Error;(.+)</script>'
|
||||||
script_text = search(script_regex, html).group(1)
|
script_text = search(script_regex, html).group(1)
|
||||||
key_regex = r'var .="([0-9a-f]+)",'
|
key_regex = r'var .="([0-9a-f]+)",'
|
||||||
key_text = search(key_regex, script_text).group(1)
|
key_text = search(key_regex, script_text).group(1)
|
||||||
cipher_regex = r".\[(\d+)\]=.\[(\d+)\]"
|
cipher_regex = r'.\[(\d+)\]=.\[(\d+)\]'
|
||||||
cipher_pairs = findall(cipher_regex, script_text)
|
cipher_pairs = findall(cipher_regex, script_text)
|
||||||
|
|
||||||
formkey_list = [""] * len(cipher_pairs)
|
formkey_list = [''] * len(cipher_pairs)
|
||||||
for pair in cipher_pairs:
|
for pair in cipher_pairs:
|
||||||
formkey_index, key_index = map(int, pair)
|
formkey_index, key_index = map(int, pair)
|
||||||
formkey_list[formkey_index] = key_text[key_index]
|
formkey_list[formkey_index] = key_text[key_index]
|
||||||
formkey = "".join(formkey_list)
|
formkey = ''.join(formkey_list)
|
||||||
|
|
||||||
return formkey
|
return formkey
|
||||||
|
|
||||||
|
@ -55,35 +71,35 @@ class PoeResponse:
|
||||||
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>'''
|
||||||
|
|
||||||
def __init__(self, choices: dict) -> None:
|
def __init__(self, choices: dict) -> None:
|
||||||
self.choices = [self.Choices(choice) for choice in choices]
|
self.choices = [self.Choices(choice) for choice in choices]
|
||||||
|
|
||||||
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
|
||||||
|
@ -91,139 +107,135 @@ class PoeResponse:
|
||||||
|
|
||||||
class ModelResponse:
|
class ModelResponse:
|
||||||
def __init__(self, json_response: dict) -> None:
|
def __init__(self, json_response: dict) -> None:
|
||||||
self.id = json_response["data"]["poeBotCreate"]["bot"]["id"]
|
self.id = json_response['data']['poeBotCreate']['bot']['id']
|
||||||
self.name = json_response["data"]["poeBotCreate"]["bot"]["displayName"]
|
self.name = json_response['data']['poeBotCreate']['bot']['displayName']
|
||||||
self.limit = json_response["data"]["poeBotCreate"]["bot"]["messageLimit"][
|
self.limit = json_response['data']['poeBotCreate']['bot']['messageLimit']['dailyLimit']
|
||||||
"dailyLimit"
|
self.deleted = json_response['data']['poeBotCreate']['bot']['deletionState']
|
||||||
]
|
|
||||||
self.deleted = json_response["data"]["poeBotCreate"]["bot"]["deletionState"]
|
|
||||||
|
|
||||||
|
|
||||||
class Model:
|
class Model:
|
||||||
|
@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',
|
||||||
"claude-instant-v1.0": "a2",
|
'claude-instant-v1.0': 'a2',
|
||||||
"gpt-4": "beaver",
|
'gpt-4': 'beaver',
|
||||||
}
|
}
|
||||||
|
|
||||||
if not handle:
|
if not handle:
|
||||||
handle = f"gptx{randint(1111111, 9999999)}"
|
handle = f'gptx{randint(1111111, 9999999)}'
|
||||||
|
|
||||||
client = Session()
|
client = Session()
|
||||||
client.cookies["p-b"] = token
|
client.cookies['p-b'] = token
|
||||||
|
|
||||||
formkey = extract_formkey(client.get("https://poe.com").text)
|
formkey = extract_formkey(client.get('https://poe.com').text)
|
||||||
settings = client.get("https://poe.com/api/settings").json()
|
settings = client.get('https://poe.com/api/settings').json()
|
||||||
|
|
||||||
client.headers = {
|
client.headers = {
|
||||||
"host": "poe.com",
|
'host': 'poe.com',
|
||||||
"origin": "https://poe.com",
|
'origin': 'https://poe.com',
|
||||||
"referer": "https://poe.com/",
|
'referer': 'https://poe.com/',
|
||||||
"poe-formkey": formkey,
|
'poe-formkey': formkey,
|
||||||
"poe-tchannel": settings["tchannelData"]["channel"],
|
'poe-tchannel': settings['tchannelData']['channel'],
|
||||||
"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': UserAgent().random,
|
||||||
"connection": "keep-alive",
|
'connection': 'keep-alive',
|
||||||
"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"',
|
||||||
"content-type": "application/json",
|
'content-type': 'application/json',
|
||||||
"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": "*/*",
|
'accept': '*/*',
|
||||||
"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',
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = dumps(
|
payload = dumps(
|
||||||
separators=(",", ":"),
|
separators=(',', ':'),
|
||||||
obj={
|
obj={
|
||||||
"queryName": "CreateBotMain_poeBotCreate_Mutation",
|
'queryName': 'CreateBotMain_poeBotCreate_Mutation',
|
||||||
"variables": {
|
'variables': {
|
||||||
"model": models[model],
|
'model': models[model],
|
||||||
"handle": handle,
|
'handle': handle,
|
||||||
"prompt": system_prompt,
|
'prompt': system_prompt,
|
||||||
"isPromptPublic": True,
|
'isPromptPublic': True,
|
||||||
"introduction": "",
|
'introduction': '',
|
||||||
"description": description,
|
'description': description,
|
||||||
"profilePictureUrl": "https://qph.fs.quoracdn.net/main-qimg-24e0b480dcd946e1cc6728802c5128b6",
|
'profilePictureUrl': 'https://qph.fs.quoracdn.net/main-qimg-24e0b480dcd946e1cc6728802c5128b6',
|
||||||
"apiUrl": None,
|
'apiUrl': None,
|
||||||
"apiKey": "".join(choices(ascii_letters + digits, k=32)),
|
'apiKey': ''.join(choices(ascii_letters + digits, k=32)),
|
||||||
"isApiBot": False,
|
'isApiBot': False,
|
||||||
"hasLinkification": False,
|
'hasLinkification': False,
|
||||||
"hasMarkdownRendering": False,
|
'hasMarkdownRendering': False,
|
||||||
"hasSuggestedReplies": False,
|
'hasSuggestedReplies': False,
|
||||||
"isPrivateBot": False,
|
'isPrivateBot': False,
|
||||||
},
|
},
|
||||||
"query": "mutation CreateBotMain_poeBotCreate_Mutation(\n $model: String!\n $handle: String!\n $prompt: String!\n $isPromptPublic: Boolean!\n $introduction: String!\n $description: String!\n $profilePictureUrl: String\n $apiUrl: String\n $apiKey: String\n $isApiBot: Boolean\n $hasLinkification: Boolean\n $hasMarkdownRendering: Boolean\n $hasSuggestedReplies: Boolean\n $isPrivateBot: Boolean\n) {\n poeBotCreate(model: $model, handle: $handle, promptPlaintext: $prompt, isPromptPublic: $isPromptPublic, introduction: $introduction, description: $description, profilePicture: $profilePictureUrl, apiUrl: $apiUrl, apiKey: $apiKey, isApiBot: $isApiBot, hasLinkification: $hasLinkification, hasMarkdownRendering: $hasMarkdownRendering, hasSuggestedReplies: $hasSuggestedReplies, isPrivateBot: $isPrivateBot) {\n status\n bot {\n id\n ...BotHeader_bot\n }\n }\n}\n\nfragment BotHeader_bot on Bot {\n displayName\n messageLimit {\n dailyLimit\n }\n ...BotImage_bot\n ...BotLink_bot\n ...IdAnnotation_node\n ...botHelpers_useViewerCanAccessPrivateBot\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotImage_bot on Bot {\n displayName\n ...botHelpers_useDeletion_bot\n ...BotImage_useProfileImage_bot\n}\n\nfragment BotImage_useProfileImage_bot on Bot {\n image {\n __typename\n ... on LocalBotImage {\n localName\n }\n ... on UrlBotImage {\n url\n }\n }\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotLink_bot on Bot {\n displayName\n}\n\nfragment IdAnnotation_node on Node {\n __isNode: __typename\n id\n}\n\nfragment botHelpers_useDeletion_bot on Bot {\n deletionState\n}\n\nfragment botHelpers_useViewerCanAccessPrivateBot on Bot {\n isPrivateBot\n viewerIsCreator\n}\n",
|
'query': 'mutation CreateBotMain_poeBotCreate_Mutation(\n $model: String!\n $handle: String!\n $prompt: String!\n $isPromptPublic: Boolean!\n $introduction: String!\n $description: String!\n $profilePictureUrl: String\n $apiUrl: String\n $apiKey: String\n $isApiBot: Boolean\n $hasLinkification: Boolean\n $hasMarkdownRendering: Boolean\n $hasSuggestedReplies: Boolean\n $isPrivateBot: Boolean\n) {\n poeBotCreate(model: $model, handle: $handle, promptPlaintext: $prompt, isPromptPublic: $isPromptPublic, introduction: $introduction, description: $description, profilePicture: $profilePictureUrl, apiUrl: $apiUrl, apiKey: $apiKey, isApiBot: $isApiBot, hasLinkification: $hasLinkification, hasMarkdownRendering: $hasMarkdownRendering, hasSuggestedReplies: $hasSuggestedReplies, isPrivateBot: $isPrivateBot) {\n status\n bot {\n id\n ...BotHeader_bot\n }\n }\n}\n\nfragment BotHeader_bot on Bot {\n displayName\n messageLimit {\n dailyLimit\n }\n ...BotImage_bot\n ...BotLink_bot\n ...IdAnnotation_node\n ...botHelpers_useViewerCanAccessPrivateBot\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotImage_bot on Bot {\n displayName\n ...botHelpers_useDeletion_bot\n ...BotImage_useProfileImage_bot\n}\n\nfragment BotImage_useProfileImage_bot on Bot {\n image {\n __typename\n ... on LocalBotImage {\n localName\n }\n ... on UrlBotImage {\n url\n }\n }\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotLink_bot on Bot {\n displayName\n}\n\nfragment IdAnnotation_node on Node {\n __isNode: __typename\n id\n}\n\nfragment botHelpers_useDeletion_bot on Bot {\n deletionState\n}\n\nfragment botHelpers_useViewerCanAccessPrivateBot on Bot {\n isPrivateBot\n viewerIsCreator\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()
|
||||||
|
|
||||||
response = client.post("https://poe.com/api/gql_POST", data=payload)
|
response = client.post('https://poe.com/api/gql_POST', data=payload)
|
||||||
|
|
||||||
if "success" not in response.text:
|
if 'success' not in response.text:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"""
|
'''
|
||||||
Bot creation Failed
|
Bot creation Failed
|
||||||
!! Important !!
|
!! Important !!
|
||||||
Bot creation was not enabled on this account
|
Bot creation was not enabled on this account
|
||||||
please use: quora.Account.create with enable_bot_creation set to True
|
please use: quora.Account.create with enable_bot_creation set to True
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
return ModelResponse(response.json())
|
return ModelResponse(response.json())
|
||||||
|
|
||||||
|
|
||||||
class Account:
|
class Account:
|
||||||
|
@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 = (
|
client.proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} if proxy else None
|
||||||
{"http": f"http://{proxy}", "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:
|
if logging:
|
||||||
print("email", mail_address)
|
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-tag-id": "null",
|
'poe-tag-id': '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',
|
||||||
"poe-formkey": extract_formkey(client.get("https://poe.com/login").text),
|
'poe-formkey': extract_formkey(client.get('https://poe.com/login').text),
|
||||||
"poe-tchannel": client.get("https://poe.com/api/settings").json()[
|
'poe-tchannel': client.get('https://poe.com/api/settings').json()['tchannelData']['channel'],
|
||||||
"tchannelData"
|
|
||||||
]["channel"],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
token = reCaptchaV3(
|
token = reCaptchaV3(
|
||||||
"https://www.recaptcha.net/recaptcha/enterprise/anchor?ar=1&k=6LflhEElAAAAAI_ewVwRWI9hsyV4mbZnYAslSvlG&co=aHR0cHM6Ly9wb2UuY29tOjQ0Mw..&hl=en&v=4PnKmGB9wRHh1i04o7YUICeI&size=invisible&cb=bi6ivxoskyal"
|
'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',
|
||||||
|
@ -233,77 +245,74 @@ class Account:
|
||||||
# action = 'login',)['code']
|
# action = 'login',)['code']
|
||||||
|
|
||||||
payload = dumps(
|
payload = dumps(
|
||||||
separators=(",", ":"),
|
separators=(',', ':'),
|
||||||
obj={
|
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:
|
if logging:
|
||||||
print("bad request, retrying...", response.json())
|
print('bad request, retrying...', response.json())
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
if logging:
|
if logging:
|
||||||
print("send_code", response.json())
|
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:
|
if logging:
|
||||||
print("code", mail_token)
|
print('code', mail_token)
|
||||||
|
|
||||||
payload = dumps(
|
payload = dumps(
|
||||||
separators=(",", ":"),
|
separators=(',', ':'),
|
||||||
obj={
|
obj={
|
||||||
"queryName": "SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation",
|
'queryName': 'SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation',
|
||||||
"variables": {
|
'variables': {
|
||||||
"verificationCode": str(mail_token),
|
'verificationCode': str(mail_token),
|
||||||
"emailAddress": mail_address,
|
'emailAddress': mail_address,
|
||||||
"phoneNumber": None,
|
'phoneNumber': None,
|
||||||
},
|
},
|
||||||
"query": "mutation SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation(\n $verificationCode: String!\n $emailAddress: String\n $phoneNumber: String\n) {\n signupWithVerificationCode(verificationCode: $verificationCode, emailAddress: $emailAddress, phoneNumber: $phoneNumber) {\n status\n errorMessage\n }\n}\n",
|
'query': 'mutation SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation(\n $verificationCode: String!\n $emailAddress: String\n $phoneNumber: String\n) {\n signupWithVerificationCode(verificationCode: $verificationCode, emailAddress: $emailAddress, phoneNumber: $phoneNumber) {\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()
|
||||||
|
|
||||||
response = client.post("https://poe.com/api/gql_POST", data=payload)
|
response = client.post('https://poe.com/api/gql_POST', data=payload)
|
||||||
if logging:
|
if logging:
|
||||||
print("verify_code", response.json())
|
print('verify_code', response.json())
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
cookies = (
|
cookies = open(Path(__file__).resolve().parent / 'cookies.txt', 'r').read().splitlines()
|
||||||
open(Path(__file__).resolve().parent / "cookies.txt", "r")
|
|
||||||
.read()
|
|
||||||
.splitlines()
|
|
||||||
)
|
|
||||||
return choice(cookies)
|
return choice(cookies)
|
||||||
|
|
||||||
|
|
||||||
class StreamingCompletion:
|
class StreamingCompletion:
|
||||||
|
@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
|
||||||
|
|
||||||
|
@ -312,22 +321,22 @@ class StreamingCompletion:
|
||||||
for chunk in client.send_message(_model, prompt):
|
for chunk in client.send_message(_model, prompt):
|
||||||
yield PoeResponse(
|
yield PoeResponse(
|
||||||
{
|
{
|
||||||
"id": chunk["messageId"],
|
'id': chunk['messageId'],
|
||||||
"object": "text_completion",
|
'object': 'text_completion',
|
||||||
"created": chunk["creationTime"],
|
'created': chunk['creationTime'],
|
||||||
"model": _model,
|
'model': _model,
|
||||||
"choices": [
|
'choices': [
|
||||||
{
|
{
|
||||||
"text": chunk["text_new"],
|
'text': chunk['text_new'],
|
||||||
"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["text_new"]),
|
'completion_tokens': len(chunk['text_new']),
|
||||||
"total_tokens": len(prompt) + len(chunk["text_new"]),
|
'total_tokens': len(prompt) + len(chunk['text_new']),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -335,17 +344,17 @@ 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',
|
||||||
"gpt-4": "beaver",
|
'gpt-4': 'beaver',
|
||||||
"claude-v1.2": "a2_2",
|
'claude-v1.2': 'a2_2',
|
||||||
"claude-instant-v1.0": "a2",
|
'claude-instant-v1.0': 'a2',
|
||||||
"gpt-3.5-turbo": "chinchilla",
|
'gpt-3.5-turbo': 'chinchilla',
|
||||||
}
|
}
|
||||||
|
|
||||||
_model = models[model] if not custom_model else custom_model
|
_model = models[model] if not custom_model else custom_model
|
||||||
|
@ -357,73 +366,68 @@ class Completion:
|
||||||
|
|
||||||
return PoeResponse(
|
return PoeResponse(
|
||||||
{
|
{
|
||||||
"id": chunk["messageId"],
|
'id': chunk['messageId'],
|
||||||
"object": "text_completion",
|
'object': 'text_completion',
|
||||||
"created": chunk["creationTime"],
|
'created': chunk['creationTime'],
|
||||||
"model": _model,
|
'model': _model,
|
||||||
"choices": [
|
'choices': [
|
||||||
{
|
{
|
||||||
"text": chunk["text"],
|
'text': chunk['text'],
|
||||||
"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["text"]),
|
'completion_tokens': len(chunk['text']),
|
||||||
"total_tokens": len(prompt) + len(chunk["text"]),
|
'total_tokens': len(prompt) + len(chunk['text']),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Poe:
|
class Poe:
|
||||||
def __init__(self, model: str = "ChatGPT"):
|
def __init__(
|
||||||
|
self,
|
||||||
|
model: str = 'ChatGPT',
|
||||||
|
driver: str = 'firefox',
|
||||||
|
download_driver: bool = False,
|
||||||
|
driver_path: Optional[str] = None,
|
||||||
|
cookie_path: str = './quora/cookie.json',
|
||||||
|
):
|
||||||
# validating the model
|
# validating the model
|
||||||
if model and model not in MODELS:
|
if model and model not in MODELS:
|
||||||
raise RuntimeError(
|
raise RuntimeError('Sorry, the model you provided does not exist. Please check and try again.')
|
||||||
"Sorry, the model you provided does not exist. Please check and try again."
|
|
||||||
)
|
|
||||||
self.model = MODELS[model]
|
self.model = MODELS[model]
|
||||||
self.cookie = self.__load_cookie()
|
self.cookie_path = cookie_path
|
||||||
|
self.cookie = self.__load_cookie(driver, download_driver, driver_path=driver_path)
|
||||||
self.client = PoeClient(self.cookie)
|
self.client = PoeClient(self.cookie)
|
||||||
|
|
||||||
def __load_cookie(self) -> str:
|
def __load_cookie(self, driver: str, download_driver: bool, driver_path: Optional[str] = None) -> str:
|
||||||
if (cookie_file := Path("./quora/cookie.json")).exists():
|
if (cookie_file := Path(self.cookie_path)).exists():
|
||||||
with cookie_file.open() as fp:
|
with cookie_file.open() as fp:
|
||||||
cookie = json.load(fp)
|
cookie = json.load(fp)
|
||||||
if datetime.fromtimestamp(cookie["expiry"]) < datetime.now():
|
if datetime.fromtimestamp(cookie['expiry']) < datetime.now():
|
||||||
cookie = self.__register_and_get_cookie()
|
cookie = self.__register_and_get_cookie(driver, driver_path=driver_path)
|
||||||
else:
|
else:
|
||||||
print("Loading the cookie from file")
|
print('Loading the cookie from file')
|
||||||
else:
|
else:
|
||||||
cookie = self.__register_and_get_cookie()
|
cookie = self.__register_and_get_cookie(driver, driver_path=driver_path)
|
||||||
|
|
||||||
return unquote(cookie["value"])
|
return unquote(cookie['value'])
|
||||||
|
|
||||||
@classmethod
|
def __register_and_get_cookie(self, driver: str, driver_path: Optional[str] = None) -> dict:
|
||||||
def __register_and_get_cookie(cls) -> dict:
|
|
||||||
mail_client = Emailnator()
|
mail_client = Emailnator()
|
||||||
mail_address = mail_client.get_mail()
|
mail_address = mail_client.get_mail()
|
||||||
|
|
||||||
print(mail_address)
|
driver = self.__resolve_driver(driver, driver_path=driver_path)
|
||||||
options = webdriver.FirefoxOptions()
|
|
||||||
# options.add_argument("-headless")
|
|
||||||
try:
|
|
||||||
driver = webdriver.Firefox(options=options)
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
raise Exception(b'The error message you are receiving is due to the `geckodriver` executable not being found in your system\'s PATH. To resolve this issue, you need to download the geckodriver and add its location to your system\'s PATH.\n\nHere are the steps to resolve the issue:\n\n1. Download the geckodriver for your platform (Windows, macOS, or Linux) from the following link: https://github.com/mozilla/geckodriver/releases\n\n2. Extract the downloaded archive and locate the geckodriver executable.\n\n3. Add the geckodriver executable to your system\'s PATH.\n\nFor macOS and Linux:\n\n- Open a terminal window.\n- Move the geckodriver executable to a directory that is already in your PATH, or create a new directory and add it to your PATH:\n\n```bash\n# Example: Move geckodriver to /usr/local/bin\nmv /path/to/your/geckodriver /usr/local/bin\n```\n\n- If you created a new directory, add it to your PATH:\n\n```bash\n# Example: Add a new directory to PATH\nexport PATH=$PATH:/path/to/your/directory\n```\n\nFor Windows:\n\n- Right-click on "My Computer" or "This PC" and select "Properties".\n- Click on "Advanced system settings".\n- Click on the "Environment Variables" button.\n- In the "System variables" section, find the "Path" variable, select it, and click "Edit".\n- Click "New" and add the path to the directory containing the geckodriver executable.\n\nAfter adding the geckodriver to your PATH, restart your terminal or command prompt and try running your script again. The error should be resolved.')
|
|
||||||
|
|
||||||
driver.get("https://www.poe.com")
|
driver.get("https://www.poe.com")
|
||||||
|
|
||||||
# clicking use email button
|
# clicking use email button
|
||||||
driver.find_element(By.XPATH, '//button[contains(text(), "Use email")]').click()
|
driver.find_element(By.XPATH, '//button[contains(text(), "Use email")]').click()
|
||||||
|
|
||||||
email = WebDriverWait(driver, 30).until(
|
email = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '//input[@type="email"]')))
|
||||||
EC.presence_of_element_located((By.XPATH, '//input[@type="email"]'))
|
|
||||||
)
|
|
||||||
email.send_keys(mail_address)
|
email.send_keys(mail_address)
|
||||||
driver.find_element(By.XPATH, '//button[text()="Go"]').click()
|
driver.find_element(By.XPATH, '//button[text()="Go"]').click()
|
||||||
|
|
||||||
|
@ -434,46 +438,50 @@ class Poe:
|
||||||
EC.presence_of_element_located((By.XPATH, '//input[@placeholder="Code"]'))
|
EC.presence_of_element_located((By.XPATH, '//input[@placeholder="Code"]'))
|
||||||
)
|
)
|
||||||
verification_code.send_keys(code)
|
verification_code.send_keys(code)
|
||||||
verify_button = EC.presence_of_element_located(
|
verify_button = EC.presence_of_element_located((By.XPATH, '//button[text()="Verify"]'))
|
||||||
(By.XPATH, '//button[text()="Verify"]')
|
login_button = EC.presence_of_element_located((By.XPATH, '//button[text()="Log In"]'))
|
||||||
)
|
|
||||||
login_button = EC.presence_of_element_located(
|
|
||||||
(By.XPATH, '//button[text()="Log In"]')
|
|
||||||
)
|
|
||||||
|
|
||||||
WebDriverWait(driver, 30).until(EC.any_of(verify_button, login_button)).click()
|
WebDriverWait(driver, 30).until(EC.any_of(verify_button, login_button)).click()
|
||||||
|
|
||||||
cookie = driver.get_cookie("p-b")
|
cookie = driver.get_cookie('p-b')
|
||||||
|
|
||||||
with open("./quora/cookie.json", "w") as fw:
|
with open(self.cookie_path, 'w') as fw:
|
||||||
json.dump(cookie, fw)
|
json.dump(cookie, fw)
|
||||||
|
|
||||||
driver.close()
|
driver.close()
|
||||||
return cookie
|
return cookie
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __resolve_driver(cls, driver: str, driver_path: Optional[str] = None) -> Union[Firefox, Chrome]:
|
||||||
|
options = FirefoxOptions() if driver == 'firefox' else ChromeOptions()
|
||||||
|
options.add_argument('-headless')
|
||||||
|
|
||||||
|
if driver_path:
|
||||||
|
options.binary_location = driver_path
|
||||||
|
try:
|
||||||
|
return Firefox(options=options) if driver == 'firefox' else Chrome(options=options)
|
||||||
|
except Exception:
|
||||||
|
raise Exception(SELENIUM_WEB_DRIVER_ERROR_MSG)
|
||||||
|
|
||||||
def chat(self, message: str, model: Optional[str] = None) -> str:
|
def chat(self, message: str, model: Optional[str] = None) -> str:
|
||||||
if model and model not in MODELS:
|
if model and model not in MODELS:
|
||||||
raise RuntimeError(
|
raise RuntimeError('Sorry, the model you provided does not exist. Please check and try again.')
|
||||||
"Sorry, the model you provided does not exist. Please check and try again."
|
|
||||||
)
|
|
||||||
model = MODELS[model] if model else self.model
|
model = MODELS[model] if model else self.model
|
||||||
response = None
|
response = None
|
||||||
for chunk in self.client.send_message(model, message):
|
for chunk in self.client.send_message(model, message):
|
||||||
response = chunk["text"]
|
response = chunk['text']
|
||||||
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(
|
raise RuntimeError('Sorry, the base_model you provided does not exist. Please check and try again.')
|
||||||
"Sorry, the base_model you provided does not exist. Please check and try again."
|
|
||||||
)
|
|
||||||
|
|
||||||
response = self.client.create_bot(
|
response = self.client.create_bot(
|
||||||
handle=name,
|
handle=name,
|
||||||
|
|
83
quora/api.py
83
quora/api.py
|
@ -18,23 +18,21 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import requests
|
|
||||||
import re
|
|
||||||
import json
|
|
||||||
import random
|
|
||||||
import logging
|
|
||||||
import time
|
|
||||||
import queue
|
|
||||||
import threading
|
|
||||||
import traceback
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import string
|
import json
|
||||||
|
import logging
|
||||||
|
import queue
|
||||||
import random
|
import random
|
||||||
import requests.adapters
|
import re
|
||||||
import websocket
|
import threading
|
||||||
|
import time
|
||||||
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import requests.adapters
|
||||||
|
import websocket
|
||||||
|
|
||||||
parent_path = Path(__file__).resolve().parent
|
parent_path = Path(__file__).resolve().parent
|
||||||
queries_path = parent_path / "graphql"
|
queries_path = parent_path / "graphql"
|
||||||
|
@ -66,7 +64,7 @@ def request_with_retries(method, *args, **kwargs):
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return r
|
return r
|
||||||
logger.warn(
|
logger.warn(
|
||||||
f"Server returned a status code of {r.status_code} while downloading {url}. Retrying ({i+1}/{attempts})..."
|
f"Server returned a status code of {r.status_code} while downloading {url}. Retrying ({i + 1}/{attempts})..."
|
||||||
)
|
)
|
||||||
|
|
||||||
raise RuntimeError(f"Failed to download {url} too many times.")
|
raise RuntimeError(f"Failed to download {url} too many times.")
|
||||||
|
@ -81,9 +79,7 @@ class Client:
|
||||||
def __init__(self, token, proxy=None):
|
def __init__(self, token, proxy=None):
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.adapter = requests.adapters.HTTPAdapter(
|
self.adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100)
|
||||||
pool_connections=100, pool_maxsize=100
|
|
||||||
)
|
|
||||||
self.session.mount("http://", self.adapter)
|
self.session.mount("http://", self.adapter)
|
||||||
self.session.mount("https://", self.adapter)
|
self.session.mount("https://", self.adapter)
|
||||||
|
|
||||||
|
@ -139,9 +135,7 @@ class Client:
|
||||||
logger.info("Downloading next_data...")
|
logger.info("Downloading next_data...")
|
||||||
|
|
||||||
r = request_with_retries(self.session.get, self.home_url)
|
r = request_with_retries(self.session.get, self.home_url)
|
||||||
json_regex = (
|
json_regex = r'<script id="__NEXT_DATA__" type="application\/json">(.+?)</script>'
|
||||||
r'<script id="__NEXT_DATA__" type="application\/json">(.+?)</script>'
|
|
||||||
)
|
|
||||||
json_text = re.search(json_regex, r.text).group(1)
|
json_text = re.search(json_regex, r.text).group(1)
|
||||||
next_data = json.loads(json_text)
|
next_data = json.loads(json_text)
|
||||||
|
|
||||||
|
@ -213,19 +207,14 @@ class Client:
|
||||||
if channel is None:
|
if channel is None:
|
||||||
channel = self.channel
|
channel = self.channel
|
||||||
query = f'?min_seq={channel["minSeq"]}&channel={channel["channel"]}&hash={channel["channelHash"]}'
|
query = f'?min_seq={channel["minSeq"]}&channel={channel["channel"]}&hash={channel["channelHash"]}'
|
||||||
return (
|
return f'wss://{self.ws_domain}.tch.{channel["baseHost"]}/up/{channel["boxName"]}/updates' + query
|
||||||
f'wss://{self.ws_domain}.tch.{channel["baseHost"]}/up/{channel["boxName"]}/updates'
|
|
||||||
+ query
|
|
||||||
)
|
|
||||||
|
|
||||||
def send_query(self, query_name, variables):
|
def send_query(self, query_name, variables):
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
json_data = generate_payload(query_name, variables)
|
json_data = generate_payload(query_name, variables)
|
||||||
payload = json.dumps(json_data, separators=(",", ":"))
|
payload = json.dumps(json_data, separators=(",", ":"))
|
||||||
|
|
||||||
base_string = (
|
base_string = payload + self.gql_headers["poe-formkey"] + "WpuLMiXEKKE98j56k"
|
||||||
payload + self.gql_headers["poe-formkey"] + "WpuLMiXEKKE98j56k"
|
|
||||||
)
|
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
@ -233,15 +222,11 @@ class Client:
|
||||||
}
|
}
|
||||||
headers = {**self.gql_headers, **headers}
|
headers = {**self.gql_headers, **headers}
|
||||||
|
|
||||||
r = request_with_retries(
|
r = request_with_retries(self.session.post, self.gql_url, data=payload, headers=headers)
|
||||||
self.session.post, self.gql_url, data=payload, headers=headers
|
|
||||||
)
|
|
||||||
|
|
||||||
data = r.json()
|
data = r.json()
|
||||||
if data["data"] == None:
|
if data["data"] == None:
|
||||||
logger.warn(
|
logger.warn(f'{query_name} returned an error: {data["errors"][0]["message"]} | Retrying ({i + 1}/20)')
|
||||||
f'{query_name} returned an error: {data["errors"][0]["message"]} | Retrying ({i+1}/20)'
|
|
||||||
)
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -304,9 +289,7 @@ class Client:
|
||||||
|
|
||||||
def on_ws_close(self, ws, close_status_code, close_message):
|
def on_ws_close(self, ws, close_status_code, close_message):
|
||||||
self.ws_connected = False
|
self.ws_connected = False
|
||||||
logger.warn(
|
logger.warn(f"Websocket closed with status {close_status_code}: {close_message}")
|
||||||
f"Websocket closed with status {close_status_code}: {close_message}"
|
|
||||||
)
|
|
||||||
|
|
||||||
def on_ws_error(self, ws, error):
|
def on_ws_error(self, ws, error):
|
||||||
self.disconnect_ws()
|
self.disconnect_ws()
|
||||||
|
@ -333,11 +316,7 @@ class Client:
|
||||||
return
|
return
|
||||||
|
|
||||||
# indicate that the response id is tied to the human message id
|
# indicate that the response id is tied to the human message id
|
||||||
elif (
|
elif key != "pending" and value == None and message["state"] != "complete":
|
||||||
key != "pending"
|
|
||||||
and value == None
|
|
||||||
and message["state"] != "complete"
|
|
||||||
):
|
|
||||||
self.active_messages[key] = message["messageId"]
|
self.active_messages[key] = message["messageId"]
|
||||||
self.message_queues[key].put(message)
|
self.message_queues[key].put(message)
|
||||||
return
|
return
|
||||||
|
@ -381,9 +360,7 @@ class Client:
|
||||||
human_message = message_data["data"]["messageEdgeCreate"]["message"]
|
human_message = message_data["data"]["messageEdgeCreate"]["message"]
|
||||||
human_message_id = human_message["node"]["messageId"]
|
human_message_id = human_message["node"]["messageId"]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise RuntimeError(
|
raise RuntimeError(f"An unknown error occurred. Raw response data: {message_data}")
|
||||||
f"An unknown error occurred. Raw response data: {message_data}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# indicate that the current message is waiting for a response
|
# indicate that the current message is waiting for a response
|
||||||
self.active_messages[human_message_id] = None
|
self.active_messages[human_message_id] = None
|
||||||
|
@ -418,9 +395,7 @@ class Client:
|
||||||
|
|
||||||
def send_chat_break(self, chatbot):
|
def send_chat_break(self, chatbot):
|
||||||
logger.info(f"Sending chat break to {chatbot}")
|
logger.info(f"Sending chat break to {chatbot}")
|
||||||
result = self.send_query(
|
result = self.send_query("AddMessageBreakMutation", {"chatId": self.bots[chatbot]["chatId"]})
|
||||||
"AddMessageBreakMutation", {"chatId": self.bots[chatbot]["chatId"]}
|
|
||||||
)
|
|
||||||
return result["data"]["messageBreakCreate"]["message"]
|
return result["data"]["messageBreakCreate"]["message"]
|
||||||
|
|
||||||
def get_message_history(self, chatbot, count=25, cursor=None):
|
def get_message_history(self, chatbot, count=25, cursor=None):
|
||||||
|
@ -437,15 +412,11 @@ class Client:
|
||||||
|
|
||||||
cursor = str(cursor)
|
cursor = str(cursor)
|
||||||
if count > 50:
|
if count > 50:
|
||||||
messages = (
|
messages = self.get_message_history(chatbot, count=50, cursor=cursor) + messages
|
||||||
self.get_message_history(chatbot, count=50, cursor=cursor) + messages
|
|
||||||
)
|
|
||||||
while count > 0:
|
while count > 0:
|
||||||
count -= 50
|
count -= 50
|
||||||
new_cursor = messages[0]["cursor"]
|
new_cursor = messages[0]["cursor"]
|
||||||
new_messages = self.get_message_history(
|
new_messages = self.get_message_history(chatbot, min(50, count), cursor=new_cursor)
|
||||||
chatbot, min(50, count), cursor=new_cursor
|
|
||||||
)
|
|
||||||
messages = new_messages + messages
|
messages = new_messages + messages
|
||||||
return messages
|
return messages
|
||||||
elif count <= 0:
|
elif count <= 0:
|
||||||
|
@ -523,9 +494,7 @@ class Client:
|
||||||
|
|
||||||
data = result["data"]["poeBotCreate"]
|
data = result["data"]["poeBotCreate"]
|
||||||
if data["status"] != "success":
|
if data["status"] != "success":
|
||||||
raise RuntimeError(
|
raise RuntimeError(f"Poe returned an error while trying to create a bot: {data['status']}")
|
||||||
f"Poe returned an error while trying to create a bot: {data['status']}"
|
|
||||||
)
|
|
||||||
self.get_bots()
|
self.get_bots()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -568,9 +537,7 @@ class Client:
|
||||||
|
|
||||||
data = result["data"]["poeBotEdit"]
|
data = result["data"]["poeBotEdit"]
|
||||||
if data["status"] != "success":
|
if data["status"] != "success":
|
||||||
raise RuntimeError(
|
raise RuntimeError(f"Poe returned an error while trying to edit a bot: {data['status']}")
|
||||||
f"Poe returned an error while trying to edit a bot: {data['status']}"
|
|
||||||
)
|
|
||||||
self.get_bots()
|
self.get_bots()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,4 @@ curl_cffi
|
||||||
streamlit==1.21.0
|
streamlit==1.21.0
|
||||||
selenium
|
selenium
|
||||||
fake-useragent
|
fake-useragent
|
||||||
|
twocaptcha
|
||||||
|
|
11
testing/forefront_test.py
Normal file
11
testing/forefront_test.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import forefront
|
||||||
|
|
||||||
|
# create an account
|
||||||
|
token = forefront.Account.create(logging=True)
|
||||||
|
print(token)
|
||||||
|
|
||||||
|
# get a response
|
||||||
|
for response in forefront.StreamingCompletion.create(token = token,
|
||||||
|
prompt = 'hello world', model='gpt-4'):
|
||||||
|
|
||||||
|
print(response.completion.choices[0].text, end = '')
|
|
@ -37,4 +37,5 @@ while True:
|
||||||
if b'content' in chunk:
|
if b'content' in chunk:
|
||||||
# Parse the JSON data and print the content
|
# Parse the JSON data and print the content
|
||||||
data = loads(chunk.decode('utf-8').split('data:')[1])
|
data = loads(chunk.decode('utf-8').split('data:')[1])
|
||||||
|
|
||||||
print(data['content'], end='')
|
print(data['content'], end='')
|
||||||
|
|
Loading…
Reference in a new issue