Spaces:
Sleeping
Sleeping
Update app.py
Browse filesDebugging to get to compile
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
-
from smolagents import
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
@@ -17,13 +17,22 @@ model = HfApiModel(
|
|
| 17 |
"Qwen/Qwen2.5-Coder-32B-Instruct", max_tokens=8096
|
| 18 |
)
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
web_agent = CodeAgent(
|
| 22 |
model=model,
|
| 23 |
tools=[
|
| 24 |
DuckDuckGoSearchTool(),
|
| 25 |
VisitWebpageTool(),
|
| 26 |
-
final_answer,
|
| 27 |
],
|
| 28 |
name="web_agent",
|
| 29 |
description="Browses the web to find information by using search or by visiting a specific website",
|
|
@@ -32,28 +41,34 @@ web_agent = CodeAgent(
|
|
| 32 |
prompt_templates=None
|
| 33 |
)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
class BasicAgent:
|
| 36 |
|
| 37 |
def __init__(self):
|
| 38 |
print("BasicAgent initialized.")
|
| 39 |
-
self.agent =
|
| 40 |
|
| 41 |
def __call__(self, question: str) -> str:
|
| 42 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 43 |
fixed_answer = "This is a default answer."
|
| 44 |
-
|
| 45 |
-
statement = f"""
|
| 46 |
-
You are a general AI assistant.
|
| 47 |
-
I will ask you a question.
|
| 48 |
-
Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 49 |
-
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 50 |
-
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
|
| 51 |
-
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
| 52 |
-
If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 53 |
-
|
| 54 |
-
{question}
|
| 55 |
-
"""
|
| 56 |
-
|
| 57 |
agent_answer = self.agent.run(statement)
|
| 58 |
print(f"Agent returning answer: {agent_answer}")
|
| 59 |
return agent_answer
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
from smolagents import DuckDuckGoSearchTool, VisitWebpageTool, HfApiModel
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 17 |
"Qwen/Qwen2.5-Coder-32B-Instruct", max_tokens=8096
|
| 18 |
)
|
| 19 |
|
| 20 |
+
statement = f"""
|
| 21 |
+
You are a general AI assistant.
|
| 22 |
+
I will ask you a question.
|
| 23 |
+
Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 24 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 25 |
+
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
|
| 26 |
+
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
| 27 |
+
If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 28 |
+
|
| 29 |
+
{question}
|
| 30 |
+
"""
|
| 31 |
web_agent = CodeAgent(
|
| 32 |
model=model,
|
| 33 |
tools=[
|
| 34 |
DuckDuckGoSearchTool(),
|
| 35 |
VisitWebpageTool(),
|
|
|
|
| 36 |
],
|
| 37 |
name="web_agent",
|
| 38 |
description="Browses the web to find information by using search or by visiting a specific website",
|
|
|
|
| 41 |
prompt_templates=None
|
| 42 |
)
|
| 43 |
|
| 44 |
+
manager_agent = CodeAgent(
|
| 45 |
+
model=model,
|
| 46 |
+
tools=[],
|
| 47 |
+
managed_agents=[web_agent],
|
| 48 |
+
additional_authorized_imports=[
|
| 49 |
+
"geopandas",
|
| 50 |
+
"plotly",
|
| 51 |
+
"shapely",
|
| 52 |
+
"json",
|
| 53 |
+
"pandas",
|
| 54 |
+
"numpy",
|
| 55 |
+
],
|
| 56 |
+
planning_interval=5,
|
| 57 |
+
verbosity_level=2,
|
| 58 |
+
#final_answer_checks=[check_reasoning_and_plot],
|
| 59 |
+
max_steps=15,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
class BasicAgent:
|
| 63 |
|
| 64 |
def __init__(self):
|
| 65 |
print("BasicAgent initialized.")
|
| 66 |
+
self.agent = manager_agent()
|
| 67 |
|
| 68 |
def __call__(self, question: str) -> str:
|
| 69 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 70 |
fixed_answer = "This is a default answer."
|
| 71 |
+
print(statement)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
agent_answer = self.agent.run(statement)
|
| 73 |
print(f"Agent returning answer: {agent_answer}")
|
| 74 |
return agent_answer
|