Update base_agent.py
Browse files- base_agent.py +27 -1
base_agent.py
CHANGED
|
@@ -57,4 +57,30 @@ class BaseAgent:
|
|
| 57 |
return response.choices[0].message.content
|
| 58 |
except Exception as e:
|
| 59 |
print(f"Error calling LLM: {str(e)}")
|
| 60 |
-
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
return response.choices[0].message.content
|
| 58 |
except Exception as e:
|
| 59 |
print(f"Error calling LLM: {str(e)}")
|
| 60 |
+
return f"Error: {str(e)}"
|
| 61 |
+
|
| 62 |
+
@staticmethod
|
| 63 |
+
def extract_final_answer(text: str) -> str:
|
| 64 |
+
"""
|
| 65 |
+
Extract the final answer from potentially verbose LLM output.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
text: The full text from the LLM
|
| 69 |
+
|
| 70 |
+
Returns:
|
| 71 |
+
The extracted answer, removing any explanation
|
| 72 |
+
"""
|
| 73 |
+
# Look for explicit markers
|
| 74 |
+
markers = ["Final Answer:", "Answer:", "Therefore, the answer is"]
|
| 75 |
+
for marker in markers:
|
| 76 |
+
if marker in text:
|
| 77 |
+
parts = text.split(marker, 1)
|
| 78 |
+
if len(parts) > 1:
|
| 79 |
+
return parts[1].strip()
|
| 80 |
+
|
| 81 |
+
# If no markers, return the last non-empty line
|
| 82 |
+
lines = [line.strip() for line in text.splitlines() if line.strip()]
|
| 83 |
+
if lines:
|
| 84 |
+
return lines[-1]
|
| 85 |
+
|
| 86 |
+
return text.strip()
|