-
Notifications
You must be signed in to change notification settings - Fork 646
Consistent type checks for prepend and append tags. #1824
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,11 +110,22 @@ def __call__( | |
if message.role in self.template: | ||
prepend_tag = self.template[message.role][0] | ||
append_tag = self.template[message.role][1] | ||
content = ( | ||
[{"type": "text", "content": prepend_tag}] | ||
+ message.content | ||
+ [{"type": "text", "content": append_tag}] | ||
) | ||
if isinstance(prepend_tag, str) and isinstance(append_tag, str): | ||
content = ( | ||
[{"type": "text", "content": prepend_tag}] | ||
+ message.content | ||
+ [{"type": "text", "content": append_tag}] | ||
) | ||
elif not isinstance(prepend_tag, str) and isinstance(append_tag, str): | ||
content = message.content + [ | ||
{"type": "text", "content": append_tag} | ||
] | ||
elif isinstance(prepend_tag, str) and not isinstance(append_tag, str): | ||
content = [ | ||
{"type": "text", "content": prepend_tag} | ||
] + message.content | ||
else: | ||
content = {message.content} | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: you could move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
content = message.content | ||
formatted_dialogue.append( | ||
|
@@ -183,13 +194,30 @@ def __call__( | |
and index == len(messages) - 1 | ||
and len(message.text_content) == 0 | ||
): | ||
content = [{"type": "text", "content": prepend_tag}] + message.content | ||
if isinstance(prepend_tag, str): | ||
content = [ | ||
{"type": "text", "content": prepend_tag} | ||
] + message.content | ||
else: | ||
content = message.content | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
else: | ||
content = ( | ||
[{"type": "text", "content": prepend_tag}] | ||
+ message.content | ||
+ [{"type": "text", "content": append_tag}] | ||
) | ||
if isinstance(prepend_tag, str) and isinstance(append_tag, str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar comment above |
||
content = ( | ||
[{"type": "text", "content": prepend_tag}] | ||
+ message.content | ||
+ [{"type": "text", "content": append_tag}] | ||
) | ||
elif not isinstance(prepend_tag, str) and isinstance(append_tag, str): | ||
content = message.content + [ | ||
{"type": "text", "content": append_tag} | ||
] | ||
elif isinstance(prepend_tag, str) and not isinstance(append_tag, str): | ||
content = [ | ||
{"type": "text", "content": prepend_tag} | ||
] + message.content | ||
else: | ||
content = {message.content} | ||
|
||
formatted_dialogue.append( | ||
Message( | ||
role=message.role, | ||
|
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.
maybe we should structure this slightly different to avoid the cascade of ifs:
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.
It depends on if can something "bad" except None can come there
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.
Ah, I see now how do you want to do it. Ok, let me fix it like this. But I would like to save isinstance there