Venkat212739 commited on
Commit
a37a252
·
verified ·
1 Parent(s): 8c5c24b

Built Language Finder Agent

Browse files
Files changed (1) hide show
  1. app.py +37 -10
app.py CHANGED
@@ -7,16 +7,43 @@ 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 get_current_time_in_timezone(timezone: str) -> str:
@@ -55,13 +82,13 @@ 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,
62
  planning_interval=None,
63
- name=None,
64
- description=None,
65
  prompt_templates=prompt_templates
66
  )
67
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
+ def get_languages_by_country(country_name: str) -> str:
12
+ """Fetch the official or major languages spoken in a country.
13
+
14
  Args:
15
+ country_name: Name of the country, for example 'India', 'Estonia', or 'Japan'.
 
16
  """
17
+ try:
18
+ url = f"https://restcountries.com/v3.1/name/{country_name}"
19
+ response = requests.get(url, timeout=20)
20
+ response.raise_for_status()
21
+ data = response.json()
22
+
23
+ if not data:
24
+ return f"No country found for '{country_name}'."
25
+
26
+ country = data[0]
27
+ name = country.get("name", {}).get("common", country_name)
28
+ languages = country.get("languages", {})
29
+
30
+ if not languages:
31
+ return f"I found {name}, but no language information was available."
32
+
33
+ language_list = ", ".join(languages.values())
34
+ capital = country.get("capital", ["Unknown"])[0]
35
+ region = country.get("region", "Unknown")
36
+
37
+ return (
38
+ f"Country: {name}\n"
39
+ f"Capital: {capital}\n"
40
+ f"Region: {region}\n"
41
+ f"Languages: {language_list}"
42
+ )
43
+
44
+ except Exception as e:
45
+ return f"Error fetching language data for '{country_name}': {str(e)}"
46
+
47
 
48
  @tool
49
  def get_current_time_in_timezone(timezone: str) -> str:
 
82
 
83
  agent = CodeAgent(
84
  model=model,
85
+ tools=[final_answer, get_languages_by_country], ## add your tools here (don't remove final answer)
86
  max_steps=6,
87
  verbosity_level=1,
88
  grammar=None,
89
  planning_interval=None,
90
+ name="Language Finder Agent",
91
+ description="An AI agent that finds the languages spoken in a country.",
92
  prompt_templates=prompt_templates
93
  )
94