Skip to content

DeepSeekStreamFunctionCallingHelper#merge throw NoSuchElementException #4586

@wallezhang

Description

@wallezhang

Bug description
When calling DeepSeek using the stream approach and tools are invoked, the org.springframework.ai.deepseek.api.DeepSeekStreamFunctionCallingHelper#merge method returns a NoSuchElementException: null exception.

Analysis

Image

An exception was thrown on line 98. The previous stream returned a tool call. The current stream returns an array of tool calls, which is an empty array rather than null. So the current.toolCalls().iterator().next() will throw an NoSuchElementException.

I think the judgement on line 94 should be current.toolCalls() != null && !current.toolCalls().isEmpty()

Environment
Spring AI version: 1.0.3
Java Version: 21
DeepSeek v3.1

Expected behavior
Return tools successfully. Don't throw exception.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdeepseek

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions