You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
fix: check if eval config file exists
PiperOrigin-RevId: 824709118
This commit is contained in:
committed by
Copybara-Service
parent
b7dbfed4a3
commit
00d147d62f
@@ -15,6 +15,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
@@ -89,12 +90,14 @@ def get_evaluation_criteria_or_default(
|
||||
|
||||
Otherwise a default one is returned.
|
||||
"""
|
||||
if eval_config_file_path:
|
||||
if eval_config_file_path and os.path.exists(eval_config_file_path):
|
||||
with open(eval_config_file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
return EvalConfig.model_validate_json(content)
|
||||
|
||||
logger.info("No config file supplied. Using default criteria.")
|
||||
logger.info(
|
||||
"No config file supplied or file not found. Using default criteria."
|
||||
)
|
||||
return _DEFAULT_EVAL_CONFIG
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ def test_get_evaluation_criteria_or_default_returns_default():
|
||||
|
||||
|
||||
def test_get_evaluation_criteria_or_default_reads_from_file(mocker):
|
||||
mocker.patch("os.path.exists", return_value=True)
|
||||
eval_config = EvalConfig(
|
||||
criteria={"tool_trajectory_avg_score": 0.5, "response_match_score": 0.5}
|
||||
)
|
||||
@@ -36,6 +37,15 @@ def test_get_evaluation_criteria_or_default_reads_from_file(mocker):
|
||||
assert get_evaluation_criteria_or_default("dummy_path") == eval_config
|
||||
|
||||
|
||||
def test_get_evaluation_criteria_or_default_returns_default_if_file_not_found(
|
||||
mocker,
|
||||
):
|
||||
mocker.patch("os.path.exists", return_value=False)
|
||||
assert (
|
||||
get_evaluation_criteria_or_default("dummy_path") == _DEFAULT_EVAL_CONFIG
|
||||
)
|
||||
|
||||
|
||||
def test_get_eval_metrics_from_config():
|
||||
rubric_1 = Rubric(
|
||||
rubric_id="test-rubric",
|
||||
|
||||
Reference in New Issue
Block a user