HCho commited on
Commit
3b1fa94
·
verified ·
1 Parent(s): 6263c88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -17,15 +17,27 @@ class BasicAgent:
17
  def __init__(self):
18
  print("BasicAgent initialized.")
19
  self.graph = build_graph()
20
-
21
  def __call__(self, question: str) -> str:
22
- print(f"Agent received question (first 50 chars): {question[:50]}...")
23
- # Wrap the question in a HumanMessage from langchain_core
24
- messages = [HumanMessage(content=question)]
25
- messages = self.graph.invoke({"messages": messages})
26
- answer = messages['messages'][-1].content
27
- return answer[14:]
28
-
 
 
 
 
 
 
 
 
 
 
 
 
29
  def run_and_submit_all( profile: gr.OAuthProfile | None):
30
  """
31
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
17
  def __init__(self):
18
  print("BasicAgent initialized.")
19
  self.graph = build_graph()
20
+
21
  def __call__(self, question: str) -> str:
22
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
23
+ messages = [HumanMessage(content=question)]
24
+ messages = self.graph.invoke({"messages": messages})
25
+ answer_full = messages['messages'][-1].content
26
+
27
+ # Use .split() to get the part after "FINAL ANSWER: "
28
+ # .strip() removes any leading/trailing whitespace
29
+ if answer_full.startswith("FINAL ANSWER: "):
30
+ answer = answer_full.split("FINAL ANSWER: ", 1)[1].strip()
31
+ else:
32
+ # Handle cases where the prefix might be missing
33
+ # or the LLM didn't follow the format.
34
+ # You might want to log this or return the full answer_full
35
+ # depending on how strictly you want to enforce the format.
36
+ answer = answer_full
37
+ print(f"Warning: 'FINAL ANSWER:' prefix not found. Returning full response: {answer_full[:100]}...")
38
+
39
+ return answer
40
+
41
  def run_and_submit_all( profile: gr.OAuthProfile | None):
42
  """
43
  Fetches all questions, runs the BasicAgent on them, submits all answers,