summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Cloudflare.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-11-17 11:06:37 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-11-17 11:06:37 +0100
commitea1448001df9c66f05a52618eb3e40a88df5efe8 (patch)
tree3f113ea8beb7c43920871019512aeb8de9d1b4f7 /g4f/Provider/Cloudflare.py
parentFix api streaming, fix AsyncClient (#2357) (diff)
downloadgpt4free-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 'g4f/Provider/Cloudflare.py')
-rw-r--r--g4f/Provider/Cloudflare.py15
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]':