add ask_ai message command

This commit is contained in:
Nexus 2024-04-14 17:19:54 +01:00
parent 0cc5ce7150
commit 5ac83dd939
Signed by: nex
GPG key ID: 0FA334385D0B689F
3 changed files with 26 additions and 20 deletions

View file

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View file

@ -222,7 +222,7 @@ class FFMeta(commands.Cog):
else:
await ctx.respond(file=discord.File(file, filename=filename))
paginator = commands.Paginator(prefix="```", suffix="```")
paginator = commands.Paginator()
for line in stderr.splitlines():
if line.strip().startswith(":"):
continue

View file

@ -146,6 +146,13 @@ class OllamaChatHandler:
if line.get("prompt_eval_count"):
self.prompt_eval_count = line["prompt_eval_count"]
def __enter__(self):
self._abort.clear()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self._abort.set()
async def __aiter__(self):
async with self.client.post(
"/api/chat",
@ -943,19 +950,24 @@ class Ollama(commands.Cog):
messages = self.history.get_history(thread)
embed = discord.Embed(description=">>> ")
async for ln in client.new_chat("orca-mini:3b", messages):
embed.description += ln["message"]["content"]
if len(embed.description) >= 4032:
break
if len(embed.description) >= 3250:
embed.colour = discord.Color.gold()
embed.set_footer(text="Warning: {:,}/4096 characters.".format(len(embed.description)))
else:
embed.colour = discord.Color.blurple()
embed.set_footer(text="Using server %r" % server, icon_url=CONFIG["ollama"][server].get("icon_url"))
await ctx.edit(embed=embed)
if ln.get("done"):
break
await ctx.respond(embed=discord.Embed(description="*waiting...*"))
last_edit = time.time()
with client.new_chat("orca-mini:3b", messages) as handler:
async for ln in handler:
done = ln.get("done") is True
embed.description = ">>> " + handler.result
if len(embed.description) >= 4096:
break
if len(embed.description) >= 3250:
embed.colour = discord.Color.gold()
embed.set_footer(text="Warning: {:,}/4096 characters.".format(len(embed.description)))
else:
embed.colour = discord.Color.blurple()
embed.set_footer(text="Using server %r" % server, icon_url=CONFIG["ollama"][server].get("icon_url"))
if time.time() >= (last_edit + 5.1) or done:
await ctx.edit(embed=embed)
if done:
break
def setup(bot):