feat: Last Prompt shows full prompt with evil mode awareness
- discord_bridge before_agent_starts now checks evil_mode from
working_memory to load the correct personality files:
Normal: miku_lore/prompt/lyrics + /app/moods/{mood}.txt
Evil: evil_miku_lore/prompt/lyrics + /app/moods/evil/{mood}.txt
- Reads files directly instead of relying on cross-plugin working_memory
- cat_client.query() returns (response, full_prompt) tuple
- Full prompt includes system prefix + recalled memories + conversation
- API /prompt/cat returns full_prompt field
This commit is contained in:
@@ -203,10 +203,10 @@ def get_last_prompt():
|
||||
|
||||
@app.get("/prompt/cat")
|
||||
def get_last_cat_prompt():
|
||||
"""Get the last Cheshire Cat interaction (prompt + response) for Web UI."""
|
||||
"""Get the last Cheshire Cat interaction (full prompt + response) for Web UI."""
|
||||
interaction = globals.LAST_CAT_INTERACTION
|
||||
if not interaction.get("prompt"):
|
||||
return {"prompt": "No Cheshire Cat interaction has occurred yet.", "response": "", "user": "", "mood": "", "timestamp": ""}
|
||||
if not interaction.get("full_prompt"):
|
||||
return {"full_prompt": "No Cheshire Cat interaction has occurred yet.", "response": "", "user": "", "mood": "", "timestamp": ""}
|
||||
return interaction
|
||||
|
||||
@app.get("/mood")
|
||||
|
||||
14
bot/bot.py
14
bot/bot.py
@@ -542,7 +542,7 @@ async def on_message(message):
|
||||
if globals.USE_CHESHIRE_CAT:
|
||||
try:
|
||||
from utils.cat_client import cat_adapter
|
||||
response = await cat_adapter.query(
|
||||
cat_result = await cat_adapter.query(
|
||||
text=enhanced_prompt,
|
||||
user_id=str(message.author.id),
|
||||
guild_id=str(guild_id) if guild_id else None,
|
||||
@@ -550,11 +550,12 @@ async def on_message(message):
|
||||
mood=globals.DM_MOOD,
|
||||
response_type=response_type,
|
||||
)
|
||||
if response:
|
||||
if cat_result:
|
||||
response, cat_full_prompt = cat_result
|
||||
logger.info(f"🐱 Cat embed response for {author_name}")
|
||||
import datetime
|
||||
globals.LAST_CAT_INTERACTION = {
|
||||
"prompt": enhanced_prompt,
|
||||
"full_prompt": cat_full_prompt,
|
||||
"response": response[:500] if response else "",
|
||||
"user": author_name,
|
||||
"mood": globals.DM_MOOD,
|
||||
@@ -639,7 +640,7 @@ async def on_message(message):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
response = await cat_adapter.query(
|
||||
cat_result = await cat_adapter.query(
|
||||
text=prompt,
|
||||
user_id=str(message.author.id),
|
||||
guild_id=str(guild_id) if guild_id else None,
|
||||
@@ -647,7 +648,8 @@ async def on_message(message):
|
||||
mood=current_mood,
|
||||
response_type=response_type,
|
||||
)
|
||||
if response:
|
||||
if cat_result:
|
||||
response, cat_full_prompt = cat_result
|
||||
effective_mood = current_mood
|
||||
if globals.EVIL_MODE:
|
||||
effective_mood = f"EVIL:{getattr(globals, 'EVIL_DM_MOOD', 'evil_neutral')}"
|
||||
@@ -655,7 +657,7 @@ async def on_message(message):
|
||||
# Track Cat interaction for Web UI Last Prompt view
|
||||
import datetime
|
||||
globals.LAST_CAT_INTERACTION = {
|
||||
"prompt": prompt,
|
||||
"full_prompt": cat_full_prompt,
|
||||
"response": response[:500] if response else "",
|
||||
"user": author_name,
|
||||
"mood": effective_mood,
|
||||
|
||||
@@ -85,7 +85,7 @@ LAST_FULL_PROMPT = ""
|
||||
|
||||
# Cheshire Cat last interaction tracking (for Web UI Last Prompt toggle)
|
||||
LAST_CAT_INTERACTION = {
|
||||
"prompt": "",
|
||||
"full_prompt": "",
|
||||
"response": "",
|
||||
"user": "",
|
||||
"mood": "",
|
||||
|
||||
@@ -4047,10 +4047,10 @@ async function loadLastPrompt() {
|
||||
const result = await apiCall('/prompt/cat');
|
||||
if (result.timestamp) {
|
||||
infoEl.innerHTML = `<strong>User:</strong> ${escapeHtml(result.user || '?')} | <strong>Mood:</strong> ${escapeHtml(result.mood || '?')} | <strong>Time:</strong> ${new Date(result.timestamp).toLocaleString()}`;
|
||||
promptEl.textContent = `[User message → Cat]\n${result.prompt}\n\n[Cat response]\n${result.response}`;
|
||||
promptEl.textContent = result.full_prompt + `\n\n${'═'.repeat(60)}\n[Cat Response]\n${result.response}`;
|
||||
} else {
|
||||
infoEl.textContent = '';
|
||||
promptEl.textContent = result.prompt || 'No Cheshire Cat interaction yet.';
|
||||
promptEl.textContent = result.full_prompt || 'No Cheshire Cat interaction yet.';
|
||||
}
|
||||
} else {
|
||||
infoEl.textContent = '';
|
||||
|
||||
@@ -107,7 +107,7 @@ class CatAdapter:
|
||||
author_name: Optional[str] = None,
|
||||
mood: Optional[str] = None,
|
||||
response_type: str = "dm_response",
|
||||
) -> Optional[str]:
|
||||
) -> Optional[tuple]:
|
||||
"""
|
||||
Send a message through the Cat pipeline via WebSocket and get a response.
|
||||
|
||||
@@ -125,7 +125,8 @@ class CatAdapter:
|
||||
response_type: Type of response context
|
||||
|
||||
Returns:
|
||||
Cat's response text, or None if Cat is unavailable (caller should fallback)
|
||||
Tuple of (response_text, full_prompt) on success, or None if Cat
|
||||
is unavailable (caller should fallback to query_llama)
|
||||
"""
|
||||
if not globals.USE_CHESHIRE_CAT:
|
||||
return None
|
||||
@@ -175,6 +176,7 @@ class CatAdapter:
|
||||
# Cat may send intermediate messages (chat_token for streaming,
|
||||
# notification for status updates). We want the final "chat" one.
|
||||
reply_text = None
|
||||
full_prompt = ""
|
||||
deadline = asyncio.get_event_loop().time() + self._timeout
|
||||
|
||||
while True:
|
||||
@@ -212,8 +214,9 @@ class CatAdapter:
|
||||
msg_type = msg.get("type", "")
|
||||
|
||||
if msg_type == "chat":
|
||||
# Final response — extract text
|
||||
# Final response — extract text and full prompt
|
||||
reply_text = msg.get("content") or msg.get("text", "")
|
||||
full_prompt = msg.get("full_prompt", "")
|
||||
break
|
||||
elif msg_type == "chat_token":
|
||||
# Streaming token — skip, we wait for final
|
||||
@@ -232,7 +235,7 @@ class CatAdapter:
|
||||
if reply_text and reply_text.strip():
|
||||
self._consecutive_failures = 0
|
||||
logger.info(f"🐱 Cat response for {cat_user_id}: {reply_text[:100]}...")
|
||||
return reply_text
|
||||
return reply_text, full_prompt
|
||||
else:
|
||||
logger.warning("Cat returned empty response via WS")
|
||||
self._consecutive_failures += 1
|
||||
|
||||
Reference in New Issue
Block a user