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

Function _parse_single_answer

src/benchmarks/elaipbench/evaluate.py:28–48  ·  view source on GitHub ↗

Extract a single answer letter (A/B/C/D) from the response.

(response: str)

Source from the content-addressed store, hash-verified

26
27
28def _parse_single_answer(response: str) -> Optional[str]:
29 """Extract a single answer letter (A/B/C/D) from the response."""
30 valid = {"A", "B", "C", "D"}
31 patterns = [
32 r"answer is \((.)\)",
33 r"Answer: \((.)\)",
34 r"answer: \((.)\)",
35 r"answer is ([A-D])\b",
36 r"Answer: ([A-D])\b",
37 ]
38 for pattern in patterns:
39 match = re.search(pattern, response)
40 if match and match.group(1) in valid:
41 return match.group(1)
42
43 # Fallback: last standalone (X) pattern
44 matches = re.findall(r"\(([A-D])\)", response)
45 if matches:
46 return matches[-1]
47
48 return None
49
50
51def _parse_multi_answer(response: str) -> Optional[str]:

Callers 1

parse_answerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected