Skip to content

Commit

Permalink
Added nearby repeater search to bot.
Browse files Browse the repository at this point in the history
  • Loading branch information
afourney committed Oct 3, 2024
1 parent 6277d5c commit d88d7b3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/aprs_assistant/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
from ._bandcond import get_band_conditions
from ._weather import get_weather, format_noaa_alerts, get_noaa_alerts
from ._callsign import get_callsign_info, itu_prefix_lookup
from ._repeaters import search_repeaters_by_location, format_repeater

from ._tool_definitions import (
TOOL_WEB_SEARCH,
TOOL_USER_WEATHER,
TOOL_REGIONAL_WEATHER,
TOOL_BAND_CONDITIONS,
TOOL_CALLSIGN_SEARCH,
TOOL_NEARBY_REPEATERS,
)

tf = TimezoneFinderL(in_memory=True) # reuse
Expand Down Expand Up @@ -190,7 +192,12 @@ def _generate_reply(fromcall, messages):
inner_messages.append(response)

# Determine if it can be answered directly or if we should search
tools = [TOOL_BAND_CONDITIONS, TOOL_REGIONAL_WEATHER, TOOL_CALLSIGN_SEARCH]
tools = [
TOOL_BAND_CONDITIONS,
TOOL_REGIONAL_WEATHER,
TOOL_CALLSIGN_SEARCH,
TOOL_NEARBY_REPEATERS,
]

# API key needed for web search
if len(os.environ.get("BING_API_KEY", "").strip()) > 0:
Expand Down Expand Up @@ -275,6 +282,22 @@ def _generate_reply(fromcall, messages):
if country_code == "us"
else True, # User's location, (local preference)
)

elif function_name == TOOL_NEARBY_REPEATERS["function"]["name"]:
results = ""
n = 0

for r in search_repeaters_by_location(
lat=position["latitude"], lon=position["longitude"]
):
n += 1
results += format_repeater(r).strip() + "\n\n"
if n >= 10:
break

if n == 0:
results = "No repeaters found nearby.\nTry searching the web, or checking another database."

else:
results = f"Unknown function: {function_name}"

Expand Down
13 changes: 13 additions & 0 deletions src/aprs_assistant/_tool_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,16 @@
},
},
}

TOOL_NEARBY_REPEATERS = {
"type": "function",
"function": {
"name": "nearby_repeaters",
"description": "Return a list of amateur radio repeaters near the user's current location.",
"parameters": {
"type": "object",
"properties": {},
"required": [],
},
},
}

0 comments on commit d88d7b3

Please sign in to comment.