mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
bugfix(community): fix Playwright import paths. (#21395)
- **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.)
This commit is contained in:
parent
aa966b6161
commit
f103927b88
@ -69,19 +69,8 @@ def get_gmail_credentials(
|
|||||||
) -> Credentials:
|
) -> Credentials:
|
||||||
"""Get credentials."""
|
"""Get credentials."""
|
||||||
# From https://developers.google.com/gmail/api/quickstart/python
|
# From https://developers.google.com/gmail/api/quickstart/python
|
||||||
Request, Credentials = (
|
Request, Credentials = import_google()
|
||||||
guard_import(
|
InstalledAppFlow = import_installed_app_flow()
|
||||||
module_name="google.auth.transport.requests",
|
|
||||||
pip_name="google-auth-httplib2",
|
|
||||||
).Request,
|
|
||||||
guard_import(
|
|
||||||
module_name="google.oauth2.credentials", pip_name="google-auth-httplib2"
|
|
||||||
).Credentials,
|
|
||||||
)
|
|
||||||
|
|
||||||
InstalledAppFlow = guard_import(
|
|
||||||
module_name="google_auth_oauthlib.flow", pip_name="google-auth-oauthlib"
|
|
||||||
).InstalledAppFlow
|
|
||||||
creds = None
|
creds = None
|
||||||
scopes = scopes or DEFAULT_SCOPES
|
scopes = scopes or DEFAULT_SCOPES
|
||||||
token_file = token_file or DEFAULT_CREDS_TOKEN_FILE
|
token_file = token_file or DEFAULT_CREDS_TOKEN_FILE
|
||||||
@ -114,9 +103,7 @@ def build_resource_service(
|
|||||||
) -> Resource:
|
) -> Resource:
|
||||||
"""Build a Gmail service."""
|
"""Build a Gmail service."""
|
||||||
credentials = credentials or get_gmail_credentials()
|
credentials = credentials or get_gmail_credentials()
|
||||||
builder = guard_import(
|
builder = import_googleapiclient_resource_builder()
|
||||||
module_name="googleapiclient.discovery", pip_name="google-api-python-client"
|
|
||||||
).build
|
|
||||||
return builder(service_name, service_version, credentials=credentials)
|
return builder(service_name, service_version, credentials=credentials)
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ def lazy_import_playwright_browsers() -> Tuple[Type[AsyncBrowser], Type[SyncBrow
|
|||||||
AsyncBrowser and SyncBrowser classes.
|
AsyncBrowser and SyncBrowser classes.
|
||||||
"""
|
"""
|
||||||
return (
|
return (
|
||||||
guard_import(module_name="playwright.async_api").AsyncBrowser,
|
guard_import(module_name="playwright.async_api").Browser,
|
||||||
guard_import(module_name="playwright.sync_api").SyncBrowser,
|
guard_import(module_name="playwright.sync_api").Browser,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -41,8 +41,7 @@ class BaseBrowserTool(BaseTool):
|
|||||||
@root_validator
|
@root_validator
|
||||||
def validate_browser_provided(cls, values: dict) -> dict:
|
def validate_browser_provided(cls, values: dict) -> dict:
|
||||||
"""Check that the arguments are valid."""
|
"""Check that the arguments are valid."""
|
||||||
guard_import(module_name="playwright.async_api").AsyncBrowser
|
lazy_import_playwright_browsers()
|
||||||
guard_import(module_name="playwright.sync_api").SyncBrowser
|
|
||||||
if values.get("async_browser") is None and values.get("sync_browser") is None:
|
if values.get("async_browser") is None and values.get("sync_browser") is None:
|
||||||
raise ValueError("Either async_browser or sync_browser must be specified.")
|
raise ValueError("Either async_browser or sync_browser must be specified.")
|
||||||
return values
|
return values
|
||||||
@ -54,6 +53,5 @@ class BaseBrowserTool(BaseTool):
|
|||||||
async_browser: Optional[AsyncBrowser] = None,
|
async_browser: Optional[AsyncBrowser] = None,
|
||||||
) -> BaseBrowserTool:
|
) -> BaseBrowserTool:
|
||||||
"""Instantiate the tool."""
|
"""Instantiate the tool."""
|
||||||
guard_import(module_name="playwright.async_api").AsyncBrowser
|
lazy_import_playwright_browsers()
|
||||||
guard_import(module_name="playwright.sync_api").SyncBrowser
|
|
||||||
return cls(sync_browser=sync_browser, async_browser=async_browser)
|
return cls(sync_browser=sync_browser, async_browser=async_browser)
|
||||||
|
Loading…
Reference in New Issue
Block a user