Spaces:
Build error
Build error
Download utils/parse.py from Asapyams/Final_Agent_For_Submission: direct link, hf CLI and curl.
- Browser
- Download file 740 Bytes
-
https://huggingface.co/spaces/Asapyams/Final_Agent_For_Submission/resolve/main/utils/parse.py
- Command line
-
hf download hf://spaces/Asapyams/Final_Agent_For_Submission/utils/parse.py
-
curl -L -o parse.py https://huggingface.co/spaces/Asapyams/Final_Agent_For_Submission/resolve/main/utils/parse.py
740 Bytes
| import re | |
| def parse_answer(output: str) -> str: | |
| """ | |
| Extract the final answer from a chain-of-thought style LLM output. | |
| 1. Look for the last occurrence of 'Answer:' (case-insensitive) and return the text after it. | |
| 2. If no 'Answer:' marker is found, return the last non-empty line. | |
| """ | |
| # Find all occurrences of 'Answer: ...' | |
| matches = re.findall(r"Answer\s*:\s*(.+)", output, flags=re.IGNORECASE) | |
| if matches: | |
| return matches[-1].strip() | |
| # Fallback: return the last non-empty line | |
| lines = [line.strip() for line in output.strip().splitlines() if line.strip()] | |
| if lines: | |
| return lines[-1] | |
| # If output is empty or no lines found, return the raw output | |
| return output.strip() | |