wizofavalon commited on
Commit
eb0c64f
·
verified ·
1 Parent(s): 805ecd7

added new tool

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -9,14 +9,24 @@ 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:
@@ -52,7 +62,7 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
- print("TOOLS:", [final_answer, my_custom_tool, get_current_time_in_timezone, image_generation_tool])
56
  prompt_templates["final_answer"] = {
57
  "pre_messages": [
58
  {"role": "system", "content": "You are a helpful assistant. Return the final answer clearly."}
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def get_temperature(city:str)-> 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 fetches the current temperature given the city name or location name
15
  Args:
16
+ arg1: A string representing the city name or location
 
17
  """
18
+ url = f"https://wttr.in/{city}?format=%t"
19
+ try:
20
+ response = requests.get(url)
21
+ if response.status_code == 200:
22
+ temperature = response.text.strip()
23
+ print(f"The current temperature in {city} is {temperature}")
24
+ return f"The current temperature in {city} is {temperature}
25
+ else:
26
+ print(f"Error fetching weather for {city}: HTTP {response.status_code}")
27
+ return f"Error fetching weather for {city}: HTTP {response.status_code}"
28
+ except Exception as e:
29
+ print(f"Request failed: {e}")
30
 
31
  @tool
32
  def get_current_time_in_timezone(timezone: str) -> str:
 
62
 
63
  with open("prompts.yaml", 'r') as stream:
64
  prompt_templates = yaml.safe_load(stream)
65
+ print("TOOLS:", [final_answer, get_temperature, get_current_time_in_timezone, image_generation_tool])
66
  prompt_templates["final_answer"] = {
67
  "pre_messages": [
68
  {"role": "system", "content": "You are a helpful assistant. Return the final answer clearly."}