返回提交历史
Modified
g4f/Provider/GPTalk.py
+4
-1
XFEstudio/gpt4free
fix: GPTalk can only use 5 times (#1255)
5c16856c
代码差异
1 个文件
+4
-1
@@ -13,6 +13,7 @@ class GPTalk(AsyncGeneratorProvider):
13
13
working = True
14
14
supports_gpt_35_turbo = True
15
15
_auth = None
16
used_times = 0
16
17
17
18
@classmethod
18
19
async def create_async_generator(
@@ -44,7 +45,7 @@ class GPTalk(AsyncGeneratorProvider):
44
45
'x-auth-timestamp': f"{timestamp}",
45
46
}
46
47
async with ClientSession(headers=headers) as session:
47
if not cls._auth or cls._auth["expires_at"] < timestamp:
48
if not cls._auth or cls._auth["expires_at"] < timestamp or cls.used_times == 5:
48
49
data = {
49
50
"fingerprint": secrets.token_hex(16).zfill(32),
50
51
"platform": "fingerprint"
@@ -52,6 +53,7 @@ class GPTalk(AsyncGeneratorProvider):
52
53
async with session.post(f"{cls.url}/api/chatgpt/user/login", json=data, proxy=proxy) as response:
53
54
response.raise_for_status()
54
55
cls._auth = (await response.json())["data"]
56
cls.used_times = 0
55
57
data = {
56
58
"content": format_prompt(messages),
57
59
"accept": "stream",
@@ -72,6 +74,7 @@ class GPTalk(AsyncGeneratorProvider):
72
74
async with session.post(f"{cls.url}/api/chatgpt/chatapi/text", json=data, headers=headers, proxy=proxy) as response:
73
75
response.raise_for_status()
74
76
token = (await response.json())["data"]["token"]
77
cls.used_times += 1
75
78
last_message = ""
76
79
async with session.get(f"{cls.url}/api/chatgpt/chatapi/stream", params={"token": token}, proxy=proxy) as response:
77
80
response.raise_for_status()