Skip to content

Conversation

@janepie
Copy link
Member

@janepie janepie commented Apr 15, 2025

  • routing for car, bike, foot
  • generating map links that make use of the OSM reference widget

Retrieve a URL for a map of a given location.
:param profile: the kind of transport used to travel the route. Available are 'routed-bike', 'routed-foot', 'routed-car'
:param coordinates: the coordinates to route between, format is '53.5667,9.53333;53.550341,10.000654''
: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 :)

"""
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 coordinates: the coordinates to route between, format is '53.5667,9.53333;53.550341,10.000654''
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to split this into two arguments?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm that was me being lazy and it seems to work, splitting is fine by me if there is some benefit

Copy link
Member

Choose a reason for hiding this comment

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

I think the benefit is to make it easier for the LLM to pass the parameters. I would be in favor of doing it just like in get_public_transport_route_for_coordinates with origin_lat, origin_lon, destination_lat and destination_lon.

Copy link
Member

@julien-nc julien-nc left a comment

Choose a reason for hiding this comment

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

"""
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 coordinates: the coordinates to route between, format is '53.5667,9.53333;53.550341,10.000654''
Copy link
Member

Choose a reason for hiding this comment

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

I think the benefit is to make it easier for the LLM to pass the parameters. I would be in favor of doing it just like in get_public_transport_route_for_coordinates with origin_lat, origin_lon, destination_lat and destination_lon.

Comment on lines 97 to 99
Retrieve a URL for a map of a given location.
:param profile: the kind of transport used to travel the route. Available are 'routed-bike', 'routed-foot', 'routed-car'
:param coordinates: the coordinates to route between, format is '53.5667,9.53333;53.550341,10.000654''
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Retrieve a URL for a map of a given location.
:param profile: the kind of transport used to travel the route. Available are 'routed-bike', 'routed-foot', 'routed-car'
:param coordinates: the coordinates to route between, format is '53.5667,9.53333;53.550341,10.000654''
Get a link to a map centered on a given location.
:param location: the location name or address

Copy link
Member Author

@janepie janepie Apr 16, 2025

Choose a reason for hiding this comment

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

You're talking about asking for a route, right? Because showing a location on a map works for me
Screenshot_20250415_143229

The route tool is meant to get the JSON so the LLM can work with the routing data, like comparing routing times by car or train

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I had a look again and it seems like the routing tool is not really working, it's calling the routing tool but not using the information in the answer. It answers with a route but that seems to come from general training

Copy link
Member

@julien-nc julien-nc Apr 16, 2025

Choose a reason for hiding this comment

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

The agent can sometimes answer with a markdown link instead of the raw URL
image
so it does not render the widget. This is a limitation of the chat UI implementation or of the component it is using to render messages.

@janepie
Copy link
Member Author

janepie commented Apr 16, 2025

Found it, lat and lon mixed up :D I guess this is a really good reason to have the coordinates in 4 parameters

"""

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=0'
Copy link
Member

Choose a reason for hiding this comment

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

The values for srv are:

  • 0 for car
  • 1 for bike
  • 2 for foot

Currently it only generates a car link so there's a mismatch between the text response and the preview:
image

Copy link
Member

Choose a reason for hiding this comment

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

Also, to prevent to tool to crash if an invalid profile param is given, it could fallback to "routed-car".

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks!

Signed-off-by: Jana Peper <[email protected]>
@janepie janepie force-pushed the feat/osm branch 2 times, most recently from bb8decc to 2bdf5bd Compare April 16, 2025 12:52
@janepie
Copy link
Member Author

janepie commented Apr 16, 2025

@julien-nc Link should be correct now (by foot as fallback, let's have less cars), but the widget shows the car route

@janepie janepie requested a review from julien-nc April 17, 2025 09:10
Copy link
Member

@julien-nc julien-nc left a comment

Choose a reason for hiding this comment

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

👍

but the widget shows the car route

Fine on my side with a markdown link
image

I'm pretty sure it's because in your context, there's a plain link followed by a dot in the response message. This messes with the automatic link resolving mechanism of NcRichText. The dot is included in the link so the value of srv becomes 2. instead of 2. This is fixed in nextcloud/assistant#221

@janepie
Copy link
Member Author

janepie commented Apr 17, 2025

Yes, works fine now!

@janepie janepie merged commit 824f828 into main Apr 17, 2025
2 checks passed
@janepie janepie deleted the feat/osm branch April 17, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants