Update app.py
Browse files
app.py
CHANGED
|
@@ -12,14 +12,19 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
|
| 13 |
# --- Basic Agent Definition ---
|
| 14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 25 |
"""
|
|
@@ -42,8 +47,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 42 |
|
| 43 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 44 |
try:
|
| 45 |
-
|
| 46 |
-
agent = build_agent()
|
| 47 |
except Exception as e:
|
| 48 |
print(f"Error instantiating agent: {e}")
|
| 49 |
return f"Error initializing agent: {e}", None
|
|
@@ -83,10 +87,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 83 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 84 |
continue
|
| 85 |
try:
|
| 86 |
-
|
| 87 |
-
response = agent.invoke({"messages" :input})
|
| 88 |
-
submitted_answer = response["messages"][-1].content
|
| 89 |
-
#submitted_answer = agent(question_text)
|
| 90 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 91 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 92 |
except Exception as e:
|
|
|
|
| 12 |
|
| 13 |
# --- Basic Agent Definition ---
|
| 14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
+
class BasicAgent:
|
| 16 |
+
"""A langgraph agent."""
|
| 17 |
+
def __init__(self):
|
| 18 |
+
print("BasicAgent initialized.")
|
| 19 |
+
self.graph = build_agent()
|
| 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 |
"""
|
|
|
|
| 47 |
|
| 48 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 49 |
try:
|
| 50 |
+
agent = BasicAgent()
|
|
|
|
| 51 |
except Exception as e:
|
| 52 |
print(f"Error instantiating agent: {e}")
|
| 53 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 87 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 88 |
continue
|
| 89 |
try:
|
| 90 |
+
submitted_answer = agent(question_text)
|
|
|
|
|
|
|
|
|
|
| 91 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 92 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 93 |
except Exception as e:
|