Skip to content

Commit

Permalink
ignore irrelevant methods with decorators, upgrade browser to be head…
Browse files Browse the repository at this point in the history
…less
  • Loading branch information
leetwito committed Oct 19, 2024
1 parent 0ec3a9f commit dd632fb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ misc/

# Ignore litellm_uuid.txt
litellm_uuid.txt

# some more
.aider*
file.txt
numbers.txt
poetry.lock
poetry.lock
poetry.lock
21 changes: 15 additions & 6 deletions interpreter/core/computer/browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def __init__(self, computer):
self._driver = None

@property
def driver(self):
def driver(self, headless=True):
if self._driver is None:
self.setup()
self.setup(headless)
return self._driver

@driver.setter
Expand Down Expand Up @@ -62,10 +62,19 @@ def fast_search(self, query):

return response.json()["result"]

def setup(self):
self.service = Service(ChromeDriverManager().install())
self.options = webdriver.ChromeOptions()
self._driver = webdriver.Chrome(service=self.service, options=self.options)
def setup(self, headless):
try:
self.service = Service(ChromeDriverManager().install())
self.options = webdriver.ChromeOptions()
# Run Chrome in headless mode
if headless:
self.options.add_argument("--headless")
self.options.add_argument("--disable-gpu")
self.options.add_argument("--no-sandbox")
self._driver = webdriver.Chrome(service=self.service, options=self.options)
except Exception as e:
print(f"An error occurred while setting up the WebDriver: {e}")
self._driver = None

def go_to_url(self, url):
"""Navigate to a URL"""
Expand Down
3 changes: 2 additions & 1 deletion interpreter/core/computer/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def _extract_tool_info(self, tool):
"methods": []
}
for name, method in inspect.getmembers(tool, predicate=inspect.ismethod):
if not name.startswith("_"):
# Check if the method should be ignored based on its decorator
if not name.startswith("_") and not hasattr(method, '__wrapped__'):
# Get the method signature
method_signature = inspect.signature(method)
# Construct the signature string without *args and **kwargs
Expand Down
5 changes: 5 additions & 0 deletions tests/core/computer/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ def test_get_all_computer_tools_signature_and_description(self):

# Assert
self.assertGreater(len(tools_description), 64)

if __name__ == "__main__":
testing = TestComputer()
testing.setUp()
testing.test_get_all_computer_tools_signature_and_description()

0 comments on commit dd632fb

Please sign in to comment.