Skip to content

Commit

Permalink
added grounding tools (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuligin authored May 16, 2024
1 parent 481ed09 commit 8793ee8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions libs/vertexai/langchain_google_vertexai/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,16 @@ def get_generation_info(
if candidate.citation_metadata
else None
),
"usage_metadata": usage_metadata,
}
if usage_metadata:
info["usage_metadata"] = usage_metadata
try:
if candidate.grounding_metadata:
info["grounding_metadata"] = proto.Message.to_dict(
candidate.grounding_metadata
)
except AttributeError:
pass
info = {k: v for k, v in info.items() if v is not None}
# https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/text-chat#response_body
else:
info = dataclasses.asdict(candidate)
Expand Down
2 changes: 1 addition & 1 deletion libs/vertexai/langchain_google_vertexai/functions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _format_to_vertex_tool(
tool: Union[VertexTool, GapicTool, _VertexToolDict, List[_FunctionDeclarationLike]],
) -> GapicTool:
if isinstance(tool, VertexTool):
return tool
return tool._raw_tool
if isinstance(tool, GapicTool):
return tool
elif isinstance(tool, (list, dict)):
Expand Down

0 comments on commit 8793ee8

Please sign in to comment.