MCPcopy Index your code
hub / github.com/CodeGoat24/UniGenBench / parse_evaluation_response

Function parse_evaluation_response

eval/src/eval_common.py:228–258  ·  view source on GitHub ↗

Parse XML-formatted model response to extract analysis and score. Returns: (analysis, score) tuple on success, None on failure.

(text, testpoint)

Source from the content-addressed store, hash-verified

226
227
228def parse_evaluation_response(text, testpoint):
229 """Parse XML-formatted model response to extract analysis and score.
230
231 Returns:
232 (analysis, score) tuple on success, None on failure.
233 """
234 if text is None:
235 return None
236
237 analysis_match = re.search(r"<analysis>(.*?)</analysis>", text, re.DOTALL)
238 score_match = re.search(r"<score>(.*?)</score>", text, re.DOTALL)
239
240 if analysis_match is None or score_match is None:
241 print("Warning: <analysis> or <score> tags not found in response")
242 return None
243
244 try:
245 analysis = ast.literal_eval(analysis_match.group(1).strip())
246 score = ast.literal_eval(score_match.group(1).strip())
247 except (ValueError, SyntaxError) as e:
248 print(f"Warning: failed to parse response: {e}")
249 return None
250
251 if len(testpoint) != len(analysis) or len(testpoint) != len(score):
252 print(
253 f"Warning: length mismatch - testpoint({len(testpoint)}) "
254 f"vs analysis({len(analysis)}) vs score({len(score)})"
255 )
256 return None
257
258 return analysis, score
259
260
261def make_result(index, testpoint, prompt, img_path, output_text, result_json=None):

Callers 2

call_evaluation_geminiFunction · 0.85
call_evaluation_vllmFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected