Tuned up bot
This commit is contained in:
1 parent
55e4762db4
commit
3e4529dcc0
3 files changed
+18
-14
No files matched your search
@@ -15,6 +15,7 @@ prompts_folder=os.path.join(plugin_folder, 'prompts')
|
||||
default_prompt="default.txt"
|
||||
config_filename=os.path.join(plugin_folder, 'settings.yaml')
|
||||
llm_config = {}
|
||||
global bot_name
|
||||
|
||||
def ci_replace(text, replace_str, new_str):
|
||||
"""Case-insensitive replace"""
|
||||
@@ -96,6 +97,7 @@ async def llm_response(ctx):
|
||||
history_arr = await get_chat_history(ctx)
|
||||
history_str = '\n'.join(history_arr)
|
||||
full_prompt = prompt.replace("<CONVHISTORY>", history_str)
|
||||
full_prompt = full_prompt.replace("<BOTNAME>", bot_name)
|
||||
response = await prompt_llm(full_prompt)
|
||||
await send_chat_responses(ctx, response)
|
||||
await log_history(ctx, history_str)
|
||||
@@ -110,12 +112,12 @@ async def send_chat_responses(ctx, response_text):
|
||||
:param response_text: String containing message we want to send
|
||||
"""
|
||||
logger.info("Processing chat response")
|
||||
fullResponseLog = "dank-bot:" + response_text # first response won't include the user
|
||||
fullResponseLog = f"{bot_name}:" + response_text # first response won't include the user
|
||||
responseLines = fullResponseLog.splitlines()
|
||||
output_strs = []
|
||||
for line in responseLines:
|
||||
if line.startswith("dank-bot:"):
|
||||
truncStr = line.replace("dank-bot:","")
|
||||
if line.startswith(f"{bot_name}:"):
|
||||
truncStr = line.replace(f"{bot_name}:","")
|
||||
output_strs.append(truncStr)
|
||||
elif line.find(":") > 0 and line.find(":") < 20:
|
||||
break
|
||||
@@ -123,7 +125,8 @@ async def send_chat_responses(ctx, response_text):
|
||||
output_strs.append(line.strip())
|
||||
for outs in output_strs:
|
||||
final_output_str = await fixup_mentions(ctx, outs)
|
||||
await ctx.channel.send(final_output_str)
|
||||
if (final_output_str != ""):
|
||||
await ctx.channel.send(final_output_str)
|
||||
|
||||
async def fixup_mentions(ctx, text):
|
||||
"""
|
||||
@@ -194,10 +197,12 @@ async def setup(bot):
|
||||
:param bot: Discord bot object
|
||||
"""
|
||||
global llm_config
|
||||
global bot_name
|
||||
with open(config_filename, 'r') as conf_file:
|
||||
yaml_config = yaml.safe_load(conf_file)
|
||||
llm_config = yaml_config.copy()
|
||||
bot.add_command(llm_response)
|
||||
bot.add_listener(handle_message, "on_message")
|
||||
llm_config["bot"] = bot
|
||||
logger.info("LLM interface initialized")
|
||||
bot_name = bot.user.name
|
||||
logger.info(f"LLM interface initialized for {bot_name}")
|
||||
Reference in new issue
Block a user