Update LG_agent.py
Browse files- LG_agent.py +16 -11
LG_agent.py
CHANGED
@@ -27,24 +27,29 @@ class AgentState(TypedDict):
|
|
27 |
messages: Annotated[list[AnyMessage], add_messages]
|
28 |
|
29 |
def extract_gaia_answer(text: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
patterns = [
|
31 |
-
r"The answer is
|
32 |
-
r"Answer
|
33 |
-
r"^([a-z0-9
|
34 |
]
|
35 |
for pattern in patterns:
|
36 |
match = re.search(pattern, text.strip(), re.IGNORECASE | re.MULTILINE)
|
37 |
if match:
|
38 |
-
|
39 |
-
if any(kw in answer for kw in ["incomplete", "missing", "clarify", "need more"]):
|
40 |
-
return match.group(1).strip()
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
-
|
|
|
45 |
|
46 |
-
#
|
47 |
-
return text.strip()
|
48 |
|
49 |
# 3. Assistant node
|
50 |
|
|
|
27 |
messages: Annotated[list[AnyMessage], add_messages]
|
28 |
|
29 |
def extract_gaia_answer(text: str) -> str:
|
30 |
+
"""
|
31 |
+
Extracts just the final answer in raw form, stripping explanation and prefixes like:
|
32 |
+
- 'The answer is: ...'
|
33 |
+
- 'Answer: ...'
|
34 |
+
- Or just the raw line if short and valid.
|
35 |
+
"""
|
36 |
patterns = [
|
37 |
+
r"The answer is:\s*(.+)",
|
38 |
+
r"Answer:\s*(.+)",
|
39 |
+
r"^([a-z0-9\s,\-]+)$", # simple raw line (numbers, text)
|
40 |
]
|
41 |
for pattern in patterns:
|
42 |
match = re.search(pattern, text.strip(), re.IGNORECASE | re.MULTILINE)
|
43 |
if match:
|
44 |
+
return match.group(1).strip().lower()
|
|
|
|
|
45 |
|
46 |
+
# Fallback: return first short line if it's probably the answer
|
47 |
+
lines = [l.strip() for l in text.strip().splitlines() if l.strip()]
|
48 |
+
if lines and len(lines[0]) < 80:
|
49 |
+
return lines[0].strip().lower()
|
50 |
|
51 |
+
# Final fallback: return full text, lowercase
|
52 |
+
return text.strip().lower()
|
53 |
|
54 |
# 3. Assistant node
|
55 |
|