summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authort.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-05-02 20:15:40 +0200
committerGitHub <noreply@github.com>2023-05-02 20:15:40 +0200
commitd3836a2502c69167e7db72d7184b4a9098d3b951 (patch)
treebfa236e85da9bc5c3ff6bda23a0d2d9f5be09c66
parentMerge pull request #352 from HexyeDEV/main (diff)
parentAdd function to save Forefront cookies (diff)
downloadgpt4free-d3836a2502c69167e7db72d7184b4a9098d3b951.tar
gpt4free-d3836a2502c69167e7db72d7184b4a9098d3b951.tar.gz
gpt4free-d3836a2502c69167e7db72d7184b4a9098d3b951.tar.bz2
gpt4free-d3836a2502c69167e7db72d7184b4a9098d3b951.tar.lz
gpt4free-d3836a2502c69167e7db72d7184b4a9098d3b951.tar.xz
gpt4free-d3836a2502c69167e7db72d7184b4a9098d3b951.tar.zst
gpt4free-d3836a2502c69167e7db72d7184b4a9098d3b951.zip
-rw-r--r--gpt4free/forefront/__init__.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/gpt4free/forefront/__init__.py b/gpt4free/forefront/__init__.py
index 4d679a14..23978501 100644
--- a/gpt4free/forefront/__init__.py
+++ b/gpt4free/forefront/__init__.py
@@ -1,3 +1,5 @@
+import os
+import pickle
from json import loads
from re import findall
from time import time, sleep
@@ -13,8 +15,29 @@ from .typing import ForeFrontResponse
class Account:
+ COOKIES_FILE_NAME = 'cookies.pickle'
+
@staticmethod
- def create(proxy: Optional[str] = None, logging: bool = False):
+ def login(proxy: Optional[str] = None, logging: bool = False) -> str:
+ 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
start = time()
@@ -72,6 +95,10 @@ class Account:
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:
f.write(f'{mail_address}:{token}\n')
@@ -80,6 +107,11 @@ class Account:
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:
@staticmethod