Skip to content

Commit

Permalink
Process safety_attributes only for non-gemini models
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kozlov committed Feb 23, 2024
1 parent f549de5 commit 597cb50
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libs/vertexai/langchain_google_vertexai/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ def get_generation_info(
info_usage_metadata["prompt_token_count"] = input_usage.get("totalTokens")
info["usage_metadata"] = {k: v for k, v in info_usage_metadata.items() if v}

# NOTE:
# "safety_attributes" can contain different values for the same keys
# for each generation. Put it in a list, so it can be merged later by
# merge_dicts().
#
safety_attributes = info.get("safety_attributes") or {}
info["safety_attributes"] = [safety_attributes]

if stream:
# Remove non-streamable types, like bools.
info.pop("is_blocked")

# NOTE:
# "safety_attributes" can contain different values for the same keys
# for each generation. Put it in a list, so it can be merged later by merge_dicts().
#
safety_attributes = info.get("safety_attributes") or {}
info["safety_attributes"] = [safety_attributes]

return info

0 comments on commit 597cb50

Please sign in to comment.