Skip to content

Commit

Permalink
catch pydantic v2 schemas in dict
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Sep 12, 2024
1 parent c7a212b commit 9f55657
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 9f55657

Please sign in to comment.