Skip to content

Commit

Permalink
Fix safety_attributes merging issue (#23)
Browse files Browse the repository at this point in the history
* Fix safety_attributes merging issue

* Process safety_attributes only for non-gemini models

---------

Co-authored-by: Sergey Kozlov <[email protected]>
  • Loading branch information
skozlovf and Sergey Kozlov authored Feb 26, 2024
1 parent 78d8845 commit d0a7848
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libs/vertexai/langchain_google_vertexai/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +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")

return info

0 comments on commit d0a7848

Please sign in to comment.