fix(core): override streaming callback if streaming attribute is set #33351
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.
Currently the presence of a streaming callback handler enables streaming, even when a chat model has a
streaming
attribute that is explicitly set to False:The
streaming
attribute is not on BaseChatModel but it is on most major chat models, including OpenAI, Anthropic, and Google GenAI. Its intended purpose is to enable streaming under the hood when calling.invoke
.OpenAI and Anthropic implement
streaming
as a boolean attribute with no sentinel value, so here we disable streaming if that attribute is explicitly set to False.N.B. BaseChatModel does implement
disable_streaming
for the complementary case, and this currently works:but the behavior with
streaming
is unintuitive, so we update it here.Ideally we would have a single
bool | None = None
attribute instead of these two booleans.