|
|
@ -13,6 +13,7 @@ class GPTalk(AsyncGeneratorProvider):
|
|
|
|
working = True
|
|
|
|
working = True
|
|
|
|
supports_gpt_35_turbo = True
|
|
|
|
supports_gpt_35_turbo = True
|
|
|
|
_auth = None
|
|
|
|
_auth = None
|
|
|
|
|
|
|
|
used_times = 0
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
async def create_async_generator(
|
|
|
|
async def create_async_generator(
|
|
|
@ -44,7 +45,7 @@ class GPTalk(AsyncGeneratorProvider):
|
|
|
|
'x-auth-timestamp': f"{timestamp}",
|
|
|
|
'x-auth-timestamp': f"{timestamp}",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async with ClientSession(headers=headers) as session:
|
|
|
|
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 = {
|
|
|
|
data = {
|
|
|
|
"fingerprint": secrets.token_hex(16).zfill(32),
|
|
|
|
"fingerprint": secrets.token_hex(16).zfill(32),
|
|
|
|
"platform": "fingerprint"
|
|
|
|
"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:
|
|
|
|
async with session.post(f"{cls.url}/api/chatgpt/user/login", json=data, proxy=proxy) as response:
|
|
|
|
response.raise_for_status()
|
|
|
|
response.raise_for_status()
|
|
|
|
cls._auth = (await response.json())["data"]
|
|
|
|
cls._auth = (await response.json())["data"]
|
|
|
|
|
|
|
|
cls.used_times = 0
|
|
|
|
data = {
|
|
|
|
data = {
|
|
|
|
"content": format_prompt(messages),
|
|
|
|
"content": format_prompt(messages),
|
|
|
|
"accept": "stream",
|
|
|
|
"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:
|
|
|
|
async with session.post(f"{cls.url}/api/chatgpt/chatapi/text", json=data, headers=headers, proxy=proxy) as response:
|
|
|
|
response.raise_for_status()
|
|
|
|
response.raise_for_status()
|
|
|
|
token = (await response.json())["data"]["token"]
|
|
|
|
token = (await response.json())["data"]["token"]
|
|
|
|
|
|
|
|
cls.used_times += 1
|
|
|
|
last_message = ""
|
|
|
|
last_message = ""
|
|
|
|
async with session.get(f"{cls.url}/api/chatgpt/chatapi/stream", params={"token": token}, proxy=proxy) as response:
|
|
|
|
async with session.get(f"{cls.url}/api/chatgpt/chatapi/stream", params={"token": token}, proxy=proxy) as response:
|
|
|
|
response.raise_for_status()
|
|
|
|
response.raise_for_status()
|
|
|
|