ChatOllama in "astream_events" is switching from "on_chat_model_stream" to "on_llm_stream" #29383
Open
5 tasks done
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
Checked other resources
Example Code
This is my astream_events code:
Error Message and Stack Trace (if applicable)
No response
Description
Hi,
I am using ChatOllama and astream_events to stream my responses. I see a weird behaviour when using the astream_events function. When I call my LLM for the first time in a session, streaming works as expected and the event type is "'event': 'on_chat_model_stream'" as expected. However when I run the same question again the event type switches to "on_llm_stream". With this bug my code is not fetching the new event and the streaming does not work.
I see there is a field "Is_model_type: chat" which might be another way to debug this, however I wanted to report this weird behaviour.
First question:
'data': {'chunk': AIMessageChunk(content='-Le', id='run-80026f5b-cc9b-443a-a9f2-3f14188d25a6')}, 'parent_ids': []} ungs{'event': 'on_chat_model_stream', 'name': 'ChatOllama', 'run_id': '80026f5b-cc9b-443a-a9f2-3f14188d25a6', 'tags': ['seq:step:1'], 'metadata': {'thread_id': 'maxiw', 'langgraph_step': 3, 'langgraph_node': 'generate', 'langgraph_triggers': ['format_docs'], 'langgraph_task_idx': 0, 'thread_ts': '1efd9a0b-1fca-6892-8002-4d1eb12a4ad1', 'ls_provider': 'ollama', 'ls_model_name': 'maxiweissenbacher/sauerkrautlm-nistral-nemo-12b-instruct:fp16', 'ls_model_type': 'chat', 'ls_temperature': 0.1}, 'data':
Second question:
'data': {'chunk': AIMessageChunk(content=' Antwort', id='run-f16ce854-ba43-4225-8418-fbe5c1a3a6da')}, 'parent_ids': []} lie{'event': 'on_llm_stream', 'name': 'ChatOllama', 'run_id': 'f16ce854-ba43-4225-8418-fbe5c1a3a6da', 'tags': ['seq:step:1'], 'metadata': {'thread_id': 'maxiw', 'langgraph_step': 5, 'langgraph_node': 'generate', 'langgraph_triggers': ['no_docs_found_question'], 'langgraph_task_idx': 0, 'thread_ts': '1efd9a10-83d9-69dc-8004-84ec81d877c6', 'ls_provider': 'ollama', 'ls_model_name': 'maxiweissenbacher/sauerkrautlm-nistral-nemo-12b-instruct:fp16', 'ls_model_type': 'chat', 'ls_temperature': 0.1}, 'data'
System Info
ollama 0.4.7
langchain 0.2.7
langchain-community 0.2.7
langchain-core 0.2.43
langchain-experimental 0.0.63
langchain-groq 0.1.5
langchain-huggingface 0.0.3
langchain-ollama 0.1.1
langchain-openai 0.1.20
langchain-postgres 0.0.12
The text was updated successfully, but these errors were encountered: