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- 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 |
-
#
|
| 52 |
-
#
|
| 53 |
-
#
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": {
|