Skip to content

Commit

Permalink
catch pydantic v2 schemas in dict (#488)
Browse files Browse the repository at this point in the history
* catch pydantic v2 schemas in dict

* lock

* update test
  • Loading branch information
ccurme authored Sep 12, 2024
1 parent c7a212b commit 36c122d
Show file tree
Hide file tree
Showing 3 changed files with 792 additions and 787 deletions.
16 changes: 15 additions & 1 deletion libs/vertexai/langchain_google_vertexai/functions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,24 @@ def _format_pydantic_to_function_declaration(
def _format_dict_to_function_declaration(
tool: Union[FunctionDescription, Dict[str, Any]],
) -> gapic.FunctionDeclaration:
# Ensure we send "anyOf" parameters through pydantic v2 schema parsing
pydantic_version = None
if isinstance(tool, dict):
properties = tool.get("parameters", {}).get("properties", {}).values()
for property in properties:
if "anyOf" in property:
pydantic_version = "v2"
if pydantic_version:
parameters = _dict_to_gapic_schema(
tool.get("parameters", {}), pydantic_version=pydantic_version
)
else:
parameters = _dict_to_gapic_schema(tool.get("parameters", {}))

return gapic.FunctionDeclaration(
name=tool.get("name"),
description=tool.get("description"),
parameters=_dict_to_gapic_schema(tool.get("parameters", {})),
parameters=parameters,
)


Expand Down
Loading

0 comments on commit 36c122d

Please sign in to comment.