YaxinLuo commited on
Commit
4b9c89e
·
verified ·
1 Parent(s): 4e9d063

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -7
app.py CHANGED
@@ -9,14 +9,59 @@ 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
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +100,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[image_generation_tool,final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def my_custom_tool(activity_type: str, participants: int) -> str:
13
+ """
14
+ A tool that fetches a random activity from the Bored API, allowing you to specify
15
+ an activity type and the number of participants.
16
+
17
  Args:
18
+ activity_type: The type of activity to search for. Possible values include:
19
+ 'education', 'recreational', 'social', 'diy', 'charity', 'cooking',
20
+ 'relaxation', 'music', 'busywork'.
21
+ participants: The number of participants needed for the activity.
22
+
23
+ Returns:
24
+ A string describing the suggested activity, with additional information
25
+ such as its accessibility, price, and link if available.
26
  """
27
+ try:
28
+ response = requests.get(
29
+ "https://www.boredapi.com/api/activity",
30
+ params={
31
+ "type": activity_type.lower(),
32
+ "participants": participants
33
+ }
34
+ )
35
+ if response.status_code != 200:
36
+ return f"Failed to fetch an activity. HTTP status code: {response.status_code}"
37
+
38
+ data = response.json()
39
+
40
+ # 如果 Bored API 返回 error,表示没有符合条件的活动
41
+ if data.get("error"):
42
+ return (
43
+ f"Sorry, no activity found for type='{activity_type}' with "
44
+ f"participants={participants}. Try different parameters!"
45
+ )
46
+
47
+ # 从返回的数据中提取信息
48
+ activity = data.get("activity", "N/A")
49
+ a_type = data.get("type", "N/A")
50
+ price = data.get("price", "N/A")
51
+ accessibility = data.get("accessibility", "N/A")
52
+ link = data.get("link", "No link provided")
53
+
54
+ return (
55
+ f"Here's a fun idea:\n\n"
56
+ f"Activity: {activity}\n"
57
+ f"Type: {a_type}\n"
58
+ f"Price: {price}\n"
59
+ f"Accessibility: {accessibility}\n"
60
+ f"Link: {link}"
61
+ )
62
+
63
+ except Exception as e:
64
+ return f"An error occurred while fetching activity suggestions: {str(e)}"
65
 
66
  @tool
67
  def get_current_time_in_timezone(timezone: str) -> str:
 
100
 
101
  agent = CodeAgent(
102
  model=model,
103
+ tools=[image_generation_tool,my_custom_tool,final_answer], ## add your tools here (don't remove final answer)
104
  max_steps=6,
105
  verbosity_level=1,
106
  grammar=None,