Spaces:
Runtime error
Runtime error
Built Language Finder Agent
Browse files
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
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 64 |
-
description=
|
| 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 |
|