Update click.py to pass errors back to Agent (#4723)

Instead of halting the entire program if this tool encounters an error,
it should pass the error back to the agent to decide what to do.

This may be best suited for @vowelparrot to review.
This commit is contained in:
d 3 n 7 2023-05-15 16:54:08 +02:00 committed by GitHub
parent 3c490b5ba3
commit 435b70da47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,8 +36,11 @@ class ClickTool(BaseBrowserTool):
raise ValueError(f"Synchronous browser not provided to {self.name}") raise ValueError(f"Synchronous browser not provided to {self.name}")
page = get_current_page(self.sync_browser) page = get_current_page(self.sync_browser)
# Navigate to the desired webpage before using this tool # Navigate to the desired webpage before using this tool
page.click(selector) try:
return f"Clicked element '{selector}'" page.click(selector)
return f"Clicked element '{selector}'"
except Exception as e:
return f"Error '{e}'"
async def _arun( async def _arun(
self, self,
@ -49,5 +52,8 @@ class ClickTool(BaseBrowserTool):
raise ValueError(f"Asynchronous browser not provided to {self.name}") raise ValueError(f"Asynchronous browser not provided to {self.name}")
page = await aget_current_page(self.async_browser) page = await aget_current_page(self.async_browser)
# Navigate to the desired webpage before using this tool # Navigate to the desired webpage before using this tool
await page.click(selector) try:
return f"Clicked element '{selector}'" await page.click(selector)
return f"Clicked element '{selector}'"
except Exception as e:
return f"Error '{e}'"