MonsieurMory commited on
Commit
7f4e662
·
verified ·
1 Parent(s): ae7a494

Upload app.py

Browse files

This my edited version of the original app.py, I have added some tools to my agent such as get a GDP of a country, web search tool or image generation tool

Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -9,14 +9,25 @@ 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:
@@ -35,6 +46,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
35
 
36
 
37
  final_answer = FinalAnswerTool()
 
38
 
39
  # 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:
40
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
@@ -55,7 +67,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[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 get_gdp(country_iso_code: str, year: int) -> str:
13
+ """Retrieves the GDP of a given country for a specified year in USD.
14
+
15
  Args:
16
+ country_iso_code: The ISO 3166-1 alpha-3 code of the country (e.g., "FRA" for France, "USA" for United States).
17
+ year: The year for which to retrieve GDP data.
18
+
19
+ Returns:
20
+ The GDP of the country in the given year (in US dollars) or an error message.
21
  """
22
+ base_url = "https://api.worldbank.org/v2/country/{}/indicator/NY.GDP.MKTP.CD"
23
+ response = requests.get(base_url.format(country_iso_code), params={"date": year, "format": "json"})
24
+
25
+ if response.status_code == 200:
26
+ data = response.json()
27
+ if data and len(data) > 1 and "value" in data[1][0]:
28
+ return f"GDP of {country_iso_code} in {year}: ${data[1][0]['value']:,} USD"
29
+
30
+ return "GDP data not available."
31
 
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
 
46
 
47
 
48
  final_answer = FinalAnswerTool()
49
+ web_search_tool = DuckDuckGoSearchTool()
50
 
51
  # 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:
52
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
67
 
68
  agent = CodeAgent(
69
  model=model,
70
+ tools=[final_answer, get_gdp, image_generation_tool, web_search_tool], ## add your tools here (don't remove final answer)
71
  max_steps=6,
72
  verbosity_level=1,
73
  grammar=None,