Skip to content

Commit

Permalink
convert correct_answer_keys to list
Browse files Browse the repository at this point in the history
  • Loading branch information
aakrem committed May 16, 2024
1 parent 7424be3 commit 95b82ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
14 changes: 7 additions & 7 deletions agenta-backend/agenta_backend/resources/evaluators/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"description": "Settings for the Exact Match evaluator",
"correct_answer_keys": {
"label": "Correct Answer",
"default": "correct_answer",
"type": "string",
"default": ["correct_answer"],
"type": "array",
},
},
"description": "Exact Match evaluator determines if the output exactly matches the specified correct answer, ensuring precise alignment with expected results.",
Expand Down Expand Up @@ -40,8 +40,8 @@
},
"correct_answer_keys": {
"label": "Correct Answer",
"default": "correct_answer",
"type": "string",
"default": ["correct_answer"],
"type": "array",
},
},
"description": "Similarity Match evaluator checks if the generated answer is similar to the expected answer. You need to provide the similarity threshold. It uses the Jaccard similarity to compare the answers.",
Expand Down Expand Up @@ -81,7 +81,7 @@
},
"correct_answer_keys": {
"label": "Correct Answer",
"default": "correct_answer",
"default": ["correct_answer"],
"type": "string",
},
},
Expand Down Expand Up @@ -130,7 +130,7 @@
},
"correct_answer_keys": {
"label": "Correct Answer",
"default": "correct_answer",
"default": ["correct_answer"],
"type": "string",
},
},
Expand Down Expand Up @@ -250,7 +250,7 @@
"threshold": {"label": "Threshold", "type": "number", "required": False},
"correct_answer_keys": {
"label": "Correct Answer",
"default": "correct_answer",
"default": ["correct_answer"],
"type": "string",
},
},
Expand Down
5 changes: 1 addition & 4 deletions agenta-backend/agenta_backend/tasks/evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,7 @@ def parse_correct_answers(evaluator_config_db, data_point) -> List[CorrectAnswer
if not correct_answer_keys:
return []

# In case one evaluator has multiple correct answers
correct_answer_keys_list = [key.strip() for key in correct_answer_keys.split(",")]

for key in correct_answer_keys_list:
for key in correct_answer_keys:
correct_answer_value = data_point.get(key, "")
correct_answers.append(CorrectAnswer(key=key, value=correct_answer_value))

Expand Down
20 changes: 10 additions & 10 deletions agenta-backend/agenta_backend/tests/unit/test_evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"prefix": "He",
"case_sensitive": True,
"correct_answer_keys": "correct_answer",
"correct_answer_keys": ["correct_answer"],
},
True,
),
Expand All @@ -28,7 +28,7 @@
{
"prefix": "He",
"case_sensitive": False,
"correct_answer_keys": "correct_answer",
"correct_answer_keys": ["correct_answer"],
},
True,
),
Expand All @@ -37,7 +37,7 @@
{
"prefix": "he",
"case_sensitive": False,
"correct_answer_keys": "correct_answer",
"correct_answer_keys": ["correct_answer"],
},
True,
),
Expand All @@ -46,7 +46,7 @@
{
"prefix": "world",
"case_sensitive": True,
"correct_answer_keys": "correct_answer",
"correct_answer_keys": ["correct_answer"],
},
False,
),
Expand Down Expand Up @@ -180,37 +180,37 @@ def test_auto_contains_json(output, expected):
(
"hello world",
{"correct_answer": "hello world"},
{"threshold": 5, "correct_answer_keys": "correct_answer"},
{"threshold": 5, "correct_answer_keys": ["correct_answer"]},
True,
),
(
"hello world",
{"correct_answer": "hola mundo"},
{"threshold": 5, "correct_answer_keys": "correct_answer"},
{"threshold": 5, "correct_answer_keys": ["correct_answer"]},
False,
),
(
"hello world",
{"correct_answer": "hello world!"},
{"threshold": 2, "correct_answer_keys": "correct_answer"},
{"threshold": 2, "correct_answer_keys": ["correct_answer"]},
True,
),
(
"hello world",
{"correct_answer": "hello wor"},
{"threshold": 10, "correct_answer_keys": "correct_answer"},
{"threshold": 10, "correct_answer_keys": ["correct_answer"]},
True,
),
(
"hello world",
{"correct_answer": "hello worl"},
{"correct_answer_keys": "correct_answer"},
{"correct_answer_keys": ["correct_answer"]},
1,
),
(
"hello world",
{"correct_answer": "helo world"},
{"correct_answer_keys": "correct_answer"},
{"correct_answer_keys": ["correct_answer"]},
1,
),
],
Expand Down

0 comments on commit 95b82ef

Please sign in to comment.