Spaces:
Sleeping
Sleeping
get_coordinates_osm added
Browse files
app.py
CHANGED
|
@@ -18,6 +18,36 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -55,7 +85,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,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def get_coordinates_osm(location_name:str) -> str:
|
| 24 |
+
|
| 25 |
+
"""A tool that fetches gps coordinates of a given place in the world
|
| 26 |
+
Args:
|
| 27 |
+
arg1: the name of the location (e.g., 'Kinshasa, Gombe').
|
| 28 |
+
"""
|
| 29 |
+
headers = {
|
| 30 |
+
'User-Agent': 'MyGeocodingApp/1.0 (youremail@example.com)'
|
| 31 |
+
}
|
| 32 |
+
location_name = location_name.replace(" ", "+")
|
| 33 |
+
base_url = "https://nominatim.openstreetmap.org/search"
|
| 34 |
+
full_url = f"{base_url}?q={requests.utils.quote(location_name)}&format=json&limit=5"
|
| 35 |
+
|
| 36 |
+
response = requests.get(full_url, headers=headers)
|
| 37 |
+
|
| 38 |
+
if response.status_code != 200:
|
| 39 |
+
raise Exception("Erreur lors de la requête à l'API OpenStreetMap")
|
| 40 |
+
|
| 41 |
+
response_list = response.json()
|
| 42 |
+
|
| 43 |
+
if len(response_list) == 0:
|
| 44 |
+
raise Exception("Aucune réponse trouvée pour cette recherche")
|
| 45 |
+
|
| 46 |
+
latitude = float(response_list[0]['lat'])
|
| 47 |
+
longitude = float(response_list[0]['lon'])
|
| 48 |
+
|
| 49 |
+
return {'latitude': latitude, 'longitude': longitude}
|
| 50 |
+
|
| 51 |
@tool
|
| 52 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 53 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 85 |
|
| 86 |
agent = CodeAgent(
|
| 87 |
model=model,
|
| 88 |
+
tools=[final_answer, get_coordinates_osm], ## add your tools here (don't remove final answer)
|
| 89 |
max_steps=6,
|
| 90 |
verbosity_level=1,
|
| 91 |
grammar=None,
|