diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-11-17 11:06:37 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-11-17 11:06:37 +0100 |
commit | ea1448001df9c66f05a52618eb3e40a88df5efe8 (patch) | |
tree | 3f113ea8beb7c43920871019512aeb8de9d1b4f7 /g4f/Provider/Cloudflare.py | |
parent | Fix api streaming, fix AsyncClient (#2357) (diff) | |
download | gpt4free-ea1448001df9c66f05a52618eb3e40a88df5efe8.tar gpt4free-ea1448001df9c66f05a52618eb3e40a88df5efe8.tar.gz gpt4free-ea1448001df9c66f05a52618eb3e40a88df5efe8.tar.bz2 gpt4free-ea1448001df9c66f05a52618eb3e40a88df5efe8.tar.lz gpt4free-ea1448001df9c66f05a52618eb3e40a88df5efe8.tar.xz gpt4free-ea1448001df9c66f05a52618eb3e40a88df5efe8.tar.zst gpt4free-ea1448001df9c66f05a52618eb3e40a88df5efe8.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/Cloudflare.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/g4f/Provider/Cloudflare.py b/g4f/Provider/Cloudflare.py index 825c5027..7d477d57 100644 --- a/g4f/Provider/Cloudflare.py +++ b/g4f/Provider/Cloudflare.py @@ -7,6 +7,7 @@ import uuid from ..typing import AsyncResult, Messages, Cookies from .base_provider import AsyncGeneratorProvider, ProviderModelMixin, get_running_loop from ..requests import Session, StreamSession, get_args_from_nodriver, raise_for_status, merge_cookies +from ..errors import ResponseStatusError class Cloudflare(AsyncGeneratorProvider, ProviderModelMixin): label = "Cloudflare AI" @@ -42,10 +43,14 @@ class Cloudflare(AsyncGeneratorProvider, ProviderModelMixin): cls._args = asyncio.run(args) with Session(**cls._args) as session: response = session.get(cls.models_url) - raise_for_status(response) + cls._args["cookies"] = merge_cookies(cls._args["cookies"] , response) + try: + raise_for_status(response) + except ResponseStatusError as e: + cls._args = None + raise e json_data = response.json() cls.models = [model.get("name") for model in json_data.get("models")] - cls._args["cookies"] = merge_cookies(cls._args["cookies"] , response) return cls.models @classmethod @@ -74,8 +79,12 @@ class Cloudflare(AsyncGeneratorProvider, ProviderModelMixin): cls.api_endpoint, json=data, ) as response: - await raise_for_status(response) cls._args["cookies"] = merge_cookies(cls._args["cookies"] , response) + try: + await raise_for_status(response) + except ResponseStatusError as e: + cls._args = None + raise e async for line in response.iter_lines(): if line.startswith(b'data: '): if line == b'data: [DONE]': |