vtony commited on
Commit
04f1280
·
verified ·
1 Parent(s): c620442

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -12,19 +12,31 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
15
  class BasicAgent:
16
  def __init__(self):
17
  print("BasicAgent initialized.")
18
  self.graph = agent_graph
19
  def __call__(self, question: str) -> str:
20
- messages = [HumanMessage(content=question)]
 
 
 
 
 
21
  response = self.graph.invoke({"messages": messages})
22
- last_msg = response["messages"][-1].content
23
 
24
- if "FINAL ANSWER:" in last_msg:
25
- return last_msg.split("FINAL ANSWER:")[-1].strip()
26
- return last_msg
27
-
 
 
 
 
28
  def run_and_submit_all( profile: gr.OAuthProfile | None):
29
  """
30
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
12
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
+
16
+ # ... (other imports and constants remain the same) ...
17
+
18
+ # ... (rest of the file remains unchanged) ...
19
  class BasicAgent:
20
  def __init__(self):
21
  print("BasicAgent initialized.")
22
  self.graph = agent_graph
23
  def __call__(self, question: str) -> str:
24
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
25
+ # Create conversation history with system prompt
26
+ messages = [SystemMessage(content="Answer the user's question."),
27
+ HumanMessage(content=question)]
28
+
29
+ # Run the graph
30
  response = self.graph.invoke({"messages": messages})
 
31
 
32
+ # Extract the final AI message
33
+ final_message = response["messages"][-1].content
34
+
35
+ # Extract final answer if formatted with "FINAL ANSWER:"
36
+ if "FINAL ANSWER:" in final_message:
37
+ return final_message.split("FINAL ANSWER:")[-1].strip()
38
+ return final_message
39
+
40
  def run_and_submit_all( profile: gr.OAuthProfile | None):
41
  """
42
  Fetches all questions, runs the BasicAgent on them, submits all answers,