mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: Session input file are required for creating an eval case
Session input file contains fields that are needed to run evals and later be able retrieve the session generated by them. Co-authored-by: Ankur Sharma <ankusharma@google.com> PiperOrigin-RevId: 825742522
This commit is contained in:
committed by
Copybara-Service
parent
b23eed6a85
commit
72a8d8d85b
@@ -754,10 +754,8 @@ def cli_create_eval_set(
|
||||
type=click.Path(
|
||||
exists=True, dir_okay=False, file_okay=True, resolve_path=True
|
||||
),
|
||||
help=(
|
||||
"Optional. Path to session file containing SessionInput in JSON format."
|
||||
),
|
||||
default=None,
|
||||
help="Path to session file containing SessionInput in JSON format.",
|
||||
required=True,
|
||||
)
|
||||
@eval_options()
|
||||
def cli_add_eval_case(
|
||||
@@ -787,10 +785,8 @@ def cli_add_eval_case(
|
||||
eval_sets_manager = get_eval_sets_manager(eval_storage_uri, agents_dir)
|
||||
|
||||
try:
|
||||
session_input = None
|
||||
if session_input_file:
|
||||
with open(session_input_file, "r") as f:
|
||||
session_input = SessionInput.model_validate_json(f.read())
|
||||
with open(session_input_file, "r") as f:
|
||||
session_input = SessionInput.model_validate_json(f.read())
|
||||
|
||||
with open(scenarios_file, "r") as f:
|
||||
conversation_scenarios = ConversationScenarios.model_validate_json(
|
||||
|
||||
@@ -643,50 +643,6 @@ def test_cli_create_eval_set(tmp_path: Path):
|
||||
assert eval_set_data["eval_cases"] == []
|
||||
|
||||
|
||||
def test_cli_add_eval_case_no_session(tmp_path: Path):
|
||||
app_name = "test_app_add_1"
|
||||
eval_set_id = "test_eval_set_add_1"
|
||||
agent_path = tmp_path / app_name
|
||||
agent_path.mkdir()
|
||||
(agent_path / "__init__.py").touch()
|
||||
|
||||
scenarios_file = tmp_path / "scenarios1.json"
|
||||
scenarios_file.write_text(
|
||||
'{"scenarios": [{"starting_prompt": "hello", "conversation_plan":'
|
||||
' "world"}]}'
|
||||
)
|
||||
|
||||
runner = CliRunner()
|
||||
runner.invoke(
|
||||
cli_tools_click.main,
|
||||
["eval_set", "create", str(agent_path), eval_set_id],
|
||||
catch_exceptions=False,
|
||||
)
|
||||
result = runner.invoke(
|
||||
cli_tools_click.main,
|
||||
[
|
||||
"eval_set",
|
||||
"add_eval_case",
|
||||
str(agent_path),
|
||||
eval_set_id,
|
||||
"--scenarios_file",
|
||||
str(scenarios_file),
|
||||
],
|
||||
catch_exceptions=False,
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
eval_set_file = agent_path / f"{eval_set_id}.evalset.json"
|
||||
assert eval_set_file.exists()
|
||||
with open(eval_set_file, "r") as f:
|
||||
eval_set_data = json.load(f)
|
||||
assert len(eval_set_data["eval_cases"]) == 1
|
||||
eval_case = eval_set_data["eval_cases"][0]
|
||||
assert eval_case["eval_id"] == "0a1a5048"
|
||||
assert eval_case["conversation_scenario"]["starting_prompt"] == "hello"
|
||||
assert "session_input" not in eval_case
|
||||
|
||||
|
||||
def test_cli_add_eval_case_with_session(tmp_path: Path):
|
||||
app_name = "test_app_add_2"
|
||||
eval_set_id = "test_eval_set_add_2"
|
||||
@@ -748,6 +704,10 @@ def test_cli_add_eval_case_skip_existing(tmp_path: Path):
|
||||
'{"scenarios": [{"starting_prompt": "hello", "conversation_plan":'
|
||||
' "world"}]}'
|
||||
)
|
||||
session_file = tmp_path / "session3.json"
|
||||
session_file.write_text(
|
||||
'{"app_name": "test_app_add_3", "user_id": "test_user", "state": {}}'
|
||||
)
|
||||
|
||||
runner = CliRunner()
|
||||
runner.invoke(
|
||||
@@ -764,6 +724,8 @@ def test_cli_add_eval_case_skip_existing(tmp_path: Path):
|
||||
eval_set_id,
|
||||
"--scenarios_file",
|
||||
str(scenarios_file),
|
||||
"--session_input_file",
|
||||
str(session_file),
|
||||
],
|
||||
catch_exceptions=False,
|
||||
)
|
||||
@@ -780,6 +742,8 @@ def test_cli_add_eval_case_skip_existing(tmp_path: Path):
|
||||
eval_set_id,
|
||||
"--scenarios_file",
|
||||
str(scenarios_file),
|
||||
"--session_input_file",
|
||||
str(session_file),
|
||||
],
|
||||
catch_exceptions=False,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user