diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-17 18:32:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-17 18:32:51 +0100 |
commit | 275574d71ece22975de7df0e226d466a2056605b (patch) | |
tree | 3f113ea8beb7c43920871019512aeb8de9d1b4f7 /g4f/Provider/Cloudflare.py | |
parent | Fix api streaming, fix AsyncClient (#2357) (diff) | |
parent | Add nodriver to Gemini provider, (diff) | |
download | gpt4free-275574d71ece22975de7df0e226d466a2056605b.tar gpt4free-275574d71ece22975de7df0e226d466a2056605b.tar.gz gpt4free-275574d71ece22975de7df0e226d466a2056605b.tar.bz2 gpt4free-275574d71ece22975de7df0e226d466a2056605b.tar.lz gpt4free-275574d71ece22975de7df0e226d466a2056605b.tar.xz gpt4free-275574d71ece22975de7df0e226d466a2056605b.tar.zst gpt4free-275574d71ece22975de7df0e226d466a2056605b.zip |
Diffstat (limited to 'g4f/Provider/Cloudflare.py')
-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]': |