Update app.py
Browse files
app.py
CHANGED
|
@@ -191,18 +191,28 @@ class BasicAgent:
|
|
| 191 |
)
|
| 192 |
print("✅ Agent initialized with all tools")
|
| 193 |
|
| 194 |
-
|
| 195 |
response = self.agent.run(question)
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
for key, fallback in self.rag_fallbacks.items():
|
| 199 |
if key.lower() in question.lower():
|
| 200 |
return f"Tool response inconclusive. Based on known data: Final Answer: {fallback}"
|
| 201 |
-
|
|
|
|
|
|
|
| 202 |
last_line = response.strip().split("\n")[-1]
|
| 203 |
response += f"\nFinal Answer: {last_line}"
|
| 204 |
-
return response
|
| 205 |
|
|
|
|
| 206 |
|
| 207 |
|
| 208 |
# === Evaluation Logic ===
|
|
|
|
| 191 |
)
|
| 192 |
print("✅ Agent initialized with all tools")
|
| 193 |
|
| 194 |
+
def __call__(self, question: str) -> str:
|
| 195 |
response = self.agent.run(question)
|
| 196 |
+
|
| 197 |
+
# Use fallback RAG answers if the output is inconclusive
|
| 198 |
+
if (
|
| 199 |
+
"Final Answer:" not in response
|
| 200 |
+
or "None" in response
|
| 201 |
+
or "Out: None" in response
|
| 202 |
+
or "Execution logs:\n" in response and all(
|
| 203 |
+
x in response for x in ["Out: None", "Execution logs"]
|
| 204 |
+
)
|
| 205 |
+
):
|
| 206 |
for key, fallback in self.rag_fallbacks.items():
|
| 207 |
if key.lower() in question.lower():
|
| 208 |
return f"Tool response inconclusive. Based on known data: Final Answer: {fallback}"
|
| 209 |
+
|
| 210 |
+
# Default to last line as Final Answer if not present
|
| 211 |
+
if "Final Answer:" not in response:
|
| 212 |
last_line = response.strip().split("\n")[-1]
|
| 213 |
response += f"\nFinal Answer: {last_line}"
|
|
|
|
| 214 |
|
| 215 |
+
return response
|
| 216 |
|
| 217 |
|
| 218 |
# === Evaluation Logic ===
|