Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vertexai: fix avg log probs nan values #550

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

eliasecchig
Copy link
Contributor

Following up on https://github.com/langchain-ai/langchain-google/pull/534/files

Fixes behaviour when using astream_events and stream methods, which requires merging together metadata where some of the chunks might contain "nan" Float values.

e.g

left = {'avg_logprobs': 0.0, 'safety_ratings': []}
others = {'avg_logprobs': nan, 'safety_ratings': []}

E TypeError: Additional kwargs key avg_logprobs already exists in left dict and value has unsupported type <class 'float'>.

We introduce a generic integration test with langraph to catch this kind of errors in the future for any metadata field.

@@ -179,7 +180,10 @@ def get_generation_info(
}

if hasattr(candidate, "avg_logprobs") and candidate.avg_logprobs is not None:
info["avg_logprobs"] = candidate.avg_logprobs
if isinstance(candidate.avg_logprobs, float) and not math.isnan(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably check if it's >0 too

@lkuligin lkuligin merged commit 1ad60d2 into langchain-ai:main Oct 11, 2024
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants