Commit
·
1d1a146
1
Parent(s):
2b46018
final answer
Browse files- src/agents/verification_node.py +15 -3
- test.py +12 -1
src/agents/verification_node.py
CHANGED
|
@@ -43,10 +43,22 @@ def extract_final_answer(response_content: str) -> str:
|
|
| 43 |
|
| 44 |
# If there are still multiple lines, keep only the first non-empty line (to avoid explanations)
|
| 45 |
if '\n' in answer:
|
|
|
|
| 46 |
for line in answer.split('\n'):
|
| 47 |
-
if line.strip():
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
return answer.strip()
|
| 52 |
|
|
|
|
| 43 |
|
| 44 |
# If there are still multiple lines, keep only the first non-empty line (to avoid explanations)
|
| 45 |
if '\n' in answer:
|
| 46 |
+
candidate = None
|
| 47 |
for line in answer.split('\n'):
|
| 48 |
+
if not line.strip():
|
| 49 |
+
continue
|
| 50 |
+
cleaned_line = line.strip()
|
| 51 |
+
# Skip meta-thinking placeholders such as "<think>" or "[thinking]"
|
| 52 |
+
lower_line = cleaned_line.lower()
|
| 53 |
+
if lower_line in {"<think>", "think", "[thinking]", "<thinking>", "[think]"}:
|
| 54 |
+
continue
|
| 55 |
+
# Skip XML-like tags
|
| 56 |
+
if lower_line.startswith("<") and lower_line.endswith(">"):
|
| 57 |
+
continue
|
| 58 |
+
candidate = cleaned_line
|
| 59 |
+
break
|
| 60 |
+
if candidate is not None:
|
| 61 |
+
answer = candidate
|
| 62 |
|
| 63 |
return answer.strip()
|
| 64 |
|
test.py
CHANGED
|
@@ -30,8 +30,19 @@ class BasicAgent:
|
|
| 30 |
# Wrap the question in a HumanMessage from langchain_core
|
| 31 |
messages = [HumanMessage(content=question)]
|
| 32 |
messages = self.graph.invoke({"messages": messages})
|
|
|
|
| 33 |
answer = messages['messages'][-1].content
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 30 |
# Wrap the question in a HumanMessage from langchain_core
|
| 31 |
messages = [HumanMessage(content=question)]
|
| 32 |
messages = self.graph.invoke({"messages": messages})
|
| 33 |
+
# Retrieve the assistant's final message
|
| 34 |
answer = messages['messages'][-1].content
|
| 35 |
+
# If the answer still contains known prefixes (e.g., "Final Answer:"), strip them
|
| 36 |
+
prefixes = [
|
| 37 |
+
"Final Answer:", "Answer:", "The answer is:", "The final answer is:",
|
| 38 |
+
"Result:", "Solution:", "Response:", "Output:", "Conclusion:",
|
| 39 |
+
]
|
| 40 |
+
for p in prefixes:
|
| 41 |
+
if answer.lower().startswith(p.lower()):
|
| 42 |
+
answer = answer[len(p):].strip()
|
| 43 |
+
break
|
| 44 |
+
|
| 45 |
+
return answer.strip()
|
| 46 |
|
| 47 |
|
| 48 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|