fix(openai): handle parsed_n non integer#1470
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fixes condition in
_get_langfuse_data_from_kwargsto ensureparsed_nis an integer before comparison, preventing errors with non-integer values._get_langfuse_data_from_kwargsinlangfuse/openai.pyto check ifparsed_nis an integer before comparing it to 1.parsed_nis not an integer.This description was created by
for b8de64b. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Greptile Summary
Added type validation for the
nparameter to preventTypeErrorwhen comparing non-integer values.isinstance(parsed_n, int)check before comparingparsed_n > 1to handle edge cases where the OpenAI SDK passes non-integer valuesConfidence Score: 4/5
Important Files Changed
File Analysis
nparameter is non-integer; defensive programming improvementSequence Diagram
sequenceDiagram participant Client participant _get_langfuse_data_from_kwargs participant modelParameters Client->>_get_langfuse_data_from_kwargs: Call with kwargs containing 'n' parameter _get_langfuse_data_from_kwargs->>_get_langfuse_data_from_kwargs: Extract parsed_n from kwargs.get("n", 1) alt parsed_n is not None _get_langfuse_data_from_kwargs->>_get_langfuse_data_from_kwargs: Check isinstance(parsed_n, int) alt parsed_n is integer AND parsed_n > 1 _get_langfuse_data_from_kwargs->>modelParameters: Add n parameter to modelParameters else parsed_n is not integer OR parsed_n <= 1 _get_langfuse_data_from_kwargs->>_get_langfuse_data_from_kwargs: Skip adding n to modelParameters end end _get_langfuse_data_from_kwargs->>Client: Return langfuse data with modelParameters