File tree Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments