-
Notifications
You must be signed in to change notification settings - Fork 521
feat: support method chaining by returning self
from LLMRails.register_* methods
#1296
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
base: develop
Are you sure you want to change the base?
feat: support method chaining by returning self
from LLMRails.register_* methods
#1296
Conversation
@winstonallo thanks for opening this PR. It seems that some unrelated sections of the code has been deleted, would you revert those? |
Done, sorry about that! |
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.
Pull Request Overview
This PR adds method chaining support to the LLMRails class by modifying all register_*
methods to return self
instead of None
. This allows for a more functional programming style where multiple registration calls can be chained together in a single expression.
Key changes:
- Updated return type annotations from
None
toSelf
for all registration methods - Added
return self
statements to enable method chaining - Imported
Self
fromtyping_extensions
to support the new return types
Comments suppressed due to low confidence (1)
nemoguardrails/rails/llm/llmrails.py:367
- The removal of the streaming token usage configuration appears unrelated to the PR's purpose of adding method chaining. This change should either be reverted or explained in the PR description as it affects functionality beyond the stated scope.
if api_key:
Hey, do I need to add tests for this? If yes, I will get to that on Wednesday |
Hey, I added tests to tests/llm_rails.py verifying that all register_* methods return self and ran the pre-commit hook:) |
self
from LLMRails.register_* methods to allow for chainingself
from LLMRails.register_* methods to allow for method chaining
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.
Looks good 👍 ! Thank you, @winstonallo!
Again, you need to run pre-commits and sign your commits, similar to your other MR. |
4cd9d4a
to
31c71e4
Compare
31c71e4
to
8575b88
Compare
@trebedea done:) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1296 +/- ##
===========================================
+ Coverage 70.20% 70.27% +0.07%
===========================================
Files 161 161
Lines 16123 16131 +8
===========================================
+ Hits 11319 11336 +17
+ Misses 4804 4795 -9
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
self
from LLMRails.register_* methods to allow for method chainingself
from LLMRails.register_* methods
Description
Return
self
from theregister_*
methods in the LLMRails class to allow for function chaining, allows for structuring the code in a more functional way:Before:
After:
Note that the
Before
version is still possible, this change would just allow for more flexible structure.Checklist