Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,14 +12,15 @@ from agent import build_graph
|
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
|
| 14 |
class BasicAgent:
|
|
|
|
| 15 |
def __init__(self):
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
self.graph = build_graph()
|
| 18 |
|
| 19 |
def __call__(self, question: str) -> str:
|
| 20 |
-
|
| 21 |
state = {
|
| 22 |
-
"messages":
|
| 23 |
"query": question,
|
| 24 |
"agent_type": "",
|
| 25 |
"final_answer": "",
|
|
@@ -29,7 +30,12 @@ class BasicAgent:
|
|
| 29 |
config = {"configurable": {"thread_id": f"eval_{hash(question)}"}}
|
| 30 |
result = self.graph.invoke(state, config)
|
| 31 |
answer = result['messages'][-1].content
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 35 |
"""
|
|
|
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
|
| 14 |
class BasicAgent:
|
| 15 |
+
"""A langgraph agent."""
|
| 16 |
def __init__(self):
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
self.graph = build_graph()
|
| 19 |
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 22 |
state = {
|
| 23 |
+
"messages": [HumanMessage(content=question)],
|
| 24 |
"query": question,
|
| 25 |
"agent_type": "",
|
| 26 |
"final_answer": "",
|
|
|
|
| 30 |
config = {"configurable": {"thread_id": f"eval_{hash(question)}"}}
|
| 31 |
result = self.graph.invoke(state, config)
|
| 32 |
answer = result['messages'][-1].content
|
| 33 |
+
# Robust extraction:
|
| 34 |
+
if "FINAL ANSWER:" in answer:
|
| 35 |
+
return answer.split("FINAL ANSWER:")[-1].strip()
|
| 36 |
+
else:
|
| 37 |
+
return answer.strip()
|
| 38 |
+
|
| 39 |
|
| 40 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 41 |
"""
|