Skip to content

Commit

Permalink
Fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
hlohaus committed Dec 18, 2024
1 parent af67771 commit 6390fcc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 3 additions & 7 deletions g4f/Provider/Cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
import asyncio
import json

try:
import nodriver
has_nodriver = True
except ImportError:
has_nodriver = False

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, DEFAULT_HEADERS
from ..requests import Session, StreamSession, get_args_from_nodriver, raise_for_status, merge_cookies, DEFAULT_HEADERS, has_nodriver, has_curl_cffi
from ..errors import ResponseStatusError

class Cloudflare(AsyncGeneratorProvider, ProviderModelMixin):
Expand Down Expand Up @@ -45,6 +39,8 @@ def get_models(cls) -> str:
get_running_loop(check_nested=True)
args = get_args_from_nodriver(cls.url)
cls._args = asyncio.run(args)
elif not has_curl_cffi:
return cls.models
else:
cls._args = {"headers": DEFAULT_HEADERS, "cookies": {}}
with Session(**cls._args) as session:
Expand Down
2 changes: 1 addition & 1 deletion g4f/Provider/needs_auth/OpenaiChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def __init__(self, conversation_id: str = None, message_id: str = None, finish_r
def get_cookies(
urls: list[str] = None
):
params = dict()
params = {}
if urls is not None:
params['urls'] = [i for i in urls]
cmd_dict = {
Expand Down
7 changes: 6 additions & 1 deletion g4f/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .curl_cffi import StreamResponse, StreamSession, FormData
has_curl_cffi = True
except ImportError:
from typing import Type as Session, Type as Response
from typing import Type as Response
from .aiohttp import StreamResponse, StreamSession, FormData
has_curl_cffi = False
try:
Expand Down Expand Up @@ -38,6 +38,11 @@
from ..typing import Cookies
from .defaults import DEFAULT_HEADERS, WEBVIEW_HAEDERS

if not has_curl_cffi:
class Session:
def __init__(self, **kwargs):
raise MissingRequirementsError('Install "curl_cffi" package | pip install -U curl_cffi')

async def get_args_from_webview(url: str) -> dict:
if not has_webview:
raise MissingRequirementsError('Install "webview" package')
Expand Down

0 comments on commit 6390fcc

Please sign in to comment.