ORromu commited on
Commit
8e4f354
·
verified ·
1 Parent(s): d9aa433

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -14,6 +14,13 @@ from io import BytesIO
14
  # --- Constants ---
15
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
 
 
 
 
 
 
 
 
17
  # --- Basic Agent Definition ---
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
19
  class BasicAgent:
@@ -66,8 +73,19 @@ class BasicAgent:
66
  messages = [HumanMessage(content=question)]
67
 
68
  response = self.graph.invoke({"messages": messages})
69
- answer = response['messages'][-1].content
 
 
 
 
 
 
 
 
 
 
70
  return answer.split("FINAL ANSWER:")[-1].strip()
 
71
 
72
  except Exception as e:
73
  return f"Error during processing: {e}"
 
14
  # --- Constants ---
15
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
 
17
+ # load the system prompt from the file
18
+ with open("prompt2.txt", "r", encoding="utf-8") as f:
19
+ system_prompt = f.read()
20
+
21
+ # System message
22
+ sys_msg = SystemMessage(content=system_prompt)
23
+
24
  # --- Basic Agent Definition ---
25
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
26
  class BasicAgent:
 
73
  messages = [HumanMessage(content=question)]
74
 
75
  response = self.graph.invoke({"messages": messages})
76
+ answer = response['messages'][-1].content # First pass
77
+ #return answer.split("FINAL ANSWER:")[-1].strip() # Return for single pass
78
+
79
+ # Structure the messages
80
+ messages = [
81
+ {"role": "system", "content": sys_msg},
82
+ {"role": "user", "content": response}
83
+ ]
84
+
85
+ # Call the agent again
86
+ response = self.graph.invoke({"messages": messages})
87
  return answer.split("FINAL ANSWER:")[-1].strip()
88
+
89
 
90
  except Exception as e:
91
  return f"Error during processing: {e}"