2020 Protocol ,
2121 Tuple ,
2222 Union ,
23+ cast ,
2324)
2425
2526from langfuse .api .resources .commons .types import (
@@ -1220,6 +1221,9 @@ async def _process_batch_evaluation_item(
12201221 self ._create_score_for_scope (
12211222 scope = scope ,
12221223 item_id = item_id ,
1224+ trace_id = cast (ObservationsView , item ).trace_id
1225+ if scope == "observations"
1226+ else None ,
12231227 evaluation = evaluation ,
12241228 additional_metadata = metadata ,
12251229 )
@@ -1242,6 +1246,9 @@ async def _process_batch_evaluation_item(
12421246 self ._create_score_for_scope (
12431247 scope = scope ,
12441248 item_id = item_id ,
1249+ trace_id = cast (ObservationsView , item ).trace_id
1250+ if scope == "observations"
1251+ else None ,
12451252 evaluation = composite_eval ,
12461253 additional_metadata = metadata ,
12471254 )
@@ -1361,8 +1368,10 @@ async def _run_composite_evaluator(
13611368
13621369 def _create_score_for_scope (
13631370 self ,
1371+ * ,
13641372 scope : str ,
13651373 item_id : str ,
1374+ trace_id : Optional [str ] = None ,
13661375 evaluation : Evaluation ,
13671376 additional_metadata : Optional [Dict [str , Any ]],
13681377 ) -> None :
@@ -1371,6 +1380,7 @@ def _create_score_for_scope(
13711380 Args:
13721381 scope: The type of entity ("traces", "observations").
13731382 item_id: The ID of the entity.
1383+ trace_id: The trace ID of the entity; required if scope=observations
13741384 evaluation: The evaluation result to create a score from.
13751385 additional_metadata: Additional metadata to merge with evaluation metadata.
13761386 """
@@ -1393,6 +1403,7 @@ def _create_score_for_scope(
13931403 elif scope == "observations" :
13941404 self .client .create_score (
13951405 observation_id = item_id ,
1406+ trace_id = trace_id ,
13961407 name = evaluation .name ,
13971408 value = evaluation .value , # type: ignore
13981409 comment = evaluation .comment ,
0 commit comments