refactor: consolidate conversation_history to ConversationHistory class
Remove legacy globals.conversation_history (defaultdict of deques) and
route all callers through utils.conversation_history.ConversationHistory:
- globals.py: remove conversation_history + unused collections imports
- llm.py: remove backward-compat dual-write to legacy system
- api.py: /conversation/{user_id} now reads from ConversationHistory
- actions.py: reset_conversation uses clear_channel()
- figurine_notifier.py: use add_message() instead of buggy setdefault()
- bipolar_mode.py: fix clear_history -> clear_channel (was AttributeError
silently swallowed by bare except), fix bare except -> except Exception
This commit is contained in:
@@ -5,8 +5,8 @@ from datetime import datetime
|
||||
from typing import List, Dict, Any, Tuple
|
||||
|
||||
import discord
|
||||
import globals
|
||||
|
||||
from utils.conversation_history import conversation_history
|
||||
from utils.twitter_fetcher import fetch_figurine_tweets_latest
|
||||
from utils.image_handling import analyze_image_with_qwen, download_and_encode_image
|
||||
from utils.llm import query_llama
|
||||
@@ -204,15 +204,11 @@ async def send_figurine_dm_to_user(client: discord.Client, user_id: int, tweet:
|
||||
# Log the comment message
|
||||
dm_logger.log_user_message(user, comment_message, is_bot_message=True)
|
||||
|
||||
# IMPORTANT: Also add to globals.conversation_history for LLM context
|
||||
# Add to conversation history for LLM context (uses centralized ConversationHistory)
|
||||
user_id_str = str(user_id)
|
||||
|
||||
# Add the tweet URL as a "system message" about what Miku just sent (use original URL for context)
|
||||
tweet_context = f"[I just sent you this figurine tweet: {tweet_url}]"
|
||||
|
||||
# Add the figurine comment to conversation history
|
||||
# Use empty user prompt since this was initiated by Miku
|
||||
globals.conversation_history.setdefault(user_id_str, []).append((tweet_context, miku_comment))
|
||||
conversation_history.add_message(channel_id=user_id_str, author_name="Miku", content=tweet_context, is_bot=True)
|
||||
conversation_history.add_message(channel_id=user_id_str, author_name="Miku", content=miku_comment, is_bot=True)
|
||||
|
||||
logger.debug(f"Messages logged to both DM history and conversation context for user {user_id}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user