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:
@@ -31,18 +31,45 @@ def get_logs():
|
||||
|
||||
@router.get("/prompt")
|
||||
def get_last_prompt():
|
||||
return {"prompt": globals.LAST_FULL_PROMPT or "No prompt has been issued yet."}
|
||||
"""Legacy endpoint: returns the most recent fallback prompt (backward compat)."""
|
||||
prompt_text = globals._get_last_fallback_prompt()
|
||||
return {"prompt": prompt_text or "No prompt has been issued yet."}
|
||||
|
||||
|
||||
@router.get("/prompt/cat")
|
||||
def get_last_cat_prompt():
|
||||
"""Get the last Cheshire Cat interaction (full prompt + response) for Web UI."""
|
||||
interaction = globals.LAST_CAT_INTERACTION
|
||||
"""Legacy endpoint: returns the most recent Cat interaction (backward compat)."""
|
||||
interaction = globals._get_last_cat_interaction()
|
||||
if not interaction.get("full_prompt"):
|
||||
return {"full_prompt": "No Cheshire Cat interaction has occurred yet.", "response": "", "user": "", "mood": "", "timestamp": ""}
|
||||
return {"full_prompt": "No Cheshire Cat interaction has occurred yet.",
|
||||
"response": "", "user": "", "mood": "", "timestamp": ""}
|
||||
return interaction
|
||||
|
||||
|
||||
@router.get("/prompts")
|
||||
def get_prompt_history(source: str = None):
|
||||
"""
|
||||
Return the unified prompt history.
|
||||
Optional query param ?source=cat or ?source=fallback to filter.
|
||||
"""
|
||||
history = list(globals.PROMPT_HISTORY)
|
||||
if source and source in ("cat", "fallback"):
|
||||
history = [e for e in history if e.get("source") == source]
|
||||
return {"history": history}
|
||||
|
||||
|
||||
@router.get("/prompts/{prompt_id}")
|
||||
def get_prompt_by_id(prompt_id: int):
|
||||
"""Return a single prompt history entry by ID."""
|
||||
for entry in globals.PROMPT_HISTORY:
|
||||
if entry.get("id") == prompt_id:
|
||||
return entry
|
||||
return JSONResponse(
|
||||
status_code=404,
|
||||
content={"status": "error", "message": f"Prompt #{prompt_id} not found"}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
def status():
|
||||
# Get per-server mood summary
|
||||
|
||||
Reference in New Issue
Block a user