Skip to content

Commit 97a4168

Browse files
committed
add test
1 parent f938def commit 97a4168

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/google/adk/evaluation/llm_as_judge_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def get_text_from_content(
7676
if final_text:
7777
parts.append(final_text)
7878

79-
return "\n\n".join(parts) if parts else None
79+
return "\n".join(parts) if parts else None
8080

8181
if content and content.parts:
8282
return "\n".join([p.text for p in content.parts if p.text])

tests/unittests/evaluation/test_llm_as_judge_utils.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from google.adk.evaluation.app_details import AgentDetails
2020
from google.adk.evaluation.app_details import AppDetails
2121
from google.adk.evaluation.eval_case import IntermediateData
22+
from google.adk.evaluation.eval_case import Invocation
2223
from google.adk.evaluation.eval_case import InvocationEvent
2324
from google.adk.evaluation.eval_case import InvocationEvents
2425
from google.adk.evaluation.eval_rubrics import RubricScore
@@ -88,6 +89,49 @@ def test_get_text_from_content_with_mixed_parts():
8889
assert get_text_from_content(content) == "Hello\nWorld"
8990

9091

92+
def test_get_text_from_content_with_invocation_include_intermediate_responses_in_final():
93+
"""Tests get_text_from_content on an Invocation with and without the flag."""
94+
intermediate_text = "Let me check."
95+
final_response_text = "Done."
96+
invocation = Invocation(
97+
user_content=genai_types.Content(parts=[genai_types.Part(text="user")]),
98+
intermediate_data=InvocationEvents(
99+
invocation_events=[
100+
InvocationEvent(
101+
author="agent",
102+
content=genai_types.Content(
103+
parts=[genai_types.Part(text=intermediate_text)]
104+
),
105+
),
106+
InvocationEvent(
107+
author="tool",
108+
content=genai_types.Content(
109+
parts=[
110+
genai_types.Part(
111+
function_call=genai_types.FunctionCall(name="t")
112+
)
113+
]
114+
),
115+
),
116+
]
117+
),
118+
final_response=genai_types.Content(
119+
parts=[genai_types.Part(text=final_response_text)]
120+
),
121+
)
122+
123+
# Flag off (default): only the final response text is returned.
124+
assert get_text_from_content(invocation) == final_response_text
125+
126+
# Flag on: intermediate text is concatenated before the final response.
127+
assert (
128+
get_text_from_content(
129+
invocation, include_intermediate_responses_in_final=True
130+
)
131+
== f"{intermediate_text}\n{final_response_text}"
132+
)
133+
134+
91135
def test_get_eval_status_with_none_score():
92136
"""Tests get_eval_status returns NOT_EVALUATED for a None score."""
93137
assert get_eval_status(score=None, threshold=0.5) == EvalStatus.NOT_EVALUATED

0 commit comments

Comments
 (0)