alisamak commited on
Commit
fa470ab
·
verified ·
1 Parent(s): a502d76

Update LG_agent.py

Browse files
Files changed (1) hide show
  1. LG_agent.py +10 -19
LG_agent.py CHANGED
@@ -27,32 +27,23 @@ class AgentState(TypedDict):
27
  messages: Annotated[list[AnyMessage], add_messages]
28
 
29
  def extract_gaia_answer(text: str) -> str:
30
- """
31
- Extract only the final answer from the LLM output using common patterns like:
32
- - 'The answer is: ...'
33
- - 'Answer: ...'
34
- - bullet points
35
- - Or just return raw answer if short and plain
36
-
37
- Strips everything else to conform with GAIA expectations.
38
- """
39
- # Common patterns GAIA outputs follow
40
  patterns = [
41
  r"The answer is: (.+)",
42
  r"Answer: (.+)",
43
- r"^([a-z0-9,\s]+)$", # raw answer line
44
  ]
45
  for pattern in patterns:
46
  match = re.search(pattern, text.strip(), re.IGNORECASE | re.MULTILINE)
47
  if match:
48
- return match.group(1).strip()
49
-
50
- # Fallback: if it's a single short line, return it
51
- lines = text.strip().splitlines()
52
- if len(lines) == 1 and len(lines[0]) < 100:
53
- return lines[0].strip()
54
-
55
- # Fallback: return full (stripped) content
 
56
  return text.strip()
57
 
58
  # 3. Assistant node
 
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,\s]+)$",
34
  ]
35
  for pattern in patterns:
36
  match = re.search(pattern, text.strip(), re.IGNORECASE | re.MULTILINE)
37
  if match:
38
+ answer = match.group(1).strip().lower()
39
+ if any(kw in answer for kw in ["incomplete", "missing", "clarify", "need more"]):
40
+ return match.group(1).strip()
41
+
42
+ # Add fallback keyword suggestion for vague answers
43
+ if "provide" in text.lower() and "ingredient" in text.lower():
44
+ return "The question is incomplete — please provide more information."
45
+
46
+ # Fallback
47
  return text.strip()
48
 
49
  # 3. Assistant node