1111if TYPE_CHECKING :
1212 from hive .models .base import BaseProvider
1313
14- _JUDGE_PROMPT = """You are grading an AI assistant's answer.
14+ _JUDGE_RUBRIC = (
15+ "Rate how well the actual answer satisfies the expected answer on a scale of 0 to "
16+ "10 (10 = fully correct and complete, 0 = wrong or missing). Reply with ONLY the "
17+ "number on the first line, then a one-sentence justification."
18+ )
1519
16- Task given to the assistant:
17- {instruction}
1820
19- Expected answer (reference) :
20- {expected}
21+ def _build_judge_prompt ( instruction : str , expected : str , actual : str ) -> str :
22+ """Build the judge prompt by concatenation.
2123
22- Assistant's actual answer:
23- {actual}
24-
25- Rate how well the actual answer satisfies the expected answer on a scale of 0 to 10
26- (10 = fully correct and complete, 0 = wrong or missing). Reply with ONLY the number
27- on the first line, then a one-sentence justification."""
24+ Avoids ``str.format``/f-string substitution so brace characters in the instruction,
25+ expected answer, or actual output (e.g. JSON like ``{"k": 1}``) can't raise.
26+ """
27+ return (
28+ "You are grading an AI assistant's answer.\n \n "
29+ f"Task given to the assistant:\n { instruction } \n \n "
30+ f"Expected answer (reference):\n { expected } \n \n "
31+ f"Assistant's actual answer:\n { actual } \n \n "
32+ f"{ _JUDGE_RUBRIC } "
33+ )
2834
2935
3036class AccuracyEval :
@@ -41,9 +47,7 @@ async def evaluate(self, run: EvalRun, case: EvalCase) -> CaseResult:
4147 return CaseResult (
4248 case , self .name , True , 1.0 , "no expected_answer (skipped)" , run , skipped = True
4349 )
44- prompt = _JUDGE_PROMPT .format (
45- instruction = case .instruction , expected = case .expected_answer , actual = run .output
46- )
50+ prompt = _build_judge_prompt (case .instruction , case .expected_answer , run .output )
4751 result = await self ._judge .generate_with_metadata (messages = [Message .user (prompt )])
4852 score , detail = self ._parse (result .message .content )
4953 return CaseResult (case , self .name , score >= self ._threshold , score , detail , run )
0 commit comments