Fixed an issue where tool calls could not function properly when using the new version of Ollama. #3372
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As stated in the issue: #3369, when using the new version of Ollama and a tool call is made, a
NullPointerException
occurs involving"evalDuration"
.This is because, according to the official Ollama API documentation: https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion, fields like
eval_duration
are only populated when the model response is completed. However, during a tool call, thefrom
method oforg.springframework.ai.ollama.OllamaChatModel
fails to handle null values properly, leading to this issue.I'm not entirely sure whether it's due to any changes Ollama may have made to the response interface. However, by adding more robust null checks, we can make this functionality work correctly.