From 68e0be9608155db5f76eb5213d4e86ffac1d4369 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Wed, 25 Sep 2024 20:51:14 +0200 Subject: [PATCH] OSM: Find specific stores near coordinates. --- CHANGELOG.md | 8 ++++++++ osm.py | 26 +++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b61e9e3..084d7a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # OpenStreetMap Tool +**0.8.0:** + - Added ability to find specific stores and businesses near + coordinates. Helps LLM answer questions about arbitrary businesses + that it might not find with the pre-defined search functions. + - Pull shop type from Nominatim results when class=shop. Improves + accuracy of searching for specific places by telling LLM the type + of shop. + **0.7.0:** - Emit event to web UI, showing what the tool is doing. - This can be toggled, as a valve setting (not a user valve). diff --git a/osm.py b/osm.py index 71087f0..4574cd9 100644 --- a/osm.py +++ b/osm.py @@ -2,7 +2,7 @@ title: OpenStreetMap Tool author: projectmoon author_url: https://git.agnos.is/projectmoon/open-webui-filters -version: 0.7.0 +version: 0.8.0 license: AGPL-3.0+ required_open_webui_version: 0.3.21 """ @@ -267,7 +267,7 @@ def parse_thing_amenity_type(thing: dict, tags: dict) -> Optional[dict]: if 'amenity' in tags: return tags['amenity'] - if thing.get('class') == 'amenity': + if thing.get('class') == 'amenity' or thing.get('class') == 'shop': return thing.get('type') # fall back to tag categories, like shop=* @@ -495,6 +495,8 @@ class OsmSearcher: if not data: raise ValueError(f"No results found for query '{query}'") + + print(data) return data[:limit] else: await self.event_error(Exception(response.text)) @@ -706,6 +708,25 @@ class Tools: print(f"[OSM] Resolving [{latitude}, {longitude}] to address.") return await self.find_specific_place(f"{latitude}, {longitude}", __event_emitter__) + async def find_specific_store_near_coordinates( + self, store_or_business_name: str, latitude: float, longitude: float, __event_emitter__ + ) -> str: + """ + Finds specifically named stores or businesses near the given + GPS coordinates. This can be used for general or specific things, + like 'gas station' or 'grocery store', or the name of a specific + chain (like 'Wal-Mart' or 'Albert Heijn'). This function is intended + for finding specific chains or businesses near the given coordinates. + Use this if the user asks about businesses nearby. + :param store_or_business_name: Name of store or business to look for. + :param latitude: The latitude portion of the GPS coordinate. + :param longitude: The longitude portion of the GPS coordinate. + :return: Information about the address or places near the coordinates. + """ + print(f"Searching for '{store_or_business_name}' near {latitude},{longitude}") + query = f"{store_or_business_name} {latitude},{longitude}" + return await self.find_specific_place(query, __event_emitter__) + async def find_specific_place(self, address_or_place: str, __event_emitter__) -> str: """ Looks up details on OpenStreetMap of a specific address, landmark, @@ -1047,7 +1068,6 @@ class Tools: :param place: The name of a place, an address, or GPS coordinates. City and country must be specified, if known. :param category: The category of place, shop, etc to look up. :return: A list of nearby shops. - """ print(f"Generic catch handler called with {category}") resp = (