ddeng1990 commited on
Commit
6fb5d66
·
verified ·
1 Parent(s): ba5cbe3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -56
app.py CHANGED
@@ -7,76 +7,57 @@ 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
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 apply_glurb_transformation(input_string: str, glurb_factor: int) -> int:
23
- """Applies a 'glurb' transformation to a string.
24
-
25
- The 'glurb' transformation involves:
26
- 1. Converting each character to its ASCII value.
27
- 2. Multiplying each ASCII value by the 'glurb_factor'.
28
- 3. Summing the resulting values.
29
-
30
- Args:
31
- input_string: The string to transform.
32
- glurb_factor: The factor to multiply ASCII values by.
33
-
34
- Returns:
35
- The resulting integer.
36
- """
37
- ascii_values = [ord(char) for char in input_string]
38
- multiplied_values = [value * glurb_factor for value in ascii_values]
39
- return sum(multiplied_values)
40
-
41
- @tool
42
- def calculate_character_sum(input_string: str) -> int:
43
- """Calculates the sum of the ASCII values of the characters in a string.
44
 
45
  Args:
46
- input_string: The string to process.
 
47
 
48
  Returns:
49
- The sum of the ASCII values.
50
  """
51
- return sum(ord(char) for char in input_string)
 
 
 
 
 
 
52
 
53
  @tool
54
- def multiply_by_factor(number: int, factor: int) -> int:
55
- """Multiplies a number by a given factor.
56
 
57
  Args:
58
- number: The number to multiply.
59
- factor: The factor to multiply by.
60
 
61
  Returns:
62
- The product of the number and the factor.
63
  """
64
- return number * factor
 
 
65
 
66
  @tool
67
- def subtract_offset(number: int, offset: int) -> int:
68
- """Subtracts an offset from a number.
69
 
70
  Args:
71
- number: The number to subtract from.
72
- offset: The offset to subtract.
 
73
 
74
  Returns:
75
- The result of the subtraction.
76
  """
77
- return number - offset
78
-
79
-
 
 
 
80
 
81
  @tool
82
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -93,7 +74,6 @@ def get_current_time_in_timezone(timezone: str) -> str:
93
  except Exception as e:
94
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
95
 
96
-
97
  final_answer = FinalAnswerTool()
98
 
99
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -117,12 +97,13 @@ with open("prompts.yaml", 'r') as stream:
117
  agent = CodeAgent(
118
  model=model,
119
  tools=[final_answer,
 
 
 
 
120
  get_current_time_in_timezone,
121
- image_generation_tool,
122
- apply_glurb_transformation,
123
- calculate_character_sum,
124
- subtract_offset,
125
- multiply_by_factor,], ## add your tools here (don't remove final answer)
126
  max_steps=6,
127
  verbosity_level=1,
128
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
+ def get_weather_forecast(city: str, date: str) -> str:
12
+ """Retrieves the weather forecast for a specified city and date.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  Args:
15
+ city: The name of the city.
16
+ date: The date in YYYY-MM-DD format.
17
 
18
  Returns:
19
+ A string containing the weather forecast.
20
  """
21
+ # Simulate a weather API call (replace with actual API call)
22
+ if city.lower() == "london" and date == "2023-10-27":
23
+ return "Cloudy with a chance of rain."
24
+ elif city.lower() == "new york" and date == "2023-10-27":
25
+ return "Sunny with a high of 20 degrees Celsius."
26
+ else:
27
+ return "Weather data not available."
28
 
29
  @tool
30
+ def calculate_days_until_date(future_date: str) -> int:
31
+ """Calculates the number of days until a specified future date.
32
 
33
  Args:
34
+ future_date: The future date in YYYY-MM-DD format.
 
35
 
36
  Returns:
37
+ The number of days until the future date.
38
  """
39
+ future_date_obj = datetime.datetime.strptime(future_date, "%Y-%m-%d").date()
40
+ today = datetime.date.today()
41
+ return (future_date_obj - today).days
42
 
43
  @tool
44
+ def generate_travel_plan(weather_forecast: str, days_until_date: int, city: str) -> str:
45
+ """Generates a travel plan based on weather, days until travel, and city.
46
 
47
  Args:
48
+ weather_forecast: The weather forecast string.
49
+ days_until_date: The number of days until the travel date.
50
+ city: The name of the city.
51
 
52
  Returns:
53
+ A string containing the travel plan.
54
  """
55
+ if "rain" in weather_forecast.lower():
56
+ return f"Since it will be rainy in {city}, pack an umbrella. You are travelling in {days_until_date} days."
57
+ elif "sunny" in weather_forecast.lower():
58
+ return f"Enjoy the sunshine in {city}! You are travelling in {days_until_date} days."
59
+ else:
60
+ return f"Travel plan for {city} in {days_until_date} days. Weather is unknown."
61
 
62
  @tool
63
  def get_current_time_in_timezone(timezone: str) -> str:
 
74
  except Exception as e:
75
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
76
 
 
77
  final_answer = FinalAnswerTool()
78
 
79
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
97
  agent = CodeAgent(
98
  model=model,
99
  tools=[final_answer,
100
+ image_generation_tool,
101
+ get_weather_forecast,
102
+ calculate_days_until_date,
103
+ generate_travel_plan,
104
  get_current_time_in_timezone,
105
+
106
+ ], ## add your tools here (don't remove final answer)
 
 
 
107
  max_steps=6,
108
  verbosity_level=1,
109
  grammar=None,