summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2023-12-31 22:59:43 +0100
committerGitHub <noreply@github.com>2023-12-31 22:59:43 +0100
commit85a37e484125875e21d84f3d078b075713556f2a (patch)
tree5bcf2c73c9adb955fc1475489b5d7ecc70c17bd5
parentMerge pull request #1406 from OmiiiDev/patch-1 (diff)
parentFix Liabots session (diff)
downloadgpt4free-85a37e484125875e21d84f3d078b075713556f2a.tar
gpt4free-85a37e484125875e21d84f3d078b075713556f2a.tar.gz
gpt4free-85a37e484125875e21d84f3d078b075713556f2a.tar.bz2
gpt4free-85a37e484125875e21d84f3d078b075713556f2a.tar.lz
gpt4free-85a37e484125875e21d84f3d078b075713556f2a.tar.xz
gpt4free-85a37e484125875e21d84f3d078b075713556f2a.tar.zst
gpt4free-85a37e484125875e21d84f3d078b075713556f2a.zip
-rw-r--r--g4f/Provider/Liaobots.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/g4f/Provider/Liaobots.py b/g4f/Provider/Liaobots.py
index e6857f44..88f0c4ff 100644
--- a/g4f/Provider/Liaobots.py
+++ b/g4f/Provider/Liaobots.py
@@ -78,6 +78,7 @@ class Liaobots(AsyncGeneratorProvider):
supports_gpt_35_turbo = True
supports_gpt_4 = True
_auth_code = None
+ _cookie_jar = None
@classmethod
async def create_async_generator(
@@ -97,7 +98,8 @@ class Liaobots(AsyncGeneratorProvider):
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
}
async with ClientSession(
- headers=headers
+ headers=headers,
+ cookie_jar=cls._cookie_jar
) as session:
cls._auth_code = auth if isinstance(auth, str) else cls._auth_code
if not cls._auth_code:
@@ -116,6 +118,8 @@ class Liaobots(AsyncGeneratorProvider):
) as response:
response.raise_for_status()
cls._auth_code = (await response.json(content_type=None))["authCode"]
+ cls._cookie_jar = session.cookie_jar
+
data = {
"conversationId": str(uuid.uuid4()),
"model": models[model],
@@ -131,6 +135,8 @@ class Liaobots(AsyncGeneratorProvider):
verify_ssl=False
) as response:
response.raise_for_status()
- async for stream in response.content.iter_any():
- if stream:
- yield stream.decode()
+ async for chunk in response.content.iter_any():
+ if b"<html coupert-item=" in chunk:
+ raise RuntimeError("Invalid session")
+ if chunk:
+ yield chunk.decode()