backend: replace LAST_FULL_PROMPT/LAST_CAT_INTERACTION with unified PROMPT_HISTORY deque
- globals.py: add collections.deque(maxlen=10) PROMPT_HISTORY with _prompt_id_counter
- globals.py: add legacy accessor functions _get_last_fallback_prompt() and _get_last_cat_interaction()
- bot.py: append to PROMPT_HISTORY instead of setting LAST_CAT_INTERACTION, remove 500-char truncation, add guild/channel/model fields
- image_handling.py: same pattern for Cat media responses
- llm.py: append fallback prompts to PROMPT_HISTORY with response filled after LLM reply
- routes/core.py: new GET /prompts and GET /prompts/{id} endpoints, legacy /prompt and /prompt/cat use accessor functions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# globals.py
|
||||
import os
|
||||
import discord
|
||||
from collections import deque
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
scheduler = AsyncIOScheduler()
|
||||
@@ -77,16 +78,25 @@ MIKU_NORMAL_AVATAR_URL = None # Cached CDN URL of the regular Miku pfp (valid e
|
||||
|
||||
BOT_USER = None
|
||||
|
||||
LAST_FULL_PROMPT = ""
|
||||
# Unified prompt history (replaces LAST_FULL_PROMPT and LAST_CAT_INTERACTION)
|
||||
# Each entry: {id, source, full_prompt, response, user, mood, guild, channel,
|
||||
# timestamp, model, response_type}
|
||||
PROMPT_HISTORY = deque(maxlen=10)
|
||||
_prompt_id_counter = 0
|
||||
|
||||
# Cheshire Cat last interaction tracking (for Web UI Last Prompt toggle)
|
||||
LAST_CAT_INTERACTION = {
|
||||
"full_prompt": "",
|
||||
"response": "",
|
||||
"user": "",
|
||||
"mood": "",
|
||||
"timestamp": "",
|
||||
}
|
||||
# Legacy accessors for backward compatibility (routes, CLI, etc.)
|
||||
# These are computed properties that read from PROMPT_HISTORY
|
||||
def _get_last_fallback_prompt():
|
||||
for entry in reversed(PROMPT_HISTORY):
|
||||
if entry.get("source") == "fallback":
|
||||
return entry.get("full_prompt", "")
|
||||
return ""
|
||||
|
||||
def _get_last_cat_interaction():
|
||||
for entry in reversed(PROMPT_HISTORY):
|
||||
if entry.get("source") == "cat":
|
||||
return entry
|
||||
return {"full_prompt": "", "response": "", "user": "", "mood": "", "timestamp": ""}
|
||||
|
||||
# Persona Dialogue System (conversations between Miku and Evil Miku)
|
||||
LAST_PERSONA_DIALOGUE_TIME = 0 # Timestamp of last dialogue for cooldown
|
||||
|
||||
Reference in New Issue
Block a user