Fix Ollama streaming null generate options#1648
Conversation
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a NullPointerException in OllamaChatModel.doStream() when GenerateOptions is null. The base class ChatModelBase contract explicitly documents options as "null to use defaults", but doStream() called options.getToolChoice() without a null-guard, causing an NPE. The fix introduces a null-safe effectiveOptions fallback (GenerateOptions.builder().build()) — a clean, minimal one-line guard that is consistent with the project's existing null-handling patterns (e.g., OllamaOptions.fromGenerateOptions(null) already returns a default instance, and the constructor null-guards defaultOptions). A well-structured regression test covers stream(messages, null, null). The non-streaming chat() path was already null-safe via OllamaOptions.fromGenerateOptions(). No issues found.
AgentScope-Java Version
Version: agentscope-harness:2.0.0-RC1
Java: 21
Description
Fixes #1644
This PR fixes a NullPointerException in the Ollama streaming path when
GenerateOptionsis not explicitly configured.Background:
HarnessAgent.streamEvents()can ultimately call the Ollama model streaming API withGenerateOptions == null.OllamaChatModel.doStream(...)previously accessedoptions.getToolChoice()directly, which caused an NPE. Non-streaming calls were unaffected because the options conversion path already handled null values.Changes made:
GenerateOptions.builder().build()inOllamaChatModel.doStream(...).OllamaChatModel.stream(..., null)to ensure streaming works without explicit generate options.How to test:
mvn -pl agentscope-core -Dtest=OllamaChatModelTest testmvn -pl agentscope-core -Dtest=OllamaChatModelTest#testStreamChatRequestWithNullOptions testgit diff --checkChecklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)