Skip to content

Conversation

mdrxy
Copy link
Collaborator

@mdrxy mdrxy commented Aug 27, 2025

Important

This is a breaking change

_should_stream() in BaseChatModel wasn't checking the instance-level streaming parameter, leading to streaming being enabled even when explicitly disabled

  • Before: ChatOpenAI().stream() always attempted streaming (ignored streaming=False)
  • After: ChatOpenAI().stream() respects streaming=False and falls back to invoke()

Any existing code doing:

model = ChatOpenAI()  # streaming=False by default
for chunk in model.stream(messages):  # This now calls invoke() instead of streaming!
    process(chunk)

@mdrxy mdrxy requested a review from eyurtsev as a code owner August 27, 2025 02:17
@mdrxy mdrxy added the core Related to the package `langchain-core` label Aug 27, 2025
Copy link

vercel bot commented Aug 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 8, 2025 8:21pm

Copy link

codspeed-hq bot commented Aug 27, 2025

CodSpeed WallTime Performance Report

Merging #32707 will improve performances by 13.02%

Comparing mdrxy/fix-oai-stream (8f1f9e4) with master (97dd762)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

⚡ 5 improvements
✅ 8 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_import_time[BaseChatModel] 586.7 ms 519.1 ms +13.02%
test_import_time[ChatPromptTemplate] 663.3 ms 602.7 ms +10.06%
test_import_time[Document] 229.3 ms 206.9 ms +10.86%
test_import_time[InMemoryRateLimiter] 182 ms 164.6 ms +10.54%
test_import_time[PydanticOutputParser] 597.8 ms 542.4 ms +10.2%

Copy link

codspeed-hq bot commented Aug 27, 2025

CodSpeed Instrumentation Performance Report

Merging #32707 will not alter performance

Comparing mdrxy/fix-oai-stream (8f1f9e4) with master (97dd762)

Summary

✅ 14 untouched benchmarks

@@ -350,7 +350,7 @@ def mock_glm4_completion() -> list:

async def test_glm4_astream(mock_glm4_completion: list) -> None:
llm_name = "glm-4"
llm = ChatOpenAI(model=llm_name, stream_usage=True)
llm = ChatOpenAI(model=llm_name, stream_usage=True, streaming=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit tests needed updating because they were relying on the old behavior where the streaming parameter was ignored. Now they need to set streaming=True to test streaming. This is breaking - I'll update description to reflect.

@mdrxy mdrxy assigned ccurme and mdrxy Sep 8, 2025
@mdrxy mdrxy changed the title fix(core): _should_stream respects streaming param !fix(core): _should_stream respects streaming param Sep 8, 2025
Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is motivating this change?

I think the underlying issue is that streaming: bool = False on BaseChatOpenAI has no sentinel value— ideally it should be streaming: bool | None = None.

I think intended usage is that

llm = ChatOpenAI(model="...")
llm.stream(...)

streams without you having to explicitly specify streaming=True in the constructor. Otherwise this is (very) breaking and it's unclear what the benefit is.

@ccurme
Copy link
Collaborator

ccurme commented Sep 10, 2025

Can re-open if needed.

@ccurme ccurme closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the package `langchain-core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants