Skip to content

Commit e3ecbc6

Browse files
committed
added exact match langeval
1 parent a12fd29 commit e3ecbc6

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed
Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
import ast
2-
import json
3-
from typing import Literal, Optional, Dict, Any
1+
from typing import Optional
42
from langevals_core.base_evaluator import (
53
BaseEvaluator,
6-
EvaluationResultSkipped,
74
EvaluatorEntry,
85
EvaluationResult,
96
EvaluatorSettings,
107
SingleEvaluationResult,
11-
EvaluationResultError,
128
)
13-
import markdown
149
from pydantic import Field
15-
import sqlglot
1610

1711

1812
class ExactMatchSettings(EvaluatorSettings):
19-
pass
13+
case_sensitive: bool = Field(
14+
default=False,
15+
description="True if the comparison should be case-sensitive, False otherwise",
16+
)
17+
trim_whitespace: bool = Field(
18+
default=True,
19+
description="True if the comparison should trim whitespace, False otherwise",
20+
)
21+
remove_punctuation: bool = Field(
22+
default=True,
23+
description="True if the comparison should remove punctuation, False otherwise",
24+
)
25+
2026

2127

2228
class ExactMatchResult(EvaluationResult):
@@ -35,7 +41,8 @@ class ExactMatchEvaluator(
3541
BaseEvaluator[ExactMatchEntry, ExactMatchSettings, ExactMatchResult]
3642
):
3743
"""
38-
A simple evaluator that checks if the output matches the input exactly.
44+
A simple evaluator that checks if the output matches the input exactly, with some
45+
extra bells and whistles to help with whitespace related shenanigans.
3946
"""
4047

4148
name = "Exact Match Evaluator"
@@ -44,7 +51,26 @@ class ExactMatchEvaluator(
4451
is_guardrail = False
4552

4653
def evaluate(self, entry: ExactMatchEntry) -> SingleEvaluationResult:
47-
if entry.input == entry.output:
48-
return ExactMatchResult(passed=True)
54+
# Get input and output
55+
input_text = entry.input or ""
56+
output_text = entry.output or ""
57+
58+
# Apply settings
59+
if self.settings.trim_whitespace:
60+
input_text = input_text.strip()
61+
output_text = output_text.strip()
62+
63+
if self.settings.remove_punctuation:
64+
input_text = ''.join(char for char in input_text if char.isalnum() or char.isspace())
65+
output_text = ''.join(char for char in output_text if char.isalnum() or char.isspace())
66+
67+
if not self.settings.case_sensitive:
68+
input_text = input_text.lower()
69+
output_text = output_text.lower()
70+
71+
# Perform comparison
72+
passed = input_text == output_text
4973

50-
return ExactMatchResult(passed=False)
74+
# Return result
75+
return ExactMatchResult(passed=passed)
76+

0 commit comments

Comments
 (0)