Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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,
|