AC-Angelo93 commited on
Commit
afe3bcf
·
verified ·
1 Parent(s): 942f1db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -17,19 +17,15 @@ class BasicAgent:
17
  # graph factory lives here
18
  self.agent = build_graph()
19
 
20
- def __call__(self, question: str) -> str:
21
  print(f"Agent received question: {question[:50]}...")
22
- # seed initial state(empty message list
23
- init_state = {"message": []}
24
- # run the graph, injecting the questions
25
- # bulid_graph() was compiled to accept (state, question=...)
26
- result_state = self.agent.invoke(init_state, question)
27
- # extract the final message
28
- final_msg = result_state["messages"][-1]
29
- answer = getattr(final_msg, "content", str(final_msg))
30
- # strip off any "FINAL ANSWER:" prefix if present
31
- return answer.replace("FINAL ANSWER:","",1).strip()
32
-
33
  def run_and_submit_all( profile: gr.OAuthProfile | None):
34
  """
35
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
17
  # graph factory lives here
18
  self.agent = build_graph()
19
 
20
+ def __call__(self,question: str) -> str:
21
  print(f"Agent received question: {question[:50]}...")
22
+ #invoke the ccompiled graph runner with just the question
23
+ result = self.agent.invoke(question)
24
+ # because the graph now ends in answer_node, result is a dict {id:answer}
25
+ # extract that single answer string:
26
+ answer = list(result.values())[0]
27
+ return answer.strip()
28
+
 
 
 
 
29
  def run_and_submit_all( profile: gr.OAuthProfile | None):
30
  """
31
  Fetches all questions, runs the BasicAgent on them, submits all answers,