tweak prompting strategy
This commit is contained in:
parent
bea67646b6
commit
99e987629d
|
@ -6,6 +6,7 @@ import re
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import subprocess
|
import subprocess
|
||||||
import discord.ext.commands as commands
|
import discord.ext.commands as commands
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import tio
|
import tio
|
||||||
import util
|
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)))
|
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):
|
async def ai(self, ctx, *, query=None):
|
||||||
prompt = []
|
prompt = []
|
||||||
seen = set()
|
seen = set()
|
||||||
|
|
||||||
|
def render(dt: datetime):
|
||||||
|
return f"{dt.hour}:{dt.minute}"
|
||||||
|
|
||||||
async for message in ctx.channel.history(limit=20):
|
async for message in ctx.channel.history(limit=20):
|
||||||
display_name = message.author.display_name
|
display_name = message.author.display_name
|
||||||
if message.author == self.bot.user:
|
if message.author == self.bot.user:
|
||||||
|
@ -212,13 +217,13 @@ AutoBotRobot is operated by gollark/osmarks.
|
||||||
if message.author == self.bot.user:
|
if message.author == self.bot.user:
|
||||||
if content in seen: continue
|
if content in seen: continue
|
||||||
seen.add(content)
|
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"]:
|
if sum(len(x) for x in prompt) > util.config["ai"]["max_len"]:
|
||||||
break
|
break
|
||||||
prompt.reverse()
|
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))
|
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):
|
def setup(bot):
|
||||||
bot.add_cog(GeneralCommands(bot))
|
bot.add_cog(GeneralCommands(bot))
|
||||||
|
|
|
@ -340,7 +340,7 @@ async def generate(response: aiohttp.ClientSession, prompt):
|
||||||
async with response.post(config["ai"]["llm_backend"], json={
|
async with response.post(config["ai"]["llm_backend"], json={
|
||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
"max_tokens": 200,
|
"max_tokens": 200,
|
||||||
"stop": ["\n\n"]
|
"stop": ["\n"]
|
||||||
}) as res:
|
}) as res:
|
||||||
data = await res.json()
|
data = await res.json()
|
||||||
return data["choices"][0]["text"]
|
return data["choices"][0]["text"]
|
Loading…
Reference in New Issue