mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-23 11:30:37 +00:00
fix: fixing missing Docstring Bug if no Docstring is provided in BaseModel class (#31608)
- **Description:** Ensure that the tool description is an empty string when creating a Structured Tool from a Pydantic class in case no description is provided - **Issue:** Fixes #31606 --------- Co-authored-by: Mason Daugherty <mason@langchain.dev>
This commit is contained in:
committed by
GitHub
parent
15103b0520
commit
96bf8262e2
@@ -197,7 +197,14 @@ class StructuredTool(BaseTool):
|
|||||||
description_ = source_function.__doc__ or None
|
description_ = source_function.__doc__ or None
|
||||||
if description_ is None and args_schema:
|
if description_ is None and args_schema:
|
||||||
if isinstance(args_schema, type) and is_basemodel_subclass(args_schema):
|
if isinstance(args_schema, type) and is_basemodel_subclass(args_schema):
|
||||||
description_ = args_schema.__doc__ or None
|
description_ = args_schema.__doc__
|
||||||
|
if (
|
||||||
|
description_
|
||||||
|
and "A base class for creating Pydantic models" in description_
|
||||||
|
):
|
||||||
|
description_ = ""
|
||||||
|
elif not description_:
|
||||||
|
description_ = None
|
||||||
elif isinstance(args_schema, dict):
|
elif isinstance(args_schema, dict):
|
||||||
description_ = args_schema.get("description")
|
description_ = args_schema.get("description")
|
||||||
else:
|
else:
|
||||||
|
@@ -701,6 +701,12 @@ def test_missing_docstring() -> None:
|
|||||||
def search_api(query: str) -> str:
|
def search_api(query: str) -> str:
|
||||||
return "API result"
|
return "API result"
|
||||||
|
|
||||||
|
@tool
|
||||||
|
class MyTool(BaseModel):
|
||||||
|
foo: str
|
||||||
|
|
||||||
|
assert MyTool.description == "" # type: ignore[attr-defined]
|
||||||
|
|
||||||
|
|
||||||
def test_create_tool_positional_args() -> None:
|
def test_create_tool_positional_args() -> None:
|
||||||
"""Test that positional arguments are allowed."""
|
"""Test that positional arguments are allowed."""
|
||||||
|
Reference in New Issue
Block a user