-
Notifications
You must be signed in to change notification settings - Fork 19.8k
fix(core): include llm_output in streaming LLMResult #34060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(core): include llm_output in streaming LLMResult #34060
Conversation
CodSpeed Performance ReportMerging #34060 will not alter performanceComparing
|
a3c8aef to
1087773
Compare
Fixes langchain-ai#34057 Previously, streaming mode did not include the `llm_output` field in the `LLMResult` object passed to `on_llm_end` callbacks. This broke integrations like Langfuse that rely on this field to extract metadata such as model name. This commit ensures that `llm_output` is always present in streaming mode by passing an empty dict `{}` in all streaming methods (`stream` and `astream`) for both `BaseLLM` and `BaseChatModel`. Changes: - Updated `BaseLLM.stream()` to include `llm_output={}` in LLMResult - Updated `BaseLLM.astream()` to include `llm_output={}` in LLMResult - Updated `BaseChatModel.stream()` to include `llm_output={}` in LLMResult - Updated `BaseChatModel.astream()` to include `llm_output={}` in LLMResult - Added test to verify `llm_output` is present in streaming callbacks
b2abc0d to
4813a9a
Compare
Update test_runnable_events_v1.py to expect llm_output={} instead of
llm_output=None in streaming mode, consistent with the fix for issue langchain-ai#34057.
This ensures that llm_output is always a dict ({}) rather than None when
callbacks receive LLMResult in streaming mode.
This commit comprehensively fixes issue langchain-ai#34057 by ensuring llm_output={} in ALL code paths, not just streaming: Changes to chat_models.py: - Added llm_output={} to cache retrieval paths (sync/async) - Added llm_output={} to generate_from_stream() - Added llm_output={} to SimpleChatModel._generate() Changes to llms.py: - Added llm_output={} to SimpleLLM._generate() and _agenerate() Changes to fake_chat_models.py: - Added llm_output={} to all fake model _generate() methods: - FakeMessagesListChatModel - GenericFakeChatModel - ParrotFakeChatModel This ensures that llm_output is consistently an empty dict rather than None across streaming, non-streaming, cached, and fake model paths.
Split long line to comply with max line length of 88 characters.
Test Status Update✅ All relevant tests passingThis PR successfully fixes issue #34057. All tests related to the fix are passing:
|
|
Update: I've created issue #34076 to track the pre-existing |
Summary
Fixes #34057 - Ensures that streaming mode includes
llm_outputfield inLLMResult, fixing broken callback integrations.Description
Previously, when using streaming mode (
stream()orastream()), theLLMResultpassed toon_llm_endcallbacks was missing thellm_outputfield. This caused issues for callback handlers like Langfuse that rely on this field to extract metadata such as model names.This PR adds
llm_output={}to all streamingon_llm_endcalls in bothBaseLLMandBaseChatModel, ensuring consistency with non-streaming behavior.Changes
BaseLLM.stream()to includellm_output={}in LLMResultBaseLLM.astream()to includellm_output={}in LLMResultBaseChatModel.stream()to includellm_output={}in LLMResultBaseChatModel.astream()to includellm_output={}in LLMResulttest_stream_llm_result_contains_llm_output()to verify the fixTest Plan
llm_outputfield is present and is a dict in streaming modeGenericFakeChatModelusing callback handler