Skip to content

Commit 377ea7e

Browse files
committed
fix: satisfy eval grounding typing
1 parent 954dc21 commit 377ea7e

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/google/adk/evaluation/evaluation_generator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def convert_events_to_eval_invocations(
626626
invocations = []
627627
for invocation_id, events in events_by_invocation_id.items():
628628
final_response = None
629-
final_event = None
629+
final_event: Optional[Event] = None
630630
user_content = Content(parts=[])
631631
invocation_timestamp = 0
632632
app_details = None
@@ -636,7 +636,7 @@ def convert_events_to_eval_invocations(
636636
):
637637
app_details = app_details_per_invocation[invocation_id]
638638

639-
events_to_add = []
639+
events_to_add: list[Event] = []
640640

641641
for event in events:
642642
current_author = (event.author or _DEFAULT_AUTHOR).lower()
@@ -670,7 +670,11 @@ def convert_events_to_eval_invocations(
670670

671671
invocation_events = []
672672
for e in events_to_add:
673-
if e is final_event and not e.grounding_metadata:
673+
if (
674+
final_event is not None
675+
and e is final_event
676+
and not e.grounding_metadata
677+
):
674678
continue
675679
invocation_events.append(
676680
InvocationEvent(

src/google/adk/evaluation/llm_as_judge_utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import enum
1818
import statistics
1919
from typing import Any
20+
from typing import cast
2021
from typing import Optional
2122
from typing import Union
2223

@@ -224,11 +225,14 @@ def get_grounding_metadata_as_json_str(
224225
if not grounding_metadata:
225226
return "No grounding metadata was provided."
226227

227-
return _GroundingMetadataEntries(
228-
grounding_metadata=grounding_metadata
229-
).model_dump_json(
230-
indent=2,
231-
exclude_unset=True,
232-
exclude_defaults=True,
233-
exclude_none=True,
228+
return cast(
229+
str,
230+
_GroundingMetadataEntries(
231+
grounding_metadata=grounding_metadata
232+
).model_dump_json(
233+
indent=2,
234+
exclude_unset=True,
235+
exclude_defaults=True,
236+
exclude_none=True,
237+
),
234238
)

0 commit comments

Comments
 (0)