-
Notifications
You must be signed in to change notification settings - Fork 431
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
Adds __repr__ to Message #1757
Adds __repr__ to Message #1757
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1757
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit c4616d6 with merge base a8a64ec (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
Super clean PR and thanks for adding tests!
Just one nit.
torchtune/data/_messages.py
Outdated
@@ -136,6 +136,10 @@ def _validate_message(self) -> None: | |||
f"Only assistant messages can be tool calls. Found role {self.role} in message: {self.text_content}" | |||
) | |||
|
|||
def __repr__(self) -> str: | |||
content_only = [content["content"] for content in self.content] | |||
return f"Message(role={self.role!r}, content={content_only!r})" |
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.
The repr
call for role
is not necessary as it will always just be a string.
awesome awesome, thanks for adding this! |
Context
What is the purpose of this PR? Is it to
Fixes #1639
Updating
__repr__
configures the output for__str__
as well. This PR diffs a little from the initial proposal by printing out the list of items. The content type is not printed out, since it can be inferred from the__repr__
itself. i.e. strings are printed directly andImage
uses the__repr__
from PIL.Changelog
__repr__
toMessage
.Test plan
pre-commit install
)pytest tests
pytest tests -m integration_test
UX