rhagenba commited on
Commit
6fd7328
·
verified ·
1 Parent(s): 7d17fbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -11
app.py CHANGED
@@ -1,17 +1,79 @@
1
- pip install smolagents duckduckgo-search -U
2
 
3
- from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- model = InferenceClientModel(
6
- model_id="Qwen/Qwen2.5-Coder-7B-Instruct",
7
- max_tokens=1024,
8
- temperature=0.2
9
- )
10
 
 
11
  agent = CodeAgent(
12
- model=model,
13
- tools=[DuckDuckGoSearchTool()],
14
- max_steps=5,
 
 
 
 
 
 
 
 
15
  )
16
 
17
- agent.run("Was sind die neuesten Nachrichten zur künstlichen Intelligenz?")
 
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
+ # Example list of catering services and their ratings
28
+ services = {
29
+ "Gotham Catering Co.": 4.9,
30
+ "Wayne Manor Catering": 4.8,
31
+ "Gotham City Events": 4.7,
32
+ }
33
+
34
+ # Find the highest rated catering service (simulating search query filtering)
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
+ # Alfred, the butler, preparing the menu for the party
65
  agent = CodeAgent(
66
+ tools=[
67
+ DuckDuckGoSearchTool(),
68
+ VisitWebpageTool(),
69
+ suggest_menu,
70
+ catering_service_tool,
71
+ SuperheroPartyThemeTool(),
72
+ FinalAnswerTool()
73
+ ],
74
+ model=InferenceClientModel(),
75
+ max_steps=10,
76
+ verbosity_level=2
77
  )
78
 
79
+ agent.run("Give me the best playlist for a party at the Wayne's mansion. The party idea is a 'villain masquerade' theme")