Skip to content
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

fix: chat auto, gracefully handle when str not found #781

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dataquality/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"""


__version__ = "1.1.5"
__version__ = "1.1.6"

import sys
from typing import Any, List, Optional
Expand Down
7 changes: 6 additions & 1 deletion dataquality/integrations/seq2seq/formatters/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ def format_sample(
# instance of the user or assistant role and start there
first_user_index = parsed_history.find(f"{self.user}: ")
first_assistant_index = parsed_history.find(f"{self.assistant}: ")
start_index = min(first_user_index, first_assistant_index)
# .find() returns -1 if the substring is not found, we must ignore those
non_negative = [
val for val in [first_user_index, first_assistant_index] if val >= 0
]
# If both are -1, we just take the last max_input_tokens tokens
start_index = min(non_negative) if non_negative else -self.max_input_tokens
user_inputs[i] = parsed_history[start_index:]

return formatted_sample