Update app.py
Browse files
app.py
CHANGED
|
@@ -507,6 +507,41 @@ class BasicAgent:
|
|
| 507 |
# Catch potential issues like model download failure, OOM errors
|
| 508 |
raise RuntimeError(f"Failed to initialize HuggingFacePipeline for {model_id}: {e}")
|
| 509 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
# --- Agent Initialization (remains the same) ---
|
| 511 |
self.agent = initialize_agent(
|
| 512 |
tools=TOOLS,
|
|
|
|
| 507 |
# Catch potential issues like model download failure, OOM errors
|
| 508 |
raise RuntimeError(f"Failed to initialize HuggingFacePipeline for {model_id}: {e}")
|
| 509 |
|
| 510 |
+
try:
|
| 511 |
+
# Construct a simplified test prompt (mimicking agent input)
|
| 512 |
+
test_prompt = SYSTEM_MESSAGE + "\nHuman: What is the capital of France?\nAssistant:" # A simple question
|
| 513 |
+
# Or use a prompt closer to the problematic one if you know which one it is
|
| 514 |
+
# test_prompt = SYSTEM_MESSAGE + "\nHuman: [Insert the non-commutative table question here]\nAssistant:"
|
| 515 |
+
|
| 516 |
+
# Use invoke which is standard now
|
| 517 |
+
test_response = self.llm.invoke(test_prompt)
|
| 518 |
+
print(f"--- Direct LLM Test Response ---:\n{test_response}\n-----------------------------")
|
| 519 |
+
if not test_response or len(test_response.strip()) == 0:
|
| 520 |
+
print("!!! Direct LLM Test returned empty or whitespace result.")
|
| 521 |
+
|
| 522 |
+
except Exception as test_e:
|
| 523 |
+
print(f"!!! Direct LLM Test FAILED: {test_e}")
|
| 524 |
+
# print traceback for more details
|
| 525 |
+
import traceback
|
| 526 |
+
traceback.print_exc()
|
| 527 |
+
print("BasicAgent initialized with LLM.")
|
| 528 |
+
|
| 529 |
+
def __call__(self, question: str) -> str:
|
| 530 |
+
# Comment out agent call temporarily if testing in __init__
|
| 531 |
+
# Or add the direct test here before calling the agent
|
| 532 |
+
print(f"\n>> Processing Question (Agent): {question}")
|
| 533 |
+
try:
|
| 534 |
+
response = self.agent.invoke({"input": question})
|
| 535 |
+
answer = response.get('output', "Agent did not produce an output.")
|
| 536 |
+
print(f"<< Agent Answer: {answer}")
|
| 537 |
+
return str(answer).strip()
|
| 538 |
+
except Exception as e:
|
| 539 |
+
print(f"Error during agent execution: {e}")
|
| 540 |
+
# Also print traceback here to see where the error originates
|
| 541 |
+
import traceback
|
| 542 |
+
traceback.print_exc()
|
| 543 |
+
return f"Agent Error: {e}"
|
| 544 |
+
|
| 545 |
# --- Agent Initialization (remains the same) ---
|
| 546 |
self.agent = initialize_agent(
|
| 547 |
tools=TOOLS,
|