HongyeYang commited on
Commit
06ce869
·
verified ·
1 Parent(s): e91adf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -36
app.py CHANGED
@@ -1,45 +1,78 @@
1
- import yaml
2
- import os
3
- from smolagents import GradioUI, CodeAgent, InferenceClientModel
4
 
5
- # Get current directory path
6
- CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- from tools.web_search import DuckDuckGoSearchTool as WebSearch
9
- from tools.visit_webpage import VisitWebpageTool as VisitWebpage
10
- from tools.suggest_menu import SimpleTool as SuggestMenu
11
- from tools.catering_service_tool import SimpleTool as CateringServiceTool
12
- from tools.superhero_party_theme_generator import SuperheroPartyThemeTool as SuperheroPartyThemeGenerator
13
- from tools.final_answer import FinalAnswerTool as FinalAnswer
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
-
17
- model = InferenceClientModel(
18
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
19
- provider=None,
20
- )
21
-
22
- web_search = WebSearch()
23
- visit_webpage = VisitWebpage()
24
- suggest_menu = SuggestMenu()
25
- catering_service_tool = CateringServiceTool()
26
- superhero_party_theme_generator = SuperheroPartyThemeGenerator()
27
- final_answer = FinalAnswer()
28
 
29
 
30
- with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
31
- prompt_templates = yaml.safe_load(stream)
32
-
33
  agent = CodeAgent(
34
- model=model,
35
- tools=[web_search, visit_webpage, suggest_menu, catering_service_tool, superhero_party_theme_generator],
36
- managed_agents=[],
 
 
 
 
 
37
  max_steps=10,
38
- verbosity_level=2,
39
- planning_interval=None,
40
- name=None,
41
- description=None,
42
- prompt_templates=prompt_templates
43
  )
44
- if __name__ == "__main__":
45
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, InferenceClientModel, Tool, tool, VisitWebpageTool
 
 
2
 
3
+ @tool
4
+ def suggest_menu(occasion: str) -> str:
5
+ """
6
+ Suggests a menu based on the occasion.
7
+ Args:
8
+ occasion: The type of occasion for the party.
9
+ """
10
+ if occasion == "casual":
11
+ return "Pizza, snacks, and drinks."
12
+ elif occasion == "formal":
13
+ return "3-course dinner with wine and dessert."
14
+ elif occasion == "superhero":
15
+ return "Buffet with high-energy and healthy food."
16
+ else:
17
+ return "Custom menu for the butler."
18
 
19
+ @tool
20
+ def catering_service_tool(query: str) -> str:
21
+ """
22
+ This tool returns the highest-rated catering service in Gotham City.
23
+
24
+ Args:
25
+ query: A search term for finding catering services.
26
+ """
27
+ # 餐饮服务及其评分的示例列表
28
+ services = {
29
+ "Gotham Catering Co.": 4.9,
30
+ "Wayne Manor Catering": 4.8,
31
+ "Gotham City Events": 4.7,
32
+ }
33
+
34
+ # 找到评分最高的餐饮服务(模拟搜索查询过滤)
35
+ best_service = max(services, key=services.get)
36
+
37
+ return best_service
38
 
39
+ class SuperheroPartyThemeTool(Tool):
40
+ name = "superhero_party_theme_generator"
41
+ description = """
42
+ This tool suggests creative superhero-themed party ideas based on a category.
43
+ It returns a unique party theme idea."""
44
+
45
+ inputs = {
46
+ "category": {
47
+ "type": "string",
48
+ "description": "The type of superhero party (e.g., 'classic heroes', 'villain masquerade', 'futuristic Gotham').",
49
+ }
50
+ }
51
+
52
+ output_type = "string"
53
 
54
+ def forward(self, category: str):
55
+ themes = {
56
+ "classic heroes": "Justice League Gala: Guests come dressed as their favorite DC heroes with themed cocktails like 'The Kryptonite Punch'.",
57
+ "villain masquerade": "Gotham Rogues' Ball: A mysterious masquerade where guests dress as classic Batman villains.",
58
+ "futuristic Gotham": "Neo-Gotham Night: A cyberpunk-style party inspired by Batman Beyond, with neon decorations and futuristic gadgets."
59
+ }
60
+
61
+ return themes.get(category.lower(), "Themed party idea not found. Try 'classic heroes', 'villain masquerade', or 'futuristic Gotham'.")
 
 
 
 
62
 
63
 
64
+ # 管家阿尔弗雷德,为派对准备菜单
 
 
65
  agent = CodeAgent(
66
+ tools=[
67
+ DuckDuckGoSearchTool(),
68
+ VisitWebpageTool(),
69
+ suggest_menu,
70
+ catering_service_tool,
71
+ SuperheroPartyThemeTool()
72
+ ],
73
+ model=InferenceClientModel(),
74
  max_steps=10,
75
+ verbosity_level=2
 
 
 
 
76
  )
77
+
78
+ agent.run("Give me best playlist for a party at the Wayne's mansion. The party idea is a 'villain masquerade' theme")