Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- app.py +16 -36
- tools/party_menu.py +1 -8
- tools/party_song.py +11 -14
- tools/party_time.py +19 -14
app.py
CHANGED
|
@@ -1,36 +1,16 @@
|
|
| 1 |
-
from smolagents import CodeAgent, InferenceClientModel
|
| 2 |
-
from tools.
|
| 3 |
-
from tools.
|
| 4 |
-
from tools.party_time import estimate_preparation_time
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
model_id="Qwen/Qwen2.5-Coder-7B-Instruct",
|
| 18 |
-
max_tokens=1024,
|
| 19 |
-
temperature=0.5,
|
| 20 |
-
custom_role_conversions=None,
|
| 21 |
-
)
|
| 22 |
-
|
| 23 |
-
#加载系统提示
|
| 24 |
-
with open("prompts.yaml", "r") as f:
|
| 25 |
-
prompt_templates = yaml.safe_load(f)
|
| 26 |
-
|
| 27 |
-
#构建代理
|
| 28 |
-
agent = CodeAgent(
|
| 29 |
-
model=model,
|
| 30 |
-
tools=[final_answer, suggest_party_music, suggest_menu, estimate_preparation_time],
|
| 31 |
-
prompt_templates=prompt_templates
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
from Gradio_UI import GradioUI
|
| 36 |
-
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, InferenceClientModel
|
| 2 |
+
from tools.party_menu import suggest_menu
|
| 3 |
+
from tools.party_song import suggest_party_music
|
| 4 |
+
from tools.party_time import estimate_preparation_time
|
| 5 |
+
from tools.final_answer import FinalAnswerTool
|
| 6 |
+
|
| 7 |
+
model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-7B-Instruct")
|
| 8 |
+
|
| 9 |
+
agent = CodeAgent(
|
| 10 |
+
model=model,
|
| 11 |
+
tools=[FinalAnswerTool(), suggest_menu, suggest_party_music, estimate_preparation_time],
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
if __name__ == "__main__":
|
| 15 |
+
from Gradio_UI import GradioUI
|
| 16 |
+
GradioUI(agent).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tools/party_menu.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
-
from smolagents import
|
| 2 |
|
| 3 |
-
# Tool to suggest a menu based on the occasion
|
| 4 |
@tool
|
| 5 |
def suggest_menu(occasion: str) -> str:
|
| 6 |
"""
|
|
@@ -20,9 +19,3 @@ def suggest_menu(occasion: str) -> str:
|
|
| 20 |
return "Buffet with high-energy and healthy food."
|
| 21 |
else:
|
| 22 |
return "Custom menu for the butler."
|
| 23 |
-
|
| 24 |
-
# Alfred, the butler, preparing the menu for the party
|
| 25 |
-
agent = CodeAgent(tools=[suggest_menu], model=InferenceClientModel())
|
| 26 |
-
|
| 27 |
-
# Preparing the menu for the party
|
| 28 |
-
agent.run("Prepare a casual menu for the party.")
|
|
|
|
| 1 |
+
from smolagents import tool
|
| 2 |
|
|
|
|
| 3 |
@tool
|
| 4 |
def suggest_menu(occasion: str) -> str:
|
| 5 |
"""
|
|
|
|
| 19 |
return "Buffet with high-energy and healthy food."
|
| 20 |
else:
|
| 21 |
return "Custom menu for the butler."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tools/party_song.py
CHANGED
|
@@ -1,14 +1,11 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
)
|
| 12 |
-
)
|
| 13 |
-
|
| 14 |
-
agent.run("Search for the best music recommendations for a party at the Wayne's mansion.")
|
|
|
|
| 1 |
+
from smolagents import tool, DuckDuckGoSearchTool
|
| 2 |
+
|
| 3 |
+
@tool
|
| 4 |
+
def suggest_party_music(query: str = "best music for a party") -> str:
|
| 5 |
+
"""
|
| 6 |
+
Suggests music playlists or songs for a party by searching online.
|
| 7 |
+
Args:
|
| 8 |
+
query (str): Search query for music.
|
| 9 |
+
"""
|
| 10 |
+
search_tool = DuckDuckGoSearchTool()
|
| 11 |
+
return search_tool(query)
|
|
|
|
|
|
|
|
|
tools/party_time.py
CHANGED
|
@@ -1,18 +1,23 @@
|
|
| 1 |
-
from smolagents import
|
| 2 |
-
import numpy as np
|
| 3 |
-
import time
|
| 4 |
import datetime
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
agent.run(
|
| 9 |
"""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
3. Set up the menu - 45 minutes
|
| 14 |
-
4. Prepare the music and playlist - 45 minutes
|
| 15 |
-
|
| 16 |
-
If we start right now, at what time will the party be ready?
|
| 17 |
"""
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import tool
|
|
|
|
|
|
|
| 2 |
import datetime
|
| 3 |
|
| 4 |
+
@tool
|
| 5 |
+
def estimate_preparation_time(start_time: str = None) -> str:
|
|
|
|
| 6 |
"""
|
| 7 |
+
Estimates total preparation time for a party and returns when everything will be ready.
|
| 8 |
+
Args:
|
| 9 |
+
start_time (str, optional): Start time in format HH:MM. Defaults to current time.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"""
|
| 11 |
+
tasks = {
|
| 12 |
+
"Prepare the drinks": 30,
|
| 13 |
+
"Decorate the mansion": 60,
|
| 14 |
+
"Set up the menu": 45,
|
| 15 |
+
"Prepare the music and playlist": 45,
|
| 16 |
+
}
|
| 17 |
+
total_minutes = sum(tasks.values())
|
| 18 |
+
if start_time:
|
| 19 |
+
now = datetime.datetime.strptime(start_time, "%H:%M")
|
| 20 |
+
else:
|
| 21 |
+
now = datetime.datetime.now()
|
| 22 |
+
ready_time = now + datetime.timedelta(minutes=total_minutes)
|
| 23 |
+
return f"Total prep time: {total_minutes} minutes. The party will be ready at {ready_time.strftime('%H:%M')}."
|