Added ability to adjust short-term memory limit
This commit is contained in:
parent
b8790f57b4
commit
d970df5a12
@ -14,6 +14,7 @@ class ReginaldCog(commands.Cog):
|
|||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.config = Config.get_conf(self, identifier=71717171171717)
|
self.config = Config.get_conf(self, identifier=71717171171717)
|
||||||
self.memory_locks = {} # ✅ Prevents race conditions per channel
|
self.memory_locks = {} # ✅ Prevents race conditions per channel
|
||||||
|
self.short_term_memory_limit = 100 # Default value, can be changed dynamically
|
||||||
|
|
||||||
# ✅ Properly Registered Configuration Keys
|
# ✅ Properly Registered Configuration Keys
|
||||||
default_global = {"openai_model": "gpt-4o-mini"}
|
default_global = {"openai_model": "gpt-4o-mini"}
|
||||||
@ -96,7 +97,7 @@ class ReginaldCog(commands.Cog):
|
|||||||
|
|
||||||
memory.append({"user": user_name, "content": prompt})
|
memory.append({"user": user_name, "content": prompt})
|
||||||
memory.append({"user": "Reginald", "content": response_text})
|
memory.append({"user": "Reginald", "content": response_text})
|
||||||
if len(memory) > 100:
|
if len(memory) > self.short_term_memory_limit:
|
||||||
summary = await self.summarize_memory(memory)
|
summary = await self.summarize_memory(memory)
|
||||||
|
|
||||||
if channel_id not in mid_memory:
|
if channel_id not in mid_memory:
|
||||||
@ -265,6 +266,17 @@ class ReginaldCog(commands.Cog):
|
|||||||
"""Allows an admin to set the OpenAI API key for Reginald."""
|
"""Allows an admin to set the OpenAI API key for Reginald."""
|
||||||
await self.config.guild(ctx.guild).openai_api_key.set(api_key)
|
await self.config.guild(ctx.guild).openai_api_key.set(api_key)
|
||||||
await ctx.send("OpenAI API key set successfully.")
|
await ctx.send("OpenAI API key set successfully.")
|
||||||
|
|
||||||
|
@commands.command(name="reginald_set_limit", help="Set the short-term memory message limit.")
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
|
async def set_short_term_memory_limit(self, ctx, limit: int):
|
||||||
|
"""Allows an admin to change the short-term memory limit dynamically."""
|
||||||
|
if limit < 5:
|
||||||
|
await ctx.send("⚠️ The short-term memory limit must be at least 5.")
|
||||||
|
return
|
||||||
|
|
||||||
|
self.short_term_memory_limit = limit
|
||||||
|
await ctx.send(f"✅ Short-term memory limit set to {limit} messages.")
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
"""✅ Correct async cog setup for Redbot"""
|
"""✅ Correct async cog setup for Redbot"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user