mirror of
https://github.com/hwchase17/langchain
synced 2024-11-18 09:25:54 +00:00
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:
parent
3c490b5ba3
commit
435b70da47
@ -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}'"
|
||||||
|
Loading…
Reference in New Issue
Block a user