From 5daa71e6c1966d31064f048f5169a1fb3ae1d59d Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 3 Sep 2024 22:52:27 -0700 Subject: [PATCH] llmLocationAware enhance with local data to the AI --- mesh_bot.py | 4 +++- modules/llm.py | 2 +- modules/locationdata.py | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index b6f2071..25b62f3 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -107,6 +107,8 @@ def handle_wiki(message): def handle_llm(message_from_id, channel_number, deviceID, message, publicChannel): global llmRunCounter, llmTotalRuntime + location = get_node_location(message_from_id, deviceID) + location_name = where_am_i(str(location[0]), str(location[1], short=True)) if "ask:" in message.lower(): user_input = message.split(":")[1] elif "askai" in message.lower(): @@ -137,7 +139,7 @@ def handle_llm(message_from_id, channel_number, deviceID, message, publicChannel start = time.time() #response = asyncio.run(llm_query(user_input, message_from_id)) - response = llm_query(user_input, message_from_id) + response = llm_query(user_input, message_from_id, location_name) # handle the runtime counter end = time.time() diff --git a/modules/llm.py b/modules/llm.py index 0e8dc67..e75a040 100644 --- a/modules/llm.py +++ b/modules/llm.py @@ -58,7 +58,7 @@ ollama_model = OllamaLLM(model=llmModel) model_prompt = ChatPromptTemplate.from_template(meshBotAI) chain_prompt_model = model_prompt | ollama_model -def llm_query(input, nodeID=0): +def llm_query(input, nodeID=0, location_name=None): global antiFloodLLM, llmChat_history googleResults = [] diff --git a/modules/locationdata.py b/modules/locationdata.py index 7eb21d1..c6ea9cc 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -11,7 +11,7 @@ from modules.log import * trap_list_location = ("whereami", "tide", "moon", "wx", "wxc", "wxa", "wxalert") -def where_am_i(lat=0, lon=0): +def where_am_i(lat=0, lon=0, short=False): whereIam = "" grid = mh.to_maiden(float(lat), float(lon)) @@ -32,11 +32,18 @@ def where_am_i(lat=0, lon=0): whereIam += " Grid: " + grid return whereIam else: - location = geolocator.reverse(lat + ", " + lon) - address = location.raw['address'] - address_components = ['house_number', 'road', 'city', 'state', 'postcode', 'county', 'country'] - whereIam += ' '.join([address.get(component, '') for component in address_components if component in address]) - whereIam += " Grid: " + grid + if short: + location = geolocator.reverse(lat + ", " + lon) + address = location.raw['address'] + address_components = ['city', 'state', 'county', 'country'] + whereIam += ' '.join([address.get(component, '') for component in address_components if component in address]) + return whereIam + else: + location = geolocator.reverse(lat + ", " + lon) + address = location.raw['address'] + address_components = ['house_number', 'road', 'city', 'state', 'postcode', 'county', 'country'] + whereIam += ' '.join([address.get(component, '') for component in address_components if component in address]) + whereIam += " Grid: " + grid return whereIam def get_tide(lat=0, lon=0):