diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2023-12-31 22:59:24 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2023-12-31 22:59:24 +0100 |
commit | 6c2f3c641655ca358741f1d274a4d93679b5931d (patch) | |
tree | 5bcf2c73c9adb955fc1475489b5d7ecc70c17bd5 | |
parent | Merge pull request #1406 from OmiiiDev/patch-1 (diff) | |
download | gpt4free-6c2f3c641655ca358741f1d274a4d93679b5931d.tar gpt4free-6c2f3c641655ca358741f1d274a4d93679b5931d.tar.gz gpt4free-6c2f3c641655ca358741f1d274a4d93679b5931d.tar.bz2 gpt4free-6c2f3c641655ca358741f1d274a4d93679b5931d.tar.lz gpt4free-6c2f3c641655ca358741f1d274a4d93679b5931d.tar.xz gpt4free-6c2f3c641655ca358741f1d274a4d93679b5931d.tar.zst gpt4free-6c2f3c641655ca358741f1d274a4d93679b5931d.zip |
-rw-r--r-- | g4f/Provider/Liaobots.py | 14 |
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() |