From feb83c168b0a57ecd8c511aa654209c5f40da30e Mon Sep 17 00:00:00 2001 From: H Lohaus Date: Fri, 26 Jan 2024 07:54:13 +0100 Subject: New minimum requirements (#1515) * New minimum requirements * Add ConversationStyleOptionSets to Bing * Add image.ImageRequest * Improve python version support * Improve unittests --- g4f/webdriver.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'g4f/webdriver.py') diff --git a/g4f/webdriver.py b/g4f/webdriver.py index 85d6d695..d2009ddc 100644 --- a/g4f/webdriver.py +++ b/g4f/webdriver.py @@ -1,12 +1,20 @@ from __future__ import annotations -from platformdirs import user_config_dir -from selenium.webdriver.remote.webdriver import WebDriver -from undetected_chromedriver import Chrome, ChromeOptions -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC + +try: + from platformdirs import user_config_dir + from selenium.webdriver.remote.webdriver import WebDriver + from undetected_chromedriver import Chrome, ChromeOptions + from selenium.webdriver.common.by import By + from selenium.webdriver.support.ui import WebDriverWait + from selenium.webdriver.support import expected_conditions as EC + has_requirements = True +except ImportError: + WebDriver = type + has_requirements = False + from os import path from os import access, R_OK +from .errors import MissingRequirementsError from . import debug try: @@ -33,6 +41,8 @@ def get_browser( Returns: WebDriver: An instance of WebDriver configured with the specified options. """ + if not has_requirements: + raise MissingRequirementsError('Install "undetected_chromedriver" and "platformdirs" package') if user_data_dir is None: user_data_dir = user_config_dir("g4f") if user_data_dir and debug.logging: @@ -144,7 +154,7 @@ class WebDriverSession: Returns: WebDriver: The reopened WebDriver instance. """ - user_data_dir = user_data_data_dir or self.user_data_dir + user_data_dir = user_data_dir or self.user_data_dir if self.default_driver: self.default_driver.quit() if not virtual_display and self.virtual_display: -- cgit v1.2.3