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

Cover Edge Case: Empty array instead of None for Assistant tool calls #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 src/mistral_common/protocol/instruct/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _aggregate_assistant_messages(self, messages: List[UATS]) -> AssistantMessag
weight: Optional[float] = None
for message in messages:
assert isinstance(message, self._assistant_message_class), "Expected assistant message"
if message.tool_calls is not None:
if message.tool_calls:
for tool_call in message.tool_calls:
normalized_tool_call = self._normalize_tool_call(tool_call)
tool_calls.append(normalized_tool_call)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ def test_normalize_funcalls(self, normalizer: InstructRequestNormalizer) -> None
normalized = normalizer.from_chat_completion_request(request)
assert normalized == gt

def test_normalize_empty_array_tool_calls(self, normalizer: InstructRequestNormalizer) -> None:
message = AssistantMessage(role="assistant", content="Hello", tool_calls=[])
normalized_message = normalizer._aggregate_assistant_messages([message])
assert normalized_message.content == "Hello"

class TestFineTuningNormalizer:
@pytest.fixture(autouse=True)
Expand Down