From 99e987629da8cec3eb647284e170f8e8fee6d33a Mon Sep 17 00:00:00 2001 From: osmarks Date: Fri, 26 Apr 2024 18:32:27 +0100 Subject: [PATCH] tweak prompting strategy --- src/commands.py | 13 +++++++++---- src/util.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/commands.py b/src/commands.py index 9878039..8b2b95e 100644 --- a/src/commands.py +++ b/src/commands.py @@ -6,6 +6,7 @@ import re import aiohttp import subprocess import discord.ext.commands as commands +from datetime import datetime import tio import util @@ -192,10 +193,14 @@ AutoBotRobot is operated by gollark/osmarks. await ctx.send("\n".join(map(lambda x: f"{x[0]} x{x[1]}", results))) - @commands.command(help="Highly advanced AI Asisstant.") + @commands.command(help="Highly advanced AI Assistant.") async def ai(self, ctx, *, query=None): prompt = [] seen = set() + + def render(dt: datetime): + return f"{dt.hour}:{dt.minute}" + async for message in ctx.channel.history(limit=20): display_name = message.author.display_name if message.author == self.bot.user: @@ -212,13 +217,13 @@ AutoBotRobot is operated by gollark/osmarks. if message.author == self.bot.user: if content in seen: continue seen.add(content) - prompt.append(f"{display_name}: {content}\n\n") + prompt.append(f"[{render(message.created_at)}] {display_name}: {content}\n") if sum(len(x) for x in prompt) > util.config["ai"]["max_len"]: break prompt.reverse() - prompt.append(util.config["ai"]["own_name"] + ": ") + prompt.append(f'[{render(datetime.utcnow())}] {util.config["ai"]["own_name"]}:') generation = await util.generate(self.session, "".join(prompt)) - if generation: await ctx.send(generation) + if generation.strip(): await ctx.send(generation.strip()) def setup(bot): bot.add_cog(GeneralCommands(bot)) diff --git a/src/util.py b/src/util.py index cfc1d5f..346d29e 100644 --- a/src/util.py +++ b/src/util.py @@ -340,7 +340,7 @@ async def generate(response: aiohttp.ClientSession, prompt): async with response.post(config["ai"]["llm_backend"], json={ "prompt": prompt, "max_tokens": 200, - "stop": ["\n\n"] + "stop": ["\n"] }) as res: data = await res.json() return data["choices"][0]["text"] \ No newline at end of file