summaryrefslogtreecommitdiffstats
path: root/gpt4free
diff options
context:
space:
mode:
authorkondo <test@example.com>2023-05-02 19:12:37 +0200
committerkondo <test@example.com>2023-05-02 19:12:37 +0200
commitf6db1426e489e7d79c52edc57133abb6525fe993 (patch)
treebfa236e85da9bc5c3ff6bda23a0d2d9f5be09c66 /gpt4free
parentMerge pull request #352 from HexyeDEV/main (diff)
downloadgpt4free-f6db1426e489e7d79c52edc57133abb6525fe993.tar
gpt4free-f6db1426e489e7d79c52edc57133abb6525fe993.tar.gz
gpt4free-f6db1426e489e7d79c52edc57133abb6525fe993.tar.bz2
gpt4free-f6db1426e489e7d79c52edc57133abb6525fe993.tar.lz
gpt4free-f6db1426e489e7d79c52edc57133abb6525fe993.tar.xz
gpt4free-f6db1426e489e7d79c52edc57133abb6525fe993.tar.zst
gpt4free-f6db1426e489e7d79c52edc57133abb6525fe993.zip
Diffstat (limited to 'gpt4free')
-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