Spaces:
Runtime error
Runtime error
Commit ·
ce895ac
1
Parent(s): ae7a494
agent that creates tools, because why not
Browse files- app.py +29 -5
- requirements.txt +2 -0
- tools/csv_to_excel.py +18 -0
app.py
CHANGED
|
@@ -7,6 +7,10 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -18,6 +22,25 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -40,10 +63,10 @@ final_answer = FinalAnswerTool()
|
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
|
| 42 |
model = HfApiModel(
|
| 43 |
-
max_tokens=2096,
|
| 44 |
-
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 46 |
-
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
|
|
@@ -55,7 +78,8 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
|
|
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from dotenv import load_dotenv
|
| 11 |
+
|
| 12 |
+
load_dotenv()
|
| 13 |
+
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 22 |
"""
|
| 23 |
return "What magic will you build ?"
|
| 24 |
|
| 25 |
+
@tool
|
| 26 |
+
def write_tool_to_file(code: str, file_name: str) -> str:
|
| 27 |
+
"""A tool that lets the agent create custom tools on the fly, and save them for later. No need to search for a path, the tool takes care of it.
|
| 28 |
+
Since you are generating code but not executing it, you can import anything without having to take care about if you can import these or not.
|
| 29 |
+
The python code should ALWAYS contain a docstring that describes what the function does, an explicit function name, explicit argument names with their types, and a return type
|
| 30 |
+
Args:
|
| 31 |
+
code: A Python function the agent generated
|
| 32 |
+
file_name: the filename
|
| 33 |
+
"""
|
| 34 |
+
if "@tool" not in code:
|
| 35 |
+
code = "from smolagents import tool\n\n@tool\n" + code.strip()
|
| 36 |
+
if not file_name.endswith(".py"):
|
| 37 |
+
file_name += ".py"
|
| 38 |
+
with open(f"tools/{file_name}", "w") as f:
|
| 39 |
+
f.write(code)
|
| 40 |
+
|
| 41 |
+
return f"Success creating new tool {file_name}"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 46 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 63 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 64 |
|
| 65 |
model = HfApiModel(
|
| 66 |
+
max_tokens=2096,
|
| 67 |
+
temperature=0.5,
|
| 68 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 69 |
+
custom_role_conversions=None,
|
| 70 |
)
|
| 71 |
|
| 72 |
|
|
|
|
| 78 |
|
| 79 |
agent = CodeAgent(
|
| 80 |
model=model,
|
| 81 |
+
tools=[final_answer, write_tool_to_file], ## add your tools here (don't remove final answer)
|
| 82 |
+
additional_authorized_imports=["pandas", "csv", "openpyxl"],
|
| 83 |
max_steps=6,
|
| 84 |
verbosity_level=1,
|
| 85 |
grammar=None,
|
requirements.txt
CHANGED
|
@@ -3,3 +3,5 @@ smolagents
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
|
|
|
|
|
|
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
| 6 |
+
smolagents[gradio]
|
| 7 |
+
python-dotenv
|
tools/csv_to_excel.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import tool
|
| 2 |
+
|
| 3 |
+
@tool
|
| 4 |
+
def csv_to_excel(csv_file_path: str, excel_file_path: str) -> None:
|
| 5 |
+
"""
|
| 6 |
+
Converts a CSV file to an Excel spreadsheet.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
csv_file_path (str): The path to the input CSV file.
|
| 10 |
+
excel_file_path (str): The path to the output Excel file.
|
| 11 |
+
"""
|
| 12 |
+
import pandas as pd
|
| 13 |
+
|
| 14 |
+
# Read the CSV file into a DataFrame
|
| 15 |
+
df = pd.read_csv(csv_file_path)
|
| 16 |
+
|
| 17 |
+
# Write the DataFrame to an Excel file
|
| 18 |
+
df.to_excel(excel_file_path, index=False)
|