From ea1448001df9c66f05a52618eb3e40a88df5efe8 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 17 Nov 2024 11:06:37 +0100 Subject: Add nodriver to Gemini provider, Add slim docker image with google-chrome usage, Add the new docker images to publish worklow, Update requirements.txt and pip requirements --- g4f/Provider/Cloudflare.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'g4f/Provider/Cloudflare.py') 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]': -- cgit v1.2.3