Skip to content

Conversation

sunyuhan1998
Copy link
Contributor

As mentioned in the issue, there is currently a problem in DeepSeekStreamFunctionCallingHelper when merging instances where toolCalls() is an empty list rather than null. This PR fixes that issue.

Additionally, I noticed that the class previously lacked unit tests, so I've added relevant test cases.

Through these new tests, I discovered an issue in the DeepSeekStreamFunctionCallingHelper#merge(ChatCompletionMessage, ChatCompletionMessage) method:

String content = (current.content() != null ? current.content()
        : "" + ((previous.content() != null) ? previous.content() : ""));

This line has an operator precedence problem. The string concatenation operator + has higher precedence than the ternary operator ? :, so the expression is effectively parsed as:

String content = current.content() != null 
    ? current.content() 
    : ("" + ((previous.content() != null) ? previous.content() : ""));

This means that if current.content() is not null, it is returned directly, and only when it is null does the string concatenation with previous.content() occur. This behavior clearly deviates from the intended merge logic.

The correct behavior should be to concatenate the contents of both previous and current. This PR fixes the issue, ensuring that message content is properly merged regardless of whether current.content() is null, and the fix is validated through newly added unit tests.

Fixes #4586

…reamFunctionCallingHelper` when `toolCalls()` returns an empty list instead of null; corrected a flawed ternary expression; and added corresponding unit tests to improve code robustness.

Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeepSeekStreamFunctionCallingHelper#merge throw NoSuchElementException

2 participants