@@ -224,7 +224,7 @@ async def tap_output_aiter(
224
224
yield chunk
225
225
226
226
def tap_output_iter (self , run_id : UUID , output : Iterator [T ]) -> Iterator [T ]:
227
- """Tap the output aiter .
227
+ """Tap the output iter .
228
228
229
229
Args:
230
230
run_id: The ID of the run.
@@ -315,7 +315,7 @@ async def on_chat_model_start(
315
315
name : Optional [str ] = None ,
316
316
** kwargs : Any ,
317
317
) -> None :
318
- """Start a trace for an LLM run."""
318
+ """Start a trace for a chat model run."""
319
319
name_ = _assign_name (name , serialized )
320
320
run_type = "chat_model"
321
321
@@ -357,7 +357,7 @@ async def on_llm_start(
357
357
name : Optional [str ] = None ,
358
358
** kwargs : Any ,
359
359
) -> None :
360
- """Start a trace for an LLM run."""
360
+ """Start a trace for a (non-chat model) LLM run."""
361
361
name_ = _assign_name (name , serialized )
362
362
run_type = "llm"
363
363
@@ -421,6 +421,10 @@ async def on_llm_new_token(
421
421
parent_run_id : Optional [UUID ] = None ,
422
422
** kwargs : Any ,
423
423
) -> None :
424
+ """Run on new output token. Only available when streaming is enabled.
425
+
426
+ For both chat models and non-chat models (legacy LLMs).
427
+ """
424
428
run_info = self .run_map .get (run_id )
425
429
chunk_ : Union [GenerationChunk , BaseMessageChunk ]
426
430
@@ -466,17 +470,15 @@ async def on_llm_new_token(
466
470
async def on_llm_end (
467
471
self , response : LLMResult , * , run_id : UUID , ** kwargs : Any
468
472
) -> None :
469
- """End a trace for an LLM run.
473
+ """End a trace for a model run.
470
474
471
- Args:
472
- response (LLMResult): The response which was generated.
473
- run_id (UUID): The run ID. This is the ID of the current run.
475
+ For both chat models and non-chat models (legacy LLMs).
474
476
475
477
Raises:
476
478
ValueError: If the run type is not ``'llm'`` or ``'chat_model'``.
477
479
"""
478
480
run_info = self .run_map .pop (run_id )
479
- inputs_ = run_info [ "inputs" ]
481
+ inputs_ = run_info . get ( "inputs" )
480
482
481
483
generations : Union [list [list [GenerationChunk ]], list [list [ChatGenerationChunk ]]]
482
484
output : Union [dict , BaseMessage ] = {}
@@ -654,10 +656,6 @@ async def on_tool_start(
654
656
async def on_tool_end (self , output : Any , * , run_id : UUID , ** kwargs : Any ) -> None :
655
657
"""End a trace for a tool run.
656
658
657
- Args:
658
- output: The output of the tool.
659
- run_id: The run ID. This is the ID of the current run.
660
-
661
659
Raises:
662
660
AssertionError: If the run ID is a tool call and does not have inputs
663
661
"""
@@ -742,7 +740,7 @@ async def on_retriever_end(
742
740
"event" : "on_retriever_end" ,
743
741
"data" : {
744
742
"output" : documents ,
745
- "input" : run_info [ "inputs" ] ,
743
+ "input" : run_info . get ( "inputs" ) ,
746
744
},
747
745
"run_id" : str (run_id ),
748
746
"name" : run_info ["name" ],
@@ -854,12 +852,12 @@ async def _astream_events_implementation_v1(
854
852
# Usually they will NOT be available for components that operate
855
853
# on streams, since those components stream the input and
856
854
# don't know its final value until the end of the stream.
857
- inputs = log_entry [ "inputs" ]
855
+ inputs = log_entry . get ( "inputs" )
858
856
if inputs is not None :
859
857
data ["input" ] = inputs
860
858
861
859
if event_type == "end" :
862
- inputs = log_entry [ "inputs" ]
860
+ inputs = log_entry . get ( "inputs" )
863
861
if inputs is not None :
864
862
data ["input" ] = inputs
865
863
0 commit comments