Updated logging

This commit is contained in:
cameron committed 2024-05-10 16:08:06 -04:00
1 parent a190e523d4
commit f0fc5b643a
3 files changed
+25 -19

No files matched your search

+16 -14
View File
@@ -6,7 +6,9 @@ import aiohttp
import yaml
import random
import os
import logging
logger=logging.getLogger("plugin.botchat")
plugin_folder=os.path.dirname(os.path.realpath(__file__))
prompts_folder=os.path.join(plugin_folder, 'prompts')
default_prompt="default.txt"
@@ -20,24 +22,24 @@ async def prompt_llm(prompt):
:param prompt: prompt to complete
:return: returns a string consisting of completion text
"""
print("Prompting LLM")
print(f"PROMPT DATA\n{prompt}")
logger.info("Prompting LLM")
logger.info(f"PROMPT DATA\n{prompt}")
async with aiohttp.ClientSession(llm_data["api_base"]) as session:
async with session.post("/completion", json={"prompt": prompt, "n_predict": 250, "mirostat": 2}) as resp:
print(f"LLM response status {resp.status}")
async with session.post("/completion", json={"prompt": prompt, "n_predict": 350, "mirostat": 2}) as resp:
logger.info(f"LLM response status {resp.status}")
response_json=await resp.json()
content=response_json["content"]
return content
def get_message_contents(msg):
"""
Given a Discord message object, prints the contents in an IRC-like format
Given a Discord message object, logger.infos the contents in an IRC-like format
:param msg: discord.Message to get the contents of
:return: returns a string in the format "user: message"
"""
message_text = f"{msg.author.name}: {msg.clean_content}"
print(f"Message contents -- {message_text}")
logger.info(f"Message contents -- {message_text}")
return message_text
async def get_chat_history(ctx, limit=20):
@@ -98,7 +100,7 @@ async def send_chat_responses(ctx, response_text):
:param ctx: Message context that we're replying to
:param response_text: String containing message we want to send
"""
print("Processing chat response")
logger.info("Processing chat response")
fullResponseLog = "dank-bot:" + response_text # first response won't include the user
responseLines = fullResponseLog.splitlines()
output_strs = []
@@ -147,28 +149,28 @@ async def handle_message(ctx):
:param ctx: Message context
"""
print("Dank-bot received message")
print(f"Dank-bot ID is {llm_data['bot'].user.id}")
logger.info("Dank-bot received message")
logger.info(f"Dank-bot ID is {llm_data['bot'].user.id}")
bot_id = llm_data['bot'].user.id
# First case, bot DMed
if (isinstance(ctx.channel,discord.DMChannel) and ctx.author.id != bot_id):
print("Dank-bot DMed, responding")
logger.info("Dank-bot DMed, responding")
await llm_response(ctx)
return
# Second case, bot mentioned
bot_mentions=list(filter(lambda x: x.id == bot_id, ctx.mentions))
if (len(bot_mentions) > 0):
print("Dank-bot mentioned, responding")
logger.info("Dank-bot mentioned, responding")
await llm_response(ctx)
return
# Other case, random response
random_roll = random.random()
print(f"Dank-bot rolled {random_roll}")
logger.info(f"Dank-bot rolled {random_roll}")
if (random_roll < llm_data['response_probability']):
print(f"{random_roll} < {llm_data['response_probability']}, responding")
logger.info(f"{random_roll} < {llm_data['response_probability']}, responding")
await llm_response(ctx)
return
@@ -185,4 +187,4 @@ async def setup(bot):
bot.add_command(llm_response)
bot.add_listener(handle_message, "on_message")
llm_data["bot"] = bot
print("LLM interface initialized")
logger.info("LLM interface initialized")