Commits
Click on a commit to change the comparison rangefix(core): include llm_output in streaming LLMResult
Fixes #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 callbacks2 days ago
by zhangzhefang-github test(core): update test expectations for llm_output in streaming mode
Fix test_event_stream_with_simple_chain to expect llm_output={} instead of llm_output=None in streaming mode, consistent with the fix for issue #340572 days ago
by zhangzhefang-github fix(core): ensure llm_output is always dict in LLMResult, never None
This commit comprehensively fixes issue #34057 where streaming mode
was returning LLMResult with llm_output: None instead of llm_output: {}.
Root cause: Multiple code paths were creating ChatResult/LLMResult
without explicitly setting llm_output={}, causing it to default to None.
Changes:
- chat_models.py: Added llm_output={} to cache retrieval paths (sync/async),
generate_from_stream(), and SimpleChatModel._generate()
- llms.py: Added llm_output={} to SimpleLLM._generate() and _agenerate()
- fake_chat_models.py: Fixed all 4 fake model _generate() methods
- event_stream.py: Improved llm_output serialization in on_llm_end()
- test_runnable_events_v1.py: Updated test expectations
Tests:
- test_astream_events_from_model: PASSED ✓
- test_event_stream_with_simple_chain: PASSED ✓
- All linting checks: PASSED ✓2 days ago
by zhangzhefang-github