langchain-ai / langchain-google

MIT License
117 stars 149 forks source link

vertexai: fix avg log probs nan values #550

Closed eliasecchig closed 1 month ago

eliasecchig commented 1 month ago

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.