From 9b0261170060cfe35da9580336bffc536bd04bdb Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 3 Sep 2024 23:02:04 -0700 Subject: [PATCH] LocationAware --- mesh_bot.py | 7 ++++++- modules/llm.py | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 25b62f3..29cfd58 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -107,8 +107,13 @@ 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 location_enabled: + location_name = where_am_i(str(location[0]), str(location[1], short=True)) + else: + location_name = "Unknown" + if "ask:" in message.lower(): user_input = message.split(":")[1] elif "askai" in message.lower(): diff --git a/modules/llm.py b/modules/llm.py index e75a040..7585f90 100644 --- a/modules/llm.py +++ b/modules/llm.py @@ -33,15 +33,24 @@ PROMPT {input} user={userID} - """ if llmContext_fromGoogle: meshBotAI = meshBotAI + """ CONTEXT + The following is the location the user + {location_name} + The following is for context around the prompt to help guide your response. {context} + """ +else: + meshBotAI = meshBotAI + """ + CONTEXT + The following is the location the user + {location_name} + """ if llmEnableHistory: @@ -80,10 +89,10 @@ def llm_query(input, nodeID=0, location_name=None): # SearchResult object has url= title= description= just grab title and description googleResults.append(f"{result.title} {result.description}") else: - googleResults = ['no context provided'] + googleResults = ['no other context provided'] except Exception as e: logger.debug(f"System: LLM Query: context gathering error: {e}") - googleResults = ['no context provided'] + googleResults = ['no other context provided'] if googleResults: @@ -93,7 +102,8 @@ def llm_query(input, nodeID=0, location_name=None): response = "" result = "" - result = chain_prompt_model.invoke({"input": input, "llmModel": llmModel, "userID": nodeID, "history": llmChat_history, "context": googleResults}) + result = chain_prompt_model.invoke({"input": input, "llmModel": llmModel, "userID": nodeID, \ + "history": llmChat_history, "context": googleResults, "location_name": location_name}) #logger.debug(f"System: LLM Response: " + result.strip().replace('\n', ' ')) response = result.strip().replace('\n', ' ')