Update app.py
Browse files
app.py
CHANGED
@@ -12,11 +12,21 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
-
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
18 |
-
fixed_answer = "
|
19 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
20 |
return fixed_answer
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
+
try:
|
16 |
+
self.llm = init_chat_model(model="openai:gpt-4.1")
|
17 |
+
self.agent = create_react_agent(
|
18 |
+
model=self.llm,
|
19 |
+
tools=[websearch_tool, code_interpreter_tool],
|
20 |
+
prompt="You are a helpful assistant. You can use tools to answer questions."
|
21 |
+
)
|
22 |
+
BasicAgentprint("BasicAgent initialized.")
|
23 |
+
except Exception as e:
|
24 |
+
print(f"Failed to initialize BasicAgent: {e}")
|
25 |
+
|
26 |
def __call__(self, question: str) -> str:
|
27 |
+
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
28 |
+
fixed_answer = self.agent.invoke({"messages": [{"role": "user", "content": question}]}).get("messages", [])[-1].content
|
29 |
+
# print(f"Agent returning fixed answer: {fixed_answer}")
|
30 |
return fixed_answer
|
31 |
|
32 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|