judgeval 0.0.3__py3-none-any.whl → 0.0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. judgeval/__init__.py +0 -71
  2. judgeval/clients.py +14 -3
  3. judgeval/common/tracer.py +57 -31
  4. judgeval/constants.py +1 -0
  5. judgeval/data/__init__.py +2 -1
  6. judgeval/data/scorer_data.py +2 -2
  7. judgeval/evaluation_run.py +16 -15
  8. judgeval/judges/__init__.py +2 -2
  9. judgeval/judges/base_judge.py +1 -1
  10. judgeval/judges/litellm_judge.py +2 -2
  11. judgeval/judges/mixture_of_judges.py +2 -2
  12. judgeval/judges/together_judge.py +2 -2
  13. judgeval/judges/utils.py +4 -4
  14. judgeval/judgment_client.py +67 -15
  15. judgeval/run_evaluation.py +79 -14
  16. judgeval/scorers/__init__.py +8 -4
  17. judgeval/scorers/api_scorer.py +64 -0
  18. judgeval/scorers/base_scorer.py +3 -2
  19. judgeval/scorers/exceptions.py +11 -0
  20. judgeval/scorers/{custom_scorer.py → judgeval_scorer.py} +9 -5
  21. judgeval/scorers/judgeval_scorers/__init__.py +132 -9
  22. judgeval/scorers/judgeval_scorers/api_scorers/__init__.py +23 -0
  23. judgeval/scorers/judgeval_scorers/api_scorers/answer_correctness.py +19 -0
  24. judgeval/scorers/judgeval_scorers/{answer_relevancy.py → api_scorers/answer_relevancy.py} +2 -2
  25. judgeval/scorers/judgeval_scorers/{contextual_precision.py → api_scorers/contextual_precision.py} +2 -2
  26. judgeval/scorers/judgeval_scorers/{contextual_recall.py → api_scorers/contextual_recall.py} +2 -2
  27. judgeval/scorers/judgeval_scorers/{contextual_relevancy.py → api_scorers/contextual_relevancy.py} +2 -2
  28. judgeval/scorers/judgeval_scorers/{faithfulness.py → api_scorers/faithfulness.py} +2 -2
  29. judgeval/scorers/judgeval_scorers/{hallucination.py → api_scorers/hallucination.py} +2 -2
  30. judgeval/scorers/judgeval_scorers/{json_correctness.py → api_scorers/json_correctness.py} +7 -7
  31. judgeval/scorers/judgeval_scorers/{summarization.py → api_scorers/summarization.py} +2 -2
  32. judgeval/scorers/judgeval_scorers/{tool_correctness.py → api_scorers/tool_correctness.py} +2 -2
  33. judgeval/scorers/judgeval_scorers/local_implementations/__init__.py +24 -0
  34. judgeval/scorers/judgeval_scorers/local_implementations/answer_correctness/__init__.py +4 -0
  35. judgeval/scorers/judgeval_scorers/local_implementations/answer_correctness/answer_correctness_scorer.py +272 -0
  36. judgeval/scorers/judgeval_scorers/local_implementations/answer_correctness/prompts.py +169 -0
  37. judgeval/scorers/judgeval_scorers/local_implementations/answer_relevancy/__init__.py +4 -0
  38. judgeval/scorers/judgeval_scorers/local_implementations/answer_relevancy/answer_relevancy_scorer.py +292 -0
  39. judgeval/scorers/judgeval_scorers/local_implementations/answer_relevancy/prompts.py +174 -0
  40. judgeval/scorers/judgeval_scorers/local_implementations/contextual_precision/__init__.py +3 -0
  41. judgeval/scorers/judgeval_scorers/local_implementations/contextual_precision/contextual_precision_scorer.py +259 -0
  42. judgeval/scorers/judgeval_scorers/local_implementations/contextual_precision/prompts.py +106 -0
  43. judgeval/scorers/judgeval_scorers/local_implementations/contextual_recall/__init__.py +3 -0
  44. judgeval/scorers/judgeval_scorers/local_implementations/contextual_recall/contextual_recall_scorer.py +249 -0
  45. judgeval/scorers/judgeval_scorers/local_implementations/contextual_recall/prompts.py +142 -0
  46. judgeval/scorers/judgeval_scorers/local_implementations/contextual_relevancy/__init__.py +3 -0
  47. judgeval/scorers/judgeval_scorers/local_implementations/contextual_relevancy/contextual_relevancy_scorer.py +240 -0
  48. judgeval/scorers/judgeval_scorers/local_implementations/contextual_relevancy/prompts.py +121 -0
  49. judgeval/scorers/judgeval_scorers/local_implementations/faithfulness/__init__.py +3 -0
  50. judgeval/scorers/judgeval_scorers/local_implementations/faithfulness/faithfulness_scorer.py +318 -0
  51. judgeval/scorers/judgeval_scorers/local_implementations/faithfulness/prompts.py +265 -0
  52. judgeval/scorers/judgeval_scorers/local_implementations/hallucination/__init__.py +3 -0
  53. judgeval/scorers/judgeval_scorers/local_implementations/hallucination/hallucination_scorer.py +258 -0
  54. judgeval/scorers/judgeval_scorers/local_implementations/hallucination/prompts.py +104 -0
  55. judgeval/scorers/judgeval_scorers/local_implementations/json_correctness/json_correctness_scorer.py +127 -0
  56. judgeval/scorers/judgeval_scorers/local_implementations/summarization/__init__.py +3 -0
  57. judgeval/scorers/judgeval_scorers/local_implementations/summarization/prompts.py +247 -0
  58. judgeval/scorers/judgeval_scorers/local_implementations/summarization/summarization_scorer.py +541 -0
  59. judgeval/scorers/judgeval_scorers/local_implementations/tool_correctness/__init__.py +3 -0
  60. judgeval/scorers/judgeval_scorers/local_implementations/tool_correctness/tool_correctness_scorer.py +151 -0
  61. judgeval/scorers/prompt_scorer.py +4 -4
  62. judgeval/scorers/score.py +14 -14
  63. judgeval/scorers/utils.py +40 -6
  64. {judgeval-0.0.3.dist-info → judgeval-0.0.5.dist-info}/METADATA +1 -1
  65. judgeval-0.0.5.dist-info/RECORD +78 -0
  66. judgeval-0.0.3.dist-info/RECORD +0 -46
  67. {judgeval-0.0.3.dist-info → judgeval-0.0.5.dist-info}/WHEEL +0 -0
  68. {judgeval-0.0.3.dist-info → judgeval-0.0.5.dist-info}/licenses/LICENSE.md +0 -0
@@ -6,11 +6,11 @@ TODO add link to docs page for this scorer
6
6
  """
7
7
 
8
8
  # Internal imports
9
- from judgeval.scorers.base_scorer import JudgmentScorer
9
+ from judgeval.scorers.api_scorer import APIJudgmentScorer
10
10
  from judgeval.constants import APIScorer
11
11
 
12
12
 
13
- class ToolCorrectnessScorer(JudgmentScorer):
13
+ class ToolCorrectnessScorer(APIJudgmentScorer):
14
14
  def __init__(self, threshold: float):
15
15
  super().__init__(threshold=threshold, score_type=APIScorer.TOOL_CORRECTNESS)
16
16
 
@@ -0,0 +1,24 @@
1
+ from judgeval.scorers.judgeval_scorers.local_implementations.answer_relevancy.answer_relevancy_scorer import AnswerRelevancyScorer
2
+ from judgeval.scorers.judgeval_scorers.local_implementations.contextual_precision.contextual_precision_scorer import ContextualPrecisionScorer
3
+ from judgeval.scorers.judgeval_scorers.local_implementations.contextual_recall.contextual_recall_scorer import ContextualRecallScorer
4
+ from judgeval.scorers.judgeval_scorers.local_implementations.contextual_relevancy.contextual_relevancy_scorer import ContextualRelevancyScorer
5
+ from judgeval.scorers.judgeval_scorers.local_implementations.faithfulness.faithfulness_scorer import FaithfulnessScorer
6
+ from judgeval.scorers.judgeval_scorers.local_implementations.json_correctness.json_correctness_scorer import JsonCorrectnessScorer
7
+ from judgeval.scorers.judgeval_scorers.local_implementations.tool_correctness.tool_correctness_scorer import ToolCorrectnessScorer
8
+ from judgeval.scorers.judgeval_scorers.local_implementations.hallucination.hallucination_scorer import HallucinationScorer
9
+ from judgeval.scorers.judgeval_scorers.local_implementations.summarization.summarization_scorer import SummarizationScorer
10
+ from judgeval.scorers.judgeval_scorers.local_implementations.answer_correctness.answer_correctness_scorer import AnswerCorrectnessScorer
11
+
12
+
13
+ __all__ = [
14
+ "AnswerCorrectnessScorer",
15
+ "AnswerRelevancyScorer",
16
+ "ContextualPrecisionScorer",
17
+ "ContextualRecallScorer",
18
+ "ContextualRelevancyScorer",
19
+ "FaithfulnessScorer",
20
+ "JsonCorrectnessScorer",
21
+ "ToolCorrectnessScorer",
22
+ "HallucinationScorer",
23
+ "SummarizationScorer",
24
+ ]
@@ -0,0 +1,4 @@
1
+ from judgeval.scorers.judgeval_scorers.local_implementations.answer_correctness.answer_correctness_scorer import AnswerCorrectnessScorer
2
+
3
+
4
+ __all__ = ["AnswerCorrectnessScorer"]
@@ -0,0 +1,272 @@
1
+ from typing import Optional, List, Union, Tuple
2
+ from pydantic import BaseModel
3
+
4
+ from judgeval.judges import JudgevalJudge
5
+ from judgeval.judges.utils import create_judge
6
+ from judgeval.data import Example, ExampleParams
7
+ from judgeval.scorers import JudgevalScorer
8
+ from judgeval.scorers.utils import (
9
+ get_or_create_event_loop,
10
+ parse_response_json,
11
+ scorer_progress_meter,
12
+ create_verbose_logs,
13
+ check_example_params,
14
+ )
15
+ from .prompts import (
16
+ ACVerdict,
17
+ AnswerCorrectnessTemplate,
18
+ Statements,
19
+ Verdicts,
20
+ Reason,
21
+ )
22
+
23
+
24
+ required_params = [
25
+ ExampleParams.INPUT,
26
+ ExampleParams.ACTUAL_OUTPUT,
27
+ ExampleParams.EXPECTED_OUTPUT,
28
+ ]
29
+
30
+
31
+ class AnswerCorrectnessScorer(JudgevalScorer):
32
+ def __init__(
33
+ self,
34
+ threshold: float = 0.5,
35
+ model: Optional[Union[str, JudgevalJudge]] = None,
36
+ include_reason: bool = True,
37
+ async_mode: bool = True,
38
+ strict_mode: bool = False,
39
+ verbose_mode: bool = False
40
+ ):
41
+ self.threshold = 1 if strict_mode else threshold
42
+ self.include_reason = include_reason
43
+ self.model, self.using_native_model = create_judge(model)
44
+ self.evaluation_model = self.model.get_model_name()
45
+ self.async_mode = async_mode
46
+ self.strict_mode = strict_mode
47
+ self.verbose_mode = verbose_mode
48
+
49
+ async def _a_get_statements(self, expected_output: str) -> List[str]:
50
+ prompt = AnswerCorrectnessTemplate.deduce_statements(
51
+ expected_output=expected_output,
52
+ )
53
+ if self.using_native_model:
54
+ res = await self.model.a_generate(prompt)
55
+ data = parse_response_json(res, self)
56
+ return data["statements"]
57
+ else:
58
+ try:
59
+ res: Statements = await self.model.a_generate(
60
+ prompt, schema=Statements
61
+ )
62
+ return res.statements
63
+ except TypeError:
64
+ res = await self.model.a_generate(prompt)
65
+ data = parse_response_json(res, self)
66
+ return data["statements"]
67
+
68
+ def _get_statements(self, expected_output: str) -> List[str]:
69
+ prompt = AnswerCorrectnessTemplate.deduce_statements(
70
+ expected_output=expected_output,
71
+ )
72
+ if self.using_native_model:
73
+ res = self.model.generate(prompt)
74
+ data = parse_response_json(res, self)
75
+ return data["statements"]
76
+ else:
77
+ try:
78
+ res: Statements = self.model.generate(
79
+ prompt, schema=Statements
80
+ )
81
+ return res.statements
82
+ except TypeError:
83
+ res = self.model.generate(prompt)
84
+ data = parse_response_json(res, self)
85
+ return data["statements"]
86
+
87
+ async def _a_get_verdicts(self, actual_output: str) -> List[ACVerdict]:
88
+ if len(self.statements) == 0:
89
+ return []
90
+
91
+ prompt = AnswerCorrectnessTemplate.generate_verdicts(
92
+ actual_output=actual_output,
93
+ statements=self.statements,
94
+ )
95
+
96
+ if self.using_native_model:
97
+ res = await self.model.a_generate(prompt)
98
+ data = parse_response_json(res, self)
99
+ return [ACVerdict(**item) for item in data["verdicts"]]
100
+ else:
101
+ try:
102
+ res: Verdicts = await self.model.a_generate(prompt, schema=Verdicts)
103
+ return [item for item in res.verdicts]
104
+ except TypeError:
105
+ res = await self.model.a_generate(prompt)
106
+ data = parse_response_json(res, self)
107
+ return [ACVerdict(**item) for item in data["verdicts"]]
108
+
109
+ def _get_verdicts(self, actual_output: str) -> List[ACVerdict]:
110
+ if len(self.statements) == 0:
111
+ return []
112
+
113
+ prompt = AnswerCorrectnessTemplate.generate_verdicts(
114
+ actual_output=actual_output,
115
+ statements=self.statements,
116
+ )
117
+
118
+ if self.using_native_model:
119
+ res = self.model.generate(prompt)
120
+ data = parse_response_json(res, self)
121
+ return [ACVerdict(**item) for item in data["verdicts"]]
122
+ else:
123
+ try:
124
+ res: Verdicts = self.model.generate(prompt, schema=Verdicts)
125
+ return [item for item in res.verdicts]
126
+ except TypeError:
127
+ res = self.model.generate(prompt)
128
+ data = parse_response_json(res, self)
129
+ return [ACVerdict(**item) for item in data["verdicts"]]
130
+
131
+ async def _a_get_reason(self) -> str:
132
+ if self.include_reason is False:
133
+ return None
134
+
135
+ incorrect_statements: List[Tuple[str, str]] = []
136
+ for idx, verdict in enumerate(self.verdicts):
137
+ if verdict.verdict.strip().lower() == "no":
138
+ incorrect_statements.append((self.statements[idx], verdict.reason))
139
+
140
+ prompt = AnswerCorrectnessTemplate.generate_reason(
141
+ incorrect_statements=incorrect_statements,
142
+ score=format(self.score, ".2f"),
143
+ )
144
+ if self.using_native_model:
145
+ res = await self.model.a_generate(prompt)
146
+ data = parse_response_json(res, self)
147
+ return data["reason"]
148
+ else:
149
+ try:
150
+ res: Reason = await self.model.a_generate(
151
+ prompt=prompt, schema=Reason
152
+ )
153
+ return res.reason
154
+ except TypeError:
155
+ res = await self.model.a_generate(prompt)
156
+ data = parse_response_json(res, self)
157
+ return data["reason"]
158
+
159
+ def _get_reason(self) -> str:
160
+ if self.include_reason is False:
161
+ return None
162
+
163
+ incorrect_statements: List[Tuple[str, str]] = []
164
+ for idx, verdict in enumerate(self.verdicts):
165
+ if verdict.verdict.strip().lower() == "no":
166
+ incorrect_statements.append((self.statements[idx], verdict.reason))
167
+
168
+ prompt = AnswerCorrectnessTemplate.generate_reason(
169
+ incorrect_statements=incorrect_statements,
170
+ score=format(self.score, ".2f"),
171
+ )
172
+ if self.using_native_model:
173
+ res = self.model.generate(prompt)
174
+ data = parse_response_json(res, self)
175
+ return data["reason"]
176
+ else:
177
+ try:
178
+ res: Reason = self.model.generate(
179
+ prompt=prompt, schema=Reason
180
+ )
181
+ return res.reason
182
+ except TypeError:
183
+ res = self.model.generate(prompt)
184
+ data = parse_response_json(res, self)
185
+ return data["reason"]
186
+
187
+ def _compute_score(self) -> float:
188
+ number_of_verdicts = len(self.verdicts)
189
+ if number_of_verdicts == 0:
190
+ return 1
191
+
192
+ correct_count = 0
193
+ for verdict in self.verdicts:
194
+ if verdict.verdict.strip().lower() == "yes":
195
+ correct_count += 1
196
+
197
+ score = correct_count / number_of_verdicts
198
+ return 0 if self.strict_mode and score < self.threshold else score
199
+
200
+ def score_example(
201
+ self,
202
+ example: Example,
203
+ _show_indicator: bool = True,
204
+ ) -> float:
205
+ check_example_params(example, required_params, self)
206
+
207
+ with scorer_progress_meter(self, display_meter=_show_indicator):
208
+ try:
209
+ if self.async_mode:
210
+ loop = get_or_create_event_loop()
211
+ loop.run_until_complete(
212
+ self.a_score_example(example, _show_indicator=False)
213
+ )
214
+ else:
215
+ self.statements = self._get_statements(example.expected_output)
216
+ self.verdicts = self._get_verdicts(example.actual_output)
217
+ self.score = self._compute_score()
218
+ self.reason = self._get_reason()
219
+ self.success = self.score >= self.threshold
220
+ self.verbose_logs = create_verbose_logs(
221
+ self,
222
+ steps=[
223
+ f"Statements:\n{self.statements}",
224
+ f"Verdicts:\n{[v.model_dump() for v in self.verdicts]}",
225
+ f"Score: {self.score}\nReason: {self.reason}",
226
+ ],
227
+ )
228
+ return self.score
229
+ except Exception as e:
230
+ print(f"Error in score_example for AnswerCorrectnessScorer: {e}")
231
+ raise
232
+
233
+ async def a_score_example(
234
+ self,
235
+ example: Example,
236
+ _show_indicator: bool = True,
237
+ ) -> float:
238
+ check_example_params(example, required_params, self)
239
+
240
+ with scorer_progress_meter(self, async_mode=True, display_meter=_show_indicator):
241
+ try:
242
+ self.statements: List[str] = await self._a_get_statements(example.expected_output)
243
+ self.verdicts: List[ACVerdict] = await self._a_get_verdicts(example.actual_output)
244
+ self.score = self._compute_score()
245
+ self.reason = await self._a_get_reason()
246
+ self.success = self.score >= self.threshold
247
+ self.verbose_logs = create_verbose_logs(
248
+ self,
249
+ steps=[
250
+ f"Statements:\n{self.statements}",
251
+ f"Verdicts:\n{[v.model_dump() for v in self.verdicts]}",
252
+ f"Score: {self.score}\nReason: {self.reason}",
253
+ ],
254
+ )
255
+ return self.score
256
+ except Exception as e:
257
+ print(f"Error in a_score_example for AnswerCorrectnessScorer: {e}")
258
+ raise
259
+
260
+ def _success_check(self) -> bool:
261
+ if self.error is not None:
262
+ self.success = False
263
+ else:
264
+ try:
265
+ self.success = self.score >= self.threshold
266
+ except:
267
+ self.success = False
268
+ return self.success
269
+
270
+ @property
271
+ def __name__(self):
272
+ return "Answer Correctness"
@@ -0,0 +1,169 @@
1
+ """
2
+ Util prompts for AnswerCorrectnessScorer
3
+ """
4
+
5
+ from typing import List, Optional, Tuple
6
+ from pydantic import BaseModel, Field
7
+
8
+
9
+ # BaseModels to enforce formatting in LLM JSON response
10
+ class Statements(BaseModel):
11
+ statements: List[str]
12
+
13
+
14
+ class ACVerdict(BaseModel):
15
+ verdict: str
16
+ reason: str
17
+
18
+
19
+ class Verdicts(BaseModel):
20
+ verdicts: List[ACVerdict]
21
+
22
+
23
+ class Reason(BaseModel):
24
+ reason: str
25
+
26
+
27
+ class AnswerCorrectnessTemplate:
28
+ @staticmethod
29
+ def deduce_statements(expected_output):
30
+ return f"""You will be presented with a piece of text. Your task is to break down the text and generate a list of statements contained within the text. Single words and ambiguous phrases should be considered statements.
31
+
32
+ ===== START OF EXAMPLES =====
33
+ Example 1:
34
+ Example text: The weather is sunny today. Temperature is 75 degrees. Don't forget your sunscreen!
35
+
36
+ Output:
37
+ {{
38
+ "statements": ["The weather is sunny today", "Temperature is 75 degrees", "Don't forget your sunscreen!"]
39
+ }}
40
+
41
+ Example 2:
42
+ Example text: I love pizza. It has cheese and tomato sauce and the crust is crispy.
43
+
44
+ Output:
45
+ {{
46
+ "statements": ["I love pizza", "It has cheese and tomato sauce", "The crust is crispy"]
47
+ }}
48
+ ===== END OF EXAMPLES =====
49
+
50
+
51
+ **
52
+ IMPORTANT: Please return your answer in valid JSON format, with the "statements" key mapping to a list of strings. No words or explanation is needed.
53
+ **
54
+
55
+ ==== START OF INPUT ====
56
+ Text:
57
+ {expected_output}
58
+ ==== END OF INPUT ====
59
+
60
+ ==== YOUR ANSWER ====
61
+ JSON:
62
+ """
63
+
64
+ @staticmethod
65
+ def generate_verdicts(statements, actual_output):
66
+ return f"""You will be provided with:\n
67
+ - a list of statements from a text that we will refer to as expected output
68
+ - a text that we will refer to as actual output\n
69
+
70
+ Your task is to determine whether each statement from the expected output is correct/consistent with the actual output text.
71
+ More specifically, you should generate a JSON object with the key "verdicts". "verdicts" will map to a list of nested JSON objects with two keys: `verdict` and `reason`.
72
+ The "reason" key should provide an explanation for your choice, regardless of which verdict you select. Try providing quotes from the text(s) to justify your answer where possible.
73
+ The "verdict" key be EXACTLY EITHER "yes" or "no". You should select "yes" if the statement is correct/consistent based on the actual output and "no" otherwise.
74
+
75
+ ==== OUTPUT FORMATTING ====
76
+ IMPORTANT: Please make sure to only return in JSON format, with the "verdicts" key mapping to a list of JSON objects. Each JSON object should contain keys "verdict" (one of "yes" or "no") and "reason" (str).
77
+
78
+ ==== START OF EXAMPLES ====
79
+ Example input 1: What's the capital of France?
80
+ Example expected output statements 1: ["Paris is the capital of France", "It is located in northern France", "The city has a population of over 2 million"]
81
+ Example actual output 1: "Paris is the capital city of France. It is situated in the northern part of the country and has over 2 million residents."
82
+ Example JSON 1:
83
+ {{
84
+ "verdicts": [
85
+ {{
86
+ "verdict": "yes",
87
+ "reason": "The actual output directly states 'Paris is the capital city of France', which matches the statement"
88
+ }},
89
+ {{
90
+ "verdict": "yes",
91
+ "reason": "The actual output confirms this by saying it is 'situated in the northern part of the country'"
92
+ }},
93
+ {{
94
+ "verdict": "yes",
95
+ "reason": "The actual output mentions the city 'has over 2 million residents', matching the population statement"
96
+ }}
97
+ ]
98
+ }}
99
+
100
+ Example input 2: What is the largest planet in our solar system?
101
+ Example expected output statements 2: ["Jupiter is the largest planet", "It is a gas giant", "Jupiter has 79 known moons", "The Great Red Spot is a storm on Jupiter"]
102
+ Example actual output 2: "Jupiter is the biggest planet in the solar system. It is made mostly of gas. The planet has many moons orbiting it."
103
+ Example JSON 2:
104
+ {{
105
+ "verdicts": [
106
+ {{
107
+ "verdict": "yes",
108
+ "reason": "The actual output confirms 'Jupiter is the biggest planet', which is equivalent to it being the largest"
109
+ }},
110
+ {{
111
+ "verdict": "yes",
112
+ "reason": "The actual output states it is 'made mostly of gas', indicating it is a gas giant"
113
+ }},
114
+ {{
115
+ "verdict": "no",
116
+ "reason": "While the actual output mentions Jupiter has 'many moons', it does not specify the exact number of 79 known moons"
117
+ }},
118
+ {{
119
+ "verdict": "no",
120
+ "reason": "The actual output makes no mention of the Great Red Spot or any storms on Jupiter"
121
+ }}
122
+ ]
123
+ }}
124
+ ==== END OF EXAMPLES ====
125
+
126
+ ** LASTLY **
127
+ Since you are tasked to choose a verdict for each statement, the number of "verdicts" SHOULD BE EXACTLY EQUAL to the number of "statements".
128
+
129
+
130
+ ==== YOUR TURN =====
131
+
132
+ Statements:
133
+ {statements}
134
+
135
+ Actual output:
136
+ {actual_output}
137
+
138
+ JSON:
139
+ """
140
+
141
+ @staticmethod
142
+ def generate_reason(incorrect_statements: List[Tuple[str, str]], score: float):
143
+ incorrect_statements = "\n".join([f"statement: {statement}\nreason: {reason}\n------" for statement, reason in incorrect_statements])
144
+ return f"""==== TASK INSTRUCTIONS ====\nYou will provided with two inputs: an answer correctness score and a list of inconsistent/incorrect statements made in a model's output (with the reason why it's irrelevant). Your task is to provide a CLEAR and CONCISE reason for the answer correctness score.
145
+ For context, there were a list of statements generated from an expected output. The model's actual output was then compared to the expected output, and we collected a list of claims made in the expected output that were either incorrect or inconsistent with the actual output.
146
+ The score represents how well the model's output matches the expected output.
147
+ You should explain why the score is not higher, but also include why its current score is fair.
148
+ The incorrect statements represent parts of the model output that are incorrect or inconsistent with the expected output. The incorrect statement will be paired with the reason why it's incorrect.
149
+ If there are no incorrect statements, instead respond with a positive remark with an upbeat encouraging tone (but don't overblow the kind attitude).
150
+
151
+
152
+ ==== FORMATTING YOUR ANSWER ====
153
+ IMPORTANT: Please make sure to only return in JSON format, with the 'reason' key providing the reason.
154
+ Example JSON:
155
+ {{
156
+ "reason": "The score is <answer_relevancy_score> because <your_reason>."
157
+ }}
158
+
159
+ ==== YOUR TURN ====
160
+ ---- ANSWER CORRECTNESS SCORE ----
161
+ {score}
162
+
163
+ ---- INCORRECT STATEMENTS ----
164
+ {incorrect_statements}
165
+
166
+ ---- YOUR RESPONSE ----
167
+ JSON:
168
+ """
169
+
@@ -0,0 +1,4 @@
1
+ from judgeval.scorers.judgeval_scorers.local_implementations.answer_relevancy.answer_relevancy_scorer import AnswerRelevancyScorer
2
+
3
+
4
+ __all__ = ["AnswerRelevancyScorer"]