Update
This commit is contained in:
1 parent
2e426e3edb
commit
a3c5458e57
2 files changed
+16
-3
No files matched your search
@@ -72,6 +72,7 @@ async def prompt_llm(prompt, override_params={}):
|
||||
async with session.post("/completion", json=llm_params) as resp:
|
||||
logger.info(f"LLM response status {resp.status}")
|
||||
response_json=await resp.json()
|
||||
logger.info(f"Context {response_json['tokens_evaluated']}")
|
||||
content=response_json["content"]
|
||||
return content
|
||||
|
||||
@@ -86,7 +87,7 @@ def get_message_contents(msg):
|
||||
logger.debug(f"Message contents -- {message_text}")
|
||||
return message_text
|
||||
|
||||
async def get_chat_history(ctx, limit=20):
|
||||
async def get_chat_history(ctx, limit=25):
|
||||
"""
|
||||
Returns a list containing {limit} number of previous messages in the channel
|
||||
referenced by chat context {ctx}
|
||||
@@ -304,7 +305,7 @@ async def fixup_mentions(ctx, text):
|
||||
:param ctx: Message context that we're replying to
|
||||
:param text: String containing message we want to send
|
||||
:return: A string with all @User/@Role mentions changed to <@12345> format
|
||||
"""
|
||||
-"""
|
||||
newtext = text
|
||||
if (isinstance(ctx.channel,discord.DMChannel)):
|
||||
newtext = ci_replace(newtext, f"@{ctx.author.name}", ctx.author.mention)
|
||||
@@ -336,6 +337,8 @@ async def handle_message(ctx):
|
||||
"""
|
||||
bot_id = llm_config['bot'].user.id
|
||||
logger.info(f"Dank-bot <@{bot_id}> received message")
|
||||
very_recent_history = await get_chat_history(ctx, 2) # to see if someone is speaking immediately after us
|
||||
|
||||
if (ctx.content.startswith("!")):
|
||||
logger.info("Dank-bot command, not running LLM")
|
||||
return
|
||||
@@ -353,6 +356,16 @@ async def handle_message(ctx):
|
||||
await llm_response(ctx)
|
||||
return
|
||||
|
||||
# Third case, somebody said something right after the bot
|
||||
# Don't always do this or we'll never STFU
|
||||
if (len(very_recent_history) == 2):
|
||||
if very_recent_history[0].startswith(f"{bot_name}") and not very_recent_history[1].startswith(f"{bot_name}"):
|
||||
random_roll = random.random()
|
||||
if (random_roll < 0.7):
|
||||
logger.info("Messaged right after us... Replying")
|
||||
await llm_response(ctx)
|
||||
return
|
||||
|
||||
# Other case, random response
|
||||
random_roll = random.random()
|
||||
logger.info(f"Dank-bot rolled {random_roll} for random response")
|
||||
|
||||
Reference in new issue
Block a user