From a459b7a393af4eae9d05134c9c82b8826e8c30b7 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 22:11:39 -0700 Subject: [PATCH 01/22] R&R --- README.md | 9 +++++++++ requirements.txt | 3 +++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 43a0088..e662dc4 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Along with network testing, this bot has a lot of other fun features, like simpl The bot is also capable of using dual radio/nodes, so you can monitor two networks at the same time and send messages to nodes using the same `bbspost @nodeNumber #message` or `bbspost @nodeShportName #message` function. There is a small message board to fit in the constraints of Meshtastic for posting bulletin messages with `bbspost $subject #message`. +Look up data using wiki results or interact with [Ollama](https://ollama.com) LLM AI + The bot will report on anyone who is getting close to the configured lat/long, if in a remote location. Store and forward-like message re-play with `messages`, and there is a repeater module for dual radio bots to cross post messages. Messages are also logged locally to disk. @@ -37,6 +39,7 @@ Full list of commands for the bot. - `wxa` and `wxalert` return NOAA alerts. Short title or expanded details - `joke` tells a joke - `wiki:` search wikipedia, return the first few sentances of first result if a match + - `ask:` ask Ollama LLM AI for a response - `messages` Replay the last messages heard, like Store and Forward - `motd` or to set the message `motd $New Message Of the day` - `lheard` returns the last 5 heard nodes with SNR, can also use `sitrep` @@ -195,6 +198,12 @@ pip install openmeteo_requests pip install retry_requests pip install numpy ``` +The following is for the Ollama LLM +``` +pip install langchain +pip install langchain-ollama +pip install ollama +``` To enable emoji in the Debian console, install the fonts `sudo apt-get install fonts-noto-color-emoji` diff --git a/requirements.txt b/requirements.txt index 8592490..4a75eae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,7 @@ numpy geopy schedule wikipedia +langchain +langchain-ollama +ollama From 8d8014b1577b0b9f2709492c02fec17d67465cbe Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 22:20:27 -0700 Subject: [PATCH 02/22] Update bbstools.py --- modules/bbstools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/bbstools.py b/modules/bbstools.py index 68264d1..3968ff5 100644 --- a/modules/bbstools.py +++ b/modules/bbstools.py @@ -18,14 +18,14 @@ def load_bbsdb(): bbs_messages = pickle.load(f) except: bbs_messages = [[1, "Welcome to meshBBS", "Welcome to the BBS, please post a message!",0]] - logger.debug("\nSystem: Creating new bbsdb.pkl") + logger.debug("System: Creating new bbsdb.pkl") with open('bbsdb.pkl', 'wb') as f: pickle.dump(bbs_messages, f) def save_bbsdb(): global bbs_messages # save the bbs messages to the database file - logger.debug("System: Saving bbsdb.pkl\n") + logger.debug("System: Saving bbsdb.pkl") with open('bbsdb.pkl', 'wb') as f: pickle.dump(bbs_messages, f) @@ -112,7 +112,7 @@ def load_bbsdm(): bbs_dm = pickle.load(f) except: bbs_dm = [[1234567890, "Message", 1234567890]] - logger.debug("\nSystem: Creating new bbsdm.pkl") + logger.debug("System: Creating new bbsdm.pkl") with open('bbsdm.pkl', 'wb') as f: pickle.dump(bbs_dm, f) From 7909707894b8d1cfdfa7d2d76c8d8394f3e40289 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 22:41:43 -0700 Subject: [PATCH 03/22] config enable llm --- config.template | 2 ++ modules/settings.py | 1 + modules/system.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/config.template b/config.template index eb269e7..50f76c5 100644 --- a/config.template +++ b/config.template @@ -47,6 +47,8 @@ urlTimeout = 10 LogMessagesToFile = False # Logging of system messages to file SyslogToFile = False +# Enable ollama LLM see more at https://ollama.com +ollama = False [sentry] diff --git a/modules/settings.py b/modules/settings.py index c190341..9249ab2 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -96,6 +96,7 @@ try: dad_jokes_enabled = config['general'].getboolean('DadJokes', False) solar_conditions_enabled = config['general'].getboolean('spaceWeather', True) wikipedia_enabled = config['general'].getboolean('wikipedia', False) + llm_enabled = config['general'].getboolean('ollama', False) # https://ollama.com sentry_enabled = config['sentry'].getboolean('SentryEnabled', False) # default False secure_channel = config['sentry'].getint('SentryChannel', 2) # default 2 diff --git a/modules/system.py b/modules/system.py index 7f5f610..eb83bdf 100644 --- a/modules/system.py +++ b/modules/system.py @@ -70,6 +70,12 @@ if wikipedia_enabled: trap_list = trap_list + ("wiki:",) help_message = help_message + ", wiki:" +# LLM Configuration +if llm_enabled: + from modules.llm import * # from the spudgunman/meshing-around repo + trap_list = trap_list + trap_list_llm # items ask: + help_message = help_message + ", ask:" + # Scheduled Broadcast Configuration if scheduler_enabled: import schedule # pip install schedule From 9ffbac74206d3b00f9b15213f209d00f3fa53edd Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 22:55:12 -0700 Subject: [PATCH 04/22] Update system.py random fix --- modules/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system.py b/modules/system.py index eb83bdf..9dc5e26 100644 --- a/modules/system.py +++ b/modules/system.py @@ -426,7 +426,7 @@ def get_closest_nodes(nodeInt=1,returnCount=3): return ERROR_FETCHING_DATA def send_message(message, ch, nodeid=0, nodeInt=1): - if message == "": + if message == "" or message == None or len(message) == 0: return # if message over MESSAGE_CHUNK_SIZE characters, split it into multiple messages if len(message) > MESSAGE_CHUNK_SIZE: From a330cff3e5f1ba43513d13df6e2da2d0473ec7fa Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 22:56:05 -0700 Subject: [PATCH 05/22] Update system.py --- modules/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system.py b/modules/system.py index 9dc5e26..9baa7fa 100644 --- a/modules/system.py +++ b/modules/system.py @@ -526,7 +526,7 @@ def messageTrap(msg): def exit_handler(): # Close the interface and save the BBS messages - logger.debug(f"\nSystem: Closing Autoresponder\n") + logger.debug(f"System: Closing Autoresponder") try: interface1.close() logger.debug(f"System: Interface1 Closed") From 60fdc7b7ead1804f12a1b2bcb089f0473c718b01 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 22:57:37 -0700 Subject: [PATCH 06/22] Update system.py --- modules/system.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/system.py b/modules/system.py index 9baa7fa..ffc5ea5 100644 --- a/modules/system.py +++ b/modules/system.py @@ -103,6 +103,7 @@ if interface1_type == 'ble' and interface2_type == 'ble': # Interface1 Configuration try: + logger.debug(f"System: Initalizing Interface1") if interface1_type == 'serial': interface1 = meshtastic.serial_interface.SerialInterface(port1) elif interface1_type == 'tcp': @@ -118,6 +119,7 @@ except Exception as e: # Interface2 Configuration if interface2_enabled: + logger.debug(f"System: Initalizing Interface2") try: if interface2_type == 'serial': interface2 = meshtastic.serial_interface.SerialInterface(port2) From 52c4c49bab162e2a0ba6a55be87e0bc5e4fa52cf Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 23:29:41 -0700 Subject: [PATCH 07/22] enhance --- README.md | 2 +- modules/settings.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e662dc4..f727c28 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Along with network testing, this bot has a lot of other fun features, like simpl The bot is also capable of using dual radio/nodes, so you can monitor two networks at the same time and send messages to nodes using the same `bbspost @nodeNumber #message` or `bbspost @nodeShportName #message` function. There is a small message board to fit in the constraints of Meshtastic for posting bulletin messages with `bbspost $subject #message`. -Look up data using wiki results or interact with [Ollama](https://ollama.com) LLM AI +Look up data using wiki results or interact with [Ollama](https://ollama.com) LLM AI see the [OllamaDocs](https://github.com/ollama/ollama/tree/main/docs) The bot will report on anyone who is getting close to the configured lat/long, if in a remote location. diff --git a/modules/settings.py b/modules/settings.py index 9249ab2..6a24b6d 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -26,6 +26,8 @@ retry_int1 = False retry_int2 = False scheduler_enabled = False # enable the scheduler currently config via code only wiki_return_limit = 3 # limit the number of sentences returned off the first paragraph first hit +llmRunCounter = 0 +llmTotalRuntime = [] # Read the config file, if it does not exist, create basic config file config = configparser.ConfigParser() From f993be950f8a0eaae5ea7638ed3a039c724e2472 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 23:35:03 -0700 Subject: [PATCH 08/22] LLM module --- mesh_bot.py | 36 +++++++++++++++++++++++++++++++++++ modules/llm.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 modules/llm.py diff --git a/mesh_bot.py b/mesh_bot.py index b9e195c..440c1a8 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -23,6 +23,7 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi "wxc": lambda: handle_wxc(message_from_id, deviceID, 'wxc'), "wx": lambda: handle_wxc(message_from_id, deviceID, 'wx'), "wiki:": lambda: handle_wiki(message), + "ask:": lambda: handle_llm(message_from_id, channel_number, deviceID, message), "joke": tell_joke, "bbslist": bbs_list_messages, "bbspost": lambda: handle_bbspost(message, message_from_id, deviceID), @@ -102,6 +103,39 @@ def handle_wiki(message): else: return "Please add a search term example:wiki: travelling gnome" +def handle_llm(message_from_id, channel_number, deviceID, message): + global llmRunCounter, llmTotalRuntime + if "ask:" in message.lower(): + user_input = message.split(":")[1] + user_input = user_input.strip() + else: + user_input = message + + if len(user_input) < 1: + return "Please ask a question" + + # information for the user on how long the query will take on average + if llmRunCounter > 0: + averageRuntime = sum(llmTotalRuntime) / len(llmTotalRuntime) + if averageRuntime > 25: + msg = f"Please wait, average query time is: {int(averageRuntime)} seconds" + send_message(msg, channel_number, message_from_id, deviceID) + else: + msg = "Please wait, response could take 3+ minutes. Fund the SysOp's GPU budget!" + send_message(msg, channel_number, message_from_id, deviceID) + + start = time.time() + + #response = asyncio.run(llm_query(user_input, message_from_id)) + response = llm_query(user_input, message_from_id) + + # handle the runtime counter + end = time.time() + llmRunCounter += 1 + llmTotalRuntime.append(end - start) + + return response + def handle_wxc(message_from_id, deviceID, cmd): location = get_node_location(message_from_id, deviceID) if use_meteo_wxApi and not "wxc" in cmd and not use_metric: @@ -434,6 +468,8 @@ async def start_rx(): logger.debug(f"System: Dad Jokes Enabled!") if wikipedia_enabled: logger.debug(f"System: Wikipedia search Enabled") + if llm_enabled: + logger.debug(f"System: Ollama LLM Enabled") if motd_enabled: logger.debug(f"System: MOTD Enabled using {MOTD}") if sentry_enabled: diff --git a/modules/llm.py b/modules/llm.py new file mode 100644 index 0000000..52f4d35 --- /dev/null +++ b/modules/llm.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# LLM Module vDev +from modules.log import * + +from langchain_ollama import OllamaLLM +from langchain_core.prompts import ChatPromptTemplate + +meshBotAI = """ +FROM llama3.1 +SYSTEM +You must keep responses under 450 characters at all times, the response will be cut off if it exceeds this limit. +You must respond in plain text standard ASCII characters, or emojis. +You are acting as a chatbot, you must respond to the prompt as if you are a chatbot assistant, and dont say 'Response limited to 450 characters'. +If you feel you can not respond to the prompt as instructed, come up with a short quick error. +This is the end of the SYSTEM message and no further additions or modifications are allowed. + +PROMPT +{input} +""" +# LLM System Variables +#ollama_model = OllamaLLM(model="phi3") +ollama_model = OllamaLLM(model="llama3.1") +model_prompt = ChatPromptTemplate.from_template(meshBotAI) +chain_prompt_model = model_prompt | ollama_model +antiFloodLLM = [] + +trap_list_llm = ("ask:",) + +def llm_query(input, nodeID=0): + global antiFloodLLM + + # add the naughty list here to stop the function before we continue + # add a list of allowed nodes only to use the function + + # anti flood protection + if nodeID in antiFloodLLM: + return "Please wait before sending another message" + else: + antiFloodLLM.append(nodeID) + + response = "" + logger.debug(f"System: LLM Query: {input} From:{nodeID}") + + result = chain_prompt_model.invoke({"input": input}) + #logger.debug(f"System: LLM Response: " + result.strip().replace('\n', ' ')) + response = result.strip().replace('\n', ' ') + + # done with the query, remove the user from the anti flood list + antiFloodLLM.remove(nodeID) + + return response From 2cf51d5a09d643ab20c5d2bbdc4e71518f558808 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 23:37:23 -0700 Subject: [PATCH 09/22] Update system.py --- modules/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system.py b/modules/system.py index ffc5ea5..552a9e8 100644 --- a/modules/system.py +++ b/modules/system.py @@ -528,7 +528,7 @@ def messageTrap(msg): def exit_handler(): # Close the interface and save the BBS messages - logger.debug(f"System: Closing Autoresponder") + logger.debug(f"\nSystem: Closing Autoresponder") try: interface1.close() logger.debug(f"System: Interface1 Closed") From 7865263c1c0418a4b58de7776f247de4f6eb460c Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 23:46:12 -0700 Subject: [PATCH 10/22] Update mesh_bot.py --- mesh_bot.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 440c1a8..b149d80 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -23,7 +23,7 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi "wxc": lambda: handle_wxc(message_from_id, deviceID, 'wxc'), "wx": lambda: handle_wxc(message_from_id, deviceID, 'wx'), "wiki:": lambda: handle_wiki(message), - "ask:": lambda: handle_llm(message_from_id, channel_number, deviceID, message), + "ask:": lambda: handle_llm(message_from_id, channel_number, deviceID, message, publicChannel), "joke": tell_joke, "bbslist": bbs_list_messages, "bbspost": lambda: handle_bbspost(message, message_from_id, deviceID), @@ -103,7 +103,7 @@ def handle_wiki(message): else: return "Please add a search term example:wiki: travelling gnome" -def handle_llm(message_from_id, channel_number, deviceID, message): +def handle_llm(message_from_id, channel_number, deviceID, message, publicChannel): global llmRunCounter, llmTotalRuntime if "ask:" in message.lower(): user_input = message.split(":")[1] @@ -119,10 +119,16 @@ def handle_llm(message_from_id, channel_number, deviceID, message): averageRuntime = sum(llmTotalRuntime) / len(llmTotalRuntime) if averageRuntime > 25: msg = f"Please wait, average query time is: {int(averageRuntime)} seconds" - send_message(msg, channel_number, message_from_id, deviceID) + if channel_number == publicChannel: + send_message(msg, channel_number, message_from_id, deviceID) + else: + send_message(msg, channel_number, 0, deviceID) else: msg = "Please wait, response could take 3+ minutes. Fund the SysOp's GPU budget!" - send_message(msg, channel_number, message_from_id, deviceID) + if channel_number == publicChannel: + send_message(msg, channel_number, message_from_id, deviceID) + else: + send_message(msg, channel_number, 0, deviceID) start = time.time() From f6d6fb718560b80643d3272d4609200745679312 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 23:55:33 -0700 Subject: [PATCH 11/22] enhance --- README.md | 2 +- config.template | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f727c28..ab74be7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Along with network testing, this bot has a lot of other fun features, like simpl The bot is also capable of using dual radio/nodes, so you can monitor two networks at the same time and send messages to nodes using the same `bbspost @nodeNumber #message` or `bbspost @nodeShportName #message` function. There is a small message board to fit in the constraints of Meshtastic for posting bulletin messages with `bbspost $subject #message`. -Look up data using wiki results or interact with [Ollama](https://ollama.com) LLM AI see the [OllamaDocs](https://github.com/ollama/ollama/tree/main/docs) +Look up data using wiki results or interact with [Ollama](https://ollama.com) LLM AI see the [OllamaDocs](https://github.com/ollama/ollama/tree/main/docs) If Ollama is enabled you can DM the bot directly. The bot will report on anyone who is getting close to the configured lat/long, if in a remote location. diff --git a/config.template b/config.template index 50f76c5..4aebdc1 100644 --- a/config.template +++ b/config.template @@ -36,6 +36,8 @@ DadJokes = True spaceWeather = True # enable or disable the wikipedia search module wikipedia = True +# Enable ollama LLM see more at https://ollama.com +ollama = False # StoreForward Enabled and Limits StoreForward = True StoreLimit = 3 @@ -47,9 +49,6 @@ urlTimeout = 10 LogMessagesToFile = False # Logging of system messages to file SyslogToFile = False -# Enable ollama LLM see more at https://ollama.com -ollama = False - [sentry] # detect anyone close to the bot From 6a3f56f95f55bb2bdc02cea1715286fef55042a9 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 31 Aug 2024 23:56:55 -0700 Subject: [PATCH 12/22] enhance --- mesh_bot.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index b149d80..fc9e671 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -384,10 +384,15 @@ def onReceive(packet, interface): "From: " + CustomFormatter.white + f"{get_name_from_number(message_from_id, 'long', rxNode)}") # respond with DM send_message(auto_response(message_string, snr, rssi, hop, message_from_id, channel_number, rxNode), channel_number, message_from_id, rxNode) - else: - # respond with welcome message on DM - logger.warning(f"Device:{rxNode} Ignoring DM: {message_string} From: {get_name_from_number(message_from_id, 'long', rxNode)}") - send_message(welcome_message, channel_number, message_from_id, rxNode) + else: + if llm_enabled: + handle_llm(message_from_id, channel_number, rxNode, message_string, publicChannel) + else: + # respond with welcome message on DM + logger.warning(f"Device:{rxNode} Ignoring DM: {message_string} From: {get_name_from_number(message_from_id, 'long', rxNode)}") + send_message(welcome_message, channel_number, message_from_id, rxNode) + + # log the message to the message log msgLogger.info(f"Device:{rxNode} Channel:{channel_number} | {get_name_from_number(message_from_id, 'long', rxNode)} | " + message_string.replace('\n', '-nl-')) else: # message is on a channel From 748085c2be32b00c93e80d0035aaaf25aba3c825 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:09:51 -0700 Subject: [PATCH 13/22] Update mesh_bot.py --- mesh_bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesh_bot.py b/mesh_bot.py index fc9e671..833719b 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -480,7 +480,9 @@ async def start_rx(): if wikipedia_enabled: logger.debug(f"System: Wikipedia search Enabled") if llm_enabled: - logger.debug(f"System: Ollama LLM Enabled") + logger.debug(f"System: Ollama LLM Enabled, loading model please wait") + llm_query("", 0) + logger.debug(f"System: LLM model loaded") if motd_enabled: logger.debug(f"System: MOTD Enabled using {MOTD}") if sentry_enabled: From 3a417a92815113206886eca2a9efcc2fa10f68b9 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:11:37 -0700 Subject: [PATCH 14/22] Update mesh_bot.py --- mesh_bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh_bot.py b/mesh_bot.py index 833719b..a7ac92d 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -481,7 +481,7 @@ async def start_rx(): logger.debug(f"System: Wikipedia search Enabled") if llm_enabled: logger.debug(f"System: Ollama LLM Enabled, loading model please wait") - llm_query("", 0) + llm_query("", myNodeNum1) logger.debug(f"System: LLM model loaded") if motd_enabled: logger.debug(f"System: MOTD Enabled using {MOTD}") From b7882b0322b6db84de9aa5353f3e4156cf430c77 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:17:11 -0700 Subject: [PATCH 15/22] Update mesh_bot.py --- mesh_bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh_bot.py b/mesh_bot.py index a7ac92d..6c75803 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -481,7 +481,7 @@ async def start_rx(): logger.debug(f"System: Wikipedia search Enabled") if llm_enabled: logger.debug(f"System: Ollama LLM Enabled, loading model please wait") - llm_query("", myNodeNum1) + llm_query(" ", myNodeNum1) logger.debug(f"System: LLM model loaded") if motd_enabled: logger.debug(f"System: MOTD Enabled using {MOTD}") From 0f428438a33624cba923979187b2b0347e51bb45 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:28:28 -0700 Subject: [PATCH 16/22] Update mesh_bot.py --- mesh_bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesh_bot.py b/mesh_bot.py index 6c75803..69d2e2c 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -386,7 +386,8 @@ def onReceive(packet, interface): send_message(auto_response(message_string, snr, rssi, hop, message_from_id, channel_number, rxNode), channel_number, message_from_id, rxNode) else: if llm_enabled: - handle_llm(message_from_id, channel_number, rxNode, message_string, publicChannel) + llm = handle_llm(message_from_id, channel_number, rxNode, message_string, publicChannel) + send_message(llm, channel_number, message_from_id, rxNode) else: # respond with welcome message on DM logger.warning(f"Device:{rxNode} Ignoring DM: {message_string} From: {get_name_from_number(message_from_id, 'long', rxNode)}") From f31f920137e404f0b01088cb6e29dc82c1cda2c3 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:43:20 -0700 Subject: [PATCH 17/22] Update system.py --- modules/system.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/system.py b/modules/system.py index 552a9e8..751f979 100644 --- a/modules/system.py +++ b/modules/system.py @@ -510,6 +510,8 @@ def get_wikipedia_summary(search_term): def messageTrap(msg): # Check if the message contains a trap word + if "wiki:" in msg or "ask:" in msg: + return True message_list=msg.split(" ") for m in message_list: for t in trap_list: From f20d83ca8c59defd109026e16818fd38d0759873 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:48:45 -0700 Subject: [PATCH 18/22] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab74be7..05738b0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ The bot can also be used to monitor a radio frequency and let you know when high Any messages that are over 160 characters are chunked into 160 message bytes to help traverse hops, in testing, this keeps delivery success higher. -Full list of commands for the bot. +[Donate$](https://www.paypal.com/donate?token=ZpiU7zDh-AQDyK76nWmWPQLf04iOm-Iyr3f85lpubt37NWGRYtfe11UyC0LmY1wdcC20UubWo4Kec-_G) via PayPal if you like the project! + +## Full list of commands for the bot. - Various solar details for radio propagation (spaceWeather module) - `sun` and `moon` return info on rise and set local time From 7e2dd4c7ff7c9e18d6201a3fe00cd83912d201eb Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:55:34 -0700 Subject: [PATCH 19/22] Update mesh_bot.py --- mesh_bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 69d2e2c..5a879e8 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -455,6 +455,10 @@ def onReceive(packet, interface): async def start_rx(): print (CustomFormatter.bold_white + f"\nMeshtastic Autoresponder Bot CTL+C to exit\n" + CustomFormatter.reset) + if llm_enabled: + logger.debug(f"System: Ollama LLM Enabled, loading model please wait") + llm_query(" ", myNodeNum1) + logger.debug(f"System: LLM model loaded") # Start the receive subscriber using pubsub via meshtastic library pub.subscribe(onReceive, 'meshtastic.receive') pub.subscribe(onDisconnect, 'meshtastic.connection.lost') @@ -480,10 +484,6 @@ async def start_rx(): logger.debug(f"System: Dad Jokes Enabled!") if wikipedia_enabled: logger.debug(f"System: Wikipedia search Enabled") - if llm_enabled: - logger.debug(f"System: Ollama LLM Enabled, loading model please wait") - llm_query(" ", myNodeNum1) - logger.debug(f"System: LLM model loaded") if motd_enabled: logger.debug(f"System: MOTD Enabled using {MOTD}") if sentry_enabled: From 7024f2d472f8964872f4eae37a6561926b009c9c Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 00:58:52 -0700 Subject: [PATCH 20/22] Update system.py --- modules/system.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/system.py b/modules/system.py index 751f979..4c80daa 100644 --- a/modules/system.py +++ b/modules/system.py @@ -519,15 +519,6 @@ def messageTrap(msg): return True return False -def messageTrap(msg): - # Check if the message contains a trap word - message_list=msg.split(" ") - for m in message_list: - for t in trap_list: - if t.lower() == m.lower(): - return True - return False - def exit_handler(): # Close the interface and save the BBS messages logger.debug(f"\nSystem: Closing Autoresponder") From 8e35d77e07b84ab2c87ff319b439933c7e95ad45 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 01:00:33 -0700 Subject: [PATCH 21/22] Update system.py --- modules/system.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/system.py b/modules/system.py index 4c80daa..b2dc895 100644 --- a/modules/system.py +++ b/modules/system.py @@ -564,14 +564,14 @@ async def handleSignalWatcher(): if interface2_enabled: send_message(msg, int(ch), 0, 2) else: - logger.error(f"System: antiSpam prevented Alert from Hamlib {msg}") + logger.warning(f"System: antiSpam prevented Alert from Hamlib {msg}") else: if antiSpam and sigWatchBroadcastCh != publicChannel: send_message(msg, int(sigWatchBroadcastCh), 0, 1) if interface2_enabled: send_message(msg, int(sigWatchBroadcastCh), 0, 2) else: - logger.error(f"System: antiSpam prevented Alert from Hamlib {msg}") + logger.warning(f"System: antiSpam prevented Alert from Hamlib {msg}") await asyncio.sleep(1) pass From 70f47635b4425a5697b77f8d0822876922f72f14 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 1 Sep 2024 01:04:47 -0700 Subject: [PATCH 22/22] Update system.py --- modules/system.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/system.py b/modules/system.py index b2dc895..4b7cb79 100644 --- a/modules/system.py +++ b/modules/system.py @@ -510,8 +510,6 @@ def get_wikipedia_summary(search_term): def messageTrap(msg): # Check if the message contains a trap word - if "wiki:" in msg or "ask:" in msg: - return True message_list=msg.split(" ") for m in message_list: for t in trap_list: