From ccd74eda81254356e8cf083719c11b925f073199 Mon Sep 17 00:00:00 2001 From: "valerii@valeriis-air.(none)" Date: Mon, 1 May 2023 04:09:27 +0300 Subject: update(docker-compose.yml): Removed docker-compose.yml --- docker-compose.yml | 14 -------- gpt4free/forefront/__init__.py | 81 ++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 53 deletions(-) delete mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index e8fcb0de..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: '3.8' - -services: - gpt4: - build: - context: . - dockerfile: Dockerfile - image: gpt4free:latest - container_name: gpt4 - ports: - - 8501:8501 - restart: unless-stopped - read_only: true - diff --git a/gpt4free/forefront/__init__.py b/gpt4free/forefront/__init__.py index 7a4f4f28..d646de92 100644 --- a/gpt4free/forefront/__init__.py +++ b/gpt4free/forefront/__init__.py @@ -1,47 +1,59 @@ -from json import loads -from re import findall -from time import time, sleep +import re +import time from typing import Generator, Optional from uuid import uuid4 -from fake_useragent import UserAgent -from requests import post -from pymailtm import MailTm, Message -from tls_client import Session +import fake_useragent +import pymailtm +import requests from .typing import ForeFrontResponse +def speed_logging(func): + def wrapper(*args, **kwargs): + start = time.time() + res = func(*args, **kwargs) + print(time() - start) + return res + return wrapper + + class Account: + @speed_logging @staticmethod - def create(proxy: Optional[str] = None, logging: bool = False): - proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False + def create_forefront_account(proxy: Optional[str] = None) -> Optional[str]: + """Create a ForeFront account. + + Args: + proxy: The proxy to use for the request. - start = time() + Returns: + The ForeFront token if successful, else None. + """ + proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} if proxy else None - mail_client = MailTm().get_account() + mail_client = pymailtm.MailTm().get_account() mail_address = mail_client.address - client = Session(client_identifier='chrome110') - client.proxies = proxies - client.headers = { + session = requests.Session() + session.proxies = proxies + session.headers = { 'origin': 'https://accounts.forefront.ai', - 'user-agent': UserAgent().random, + 'user-agent': fake_useragent.UserAgent().random, } - response = client.post( + response = session.post( 'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.38.4', data={'email_address': mail_address}, ) try: trace_token = response.json()['response']['id'] - if logging: - print(trace_token) except KeyError: - return 'Failed to create account!' + return None - response = client.post( + response = session.post( f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4', data={ 'strategy': 'email_link', @@ -49,38 +61,26 @@ class Account: }, ) - if logging: - print(response.text) - if 'sign_up_attempt' not in response.text: - return 'Failed to create account!' + return None while True: - sleep(1) - new_message: Message = mail_client.wait_for_message() - if logging: - print(new_message.data['id']) - - verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', new_message.text)[0] + time.sleep(1) + new_message = mail_client.wait_for_message() + verification_url = re.findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', new_message.text) if verification_url: break - if logging: - print(verification_url) + response = session.get(verification_url[0]) - response = client.get(verification_url) - - response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4') + response = session.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4') token = response.json()['response']['sessions'][0]['last_active_token']['jwt'] with open('accounts.txt', 'a') as f: f.write(f'{mail_address}:{token}\n') - if logging: - print(time() - start) - return token @@ -100,7 +100,7 @@ class StreamingCompletion: if not chat_id: chat_id = str(uuid4()) - proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else None + proxies = { 'http': f'http://{proxy}', 'https': f'http://{proxy}' } if proxy else None headers = { 'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com', @@ -191,3 +191,6 @@ class Completion: raise Exception('Unable to get the response, Please try again') return final_response + + + -- cgit v1.2.3