diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-09 04:24:21 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-09 04:24:21 +0100 |
commit | 4b41a8f4e83d4b455b1196f09def14828c73c12f (patch) | |
tree | 6fe8d511e6da448bc19f5d62f6cb747e609f8b18 /g4f | |
parent | Resolve images in Gemini Provider (diff) | |
download | gpt4free-4b41a8f4e83d4b455b1196f09def14828c73c12f.tar gpt4free-4b41a8f4e83d4b455b1196f09def14828c73c12f.tar.gz gpt4free-4b41a8f4e83d4b455b1196f09def14828c73c12f.tar.bz2 gpt4free-4b41a8f4e83d4b455b1196f09def14828c73c12f.tar.lz gpt4free-4b41a8f4e83d4b455b1196f09def14828c73c12f.tar.xz gpt4free-4b41a8f4e83d4b455b1196f09def14828c73c12f.tar.zst gpt4free-4b41a8f4e83d4b455b1196f09def14828c73c12f.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/needs_auth/Gemini.py | 39 | ||||
-rw-r--r-- | g4f/__init__.py | 2 |
2 files changed, 22 insertions, 19 deletions
diff --git a/g4f/Provider/needs_auth/Gemini.py b/g4f/Provider/needs_auth/Gemini.py index da7230dd..402fc02f 100644 --- a/g4f/Provider/needs_auth/Gemini.py +++ b/g4f/Provider/needs_auth/Gemini.py @@ -65,25 +65,28 @@ class Gemini(AsyncGeneratorProvider): ) -> AsyncResult: prompt = format_prompt(messages) - try: - driver = get_browser(proxy=proxy) + if not cookies: + driver = None try: - driver.get(f"{cls.url}/app") - WebDriverWait(driver, 5).until( - EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ql-editor.textarea")) - ) - except: - login_url = os.environ.get("G4F_LOGIN_URL") - if login_url: - yield f"Please login: [Google Gemini]({login_url})\n\n" - WebDriverWait(driver, 240).until( - EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ql-editor.textarea")) - ) - cookies = get_driver_cookies(driver) - except MissingRequirementsError: - pass - finally: - driver.close() + driver = get_browser(proxy=proxy) + try: + driver.get(f"{cls.url}/app") + WebDriverWait(driver, 5).until( + EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ql-editor.textarea")) + ) + except: + login_url = os.environ.get("G4F_LOGIN_URL") + if login_url: + yield f"Please login: [Google Gemini]({login_url})\n\n" + WebDriverWait(driver, 240).until( + EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ql-editor.textarea")) + ) + cookies = get_driver_cookies(driver) + except MissingRequirementsError: + pass + finally: + if driver: + driver.close() if not cookies: cookies = get_cookies(".google.com", False) diff --git a/g4f/__init__.py b/g4f/__init__.py index d76d70b5..34c8aa19 100644 --- a/g4f/__init__.py +++ b/g4f/__init__.py @@ -136,7 +136,7 @@ class ChatCompletion: provider = patch_provider(provider) result = provider.create_completion(model, messages, stream, **kwargs) - return result if stream else ''.join(result) + return result if stream else ''.join([str(chunk) for chunk in result]) @staticmethod def create_async(model : Union[Model, str], |