Add reasoning command to control reasoning_effort per guild

This commit is contained in:
2026-08-16 23:49:15 -05:00
parent 28abf4aced
commit 58b1c85bcb
+24 -1
View File
@@ -49,6 +49,7 @@ class Assistant(commands.Cog):
system_prompt="You are a helpful assistant.", system_prompt="You are a helpful assistant.",
question_mode=False, question_mode=False,
max_tokens=None, max_tokens=None,
reasoning_effort=None,
) )
self.config.register_global(api_key=None) self.config.register_global(api_key=None)
self.history: dict[int, list[dict]] = {} self.history: dict[int, list[dict]] = {}
@@ -134,6 +135,7 @@ class Assistant(commands.Cog):
temperature = await self.config.guild(guild).temperature() temperature = await self.config.guild(guild).temperature()
system_prompt = await self.config.guild(guild).system_prompt() system_prompt = await self.config.guild(guild).system_prompt()
max_tokens = await self.config.guild(guild).max_tokens() max_tokens = await self.config.guild(guild).max_tokens()
reasoning_effort = await self.config.guild(guild).reasoning_effort()
key = (guild.id, channel_id) key = (guild.id, channel_id)
if key not in self.history: if key not in self.history:
@@ -147,12 +149,14 @@ class Assistant(commands.Cog):
"model": model, "model": model,
"messages": messages, "messages": messages,
"temperature": temperature, "temperature": temperature,
"reasoning_effort": "none",
} }
if max_tokens: if max_tokens:
payload["max_tokens"] = max_tokens payload["max_tokens"] = max_tokens
if reasoning_effort:
payload["reasoning_effort"] = reasoning_effort
try: try:
async with self.session.post( async with self.session.post(
f"{self.BASE_URL}/chat/completions", f"{self.BASE_URL}/chat/completions",
@@ -353,6 +357,23 @@ class Assistant(commands.Cog):
await self.config.guild(ctx.guild).max_tokens.set(tokens) await self.config.guild(ctx.guild).max_tokens.set(tokens)
await ctx.send(f"Max response length set to **{tokens}** tokens.") await ctx.send(f"Max response length set to **{tokens}** tokens.")
@assistant.command(name="reasoning")
async def assistant_reasoning(self, ctx: commands.Context, level: str = None):
"""Set reasoning effort level. Omit to clear (model default).
Levels: none, minimal, low, medium, high
Not all models support all levels. Use 'none' to disable thinking.
"""
valid_levels = ("none", "minimal", "low", "medium", "high")
if level is None:
await self.config.guild(ctx.guild).reasoning_effort.set(None)
await ctx.send("Reasoning effort cleared (model default — thinking enabled).")
elif level.lower() not in valid_levels:
await ctx.send(f"Invalid level. Choose from: {', '.join(valid_levels)}")
else:
await self.config.guild(ctx.guild).reasoning_effort.set(level.lower())
await ctx.send(f"Reasoning effort set to **{level.lower()}**.")
@assistant.command(name="system") @assistant.command(name="system")
async def assistant_system(self, ctx: commands.Context, *, prompt: str): async def assistant_system(self, ctx: commands.Context, *, prompt: str):
"""Set the system prompt.""" """Set the system prompt."""
@@ -385,6 +406,7 @@ class Assistant(commands.Cog):
sys_prompt = await cfg.system_prompt() sys_prompt = await cfg.system_prompt()
q_mode = await cfg.question_mode() q_mode = await cfg.question_mode()
max_tokens = await cfg.max_tokens() max_tokens = await cfg.max_tokens()
reasoning_effort = await cfg.reasoning_effort()
has_key = await self.config.api_key() is not None has_key = await self.config.api_key() is not None
channel_str = f"<#{chat_channel}>" if chat_channel else "None" channel_str = f"<#{chat_channel}>" if chat_channel else "None"
@@ -397,6 +419,7 @@ class Assistant(commands.Cog):
embed.add_field(name="Temperature", value=str(temp), inline=True) embed.add_field(name="Temperature", value=str(temp), inline=True)
embed.add_field(name="Question Mode", value=str(q_mode), inline=True) embed.add_field(name="Question Mode", value=str(q_mode), inline=True)
embed.add_field(name="Max Tokens", value=str(max_tokens) if max_tokens else "Unlimited", inline=True) embed.add_field(name="Max Tokens", value=str(max_tokens) if max_tokens else "Unlimited", inline=True)
embed.add_field(name="Reasoning", value=reasoning_effort if reasoning_effort else "Default (on)", inline=True)
embed.add_field(name="System Prompt", value=sys_prompt[:200], inline=False) embed.add_field(name="System Prompt", value=sys_prompt[:200], inline=False)
await ctx.send(embed=embed) await ctx.send(embed=embed)