MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / _evaluate_single

Function _evaluate_single

src/benchmarks/writing_bench/evaluate.py:105–166  ·  view source on GitHub ↗

Evaluate a single result file. Returns the score dict or None if skipped.

(
    json_path: Path,
    eval_path: Path,
    benchmark: Dict[int, dict],
    client: LLMClient,
    judge_model: str,
    force: bool,
)

Source from the content-addressed store, hash-verified

103
104
105def _evaluate_single(
106 json_path: Path,
107 eval_path: Path,
108 benchmark: Dict[int, dict],
109 client: LLMClient,
110 judge_model: str,
111 force: bool,
112) -> Optional[dict]:
113 """Evaluate a single result file. Returns the score dict or None if skipped."""
114 # Use cached eval if available
115 if eval_path.exists() and not force:
116 try:
117 with eval_path.open("r") as f:
118 return json.load(f)
119 except Exception:
120 pass
121
122 with json_path.open("r") as f:
123 run_data = json.load(f)
124
125 index = run_data.get("index")
126 if index not in benchmark:
127 return None
128
129 bm_entry = benchmark[index]
130 query = bm_entry["query"]
131 checklist = bm_entry["checklist"]
132 response_text = run_data.get("response", "")
133 is_completed = run_data.get("status") == "completed"
134
135 if not response_text or not is_completed:
136 result = {
137 "index": index,
138 "status": "skipped",
139 "scores": {},
140 }
141 else:
142 response_clean = _strip_think_prefix(response_text)
143 scores: Dict[str, list] = {}
144
145 for criteria in checklist:
146 name = criteria["name"]
147 scores[name] = []
148 for _ in range(EVAL_TIMES):
149 score_result = _call_judge(
150 client, query, response_clean, criteria, judge_model
151 )
152 if score_result:
153 scores[name].append(score_result)
154 else:
155 scores[name].append({"score": 0, "reason": "Judge failed"})
156
157 result = {
158 "index": index,
159 "status": "evaluated",
160 "scores": scores,
161 }
162

Callers 1

evaluateFunction · 0.85

Calls 3

_strip_think_prefixFunction · 0.85
_call_judgeFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected