From c77c28e63147362414f5c128e59d291e5be89aa8 Mon Sep 17 00:00:00 2001 From: Serena Ruan <82044803+serena-ruan@users.noreply.github.com> Date: Fri, 20 Sep 2024 02:25:33 +0800 Subject: [PATCH] [community] Fix WorkspaceClient error with pydantic validation (#26649) Thank you for contributing to LangChain! Fix error like image After the fix: image - [ ] **Add tests and docs**: If you're adding a new integration, please include 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory. - [ ] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17. --------- Signed-off-by: serena-ruan Co-authored-by: Erick Friis --- libs/community/langchain_community/tools/databricks/tool.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/tools/databricks/tool.py b/libs/community/langchain_community/tools/databricks/tool.py index 2255caf4d0..f64616ea5f 100644 --- a/libs/community/langchain_community/tools/databricks/tool.py +++ b/libs/community/langchain_community/tools/databricks/tool.py @@ -10,7 +10,6 @@ from pydantic import BaseModel, Field, create_model from typing_extensions import Self if TYPE_CHECKING: - from databricks.sdk import WorkspaceClient from databricks.sdk.service.catalog import FunctionInfo from pydantic import ConfigDict @@ -121,7 +120,7 @@ def _get_tool_name(function: "FunctionInfo") -> str: return tool_name -def _get_default_workspace_client() -> "WorkspaceClient": +def _get_default_workspace_client() -> Any: try: from databricks.sdk import WorkspaceClient except ImportError as e: @@ -137,7 +136,7 @@ class UCFunctionToolkit(BaseToolkit): description="The ID of a Databricks SQL Warehouse to execute functions." ) - workspace_client: "WorkspaceClient" = Field( + workspace_client: Any = Field( default_factory=_get_default_workspace_client, description="Databricks workspace client.", )