Yongkang ZOU
commited on
Commit
·
4e6c049
1
Parent(s):
dfe572b
update answer format
Browse files
app.py
CHANGED
@@ -8,23 +8,21 @@ from langchain_core.messages import HumanMessage
|
|
8 |
|
9 |
import re
|
10 |
|
11 |
-
import re
|
12 |
-
|
13 |
def extract_answer(text: str) -> str:
|
14 |
"""
|
15 |
Clean and extract the final answer from agent output.
|
16 |
-
|
17 |
-
|
18 |
-
- Normalizes comma/semicolon-separated lists.
|
19 |
"""
|
20 |
-
# 提取
|
21 |
-
match = re.search(r"final
|
22 |
-
answer = match.group(
|
23 |
|
24 |
-
#
|
25 |
-
answer = answer.strip().
|
|
|
26 |
|
27 |
-
#
|
28 |
if ',' in answer:
|
29 |
answer = ",".join(part.strip() for part in answer.split(','))
|
30 |
if ';' in answer:
|
@@ -33,6 +31,7 @@ def extract_answer(text: str) -> str:
|
|
33 |
return answer
|
34 |
|
35 |
|
|
|
36 |
# --- Constants ---
|
37 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
38 |
|
|
|
8 |
|
9 |
import re
|
10 |
|
|
|
|
|
11 |
def extract_answer(text: str) -> str:
|
12 |
"""
|
13 |
Clean and extract the final answer from agent output.
|
14 |
+
Removes prefixes like 'FINAL ANSWER:', trims punctuation,
|
15 |
+
and normalizes separators.
|
|
|
16 |
"""
|
17 |
+
# 提取 final answer 后内容
|
18 |
+
match = re.search(r"(final\s*answer|answer\s*is)[::]?\s*(.+)", text, re.IGNORECASE)
|
19 |
+
answer = match.group(2) if match else text
|
20 |
|
21 |
+
# 清理格式
|
22 |
+
answer = answer.strip().lstrip(":").strip() # ✅ 去掉前导冒号和空格
|
23 |
+
answer = answer.rstrip('.').strip()
|
24 |
|
25 |
+
# 多项格式化
|
26 |
if ',' in answer:
|
27 |
answer = ",".join(part.strip() for part in answer.split(','))
|
28 |
if ';' in answer:
|
|
|
31 |
return answer
|
32 |
|
33 |
|
34 |
+
|
35 |
# --- Constants ---
|
36 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
37 |
|