-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove crashing extra_params.append in NeMoGuardrailsServer.__init__ #1947
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
Open
chuenchen309
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
chuenchen309:fix/guardrails-extra-params-crash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, there is definitely a logic bug here. The approach taken though does not look to align with the intent as the original guard logic was flawed and does not have a clear comment on what it was meant to change after the call to
super.__init__()completed.The fix to this should not be to remove support for an existing
extra_bodyfound in theextra_paramsdict, a fix should properly handle when one does exist. The changes here actually would result in the user providedextra_bodyoverriding what this generator is attempting to support asself.extra_bodywould shadowed byself.extra_params["extra_body"]in the currentOpenAICompatible._call_model().This suggests the the guard clause is checking the wrong condition and should be improved so the action taken will preform the correct addition. This guard exists augment the existing expectations for
extra_paramsinOpenAICompatibleto pass thru any keys in theextra_paramsprovided via config as parameters to the OpenAI client method used for the inference request by merging theguardrailsspecificextra_bodyvalues.This would align with the rest of the initialization here by setting
self.extra_bodyto the configured value and allowing theguardrailsspecific injections to beaddedto a configuration providedextra_body.Note the suggestion above is still somewhat naive and should probably be extended with type checking to ensure
self.extra_params["extra_body"]is adictto avoid a type mis-match and raise an early exception about invalid configuration values.Consider exploring adding more unit tests that evaluate how
self.extra_bodyandself.extra_paramswill behave in the various combinations. Also consider looking at what happens if you were to mock the call to the underlying OpenAI client object in_call_modelto see how these values end up mapping into that methods arguments.