diff --git a/config.template b/config.template index efe9409..a9ef433 100644 --- a/config.template +++ b/config.template @@ -63,6 +63,8 @@ ollamaHostName = http://localhost:11434 # Produce LLM replies to messages that aren't commands? # If False, the LLM only replies to the "ask:" and "askai" commands. llmReplyToNonCommands = True +# if True, the input is sent raw to the LLM, if False uses legacy template query +rawLLMQuery = True # StoreForward Enabled and Limits StoreForward = True diff --git a/modules/llm.py b/modules/llm.py index cc9f034..d18e5ac 100644 --- a/modules/llm.py +++ b/modules/llm.py @@ -8,11 +8,13 @@ from modules.log import * # https://github.com/ollama/ollama/blob/main/docs/faq.md#how-do-i-configure-ollama-server import requests import json -from googlesearch import search # pip install googlesearch-python + +if not rawLLMQuery: + # this may be removed in the future + from googlesearch import search # pip install googlesearch-python # LLM System Variables ollamaAPI = ollamaHostName + "/api/generate" -rawQuery = True # if True, the input is sent raw to the LLM, if False, it is processed by the meshBotAI template tokens = 450 # max charcters for the LLM response, this is the max length of the response also in prompts requestTruncation = True # if True, the LLM "will" truncate the response @@ -80,7 +82,7 @@ def llm_query(input, nodeID=0, location_name=None): # if this is the first initialization of the LLM the query of " " should bring meshbotAIinit OTA shouldnt reach this? # This is for LLM like gemma and others now? - if input == " " and rawQuery: + if input == " " and rawLLMQuery: logger.warning("System: These LLM models lack a traditional system prompt, they can be verbose and not very helpful be advised.") input = meshbotAIinit @@ -102,7 +104,7 @@ def llm_query(input, nodeID=0, location_name=None): else: antiFloodLLM.append(nodeID) - if llmContext_fromGoogle and not rawQuery: + if llmContext_fromGoogle and not rawLLMQuery: # grab some context from the internet using google search hits (if available) # localization details at https://pypi.org/project/googlesearch-python/ @@ -133,7 +135,7 @@ def llm_query(input, nodeID=0, location_name=None): location_name += f" at the current time of {datetime.now().strftime('%Y-%m-%d %H:%M:%S %Z')}" try: - if rawQuery: + if rawLLMQuery: # sanitize the input to remove tool call syntax if '```' in input: logger.warning("System: LLM Query: Code markdown detected, removing for raw query") @@ -165,7 +167,7 @@ def llm_query(input, nodeID=0, location_name=None): # cleanup for message output response = result.strip().replace('\n', ' ') - if rawQuery and requestTruncation and len(response) > 450: + if rawLLMQuery and requestTruncation and len(response) > 450: #retryy loop to truncate the response logger.warning(f"System: LLM Query: Response exceeded {tokens} characters, requesting truncation") truncateQuery = {"model": llmModel, "prompt": truncatePrompt + response, "stream": False, "max_tokens": tokens} diff --git a/modules/settings.py b/modules/settings.py index 2c2948a..08ab3b7 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -219,8 +219,9 @@ try: 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 - llmModel = config['general'].get('ollamaModel', 'gemma3:270m') # default gemma3:270m ollamaHostName = config['general'].get('ollamaHostName', 'http://localhost:11434') # default localhost + llmModel = config['general'].get('ollamaModel', 'gemma3:270m') # default gemma3:270m + rawLLMQuery = config['general'].getboolean('rawLLMQuery', True) #default True llmReplyToNonCommands = config['general'].getboolean('llmReplyToNonCommands', True) dont_retry_disconnect = config['general'].getboolean('dont_retry_disconnect', False) # default False, retry on disconnect # emergency response