Skip to content

Commit 933e6c7

Browse files
committed
added exact match evaulator
1 parent 6ccf098 commit 933e6c7

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import ast
2+
import json
3+
from typing import Literal, Optional, Dict, Any
4+
from langevals_core.base_evaluator import (
5+
BaseEvaluator,
6+
EvaluationResultSkipped,
7+
EvaluatorEntry,
8+
EvaluationResult,
9+
EvaluatorSettings,
10+
SingleEvaluationResult,
11+
EvaluationResultError,
12+
)
13+
import markdown
14+
from pydantic import Field
15+
import sqlglot
16+
17+
18+
class ExactMatchSettings(EvaluatorSettings):
19+
pass
20+
21+
22+
class ExactMatchResult(EvaluationResult):
23+
passed: Optional[bool] = Field(
24+
default=True,
25+
description="True if the output matched the input exactly, False otherwise",
26+
)
27+
28+
29+
class ExactMatchEntry(EvaluatorEntry):
30+
input: Optional[str] = None
31+
output: Optional[str] = None
32+
33+
34+
class ExactMatchEvaluator(
35+
BaseEvaluator[ExactMatchEntry, ExactMatchSettings, ExactMatchResult]
36+
):
37+
"""
38+
A simple evaluator that checks if the output matches the input exactly.
39+
"""
40+
41+
name = "Exact Match Evaluator"
42+
category = "quality"
43+
default_settings = ExactMatchSettings()
44+
is_guardrail = False
45+
46+
def evaluate(self, entry: ExactMatchEntry) -> SingleEvaluationResult:
47+
if entry.input == entry.output:
48+
return ExactMatchResult(passed=True)
49+
50+
return ExactMatchResult(passed=False)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import dotenv
2+
3+
dotenv.load_dotenv()
4+
5+
from langevals_langevals.exact_match import (
6+
ExactMatchEvaluator,
7+
ExactMatchEntry,
8+
ExactMatchSettings,
9+
)
10+
11+
12+
def test_langeval_exact_match_evaluator_exact():
13+
entry = ExactMatchEntry(
14+
input="What is the capital of France?",
15+
output="What is the capital of France?",
16+
)
17+
settings = ExactMatchSettings()
18+
19+
evaluator = ExactMatchEvaluator(settings=settings)
20+
result = evaluator.evaluate(entry)
21+
22+
assert result == True
23+
24+
25+
def test_langeval_exact_match_evaluator_different():
26+
entry = ExactMatchEntry(
27+
input="What is the capital of France?",
28+
output="The capital of France is London.",
29+
)
30+
settings = ExactMatchSettings()
31+
32+
evaluator = ExactMatchEvaluator(settings=settings)
33+
result = evaluator.evaluate(entry)
34+
35+
assert result == False

0 commit comments

Comments
 (0)