|
1 | | -"""LLM-as-a-Judge for Automated, Scientific Epistemic Evaluation (G-Eval style).""" |
2 | | - |
3 | | -from pydantic import BaseModel, Field |
| 1 | +"""LLM-as-a-Judge for Automated, Scientific Epistemic Evaluation (Toulmin Model).""" |
4 | 2 | from typing import Dict, Any |
| 3 | +from epistemic_forge.models import JudgeEvaluation |
5 | 4 | from epistemic_forge.llm import generate_structured |
6 | | - |
7 | | - |
8 | | -class JudgeEvaluation(BaseModel): |
9 | | - """Strict schema for the AI Judge.""" |
10 | | - |
11 | | - logical_coherence_score: int = Field( |
12 | | - ge=1, |
13 | | - le=5, |
14 | | - description="1-5 score on how well the premises support the conclusion.", |
15 | | - ) |
16 | | - hallucination_detected: bool = Field( |
17 | | - description="True if the text makes empirical claims without warrants." |
18 | | - ) |
19 | | - critique: str = Field( |
20 | | - description="Academic peer-review style critique of the artifact." |
21 | | - ) |
22 | | - |
| 5 | +from loguru import logger |
23 | 6 |
|
24 | 7 | def evaluate_artifact_quality(question: str, artifact_text: str) -> Dict[str, Any]: |
25 | | - """Uses a stronger model (e.g., GPT-4o) to judge the output of the cheaper pipeline.""" |
| 8 | + """Uses a stronger model to judge the output based strictly on Toulmin's Model of Argumentation.""" |
| 9 | + logger.info("⚖️ Initiating strict Toulmin-based evaluation of the final artifact...") |
| 10 | + |
26 | 11 | messages = [ |
27 | 12 | { |
28 | | - "role": "system", |
29 | | - "content": "You are a highly critical, NeurIPS-level peer reviewer. Evaluate the following research artifact for logical coherence and hallucination.", |
30 | | - }, |
31 | | - { |
32 | | - "role": "user", |
33 | | - "content": f"Research Question: {question}\n\nArtifact Output:\n{artifact_text}", |
| 13 | + "role": "system", |
| 14 | + "content": ( |
| 15 | + "You are an Elite Academic Peer Reviewer specializing in the Toulmin Model of Argumentation. " |
| 16 | + "Do NOT judge the artifact based on prose or formatting. You must ONLY evaluate the strength of the 'Warrants' (do they bridge the data to the claim?) " |
| 17 | + "and the validity of the 'Rebuttals/Falsifiers' (are they real weaknesses or just strawmen?)." |
| 18 | + ) |
34 | 19 | }, |
| 20 | + {"role": "user", "content": f"Core Inquiry: {question}\n\nSubmitted Artifact:\n{artifact_text}\n\nExecute the Toulmin Evaluation."} |
35 | 21 | ] |
36 | | - |
37 | | - # We use a heavier model for judging, but keep temp 0.0 for deterministic grading |
38 | | - evaluation = generate_structured( |
39 | | - messages=messages, response_model=JudgeEvaluation, model="gpt-4o-2024-08-06" |
| 22 | + |
| 23 | + # We use a robust model for judging, maintaining temp 0.0 for deterministic grading |
| 24 | + evaluation: JudgeEvaluation = generate_structured( |
| 25 | + messages=messages, |
| 26 | + response_model=JudgeEvaluation, |
| 27 | + model="openai/gpt-4o-mini", # Standardizing to openrouter/openai model format |
| 28 | + api_base="https://openrouter.ai/api/v1" # Enforce OpenRouter for testing consistency |
40 | 29 | ) |
41 | | - |
| 30 | + |
42 | 31 | return { |
43 | 32 | "score": evaluation.logical_coherence_score, |
44 | 33 | "hallucination": evaluation.hallucination_detected, |
45 | | - "critique": evaluation.critique, |
| 34 | + "critique": evaluation.critique |
46 | 35 | } |
0 commit comments