summaryrefslogtreecommitdiffstats
path: root/g4f/Provider
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2023-11-16 12:11:57 +0100
committerGitHub <noreply@github.com>2023-11-16 12:11:57 +0100
commit3f7b3b218492f9f32beda09171b01f27caa67cc9 (patch)
treeef3709e3c654c0d2a9b2c207eccace565e69663e /g4f/Provider
parentMerge pull request #1250 from kacperkwapisz/patch-1 (diff)
parentMerge branch 'xtekky:main' into test (diff)
downloadgpt4free-3f7b3b218492f9f32beda09171b01f27caa67cc9.tar
gpt4free-3f7b3b218492f9f32beda09171b01f27caa67cc9.tar.gz
gpt4free-3f7b3b218492f9f32beda09171b01f27caa67cc9.tar.bz2
gpt4free-3f7b3b218492f9f32beda09171b01f27caa67cc9.tar.lz
gpt4free-3f7b3b218492f9f32beda09171b01f27caa67cc9.tar.xz
gpt4free-3f7b3b218492f9f32beda09171b01f27caa67cc9.tar.zst
gpt4free-3f7b3b218492f9f32beda09171b01f27caa67cc9.zip
Diffstat (limited to 'g4f/Provider')
-rw-r--r--g4f/Provider/GPTalk.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/g4f/Provider/GPTalk.py b/g4f/Provider/GPTalk.py
index b5881e5d..5749ff2e 100644
--- a/g4f/Provider/GPTalk.py
+++ b/g4f/Provider/GPTalk.py
@@ -13,6 +13,7 @@ class GPTalk(AsyncGeneratorProvider):
working = True
supports_gpt_35_turbo = True
_auth = None
+ used_times = 0
@classmethod
async def create_async_generator(
@@ -44,7 +45,7 @@ class GPTalk(AsyncGeneratorProvider):
'x-auth-timestamp': f"{timestamp}",
}
async with ClientSession(headers=headers) as session:
- if not cls._auth or cls._auth["expires_at"] < timestamp:
+ if not cls._auth or cls._auth["expires_at"] < timestamp or cls.used_times == 5:
data = {
"fingerprint": secrets.token_hex(16).zfill(32),
"platform": "fingerprint"
@@ -52,6 +53,7 @@ class GPTalk(AsyncGeneratorProvider):
async with session.post(f"{cls.url}/api/chatgpt/user/login", json=data, proxy=proxy) as response:
response.raise_for_status()
cls._auth = (await response.json())["data"]
+ cls.used_times = 0
data = {
"content": format_prompt(messages),
"accept": "stream",
@@ -72,6 +74,7 @@ class GPTalk(AsyncGeneratorProvider):
async with session.post(f"{cls.url}/api/chatgpt/chatapi/text", json=data, headers=headers, proxy=proxy) as response:
response.raise_for_status()
token = (await response.json())["data"]["token"]
+ cls.used_times += 1
last_message = ""
async with session.get(f"{cls.url}/api/chatgpt/chatapi/stream", params={"token": token}, proxy=proxy) as response:
response.raise_for_status()