Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ex_app/lib/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ def call_model(
Use the same language for your answers as the user used in their message.
Today is {CURRENT_DATE}.
Detect the language the user is using. Reply in the detected language. Do not output the detected language.
Only use the duckduckgo_results_json tool if the user explicitly asks for a web search. If you use the duckduckgo_results_json tool, always state clearly that you did a search on DuckDuckGo.
Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.
You can check which conversations exist using the list_talk_conversations tool, if a conversation cannot be found.
You can check which calendars exist using the list_calendars tool, if a calendar can not be found.
you can find out a user's email address and location by using the find_person_in_contacts tool.
you can find out the current user's location by using the find_details_of_current_user tool.
If an item should be added to a list, check list_calendars for a fitting calendar and add the item as a task there.
Always let the user know where you got the information.
""".replace("{CURRENT_DATE}", current_date)
)

Expand Down
55 changes: 52 additions & 3 deletions ex_app/lib/all_tools/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def get_tools(nc: Nextcloud):
def get_coordinates_for_address(address: str) -> (str, str):
"""
Calculates the coordinates for a given address
When using this tool, you must let the user know that the internet service Open Street Map was used.
:param address: the address to calculate the coordinates for
:return: a tuple of latitude and longitude
"""
Expand Down Expand Up @@ -58,7 +57,6 @@ def get_current_weather_for_coordinates(lat: str, lon: str) -> dict[str, typing.
def get_public_transport_route_for_coordinates(origin_lat: str, origin_lon: str, destination_lat: str, destination_lon: str, routes: int) -> dict[str, typing.Any]:
"""
Retrieve a public transport route between two coordinates
When using get_public_transport_route_for_coordinates, always let the user know that the routing service here.com was used.
:param origin_lat: Latitude of the starting point
:param origin_lon: Longitude of the starting point
:param destination_lat: Latitude of the destination
Expand All @@ -74,10 +72,61 @@ def get_public_transport_route_for_coordinates(origin_lat: str, origin_lon: str,
json = res.json()
return json

@tool
@safe_tool
def get_osm_route(profile: str, origin_lat: str, origin_lon: str, destination_lat: str, destination_lon: str,):
"""
Retrieve a route between two coordinates traveled by foot, car or bike
:param profile: the kind of transport used to travel the route. Available are 'routed-bike', 'routed-foot', 'routed-car'
:param origin_lat: Latitude of the starting point
:param origin_lon: Longitude of the starting point
:param destination_lat: Latitude of the destination
:param destination_lon: Longitude of the destination
:return: a JSON description of the route and a URL to show the route on a map
"""

match profile:
case "routed-car":
profile_num = "0"
case "routed-bike":
profile_num = "1"
case "routed-foot":
profile_num = "2"
case _:
profile = "routed-foot"
profile_num = "2"
url = f'https://routing.openstreetmap.de/{profile}/route/v1/driving/{origin_lon},{origin_lat};{destination_lon},{destination_lat}?overview=false&steps=true'
map_url = f' https://routing.openstreetmap.de/?loc={origin_lat}%2C{origin_lon}&loc={destination_lat}%2C{destination_lon}&srv={profile_num}'
res = httpx.get(url)
json = res.json()
return {'route_json_description': json, 'map_url': map_url}


@tool
@safe_tool
def get_osm_link(location: str):
"""
Retrieve a URL for a map of a given location.
:param location: location name or address
:return: URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copy pasta from above I think :)

"""

res = httpx.get('https://nominatim.openstreetmap.org/search', params={'q': location, 'format': 'json','limit': '1'})
json = res.json()
if 'error' in json:
raise Exception(json['error'])
if len(json) == 0:
raise Exception(f'No results for address {address}')
osm_id = json[0]['osm_id']
osm_type = json[0]['osm_type']
link = f'https://www.openstreetmap.org/{osm_type}/{osm_id}'
return link


return [
get_coordinates_for_address,
get_current_weather_for_coordinates,
get_public_transport_route_for_coordinates
get_public_transport_route_for_coordinates,
get_osm_route,
get_osm_link,
]