-
Notifications
You must be signed in to change notification settings - Fork 15.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
community[patch]: Fix Playwright Tools bug with Pydantic schemas #27050
Open
colriot
wants to merge
10
commits into
langchain-ai:master
Choose a base branch
from
colriot:colriot/playwright_pydantic_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−3
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c7f5c02
Fix Playwright Tools bug with Pydantic schemas
colriot 478f6b3
Merge branch 'master' into colriot/playwright_pydantic_fix
colriot b31e054
Merge branch 'master' into colriot/playwright_pydantic_fix
efriis be3b9e0
update
eyurtsev 24cc3f1
lint
eyurtsev a7fa9fd
lint
eyurtsev 808c53c
x
eyurtsev 5a159af
Fix naming and docstrings
colriot c5210c8
Merge branch 'master' into colriot/playwright_pydantic_fix
colriot eb48040
Merge branch 'master' into colriot/playwright_pydantic_fix
colriot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
libs/community/langchain_community/tools/playwright/extract_text.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
18 changes: 18 additions & 0 deletions
18
libs/community/tests/unit_tests/tools/playwright/test_all.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Test Playwright's Tools.""" | ||
|
||
from langchain_community.agent_toolkits import PlayWrightBrowserToolkit | ||
|
||
from langchain_community.tools.playwright.utils import create_sync_playwright_browser | ||
|
||
|
||
def test_playwright_tools_schemas() -> None: | ||
"""Test calling 'tool_call_schema' for every tool to check to serialization issues.""" | ||
|
||
sync_browser = create_sync_playwright_browser() | ||
tools = PlayWrightBrowserToolkit.from_browser(sync_browser=sync_browser).get_tools() | ||
|
||
for tool in tools: | ||
try: | ||
tool.tool_call_schema | ||
except Exception as e: | ||
raise AssertionError(f"Error for '{tool.name}' tool: {type(e).__name__}: {e}") from e |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colriot why do we need to define a default schema on the base class? Ideally sub-classes would be forced to define the schema? Could we remove it here and add an appropriate schema in each tool that uses it?
I think definition here would make sense if this was called "ParameterlessBaseBrowserTool", but I think it's meant to capture any sort of tool and the main role of the base abstraction is to make sure that it accepts the browser attributes properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eyurtsev because my suggestion was to have a default NoArgs schema applied. And only tools that actually require non-empty params will need to explicitly override it. I.e. I don't see the reason for subclasses to define their own schema if it's NoArgs (same as it was before the fix, but actually working).
I have a few suggested options:
BaseBrowserToolInput
toNoArgsToolInput
(or smth along the lines) and have it used as default schema value inBaseBrowserTool
BaseBrowserTool
and explicitly use it in every toolThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me the main reason is that it's an abstract class with an incorrect default. I don't feel strongly in this case -- end users aren't expected to use these types or subclass from the base playwright tool, so all the solutions are equivalent for end-users (and this can vary by personal style).
Do you want me to revert to the previous iteration or do you want to make the update?