MCPcopy
hub / github.com/algorithmicsuperintelligence/optillm / extract_answer

Method extract_answer

optillm/rstar.py:316–344  ·  view source on GitHub ↗
(self, final_state: str)

Source from the content-addressed store, hash-verified

314 return 0.0 # If it's not a valid number, return a low score
315
316 def extract_answer(self, final_state: str) -> Tuple[str, float]:
317 logger.debug(f"Extracting answer from state: {final_state}")
318 patterns = [
319 r"The answer is (\d+)",
320 r"The final answer is (\d+)",
321 r"Therefore, the answer is (\d+)",
322 r"So, the answer is (\d+)",
323 r"Thus, the answer is (\d+)",
324 r"In conclusion, the answer is (\d+)",
325 ]
326
327 for pattern in patterns:
328 match = re.search(pattern, final_state)
329 if match:
330 answer = match.group(1)
331 confidence = 1.0
332 logger.debug(f"Answer found using pattern '{pattern}': {answer}")
333 return answer, confidence
334
335 # If no pattern is found, try to extract any number
336 numbers = re.findall(r'\d+', final_state)
337 if numbers:
338 answer = numbers[-1] # Take the last number found
339 confidence = 0.5 # Lower confidence as it's not in the expected format
340 logger.debug(f"No pattern found. Using last number as answer: {answer}")
341 return answer, confidence
342
343 logger.warning("No answer found in the state.")
344 return "", 0.0
345
346 def solve(self, question: str) -> str:
347 """

Callers 2

solve_asyncMethod · 0.95
evaluateMethod · 0.95

Calls 1

searchMethod · 0.45

Tested by

no test coverage detected