Skip to content

fix(#2414): honor ModelCreationContext.stream in OllamaChatModel [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #2417

Closed
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-2414-ollama-stream
Closed

fix(#2414): honor ModelCreationContext.stream in OllamaChatModel [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]#2417
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-2414-ollama-stream

Conversation

@waterWang

Copy link
Copy Markdown

What

OllamaChatModel.doStream() previously ignored the streaming setting and always passed true to streamWithHttpClient(). When a caller creates the model with stream=false (via ModelCreationContext.stream) and consumes the result with blockLast(), they received empty content — the Ollama done marker carries no message.content.

Why it matters

  • ModelCreationContext.stream is never consulted, so the per-call streaming preference is lost.
  • Calling ollama:xxx with stream=false and blockLast() yields an empty response body.
  • Behavior is inconsistent with the reference implementation (OpenAIChatModel) which honors the flag end-to-end.

Changes (4 touch points)

OllamaChatModel.java:

  • Added instance field private boolean stream = true to preserve existing streaming default (backward compatible).
  • Added setStream(boolean) setter (and isStream() getter) on the model.
  • Added private boolean stream = true field to Builder plus a public Builder stream(boolean) method.
  • Builder.build() now passes the flag to the model via model.setStream(stream).
  • doStream(...) now dispatches on the effective stream value (instance field, overridable per-call via GenerateOptions.stream) instead of the hardcoded true.

OllamaModelProvider.java:

  • applyAdvancedOptions(...) now reads context.getStream() and forwards it to builder.stream(...) when present.

Verification

  • Existing streaming behavior is preserved (default is true).
  • streamWithHttpClient(..., boolean stream) already handles both paths correctly; this fix only passes the correct boolean.
  • Mirrors the approach used in OpenAIChatModel.

Closes #2414

…hatModel [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]
@CLAassistant

CLAassistant commented Jul 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jujn

jujn commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

fixed in: #2415

@jujn jujn closed this Jul 27, 2026
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...scope/extensions/model/ollama/OllamaChatModel.java 54.54% 4 Missing and 1 partial ⚠️
...e/extensions/model/ollama/OllamaModelProvider.java 33.33% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:OllamaChatModel.doStream ignores ModelCreationContext.stream, returns empty response when consumed via blockLast()

3 participants