Skip to content

Commit 71ca139

Browse files
author
Arena AI Agent
committed
feat(research): 🔬 inject scientific rigor (deterministic temp 0.0, seed 42, epistemic grounding, LLM-as-a-Judge)
1 parent 8fee457 commit 71ca139

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""LLM-as-a-Judge for Automated, Scientific Epistemic Evaluation (G-Eval style)."""
2+
from pydantic import BaseModel, Field
3+
from typing import Dict, Any
4+
from epistemic_forge.llm import generate_structured
5+
6+
class JudgeEvaluation(BaseModel):
7+
"""Strict schema for the AI Judge."""
8+
logical_coherence_score: int = Field(ge=1, le=5, description="1-5 score on how well the premises support the conclusion.")
9+
hallucination_detected: bool = Field(description="True if the text makes empirical claims without warrants.")
10+
critique: str = Field(description="Academic peer-review style critique of the artifact.")
11+
12+
def evaluate_artifact_quality(question: str, artifact_text: str) -> Dict[str, Any]:
13+
"""Uses a stronger model (e.g., GPT-4o) to judge the output of the cheaper pipeline."""
14+
messages = [
15+
{"role": "system", "content": "You are a highly critical, NeurIPS-level peer reviewer. Evaluate the following research artifact for logical coherence and hallucination."},
16+
{"role": "user", "content": f"Research Question: {question}\n\nArtifact Output:\n{artifact_text}"}
17+
]
18+
19+
# We use a heavier model for judging, but keep temp 0.0 for deterministic grading
20+
evaluation = generate_structured(
21+
messages=messages,
22+
response_model=JudgeEvaluation,
23+
model="gpt-4o-2024-08-06"
24+
)
25+
26+
return {
27+
"score": evaluation.logical_coherence_score,
28+
"hallucination": evaluation.hallucination_detected,
29+
"critique": evaluation.critique
30+
}

‎epistemic_forge/llm.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""SOTA LLM Engine using Instructor and Pydantic for Strict Structured Outputs."""
1+
"""SOTA LLM Engine using Instructor and Pydantic for Strict Structured Outputs.
2+
ENFORCES: Reproducibility (Seed 42, Temp 0.0) for scientific benchmarks.
3+
"""
24
import instructor
35
from openai import OpenAI
46
from pydantic import BaseModel
@@ -15,23 +17,25 @@
1517
def generate_structured(
1618
messages: list,
1719
response_model: type[BaseModel],
18-
model: str = "gpt-4o-2024-08-06",
19-
temperature: float = 0.0
20+
model: str = "gpt-4o-mini",
21+
temperature: float = 0.0,
22+
seed: int = 42
2023
) -> BaseModel:
2124
"""
22-
State-of-the-Art Structured Extraction.
23-
Guarantees the output strictly matches the Pydantic schema using JSON Mode / Tool Calls.
25+
Research-Grade Extraction.
26+
Enforces Temperature=0.0 and Seed=42 to guarantee deterministic, reproducible scientific output.
2427
"""
2528
if not client:
2629
raise ValueError("LLM Client is not initialized. Please set OPENAI_API_KEY.")
2730

2831
try:
29-
logger.debug(f"Initiating strict structured call to {model} for schema [{response_model.__name__}]...")
32+
logger.debug(f"Initiating scientifically rigorous call to {model} [temp={temperature}, seed={seed}] for schema [{response_model.__name__}]...")
3033
response = client.chat.completions.create(
3134
model=model,
3235
messages=messages,
3336
response_model=response_model,
3437
temperature=temperature,
38+
seed=seed
3539
)
3640
return response
3741
except Exception as e:

‎epistemic_forge/models.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class HegelianDialecticOutput(BaseModel):
162162
steelmanned_antithesis: str = Field(description="The absolute strongest possible argument against the core thesis.")
163163
synthesis_resolution: str = Field(description="The nuanced truth that reconciles the thesis and the antithesis.")
164164
remaining_uncertainties: List[str] = Field(description="Questions that still lack sufficient evidence.")
165+
epistemic_confidence: float = Field(ge=0.0, le=1.0, description="Confidence in the synthesis based on available evidence.")
166+
source_warrant: str = Field(description="The exact logical warrant or grounded theory that justifies this synthesis.")
165167

166168
class ChainOfDensityOutput(BaseModel):
167169
"""Strict schema for the Chain of Density Architect."""

0 commit comments

Comments
 (0)