Bug description
After the recent updates, the ChatClient for Ollama started throwing NullPointerException
when invoking the call
method.
It looks like it expects the Prompt
to contain some options besides the list of Messages
. In the case of Ollama, those options are null, and the code doesn't handle that scenario.
Context: https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaChatClient.java#L140
Environment Spring AI: 0.8.0-SNAPSHOT (as of today, January 25th, 22:46 UTC) Java: 21 Ollama
Steps to reproduce
See example section for more details.
General steps:
1. Autowire ChatClient
2. Call chatClient.call("What is the capital of Italy?")
3. The request fails due to a NullPointerException
Expected behavior The call should be sent successfully to Ollama.
Minimal Complete Reproducible example Sample project reproducing the error is available here: https://github.com/ThomasVitale/llm-apps-java-spring-ai/tree/main/01-chat-models/chat-models-ollama. It's a self-contained example with no external dependency other than Java 21 and Docker (no need to install Ollama, the application takes care of that).
Logs
java.lang.NullPointerException: Cannot invoke "java.util.Map.entrySet()" because "sourceMap" is null
at org.springframework.ai.ollama.OllamaChatClient.merge(OllamaChatClient.java:175) ~[spring-ai-ollama-0.8.0-SNAPSHOT.jar:0.8.0-SNAPSHOT]
at org.springframework.ai.ollama.OllamaChatClient.request(OllamaChatClient.java:141) ~[spring-ai-ollama-0.8.0-SNAPSHOT.jar:0.8.0-SNAPSHOT]
at org.springframework.ai.ollama.OllamaChatClient.call(OllamaChatClient.java:90) ~[spring-ai-ollama-0.8.0-SNAPSHOT.jar:0.8.0-SNAPSHOT]
at org.springframework.ai.chat.ChatClient.call(ChatClient.java:28) ~[spring-ai-core-0.8.0-SNAPSHOT.jar:0.8.0-SNAPSHOT]
at com.thomasvitale.ai.spring.ChatController.chat(ChatController.java:19) ~[main/:na]
...
Comment From: tzolov
Thanks @ThomasVitale This is is another bug indeed. The fix is underway.
Comment From: tzolov
Resolved by 944c4ebbaa6e28bf4c34027a5cc08ca353e06160