Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,11 +12,15 @@ 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 |
-
class
|
|
|
16 |
def __init__(self):
|
17 |
-
print("
|
|
|
|
|
18 |
def __call__(self, question: str) -> str:
|
19 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
20 |
messages = [HumanMessage(content=question)]
|
21 |
messages = self.graph.invoke({"messages": messages})
|
22 |
answer = messages['messages'][-1].content
|
@@ -43,7 +47,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
43 |
|
44 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
45 |
try:
|
46 |
-
agent =
|
47 |
except Exception as e:
|
48 |
print(f"Error instantiating agent: {e}")
|
49 |
return f"Error initializing agent: {e}", None
|
|
|
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_graph()
|
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
|
|
|
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
|