Spaces:
Sleeping
Sleeping
run and submit locally
Browse files- agent.py +20 -16
- app.py +4 -4
- prompts.py +3 -3
- requirements.txt +3 -2
agent.py
CHANGED
|
@@ -22,31 +22,35 @@ from tools import python_wikipedia_tools, smolagents_code_tools, smolagents_web_
|
|
| 22 |
# custom_role_conversions=None,
|
| 23 |
# )
|
| 24 |
|
| 25 |
-
model = OpenAIServerModel(
|
| 26 |
-
model_id="gemini-2.0-flash",
|
| 27 |
-
api_base="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 28 |
-
api_key=os.getenv("GEMINI_API_KEY"),
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
# to run locally
|
| 32 |
#model = OpenAIServerModel(
|
| 33 |
-
# model_id="
|
| 34 |
-
# api_base="
|
|
|
|
| 35 |
#)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
web_search_agent =
|
| 39 |
tools=smolagents_web_tools,
|
| 40 |
-
model=
|
| 41 |
max_steps=10,
|
| 42 |
-
additional_authorized_imports=["wikipedia", "markdownify", "requests"],
|
| 43 |
name="web_search_agent",
|
| 44 |
-
description="A
|
| 45 |
)
|
| 46 |
|
| 47 |
code_agent = CodeAgent(
|
| 48 |
tools=smolagents_code_tools + python_wikipedia_tools,
|
| 49 |
-
model=
|
| 50 |
max_steps=10,
|
| 51 |
additional_authorized_imports=["time", "numpy", "pandas", "wikipedia", "xlrd", "markdownify", "requests"],
|
| 52 |
name="code_agent",
|
|
@@ -55,10 +59,10 @@ code_agent = CodeAgent(
|
|
| 55 |
|
| 56 |
manager_agent = CodeAgent(
|
| 57 |
tools=[],
|
| 58 |
-
model=
|
| 59 |
managed_agents=[web_search_agent, code_agent],
|
| 60 |
max_steps=10,
|
| 61 |
verbosity_level=1,
|
| 62 |
name="manager_agent",
|
| 63 |
-
description="Manages the web_search_agent and code_agent.",
|
| 64 |
)
|
|
|
|
| 22 |
# custom_role_conversions=None,
|
| 23 |
# )
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
#model = OpenAIServerModel(
|
| 26 |
+
# model_id="gemini-2.0-flash",
|
| 27 |
+
# api_base="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 28 |
+
# api_key=os.getenv("GEMINI_API_KEY"),
|
| 29 |
#)
|
| 30 |
|
| 31 |
+
# to run locally
|
| 32 |
+
model_gemma = LiteLLMModel(
|
| 33 |
+
model_id="ollama/gemma3:27b",
|
| 34 |
+
api_base="http://localhost:11434",
|
| 35 |
+
)
|
| 36 |
+
model_devstral = LiteLLMModel(
|
| 37 |
+
model_id="ollama/devstral:latest",
|
| 38 |
+
api_base="http://localhost:11434",
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
|
| 42 |
+
web_search_agent = ToolCallingAgent(
|
| 43 |
tools=smolagents_web_tools,
|
| 44 |
+
model=model_gemma,
|
| 45 |
max_steps=10,
|
| 46 |
+
#additional_authorized_imports=["wikipedia", "markdownify", "requests"],
|
| 47 |
name="web_search_agent",
|
| 48 |
+
description="A tool calling agent which can perform web searches. It has available tools including GoogleSearchTool, VisitWebpageTool and WikipediaSearchTool",
|
| 49 |
)
|
| 50 |
|
| 51 |
code_agent = CodeAgent(
|
| 52 |
tools=smolagents_code_tools + python_wikipedia_tools,
|
| 53 |
+
model=model_gemma,
|
| 54 |
max_steps=10,
|
| 55 |
additional_authorized_imports=["time", "numpy", "pandas", "wikipedia", "xlrd", "markdownify", "requests"],
|
| 56 |
name="code_agent",
|
|
|
|
| 59 |
|
| 60 |
manager_agent = CodeAgent(
|
| 61 |
tools=[],
|
| 62 |
+
model=model_gemma,
|
| 63 |
managed_agents=[web_search_agent, code_agent],
|
| 64 |
max_steps=10,
|
| 65 |
verbosity_level=1,
|
| 66 |
name="manager_agent",
|
| 67 |
+
description="Manages the web_search_agent and code_agent. Can perform web searches with the ToolCallingAgent called web_search_agent. Can use the CodeAgent called code_agent to run pythin code.",
|
| 68 |
)
|
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
from agent import manager_agent
|
| 7 |
-
from time import sleep
|
| 8 |
from prompts import prompt
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -75,7 +75,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 75 |
results_log = []
|
| 76 |
answers_payload = []
|
| 77 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 78 |
-
for item in questions_data
|
| 79 |
task_id = item.get("task_id")
|
| 80 |
question_text = item.get("question")
|
| 81 |
if not task_id or question_text is None:
|
|
@@ -88,7 +88,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 88 |
except Exception as e:
|
| 89 |
print(f"Error running agent on task {task_id}: {e}")
|
| 90 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 91 |
-
sleep(30) # 30 seconds delay between questions for Gemini
|
| 92 |
if not answers_payload:
|
| 93 |
print("Agent did not produce any answers to submit.")
|
| 94 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
@@ -195,7 +195,7 @@ if __name__ == "__main__":
|
|
| 195 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 196 |
|
| 197 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 198 |
-
demo.launch(debug=True
|
| 199 |
|
| 200 |
#agent = BasicAgent()
|
| 201 |
#question = "You are a general AI assistant. You will be asked a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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. Think step by step and reason through the question. Then return your final answer.\n\nQuestion: How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
from agent import manager_agent
|
| 7 |
+
#from time import sleep
|
| 8 |
from prompts import prompt
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 75 |
results_log = []
|
| 76 |
answers_payload = []
|
| 77 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 78 |
+
for item in questions_data: # First question for testing
|
| 79 |
task_id = item.get("task_id")
|
| 80 |
question_text = item.get("question")
|
| 81 |
if not task_id or question_text is None:
|
|
|
|
| 88 |
except Exception as e:
|
| 89 |
print(f"Error running agent on task {task_id}: {e}")
|
| 90 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 91 |
+
#sleep(30) # 30 seconds delay between questions for Gemini
|
| 92 |
if not answers_payload:
|
| 93 |
print("Agent did not produce any answers to submit.")
|
| 94 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
|
|
| 195 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 196 |
|
| 197 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 198 |
+
demo.launch(debug=True)
|
| 199 |
|
| 200 |
#agent = BasicAgent()
|
| 201 |
#question = "You are a general AI assistant. You will be asked a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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. Think step by step and reason through the question. Then return your final answer.\n\nQuestion: How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
|
prompts.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
prompt = """You are a general AI assistant. You will be asked a question.
|
| 2 |
-
|
| 3 |
-
|
| 4 |
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.
|
| 5 |
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.
|
| 6 |
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.
|
| 7 |
-
|
| 8 |
"""
|
|
|
|
| 1 |
prompt = """You are a general AI assistant. You will be asked a question.
|
| 2 |
+
Think step by step, and finish your answer with your FINAL ANSWER.
|
| 3 |
+
Your FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 4 |
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.
|
| 5 |
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.
|
| 6 |
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.
|
| 7 |
+
Report only the value of your final answer, don't add any additional words.
|
| 8 |
"""
|
requirements.txt
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
-
smolagents[openai,transformers,litellm]
|
| 4 |
duckduckgo_search
|
| 5 |
wikipedia-api
|
| 6 |
wikipedia
|
| 7 |
xlrd
|
| 8 |
transformers
|
| 9 |
-
markdownify
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
+
smolagents[openai,transformers,litellm]>=1.17.0
|
| 4 |
duckduckgo_search
|
| 5 |
wikipedia-api
|
| 6 |
wikipedia
|
| 7 |
xlrd
|
| 8 |
transformers
|
| 9 |
+
markdownify
|
| 10 |
+
aiohttp>=3.8.0
|