mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-05 00:01:00 +00:00
Forefront fixed
This commit is contained in:
parent
1f2f16f02b
commit
c60d33c4a0
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"editor.tabCompletion": "on",
|
||||||
|
"diffEditor.codeLens": true
|
||||||
|
}
|
@ -1,49 +1,26 @@
|
|||||||
import os
|
|
||||||
import pickle
|
|
||||||
from json import loads
|
from json import loads
|
||||||
|
from xtempmail import Email
|
||||||
from re import findall
|
from re import findall
|
||||||
|
from faker import Faker
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
from typing import Generator, Optional
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
from pymailtm import MailTm, Message
|
|
||||||
from requests import post
|
from requests import post
|
||||||
from tls_client import Session
|
from tls_client import Session
|
||||||
|
|
||||||
from .typing import ForeFrontResponse
|
from .typing import ForeFrontResponse
|
||||||
|
|
||||||
|
|
||||||
class Account:
|
class Account:
|
||||||
COOKIES_FILE_NAME = 'cookies.pickle'
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def login(proxy: Optional[str] = None, logging: bool = False) -> str:
|
def create(proxy: Optional[str] = None, logging: bool = False):
|
||||||
if not os.path.isfile(Account.COOKIES_FILE_NAME):
|
|
||||||
return Account.create(proxy, logging)
|
|
||||||
|
|
||||||
with open(Account.COOKIES_FILE_NAME, 'rb') as f:
|
|
||||||
cookies = pickle.load(f)
|
|
||||||
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False
|
|
||||||
|
|
||||||
client = Session(client_identifier='chrome110')
|
|
||||||
client.proxies = proxies
|
|
||||||
client.cookies.update(cookies)
|
|
||||||
|
|
||||||
if Account.is_cookie_enabled(client):
|
|
||||||
response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')
|
|
||||||
return response.json()['response']['sessions'][0]['last_active_token']['jwt']
|
|
||||||
else:
|
|
||||||
return Account.create(proxy, logging)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def create(proxy: Optional[str] = None, logging: bool = False, save_cookies: bool = False) -> str:
|
|
||||||
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False
|
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False
|
||||||
|
faker = Faker()
|
||||||
|
name = (faker.name().replace(' ', '_')).lower()
|
||||||
|
|
||||||
start = time()
|
start = time()
|
||||||
|
|
||||||
mail_client = MailTm().get_account()
|
mail_client = Email(name=name)
|
||||||
mail_address = mail_client.address
|
mail_address = mail_client.email
|
||||||
|
|
||||||
client = Session(client_identifier='chrome110')
|
client = Session(client_identifier='chrome110')
|
||||||
client.proxies = proxies
|
client.proxies = proxies
|
||||||
@ -66,7 +43,10 @@ class Account:
|
|||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
|
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
|
||||||
data={'strategy': 'email_link', 'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'},
|
data={
|
||||||
|
'strategy': 'email_link',
|
||||||
|
'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if logging:
|
if logging:
|
||||||
@ -74,31 +54,23 @@ class Account:
|
|||||||
|
|
||||||
if 'sign_up_attempt' not in response.text:
|
if 'sign_up_attempt' not in response.text:
|
||||||
return 'Failed to create account!'
|
return 'Failed to create account!'
|
||||||
|
verification_url = None
|
||||||
while True:
|
new_message = mail_client.get_new_message(5)
|
||||||
sleep(1)
|
for msg in new_message:
|
||||||
new_message: Message = mail_client.wait_for_message()
|
verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', msg.text)[0]
|
||||||
if logging:
|
|
||||||
print(new_message.data['id'])
|
|
||||||
|
|
||||||
verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', new_message.text)[0]
|
|
||||||
|
|
||||||
if verification_url:
|
if verification_url:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if verification_url is None or not verification_url:
|
||||||
|
raise RuntimeError('Error while obtaining verfication URL!')
|
||||||
if logging:
|
if logging:
|
||||||
print(verification_url)
|
print(verification_url)
|
||||||
|
|
||||||
response = client.get(verification_url)
|
response = client.get(verification_url)
|
||||||
|
|
||||||
response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')
|
response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')
|
||||||
|
|
||||||
token = response.json()['response']['sessions'][0]['last_active_token']['jwt']
|
token = response.json()['response']['sessions'][0]['last_active_token']['jwt']
|
||||||
|
|
||||||
if save_cookies:
|
|
||||||
with open(Account.COOKIES_FILE_NAME, 'wb') as f:
|
|
||||||
pickle.dump(client.cookies, f)
|
|
||||||
|
|
||||||
with open('accounts.txt', 'a') as f:
|
with open('accounts.txt', 'a') as f:
|
||||||
f.write(f'{mail_address}:{token}\n')
|
f.write(f'{mail_address}:{token}\n')
|
||||||
|
|
||||||
@ -107,11 +79,6 @@ class Account:
|
|||||||
|
|
||||||
return token
|
return token
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_cookie_enabled(client: Session) -> bool:
|
|
||||||
response = client.get('https://chat.forefront.ai/')
|
|
||||||
return 'window.startClerk' in response.text
|
|
||||||
|
|
||||||
|
|
||||||
class StreamingCompletion:
|
class StreamingCompletion:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -122,14 +89,14 @@ class StreamingCompletion:
|
|||||||
action_type='new',
|
action_type='new',
|
||||||
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
||||||
model='gpt-4',
|
model='gpt-4',
|
||||||
proxy=None,
|
proxy=None
|
||||||
) -> Generator[ForeFrontResponse, None, None]:
|
) -> Generator[ForeFrontResponse, None, None]:
|
||||||
if not token:
|
if not token:
|
||||||
raise Exception('Token is required!')
|
raise Exception('Token is required!')
|
||||||
if not chat_id:
|
if not chat_id:
|
||||||
chat_id = str(uuid4())
|
chat_id = str(uuid4())
|
||||||
|
|
||||||
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else None
|
proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else None
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
|
'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
|
||||||
@ -197,7 +164,7 @@ class Completion:
|
|||||||
action_type='new',
|
action_type='new',
|
||||||
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
||||||
model='gpt-4',
|
model='gpt-4',
|
||||||
proxy=None,
|
proxy=None
|
||||||
) -> ForeFrontResponse:
|
) -> ForeFrontResponse:
|
||||||
text = ''
|
text = ''
|
||||||
final_response = None
|
final_response = None
|
||||||
@ -208,7 +175,7 @@ class Completion:
|
|||||||
action_type=action_type,
|
action_type=action_type,
|
||||||
default_persona=default_persona,
|
default_persona=default_persona,
|
||||||
model=model,
|
model=model,
|
||||||
proxy=proxy,
|
proxy=proxy
|
||||||
):
|
):
|
||||||
if response:
|
if response:
|
||||||
final_response = response
|
final_response = response
|
||||||
@ -220,3 +187,4 @@ class Completion:
|
|||||||
raise Exception('Unable to get the response, Please try again')
|
raise Exception('Unable to get the response, Please try again')
|
||||||
|
|
||||||
return final_response
|
return final_response
|
||||||
|
|
Loading…
Reference in New Issue
Block a user