@@ -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 ] = {}
@@ -705,10 +707,6 @@ async def on_tool_error(
705
707
async def on_tool_end (self , output : Any , * , run_id : UUID , ** kwargs : Any ) -> None :
706
708
"""End a trace for a tool run.
707
709
708
- Args:
709
- output: The output of the tool.
710
- run_id: The run ID. This is the ID of the current run.
711
-
712
710
Raises:
713
711
AssertionError: If the run ID is a tool call and does not have inputs
714
712
"""
@@ -786,7 +784,7 @@ async def on_retriever_end(
786
784
"event" : "on_retriever_end" ,
787
785
"data" : {
788
786
"output" : documents ,
789
- "input" : run_info [ "inputs" ] ,
787
+ "input" : run_info . get ( "inputs" ) ,
790
788
},
791
789
"run_id" : str (run_id ),
792
790
"name" : run_info ["name" ],
@@ -898,12 +896,12 @@ async def _astream_events_implementation_v1(
898
896
# Usually they will NOT be available for components that operate
899
897
# on streams, since those components stream the input and
900
898
# don't know its final value until the end of the stream.
901
- inputs = log_entry [ "inputs" ]
899
+ inputs = log_entry . get ( "inputs" )
902
900
if inputs is not None :
903
901
data ["input" ] = inputs
904
902
905
903
if event_type == "end" :
906
- inputs = log_entry [ "inputs" ]
904
+ inputs = log_entry . get ( "inputs" )
907
905
if inputs is not None :
908
906
data ["input" ] = inputs
909
907
0 commit comments