mabelwang21 commited on
Commit
d98d919
·
1 Parent(s): 1c189b6

reformat FINAL ANSWER output

Browse files
Files changed (1) hide show
  1. agent.py +7 -1
agent.py CHANGED
@@ -24,6 +24,7 @@ import pytesseract
24
  import fitz # PyMuPDF
25
 
26
  # Load environment variables from .env file
 
27
  from dotenv import load_dotenv
28
  load_dotenv()
29
 
@@ -265,7 +266,12 @@ class MyAgent:
265
 
266
  # Use invoke() instead of run()
267
  out = graph.invoke(state)
268
- return out["messages"][-1].content
 
 
 
 
 
269
 
270
  def run(self, question: str, file_paths: Optional[List[str]] = None) -> str:
271
  return self(question, file_paths)
 
24
  import fitz # PyMuPDF
25
 
26
  # Load environment variables from .env file
27
+ # in HF Spaces, the .env file is saved in Variables and secrets in settings
28
  from dotenv import load_dotenv
29
  load_dotenv()
30
 
 
266
 
267
  # Use invoke() instead of run()
268
  out = graph.invoke(state)
269
+ last_message = out["messages"][-1].content
270
+
271
+ # Extract only the FINAL ANSWER part
272
+ if "FINAL ANSWER:" in last_message:
273
+ return last_message.split("FINAL ANSWER:")[-1].strip()
274
+ return last_message.strip()
275
 
276
  def run(self, question: str, file_paths: Optional[List[str]] = None) -> str:
277
  return self(question, file_paths)