Marco-Danz commited on
Commit
cc7e8c9
·
verified ·
1 Parent(s): 146add0

test name nationality

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -9,36 +9,33 @@ 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 get_local_news_headlines(location: str) -> str:
13
  """
14
- A tool that fetches top local news headlines for a given location using Currents API.
15
  Args:
16
- location: The name of the location or a keyword for the news.
17
  Returns:
18
- A string with the top headlines or an error message.
19
  """
20
  import requests
21
  try:
22
- url = "https://api.currentsapi.services/v1/search"
23
  params = {
24
- "keywords": location,
25
- "language": "en",
26
- "apiKey": "9kgcb14yVbcFQULH9tMpF-ZS0bDx9ISbP7oJEk_lcN7pbpWu",
27
- "limit": 5 # Limit to 5 headlines
28
  }
29
  response = requests.get(url, params=params)
30
  data = response.json()
31
  if data.get("status") == "ok":
32
- headlines = [article["title"] for article in data.get("news", [])]
33
- if headlines:
34
- return f"Top headlines in {location}:\n" + "\n".join(headlines)
35
  else:
36
- return f"No news found for {location}."
37
  else:
38
- return "Error fetching news: " + data.get("message", "Unknown error")
39
  except Exception as e:
40
  return f"Error fetching news: {str(e)}"
41
-
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str:
44
  """A tool that fetches the current local time in a specified timezone.
@@ -76,7 +73,7 @@ with open("prompts.yaml", 'r') as stream:
76
 
77
  agent = CodeAgent(
78
  model=model,
79
- tools=[final_answer, get_local_news_headlines], ## add your tools here (don't remove final answer)
80
  max_steps=6,
81
  verbosity_level=1,
82
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def get_nationality_from_name(name: str) -> str:
13
  """
14
+ A tool that predict the nationality from a given name.
15
  Args:
16
+ name: The name of the person to predict natiolnality.
17
  Returns:
18
+ A string with the predicted nationality.
19
  """
20
  import requests
21
  try:
22
+ url = "https://api.nationalize.io"
23
  params = {
24
+ "name": name
 
 
 
25
  }
26
  response = requests.get(url, params=params)
27
  data = response.json()
28
  if data.get("status") == "ok":
29
+ countries = [country["country_id"] for country in data.get("country", [])]
30
+ if countries:
31
+ return f"Top countries for {name}:\n" + "\n".join(countries)
32
  else:
33
+ return f"No countries found for {name}."
34
  else:
35
+ return "Error fetching date: " + data.get("message", "Unknown error")
36
  except Exception as e:
37
  return f"Error fetching news: {str(e)}"
38
+ #https://api.nationalize.io?name=nathaniel
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str:
41
  """A tool that fetches the current local time in a specified timezone.
 
73
 
74
  agent = CodeAgent(
75
  model=model,
76
+ tools=[final_answer, get_nationality_from_name], ## add your tools here (don't remove final answer)
77
  max_steps=6,
78
  verbosity_level=1,
79
  grammar=None,