From bf61df30dd59c381bab5560e092a782c7a9ddc7b Mon Sep 17 00:00:00 2001 From: AllfatherHatt Date: Fri, 21 Feb 2025 19:12:22 +0100 Subject: [PATCH] Updated summarize memory function --- reginaldCog/reginald.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index 17c88a6..0cbcb6a 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -138,13 +138,15 @@ class ReginaldCog(commands.Cog): async def summarize_memory(self, ctx, messages): - """āœ… Generates a summary of past conversations for mid-term storage.""" + """āœ… Generates a structured, compact summary of past conversations for mid-term storage.""" summary_prompt = ( - "Condense the following conversation into an efficient, structured summary that maximizes information density while minimizing token usage. " - "Focus on key insights, decisions, disputes, and facts, ensuring clarity and conciseness without excessive detail. " - "Categorize information into: (1) Agreed Conclusions, (2) Disputed Points, (3) Notable User Contributions, and (4) Miscellaneous Context. " - "Avoid unnecessary flavor text but ensure all critical meaning and context are retained. Summarize each topic distinctly, avoiding generalization. " - "Prioritize compression while keeping essential nuances intact." + "Summarize the following conversation into a structured, concise format that retains key details while maximizing brevity. " + "The summary should be **organized** into clear sections: " + "\n\nšŸ“Œ **Key Takeaways:** Important facts or conclusions reached." + "\nšŸ”¹ **Disputed Points:** Areas where opinions or facts conflicted." + "\nšŸ—£ļø **Notable User Contributions:** Key statements from users that shaped the discussion." + "\nšŸ“œ **Additional Context:** Any other relevant information." + "\n\nEnsure the summary is **dense but not overly verbose**. Avoid unnecessary repetition while keeping essential meaning intact." ) summary_text = "\n".join(f"{msg['user']}: {msg['content']}" for msg in messages) @@ -161,7 +163,10 @@ class ReginaldCog(commands.Cog): client = openai.AsyncClient(api_key=api_key) response = await client.chat.completions.create( model="gpt-4o-mini", - messages=[{"role": "system", "content": summary_prompt}, {"role": "user", "content": summary_text}], + messages=[ + {"role": "system", "content": summary_prompt}, + {"role": "user", "content": summary_text} + ], max_tokens=2048 ) @@ -179,7 +184,7 @@ class ReginaldCog(commands.Cog): except OpenAIError as e: error_message = f"OpenAI Error: {e}" print(f"šŸ› ļø DEBUG: {error_message}") # Log error to console - + reginald_responses = [ f"Regrettably, I must inform you that I have encountered a bureaucratic obstruction whilst attempting to summarize:\n\n```{error_message}```", f"It would seem that a most unfortunate technical hiccup has befallen my faculties in the matter of summarization:\n\n```{error_message}```", @@ -189,6 +194,7 @@ class ReginaldCog(commands.Cog): return random.choice(reginald_responses) + def extract_topics_from_summary(self, summary): """Dynamically extracts the most important topics from a summary."""