Mukul Rayana commited on
Commit
ce15608
·
1 Parent(s): 5405e38

fix: MistralJudge schema detection for truths/claims/verdicts — matches DeepEval 3-call pattern (Day 15)

Browse files
Files changed (1) hide show
  1. eval/run_ragas.py +19 -10
eval/run_ragas.py CHANGED
@@ -48,17 +48,26 @@ class MistralJudge(DeepEvalBaseLLM):
48
  def generate(self, prompt: str) -> str:
49
  from llama_cpp import LlamaGrammar
50
  import json as _json
51
- # Use from_json_schema for grammar-constrained sampling.
52
- # Physically prevents Mistral from generating invalid JSON at token level.
53
- # Detect call type from prompt tail: claim extraction = array,
54
- # claim verification = object with verdicts array.
55
- prompt_tail = prompt[-300:].lower()
56
- is_extraction = any(w in prompt_tail for w in [
57
- "claims", "statements", "list", "extract", "identify"
58
- ])
59
- if is_extraction:
60
- schema = _json.dumps({"type": "array", "items": {"type": "string"}})
 
 
 
 
 
 
 
 
61
  else:
 
62
  schema = _json.dumps({
63
  "type": "object",
64
  "properties": {
 
48
  def generate(self, prompt: str) -> str:
49
  from llama_cpp import LlamaGrammar
50
  import json as _json
51
+ # DeepEval FaithfulnessMetric makes 3 types of calls:
52
+ # 1. Extract truths from retrieval_context {"truths": ["...", "..."]}
53
+ # 2. Extract claims from actual_output → {"claims": ["...", "..."]}
54
+ # 3. Verify claims against truths → {"verdicts": [{"verdict": "yes/no", "reason": "..."}]}
55
+ # Detect which call type from prompt keywords and use appropriate schema.
56
+ prompt_lower = prompt.lower()
57
+ if '"truths"' in prompt_lower or 'truths key' in prompt_lower:
58
+ # Call 1: extract truths from context
59
+ schema = _json.dumps({
60
+ "type": "object",
61
+ "properties": {"truths": {"type": "array", "items": {"type": "string"}}}
62
+ })
63
+ elif '"claims"' in prompt_lower or 'claims' in prompt_lower:
64
+ # Call 2: extract claims from output
65
+ schema = _json.dumps({
66
+ "type": "object",
67
+ "properties": {"claims": {"type": "array", "items": {"type": "string"}}}
68
+ })
69
  else:
70
+ # Call 3: verify claims (verdicts)
71
  schema = _json.dumps({
72
  "type": "object",
73
  "properties": {