second attempt to fix bug
Browse files
app.py
CHANGED
@@ -12,18 +12,22 @@ from agent import graph
|
|
12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
13 |
|
14 |
# --- Basic Agent Definition ---
|
15 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
16 |
class BasicAgent:
|
17 |
-
"""LangGraph Agent"""
|
|
|
18 |
def __init__(self):
|
19 |
print("BasicAgent initialized.")
|
20 |
-
self.graph =
|
21 |
|
22 |
def __call__(self, question: str) -> str:
|
23 |
messages = [HumanMessage(content=question)]
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
|
28 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
29 |
"""
|
|
|
12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
13 |
|
14 |
# --- Basic Agent Definition ---
|
|
|
15 |
class BasicAgent:
|
16 |
+
"""LangGraph Agent Wrapper"""
|
17 |
+
|
18 |
def __init__(self):
|
19 |
print("BasicAgent initialized.")
|
20 |
+
self.graph = graph # Using graph already compiled in agent.py
|
21 |
|
22 |
def __call__(self, question: str) -> str:
|
23 |
messages = [HumanMessage(content=question)]
|
24 |
+
result = self.graph.invoke({"messages": messages})
|
25 |
+
final_response = result['messages'][-1].content
|
26 |
+
|
27 |
+
# Assumes answer starts with "FINAL ANSWER: "
|
28 |
+
if final_response.startswith("FINAL ANSWER: "):
|
29 |
+
return final_response[len("FINAL ANSWER: "):].strip()
|
30 |
+
return final_response.strip()
|
31 |
|
32 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
33 |
"""
|