Adds eval cases to the given eval set. There are several ways that an eval case can be created, for now this method only supports adding one using a conversation scenarios file. If an eval case for the generated id already exists, then we skip adding it.
(
agent_module_file_path: str,
eval_set_id: str,
scenarios_file: str,
eval_storage_uri: str | None = None,
session_input_file: str | None = None,
log_level: str = "INFO",
)
| 1377 | ) |
| 1378 | @eval_options() |
| 1379 | def cli_add_eval_case( |
| 1380 | agent_module_file_path: str, |
| 1381 | eval_set_id: str, |
| 1382 | scenarios_file: str, |
| 1383 | eval_storage_uri: str | None = None, |
| 1384 | session_input_file: str | None = None, |
| 1385 | log_level: str = "INFO", |
| 1386 | ): |
| 1387 | """Adds eval cases to the given eval set. |
| 1388 | |
| 1389 | There are several ways that an eval case can be created, for now this method |
| 1390 | only supports adding one using a conversation scenarios file. |
| 1391 | |
| 1392 | If an eval case for the generated id already exists, then we skip adding it. |
| 1393 | """ |
| 1394 | logs.setup_adk_logger(getattr(logging, log_level.upper())) |
| 1395 | try: |
| 1396 | from ..evaluation.conversation_scenarios import ConversationScenarios |
| 1397 | from ..evaluation.eval_case import EvalCase |
| 1398 | from ..evaluation.eval_case import SessionInput |
| 1399 | from .cli_eval import get_eval_sets_manager |
| 1400 | |
| 1401 | except ModuleNotFoundError as mnf: |
| 1402 | raise click.ClickException(MISSING_EVAL_DEPENDENCIES_MESSAGE) from mnf |
| 1403 | |
| 1404 | app_name = os.path.basename(agent_module_file_path) |
| 1405 | agents_dir = os.path.dirname(agent_module_file_path) |
| 1406 | eval_sets_manager = get_eval_sets_manager(eval_storage_uri, agents_dir) |
| 1407 | |
| 1408 | try: |
| 1409 | with open(session_input_file, "r") as f: |
| 1410 | session_input = SessionInput.model_validate_json(f.read()) |
| 1411 | |
| 1412 | with open(scenarios_file, "r") as f: |
| 1413 | conversation_scenarios = ConversationScenarios.model_validate_json( |
| 1414 | f.read() |
| 1415 | ) |
| 1416 | |
| 1417 | for scenario in conversation_scenarios.scenarios: |
| 1418 | scenario_str = json.dumps(scenario.model_dump(), sort_keys=True) |
| 1419 | eval_id = hashlib.sha256(scenario_str.encode("utf-8")).hexdigest()[:8] |
| 1420 | eval_case = EvalCase( |
| 1421 | eval_id=eval_id, |
| 1422 | conversation_scenario=scenario, |
| 1423 | session_input=session_input, |
| 1424 | creation_timestamp=datetime.now().timestamp(), |
| 1425 | ) |
| 1426 | |
| 1427 | if ( |
| 1428 | eval_sets_manager.get_eval_case( |
| 1429 | app_name=app_name, eval_set_id=eval_set_id, eval_case_id=eval_id |
| 1430 | ) |
| 1431 | is None |
| 1432 | ): |
| 1433 | eval_sets_manager.add_eval_case( |
| 1434 | app_name=app_name, eval_set_id=eval_set_id, eval_case=eval_case |
| 1435 | ) |
| 1436 | click.echo( |
nothing calls this directly
no test coverage detected