OSM: better accuracy in multi-turn conversations

This commit is contained in:
projectmoon 2024-08-05 14:38:55 +02:00
parent 45bd9bb5e4
commit c115f656a4
2 changed files with 25 additions and 10 deletions

View File

@ -1,5 +1,10 @@
# OpenStreetMap Tool # OpenStreetMap Tool
**0.2.5:**
- Better accuracy in turn by turn conversations: model encouraged to
specify the name of the city and country when searching, so it's
less likely to report results from a different country.
**0.2.4:** **0.2.4:**
- Actually make use of the limit parameter when searching Nominatim. - Actually make use of the limit parameter when searching Nominatim.

26
osm.py
View File

@ -2,7 +2,7 @@
title: OpenStreetMap Tool title: OpenStreetMap Tool
author: projectmoon author: projectmoon
author_url: https://git.agnos.is/projectmoon/open-webui-filters author_url: https://git.agnos.is/projectmoon/open-webui-filters
version: 0.2.4 version: 0.2.5
license: AGPL-3.0+ license: AGPL-3.0+
required_open_webui_version: 0.3.9 required_open_webui_version: 0.3.9
""" """
@ -22,6 +22,14 @@ NO_RESULTS = ("No results found. Tell the user you found no results. "
"Do not make up answers or hallucinate. Only say you " "Do not make up answers or hallucinate. Only say you "
"found no results.") "found no results.")
NO_CONFUSION = ("**IMPORTANT!:** Check that the results match the location "
"the user is talking about, by analyzing the conversation history. "
"Sometimes there are places with the same "
"names, but in different cities or countries. If the results are for "
"a different city or country than the user is interested in, say so: "
"tell the user that the results are for the wrong place, and tell them "
"to be more specific in their query.")
def way_has_info(way): def way_has_info(way):
""" """
Determine if an OSM way entry is useful to us. This means it Determine if an OSM way entry is useful to us. This means it
@ -269,9 +277,11 @@ class OsmSearcher:
"\n\nAnd so on.\n\n" "\n\nAnd so on.\n\n"
"Only use relevant results. If there are no relevant results, " "Only use relevant results. If there are no relevant results, "
"say so. Do not make up answers or hallucinate. " "say so. Do not make up answers or hallucinate. "
f"\n\n{NO_CONFUSION}\n\n"
"The primary results are below. " "The primary results are below. "
"Remember that the CLOSEST result is first, and you should use " "Remember that the CLOSEST result is first, and you should use "
"that result first. " "that result first. "
"Prioritize OSM **nodes** over **ways** and **relations**."
"\n\n----------\n\n" "\n\n----------\n\n"
f"{str(things_nearby)}" f"{str(things_nearby)}"
f"{extra_info}" f"{extra_info}"
@ -340,7 +350,7 @@ class Tools:
OpenStreetMap near a given place or address. The location of the OpenStreetMap near a given place or address. The location of the
address or place is reverse geo-coded, then nearby results address or place is reverse geo-coded, then nearby results
are fetched from OpenStreetMap. are fetched from OpenStreetMap.
:param place: The name of a place or an address, which will be sent to Nominatim. :param place: The name of a place or an address. City and country must be specified, if known.
:return: A list of nearby grocery stores or supermarkets, if found. :return: A list of nearby grocery stores or supermarkets, if found.
""" """
searcher = OsmSearcher(self.valves) searcher = OsmSearcher(self.valves)
@ -352,7 +362,7 @@ class Tools:
Finds bakeries on OpenStreetMap near a given place or Finds bakeries on OpenStreetMap near a given place or
address. The location of the address or place is reverse address. The location of the address or place is reverse
geo-coded, then nearby results are fetched from OpenStreetMap. geo-coded, then nearby results are fetched from OpenStreetMap.
:param place: The name of a place or an address, which will be sent to Nominatim. :param place: The name of a place or an address. City and country must be specified, if known.
:return: A list of nearby bakeries, if found. :return: A list of nearby bakeries, if found.
""" """
searcher = OsmSearcher(self.valves) searcher = OsmSearcher(self.valves)
@ -365,7 +375,7 @@ class Tools:
OpenStreetMap near a given place or address. The location of the OpenStreetMap near a given place or address. The location of the
address or place is reverse geo-coded, then nearby results address or place is reverse geo-coded, then nearby results
are fetched from OpenStreetMap. are fetched from OpenStreetMap.
:param place: The name of a place or an address, which will be sent to Nominatim. :param place: The name of a place or an address. City and country must be specified, if known.
:return: A list of nearby restaurants, eateries, etc, if found. :return: A list of nearby restaurants, eateries, etc, if found.
""" """
tags = [ tags = [
@ -388,7 +398,7 @@ class Tools:
activities on OpenStreetMap near a given place or address. The location activities on OpenStreetMap near a given place or address. The location
of the address or place is reverse geo-coded, then nearby results are fetched of the address or place is reverse geo-coded, then nearby results are fetched
from OpenStreetMap. from OpenStreetMap.
:param place: The name of a place or an address, which will be sent to Nominatim. :param place: The name of a place or an address. City and country must be specified, if known.
:return: A list of swimming poools or places, if found. :return: A list of swimming poools or places, if found.
""" """
tags = [ tags = [
@ -407,7 +417,7 @@ class Tools:
activities on OpenStreetMap near a given place or address. The location activities on OpenStreetMap near a given place or address. The location
of the address or place is reverse geo-coded, then nearby results are fetched of the address or place is reverse geo-coded, then nearby results are fetched
from OpenStreetMap. from OpenStreetMap.
:param place: The name of a place or an address, which will be sent to Nominatim. :param place: The name of a place or an address. City and country must be specified, if known.
:return: A list of recreational places, if found. :return: A list of recreational places, if found.
""" """
tags = [ tags = [
@ -429,7 +439,7 @@ class Tools:
OpenStreetMap near a given place or address. The location of the OpenStreetMap near a given place or address. The location of the
address or place is reverse geo-coded, then nearby results address or place is reverse geo-coded, then nearby results
are fetched from OpenStreetMap. are fetched from OpenStreetMap.
:param place: The name of a place or an address, which will be sent to Nominatim. :param place: The name of a place or an address. City and country must be specified, if known.
:return: A list of nearby places of worship, if found. :return: A list of nearby places of worship, if found.
""" """
tags = ["amenity=place_of_worship"] tags = ["amenity=place_of_worship"]
@ -443,7 +453,7 @@ class Tools:
OpenStreetMap near a given place or address. The location of the OpenStreetMap near a given place or address. The location of the
address or place is reverse geo-coded, then nearby results address or place is reverse geo-coded, then nearby results
are fetched from OpenStreetMap. are fetched from OpenStreetMap.
:param place: The name of a place or an address, which will be sent to Nominatim. :param place: The name of a place or an address. City and country must be specified, if known.
:return: A list of nearby accommodation, if found. :return: A list of nearby accommodation, if found.
""" """
tags = [ tags = [