Skip to content
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

module 'playwright.async_api' has no attribute 'AsyncBrowser' #21354

Open
5 tasks done
mehrdad-shokri opened this issue May 7, 2024 · 0 comments
Open
5 tasks done

module 'playwright.async_api' has no attribute 'AsyncBrowser' #21354

mehrdad-shokri opened this issue May 7, 2024 · 0 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@mehrdad-shokri
Copy link
Contributor

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_community.agent_toolkits import PlayWrightBrowserToolkit
from langchain_community.tools.playwright.utils import create_async_playwright_browser

PlayWrightBrowserToolkit.from_browser(
        async_browser=create_async_playwright_browser(headless=True, args=["--disable-dev-shm-usage"])).get_tools()

Error Message and Stack Trace (if applicable)

"module 'playwright.async_api' has no attribute 'AsyncBrowser'"

Description

After 1 hour of investigation here is my findings:

  • The issue is introduced by this commit
  • As you can see from playwright-python source code, there is no AsyncBrowser or SyncBrowser exports. They were correctly imported Browser as AsyncBrowser Browser as SyncBrowser in the past but this PR broke it.
  • As a side note to the mentioned PR, the lazy_import_playwright_browsers uses guard_import for both of the browsers(although the name of the class called from the module is incorrect), but still guard_import is called inside validate_browser_provided and from_browser again. These 2 functions can just call lazy_import_playwright_browsers instead of repeating your self 6 times. Just call lazy_import_playwright_browsers inside the mentions methods.
  • The lazy_import_playwright_browsers body should look like:
def lazy_import_playwright_browsers() -> Tuple[Type[AsyncBrowser], Type[SyncBrowser]]:
    """
    Lazy import playwright browsers.

    Returns:
        Tuple[Type[AsyncBrowser], Type[SyncBrowser]]:
            AsyncBrowser and SyncBrowser classes.
    """
    return (
        guard_import(module_name="playwright.async_api").Browser,
        guard_import(module_name="playwright.sync_api").Browser,
    )
  • Side note on libs/community/langchain_community/tools/gmail/utils.py changes introduced by the commit:
    All the import functions import_googleapiclient_resource_builder, import_google, import_installed_app_flow were changed to use guard_import but later in the body of the functions get_gmail_credentials build_resource_service instead of using these functions, guard_import were called again(instead of just calling the import functions directly) to import classes from google libraries. this is obviously a code smell.

I can submit a PR for this

System Info

langchain==0.1.17
langchain-community==0.0.37
langchain-core==0.1.52
langchain-experimental==0.0.57
langchain-openai==0.1.6
langchain-text-splitters==0.0.1
langchainhub==0.1.15



System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103
> Python Version:  3.10.12 (main, May  4 2024, 19:28:08) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information
-------------------
> langchain_core: 0.1.52
> langchain: 0.1.17
> langchain_community: 0.0.37
> langsmith: 0.1.54
> langchain_experimental: 0.0.57
> langchain_openai: 0.1.6
> langchain_text_splitters: 0.0.1
> langchainhub: 0.1.15

Packages not installed (Not Necessarily a Problem)
--------------------------------------------------
The following packages were not found:

> langgraph
> langserve
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label May 7, 2024
mehrdad-shokri added a commit to mehrdad-shokri/langchain that referenced this issue May 7, 2024
…es for langchain-ai#21354

- Fix import class name exporeted from 'playwright.async_api' and 'playwright.sync_api' to match the correct name
- Change import from inline guard_import to helper function that calls guard_import to make code more readable
- Upgrade playwright version to 1.43.0
mehrdad-shokri added a commit to mehrdad-shokri/langchain that referenced this issue May 8, 2024
…es for langchain-ai#21354

- Fix import class name exporeted from 'playwright.async_api' and 'playwright.sync_api' to match the correct name
- Change import from inline guard_import to helper function that calls guard_import to make code more readable
- Upgrade playwright version to 1.43.0
hwchase17 pushed a commit that referenced this issue May 8, 2024
- **Description:** Fix import class name exporeted from
'playwright.async_api' and 'playwright.sync_api' to match the correct
name in playwright tool. Change import from inline guard_import to
helper function that calls guard_import to make code more readable in
gmail tool. Upgrade playwright version to 1.43.0
- **Issue:** #21354
- **Dependencies:** upgrade playwright version(this is not required for
the bugfix itself, just trying to keep dependencies fresh. I can remove
the playwright version upgrade if you want.)
kyle-cassidy pushed a commit to kyle-cassidy/langchain that referenced this issue May 10, 2024
- **Description:** Fix import class name exporeted from
'playwright.async_api' and 'playwright.sync_api' to match the correct
name in playwright tool. Change import from inline guard_import to
helper function that calls guard_import to make code more readable in
gmail tool. Upgrade playwright version to 1.43.0
- **Issue:** langchain-ai#21354
- **Dependencies:** upgrade playwright version(this is not required for
the bugfix itself, just trying to keep dependencies fresh. I can remove
the playwright version upgrade if you want.)
kyle-cassidy pushed a commit to kyle-cassidy/langchain that referenced this issue May 16, 2024
- **Description:** Fix import class name exporeted from
'playwright.async_api' and 'playwright.sync_api' to match the correct
name in playwright tool. Change import from inline guard_import to
helper function that calls guard_import to make code more readable in
gmail tool. Upgrade playwright version to 1.43.0
- **Issue:** langchain-ai#21354
- **Dependencies:** upgrade playwright version(this is not required for
the bugfix itself, just trying to keep dependencies fresh. I can remove
the playwright version upgrade if you want.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant