From 24a551e7c7cf14f383f9dd1c6eb6c5cde1df944a Mon Sep 17 00:00:00 2001 From: Paul Palmieri Date: Sat, 18 May 2024 15:17:15 +0200 Subject: [PATCH] Add Driver init params (headless, chrome_user_dir) (#239) * Add Driver init params (headless, chrome_user_dir) * fix chrome options flag syntax * small doc changes * update selenium driver package with options --------- Co-authored-by: lyie28 --- .../quick-tour-notebook/quick-tour.ipynb | 1 + docs/docs/get-started/quick-tour.md | 2 +- .../lavague/drivers/selenium/base.py | 9 ++++++++- .../drivers/lavague-drivers-selenium/poetry.lock | 14 +++++++------- .../lavague-drivers-selenium/pyproject.toml | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/docs/get-started/quick-tour-notebook/quick-tour.ipynb b/docs/docs/get-started/quick-tour-notebook/quick-tour.ipynb index 5e208bab..3c9eb7fe 100644 --- a/docs/docs/get-started/quick-tour-notebook/quick-tour.ipynb +++ b/docs/docs/get-started/quick-tour-notebook/quick-tour.ipynb @@ -105,6 +105,7 @@ "from lavague.core import ActionEngine\n", "from lavague.drivers.selenium import SeleniumDriver\n", "\n", + "# Drivers are initialized in headless by default\n", "selenium_driver = SeleniumDriver()\n", "action_engine = ActionEngine(selenium_driver)" ] diff --git a/docs/docs/get-started/quick-tour.md b/docs/docs/get-started/quick-tour.md index dd5b8260..b29390b4 100644 --- a/docs/docs/get-started/quick-tour.md +++ b/docs/docs/get-started/quick-tour.md @@ -33,7 +33,7 @@ Let's start by initializing an `ActionEngine`, which is responsible for generati from lavague.core import ActionEngine from lavague.drivers.selenium import SeleniumDriver -selenium_driver = SeleniumDriver() +selenium_driver = SeleniumDriver(headless=False) action_engine = ActionEngine(selenium_driver) ``` diff --git a/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py b/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py index 26fd6c7c..87fbb3f6 100644 --- a/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py +++ b/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py @@ -17,7 +17,11 @@ def __init__( self, url: Optional[str] = None, get_selenium_driver: Optional[Callable[[], WebDriver]] = None, + headless: bool = True, + chrome_user_dir: Optional[str] = None, ): + self.headless = headless + self.chrome_user_dir = chrome_user_dir super().__init__(url, get_selenium_driver) def default_init_code(self) -> Any: @@ -29,7 +33,10 @@ def default_init_code(self) -> Any: from selenium.webdriver.common.action_chains import ActionChains chrome_options = Options() - chrome_options.add_argument("--headless") + if self.headless: + chrome_options.add_argument("--headless") + if self.chrome_user_dir: + chrome_options.add_argument(f"--user-data-dir={self.chrome_user_dir}") chrome_options.add_argument("--no-sandbox") self.driver = webdriver.Chrome(options=chrome_options) diff --git a/lavague-integrations/drivers/lavague-drivers-selenium/poetry.lock b/lavague-integrations/drivers/lavague-drivers-selenium/poetry.lock index f8a1d283..bd7ab631 100644 --- a/lavague-integrations/drivers/lavague-drivers-selenium/poetry.lock +++ b/lavague-integrations/drivers/lavague-drivers-selenium/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aiohttp" @@ -1171,13 +1171,13 @@ test = ["pytest", "pytest-cov"] [[package]] name = "lavague-core" -version = "0.1.1.post1" +version = "0.1.3" description = "automation code generation from text instructions" optional = false python-versions = "<4.0.0,>=3.10.0" files = [ - {file = "lavague_core-0.1.1.post1-py3-none-any.whl", hash = "sha256:415da735028f5b22d508c6cc5784ff582f3685f31cceeb9edd636908f8104ce3"}, - {file = "lavague_core-0.1.1.post1.tar.gz", hash = "sha256:a0cbad7cb793e98db39cd7d080450fc8ff9b2d1d93b6613a03bb4a86a1aa9c3d"}, + {file = "lavague_core-0.1.3-py3-none-any.whl", hash = "sha256:7593f8e8cd2e231adc8ce4eccb6c717aeaf9e96d82da012d5839ab140c4b5446"}, + {file = "lavague_core-0.1.3.tar.gz", hash = "sha256:6ce70528c0a0942892f46748811f5cf4075d0b7fba2b2509b1c112e8970d0c4e"}, ] [package.dependencies] @@ -1247,13 +1247,13 @@ llama-index-llms-openai = ">=0.1.1,<0.2.0" [[package]] name = "llama-index-core" -version = "0.10.37" +version = "0.10.37.post1" description = "Interface between LLMs and your data" optional = false python-versions = "<4.0,>=3.8.1" files = [ - {file = "llama_index_core-0.10.37-py3-none-any.whl", hash = "sha256:1302ccbd267627199115cd68eee7f3a726611cc92b4a8e1a43dc679f67213664"}, - {file = "llama_index_core-0.10.37.tar.gz", hash = "sha256:b025ebda79b4e4c85269c96f0632b8f6badd1000ce458d7600b79a1de5a61a44"}, + {file = "llama_index_core-0.10.37.post1-py3-none-any.whl", hash = "sha256:e6b8a2dd4371e0326f57845a0b3d257ef4fa0d7d7de4e911fd45a5c814520606"}, + {file = "llama_index_core-0.10.37.post1.tar.gz", hash = "sha256:431305ecd7e8a524dc282f849ca4d7f7dccccd677cae55efefaf16b49d3d1aed"}, ] [package.dependencies] diff --git a/lavague-integrations/drivers/lavague-drivers-selenium/pyproject.toml b/lavague-integrations/drivers/lavague-drivers-selenium/pyproject.toml index 051c96b0..105d27a0 100644 --- a/lavague-integrations/drivers/lavague-drivers-selenium/pyproject.toml +++ b/lavague-integrations/drivers/lavague-drivers-selenium/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "lavague-drivers-selenium" -version = "0.1.1-post1" +version = "0.1.2" description = "Selenium integration for lavague" authors = ["lavague-ai"] readme = "README.md"