Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Dec 17, 2024
1 parent 73a47b2 commit 6d07c3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libs/core/langchain_core/utils/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def _parse_google_docstring(
}
if filtered_annotations and (
len(docstring_blocks) < 2
or not any(block.startswith("Args:") for block in docstring_blocks)
or not any(block.startswith("Args:") for block in docstring_blocks[1:])
):
msg = "Found invalid Google-Style docstring."
raise ValueError(msg)
Expand Down
10 changes: 7 additions & 3 deletions libs/core/tests/unit_tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ def test_docstring_parsing() -> None:
"required": ["bar", "baz"],
}

# Simple case
def foo(bar: str, baz: int) -> str:
"""The foo.
Expand All @@ -1227,11 +1228,13 @@ def foo2(bar: str, baz: int) -> str:
"""
return bar

# Multi-line description
as_tool = tool(foo2, parse_docstring=True)
args_schema2 = _schema(as_tool.args_schema) # type: ignore
assert args_schema2["description"] == "The foo. Additional description here."
assert args_schema2["properties"] == expected["properties"]

# Multi-line wth Returns block
def foo3(bar: str, baz: int) -> str:
"""The foo.
Expand All @@ -1251,6 +1254,7 @@ def foo3(bar: str, baz: int) -> str:
args_schema3["title"] = "foo2"
assert args_schema2 == args_schema3

# Single argument
def foo4(bar: str) -> str:
"""The foo.
Expand All @@ -1260,9 +1264,9 @@ def foo4(bar: str) -> str:
return bar

as_tool = tool(foo4, parse_docstring=True)
args_schema = _schema(as_tool.args_schema) # type: ignore
assert args_schema["description"] == "The foo."
assert args_schema["properties"] == {
args_schema4 = _schema(as_tool.args_schema) # type: ignore
assert args_schema4["description"] == "The foo."
assert args_schema4["properties"] == {
"bar": {"description": "The bar.", "title": "Bar", "type": "string"}
}

Expand Down

0 comments on commit 6d07c3f

Please sign in to comment.