diff options
Diffstat (limited to 'g4f/Provider')
-rw-r--r-- | g4f/Provider/PollinationsAI.py | 3 | ||||
-rw-r--r-- | g4f/Provider/needs_auth/Gemini.py | 21 |
2 files changed, 9 insertions, 15 deletions
diff --git a/g4f/Provider/PollinationsAI.py b/g4f/Provider/PollinationsAI.py index a30f896d..e82222b1 100644 --- a/g4f/Provider/PollinationsAI.py +++ b/g4f/Provider/PollinationsAI.py @@ -46,8 +46,7 @@ class PollinationsAI(OpenaiAPI): seed: str = None, **kwargs ) -> AsyncResult: - if model: - model = cls.get_model(model) + model = cls.get_model(model) if model in cls.image_models: if prompt is None: prompt = messages[-1]["content"] diff --git a/g4f/Provider/needs_auth/Gemini.py b/g4f/Provider/needs_auth/Gemini.py index 89f6f802..e7c9de23 100644 --- a/g4f/Provider/needs_auth/Gemini.py +++ b/g4f/Provider/needs_auth/Gemini.py @@ -20,6 +20,7 @@ from ..base_provider import AsyncGeneratorProvider, BaseConversation, Synthesize from ..helper import format_prompt, get_cookies from ...requests.raise_for_status import raise_for_status from ...requests.aiohttp import get_connector +from ...requests import get_nodriver from ...errors import MissingAuthError from ...image import ImageResponse, to_bytes from ... import debug @@ -68,17 +69,7 @@ class Gemini(AsyncGeneratorProvider): if debug.logging: print("Skip nodriver login in Gemini provider") return - try: - from platformdirs import user_config_dir - user_data_dir = user_config_dir("g4f-nodriver") - except: - user_data_dir = None - if debug.logging: - print(f"Open nodriver with user_dir: {user_data_dir}") - browser = await nodriver.start( - user_data_dir=user_data_dir, - browser_args=None if proxy is None else [f"--proxy-server={proxy}"], - ) + browser = await get_nodriver(proxy=proxy) login_url = os.environ.get("G4F_LOGIN_URL") if login_url: yield f"Please login: [Google Gemini]({login_url})\n\n" @@ -118,8 +109,11 @@ class Gemini(AsyncGeneratorProvider): if not cls._snlm0e: await cls.fetch_snlm0e(session, cls._cookies) if cls._cookies else None if not cls._snlm0e: - async for chunk in cls.nodriver_login(proxy): - yield chunk + try: + async for chunk in cls.nodriver_login(proxy): + yield chunk + except Exception as e: + raise MissingAuthError('Missing "__Secure-1PSID" cookie', e) if not cls._snlm0e: if cls._cookies is None or "__Secure-1PSID" not in cls._cookies: raise MissingAuthError('Missing "__Secure-1PSID" cookie') @@ -319,6 +313,7 @@ class Conversation(BaseConversation): self.conversation_id = conversation_id self.response_id = response_id self.choice_id = choice_id + async def iter_filter_base64(response_iter: AsyncIterator[bytes]) -> AsyncIterator[bytes]: search_for = b'[["wrb.fr","XqA3Ic","[\\"' end_with = b'\\' |