Shaukat39 commited on
Commit
fa1833e
·
verified ·
1 Parent(s): b709ac9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -19,26 +19,30 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
19
 
20
 
21
  class BasicAgent:
22
- """A langgraph agent."""
23
  def __init__(self):
24
  print("BasicAgent initialized.")
25
  self.graph = build_graph()
26
 
27
  def __call__(self, question: str) -> str:
28
- print(f"Agent received question (first 50 chars): {question[:50]}...")
29
  messages = [HumanMessage(content=question)]
30
  response = self.graph.invoke({"messages": messages})
31
- raw_output = response["messages"][-1].content.strip()
32
 
33
- # This block must be indented inside the method
 
 
 
34
  match = re.search(r"FINAL ANSWER:\s*(.+)", raw_output, re.IGNORECASE)
35
  if match:
36
  final_answer = match.group(1).strip()
37
  else:
38
  final_answer = raw_output.strip()
39
- print("⚠️ Missing 'FINAL ANSWER:' prefix.")
 
 
 
40
 
41
- return final_answer # ✅ must align with the if-block, still inside __call__
42
 
43
 
44
 
 
19
 
20
 
21
  class BasicAgent:
22
+ """A langgraph agent with debug logging."""
23
  def __init__(self):
24
  print("BasicAgent initialized.")
25
  self.graph = build_graph()
26
 
27
  def __call__(self, question: str) -> str:
28
+ print(f"\n📥 Question {repr(question)}")
29
  messages = [HumanMessage(content=question)]
30
  response = self.graph.invoke({"messages": messages})
 
31
 
32
+ raw_output = response["messages"][-1].content
33
+ print("📦 Raw model output →", repr(raw_output))
34
+
35
+ import re
36
  match = re.search(r"FINAL ANSWER:\s*(.+)", raw_output, re.IGNORECASE)
37
  if match:
38
  final_answer = match.group(1).strip()
39
  else:
40
  final_answer = raw_output.strip()
41
+ print("⚠️ Output missing 'FINAL ANSWER:' prefix. Using fallback.")
42
+
43
+ print("✅ Final parsed answer:", repr(final_answer))
44
+ return final_answer
45
 
 
46
 
47
 
48