fix: added agent initialisation in the app to be able to load everything.
Browse files- app.py +1 -1
- universal_agent.py +25 -23
app.py
CHANGED
@@ -5,7 +5,7 @@ import requests
|
|
5 |
import inspect
|
6 |
import pandas as pd
|
7 |
import logging
|
8 |
-
|
9 |
# Setup logger
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
logger = logging.getLogger(__name__)
|
|
|
5 |
import inspect
|
6 |
import pandas as pd
|
7 |
import logging
|
8 |
+
from universal_agent import agent
|
9 |
# Setup logger
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
logger = logging.getLogger(__name__)
|
universal_agent.py
CHANGED
@@ -22,7 +22,7 @@ from smolagents import (
|
|
22 |
WikipediaSearchTool,
|
23 |
)
|
24 |
|
25 |
-
_ = load_dotenv(dotenv_path=find_dotenv(raise_error_if_not_found=
|
26 |
nest_asyncio.apply()
|
27 |
with open("all_questions.pkl", "rb") as f:
|
28 |
all_questions = pickle.load(f)
|
@@ -280,29 +280,31 @@ agent = create_react_agent(
|
|
280 |
# agent_w_recursion_limit = agent.with_config(recursion_limit=recursion_limit)
|
281 |
# all_questions[0]
|
282 |
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
q["
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
|
|
|
|
300 |
|
301 |
# with open("results_gpt_mini.pkl", "wb") as f:
|
302 |
# pickle.dump(obj=results, file=f, protocol=pickle.HIGHEST_PROTOCOL)
|
303 |
-
|
304 |
-
answers = [{"task_id":j['task_id'],
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
|
|
|
22 |
WikipediaSearchTool,
|
23 |
)
|
24 |
|
25 |
+
_ = load_dotenv(dotenv_path=find_dotenv(raise_error_if_not_found=False), override=True)
|
26 |
nest_asyncio.apply()
|
27 |
with open("all_questions.pkl", "rb") as f:
|
28 |
all_questions = pickle.load(f)
|
|
|
280 |
# agent_w_recursion_limit = agent.with_config(recursion_limit=recursion_limit)
|
281 |
# all_questions[0]
|
282 |
|
283 |
+
async def run_agent():
|
284 |
+
results = []
|
285 |
+
for q in all_questions:
|
286 |
+
try:
|
287 |
+
answer = await agent.ainvoke(
|
288 |
+
# answer = agent_w_recursion_limit.invoke(
|
289 |
+
input={
|
290 |
+
"messages": f"""Complete the following task: {q["question"]}. Relevant file: {
|
291 |
+
q["file_name"]
|
292 |
+
if q["file_name"]
|
293 |
+
else "There's no relevant file to use."
|
294 |
+
}"""
|
295 |
+
}
|
296 |
+
)
|
297 |
+
results.append(answer)
|
298 |
+
except GraphRecursionError:
|
299 |
+
print("❌ Agent stopped due to max iterations.")
|
300 |
+
results.append(q["task_id"])
|
301 |
+
return results
|
302 |
|
303 |
# with open("results_gpt_mini.pkl", "wb") as f:
|
304 |
# pickle.dump(obj=results, file=f, protocol=pickle.HIGHEST_PROTOCOL)
|
305 |
+
# results = asyncio.run(run_agent())
|
306 |
+
# answers = [{"task_id":j['task_id'],
|
307 |
+
# "submitted_answer": results[i]["structured_response"].answer
|
308 |
+
# if isinstance(results[i], dict) else "No answer"}
|
309 |
+
# for i,j in enumerate(all_questions)]
|
310 |
|