Merge remote-tracking branch 'origin/master'
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 17s

This commit is contained in:
Nexus 2024-06-06 00:22:01 +01:00
commit da799b3ab5
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -487,7 +487,9 @@ class Ollama(commands.Cog):
"""Checks that a server is online and responding."""
if url in SERVER_KEYS:
url = CONFIG["ollama"][url]["base_url"]
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(10)) as session:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(connect=3, sock_connect=3, sock_read=10, total=3)
) as session:
self.log.info("Checking if %r is online.", url)
try:
async with session.get(url + "/api/tags") as resp:
@ -550,7 +552,11 @@ class Ollama(commands.Cog):
if query == "$":
v = PromptSelector(ctx)
await ctx.respond("Select edit your prompts, as desired. Click done when you want to continue.", view=v)
await ctx.respond(
"Select edit your prompts, as desired. Click done when you want to continue.",
view=v,
ephemeral=True
)
await v.wait()
query = v.user_prompt or query
system_query = v.system_prompt
@ -606,7 +612,7 @@ class Ollama(commands.Cog):
async with aiohttp.ClientSession(
base_url=server_config["base_url"],
timeout=aiohttp.ClientTimeout(connect=30, sock_read=10800, sock_connect=30, total=10830),
timeout=aiohttp.ClientTimeout(connect=5, sock_read=10800, sock_connect=5, total=10830),
) as session:
embed = discord.Embed(
title="Checking server...",
@ -992,7 +998,6 @@ class Ollama(commands.Cog):
)
msg = await ctx.reply(embed=embed)
last_edit = time.time()
tasks = {}
for server in self.servers.keys():
@ -1014,19 +1019,37 @@ class Ollama(commands.Cog):
break
await msg.edit(embed=embed)
@commands.command()
@commands.guild_only()
async def trump(self, ctx: commands.Context):
async with ctx.channel.typing():
thread_id = self.history.create_thread(
ctx.author,
async def generate_truth(self, ctx: commands.Context, entity: str, limit: int = None):
if entity == "trump":
system = (
"You are the former united states president, Donald Trump, convicted of 34 felonies."
" You have been posting approximately 50 times a day on your platform 'Truth Social' spreading your"
" words of truth to the american people in order to make america great again. After reading through all"
" words of truth to the american people in order to make america great again."
)
elif entity == "tate":
system = (
"You are the 'Top G' Andrew Tate. Andrew Tate is a former professional kickboxer who turned to the "
"world of influencing. His personality is one of arrogance and self-aggrandizement, "
"often referred to as \"King of Toxic Masculinity\" by critics due to his controversial views on "
"gender roles, relationships, and other topics. He has been involved in several controversies related "
"to his content online including promoting extremist ideologies and misogynistic views. "
"Despite this, he still has a large following and is known for being an entrepreneur who built multiple"
" successful businesses such as Trinity Kickboxing Academy, Hustlers University, "
"and Romania's Real Estate Empire. "
"You post advice regarding masculinity and success, often in a controversial manner, on Truth Social. "
)
else:
raise ValueError("Invalid entity; must be one of trump/tate")
system += (
"\n\nAfter reading through all"
" of your previous truth posts, you should generate another one, ready to be posted, "
"under 4000 characters. Write only the content to be posted, do not include any pleasantries."
" Write using the style of a twitter or facebook post. Do not repeat a previous post."
)
thread_id = self.history.create_thread(
ctx.author,
system
)
async with httpx.AsyncClient() as client:
r = CONFIG["truth"].get("api", "https://bots.nexy7574.co.uk/jimmy/v2")
username = CONFIG["truth"].get("username", "1")
@ -1037,10 +1060,15 @@ class Ollama(commands.Cog):
auth=(username, password),
)
response.raise_for_status()
truths: list[dict] = response.json()
truths = response.json()
truths: list[TruthPayload] = list(map(lambda t: TruthPayload.model_validate(t), truths))
if entity:
truths = list(filter(lambda t: t.author == entity, truths))
if limit:
truths.sort(key=lambda t: t.timestamp, reverse=True) # newest first
for truth in truths:
if truth.author == "trump":
await asyncio.to_thread(
functools.partial(
self.history.add_message,
@ -1100,6 +1128,32 @@ class Ollama(commands.Cog):
)
await msg.edit(embed=embed)
@commands.command()
@commands.guild_only()
async def trump(self, ctx: commands.Context, latest: int = None):
"""
Generates a truth social post from trump!
<latest> - limit the training history to the latest <latest> truths.
This command may take a long time.
"""
async with ctx.channel.typing():
await self.generate_truth(ctx, "trump", latest)
@commands.command()
@commands.guild_only()
async def tate(self, ctx: commands.Context, latest: int = None):
"""
Generates a truth social post from Andrew Tate
<latest> - limit the training history to the latest <latest> truths.
This command may take a long time.
"""
async with ctx.channel.typing():
await self.generate_truth(ctx, "tate", latest)
def setup(bot):
bot.add_cog(Ollama(bot))