The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
infra: fake model invoke callback prior to yielding token (#18286)
William De Vena42341bc78739
diff --git a/libs/core/tests/unit_tests/fake/chat_model.py b/libs/core/tests/unit_tests/fake/chat_model.pyindex d0135d7f11..ec03c431e3 100644--- a/libs/core/tests/unit_tests/fake/chat_model.py+++ b/libs/core/tests/unit_tests/fake/chat_model.py@@ -225,9 +225,9 @@ class GenericFakeChatModel(BaseChatModel):for token in content_chunks:chunk = ChatGenerationChunk(message=AIMessageChunk(content=token))- yield chunkif run_manager:run_manager.on_llm_new_token(token, chunk=chunk)+ yield chunkif message.additional_kwargs:for key, value in message.additional_kwargs.items():@@ -247,12 +247,12 @@ class GenericFakeChatModel(BaseChatModel):},))- yield chunkif run_manager:run_manager.on_llm_new_token("",chunk=chunk, # No token for function call)+ yield chunkelse:chunk = ChatGenerationChunk(message=AIMessageChunk(@@ -260,24 +260,24 @@ class GenericFakeChatModel(BaseChatModel):additional_kwargs={"function_call": {fkey: fvalue}},))- yield chunkif run_manager:run_manager.on_llm_new_token("",chunk=chunk, # No token for function call)+ yield chunkelse:chunk = ChatGenerationChunk(message=AIMessageChunk(content="", additional_kwargs={key: value}))- yield chunkif run_manager:run_manager.on_llm_new_token("",chunk=chunk, # No token for function call)+ yield chunkasync def _astream(self,diff --git a/libs/core/tests/unit_tests/runnables/test_runnable_events.py b/libs/core/tests/unit_tests/runnables/test_runnable_events.pyindex a31e15e7ba..54ccbbad05 100644--- a/libs/core/tests/unit_tests/runnables/test_runnable_events.py+++ b/libs/core/tests/unit_tests/runnables/test_runnable_events.py@@ -396,14 +396,6 @@ async def test_event_stream_with_simple_chain() -> None:"run_id": "","tags": ["my_chain", "my_model", "seq:step:2"],},- {- "data": {"chunk": AIMessageChunk(content="hello")},- "event": "on_chain_stream",- "metadata": {"foo": "bar"},- "name": "my_chain",- "run_id": "",- "tags": ["my_chain"],- },{"data": {"chunk": AIMessageChunk(content="hello")},"event": "on_chat_model_stream",@@ -413,7 +405,7 @@ async def test_event_stream_with_simple_chain() -> None:"tags": ["my_chain", "my_model", "seq:step:2"],},{- "data": {"chunk": AIMessageChunk(content=" ")},+ "data": {"chunk": AIMessageChunk(content="hello")},"event": "on_chain_stream","metadata": {"foo": "bar"},"name": "my_chain",@@ -429,7 +421,7 @@ async def test_event_stream_with_simple_chain() -> None:"tags": ["my_chain", "my_model", "seq:step:2"],},{- "data": {"chunk": AIMessageChunk(content="world!")},+ "data": {"chunk": AIMessageChunk(content=" ")},"event": "on_chain_stream","metadata": {"foo": "bar"},"name": "my_chain",@@ -444,6 +436,14 @@ async def test_event_stream_with_simple_chain() -> None:"run_id": "","tags": ["my_chain", "my_model", "seq:step:2"],},+ {+ "data": {"chunk": AIMessageChunk(content="world!")},+ "event": "on_chain_stream",+ "metadata": {"foo": "bar"},+ "name": "my_chain",+ "run_id": "",+ "tags": ["my_chain"],+ },{"data": {"input": {