Merge remote-tracking branch 'origin/master'
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 17s
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 17s
This commit is contained in:
commit
da799b3ab5
1 changed files with 136 additions and 82 deletions
|
@ -487,7 +487,9 @@ class Ollama(commands.Cog):
|
||||||
"""Checks that a server is online and responding."""
|
"""Checks that a server is online and responding."""
|
||||||
if url in SERVER_KEYS:
|
if url in SERVER_KEYS:
|
||||||
url = CONFIG["ollama"][url]["base_url"]
|
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)
|
self.log.info("Checking if %r is online.", url)
|
||||||
try:
|
try:
|
||||||
async with session.get(url + "/api/tags") as resp:
|
async with session.get(url + "/api/tags") as resp:
|
||||||
|
@ -550,7 +552,11 @@ class Ollama(commands.Cog):
|
||||||
|
|
||||||
if query == "$":
|
if query == "$":
|
||||||
v = PromptSelector(ctx)
|
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()
|
await v.wait()
|
||||||
query = v.user_prompt or query
|
query = v.user_prompt or query
|
||||||
system_query = v.system_prompt
|
system_query = v.system_prompt
|
||||||
|
@ -606,7 +612,7 @@ class Ollama(commands.Cog):
|
||||||
|
|
||||||
async with aiohttp.ClientSession(
|
async with aiohttp.ClientSession(
|
||||||
base_url=server_config["base_url"],
|
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:
|
) as session:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Checking server...",
|
title="Checking server...",
|
||||||
|
@ -992,7 +998,6 @@ class Ollama(commands.Cog):
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = await ctx.reply(embed=embed)
|
msg = await ctx.reply(embed=embed)
|
||||||
last_edit = time.time()
|
|
||||||
|
|
||||||
tasks = {}
|
tasks = {}
|
||||||
for server in self.servers.keys():
|
for server in self.servers.keys():
|
||||||
|
@ -1014,19 +1019,37 @@ class Ollama(commands.Cog):
|
||||||
break
|
break
|
||||||
await msg.edit(embed=embed)
|
await msg.edit(embed=embed)
|
||||||
|
|
||||||
@commands.command()
|
async def generate_truth(self, ctx: commands.Context, entity: str, limit: int = None):
|
||||||
@commands.guild_only()
|
if entity == "trump":
|
||||||
async def trump(self, ctx: commands.Context):
|
system = (
|
||||||
async with ctx.channel.typing():
|
|
||||||
thread_id = self.history.create_thread(
|
|
||||||
ctx.author,
|
|
||||||
"You are the former united states president, Donald Trump, convicted of 34 felonies."
|
"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"
|
" 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, "
|
" 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."
|
"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."
|
" 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:
|
async with httpx.AsyncClient() as client:
|
||||||
r = CONFIG["truth"].get("api", "https://bots.nexy7574.co.uk/jimmy/v2")
|
r = CONFIG["truth"].get("api", "https://bots.nexy7574.co.uk/jimmy/v2")
|
||||||
username = CONFIG["truth"].get("username", "1")
|
username = CONFIG["truth"].get("username", "1")
|
||||||
|
@ -1037,10 +1060,15 @@ class Ollama(commands.Cog):
|
||||||
auth=(username, password),
|
auth=(username, password),
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
truths: list[dict] = response.json()
|
truths = response.json()
|
||||||
truths: list[TruthPayload] = list(map(lambda t: TruthPayload.model_validate(t), truths))
|
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:
|
for truth in truths:
|
||||||
if truth.author == "trump":
|
|
||||||
await asyncio.to_thread(
|
await asyncio.to_thread(
|
||||||
functools.partial(
|
functools.partial(
|
||||||
self.history.add_message,
|
self.history.add_message,
|
||||||
|
@ -1100,6 +1128,32 @@ class Ollama(commands.Cog):
|
||||||
)
|
)
|
||||||
await msg.edit(embed=embed)
|
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):
|
def setup(bot):
|
||||||
bot.add_cog(Ollama(bot))
|
bot.add_cog(Ollama(bot))
|
||||||
|
|
Loading…
Reference in a new issue