NavyDevilDoc commited on
Commit
b663de0
Β·
verified Β·
1 Parent(s): 4da9054

Update src/modules/admin_panel.py

Browse files
Files changed (1) hide show
  1. src/modules/admin_panel.py +56 -0
src/modules/admin_panel.py CHANGED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tracker
3
+ from datetime import datetime
4
+ import json
5
+
6
+ def render_admin_sidebar():
7
+ """Renders admin-only tools in the sidebar."""
8
+ st.divider()
9
+ st.header("πŸ›‘οΈ Admin Console")
10
+
11
+ # 1. Debug Toggle
12
+ # This controls whether the "Debug Overlay" appears in the main app
13
+ if st.toggle("🐞 Enable Debug Overlay", value=st.session_state.get("debug_mode", False)):
14
+ st.session_state.debug_mode = True
15
+ st.caption("Showing raw prompts & token counts.")
16
+ else:
17
+ st.session_state.debug_mode = False
18
+
19
+ # 2. Log Downloader
20
+ log_path = tracker.get_log_path()
21
+ if log_path.exists():
22
+ with open(log_path, "r") as f:
23
+ log_data = f.read()
24
+ st.download_button(
25
+ label="πŸ“₯ Download Usage Logs",
26
+ data=log_data,
27
+ file_name=f"usage_log_{datetime.now().strftime('%Y-%m-%d')}.json",
28
+ mime="application/json"
29
+ )
30
+
31
+ def render_debug_overlay(location="Generic"):
32
+ """
33
+ Renders a collapsible expander showing the LAST input sent to the LLM.
34
+ We pull this data from session_state, which the main app populates.
35
+ """
36
+ if not st.session_state.get("debug_mode", False):
37
+ return
38
+
39
+ # Check if we have data to show
40
+ last_prompt = st.session_state.get("last_prompt_sent")
41
+ last_context = st.session_state.get("last_context_used")
42
+
43
+ if last_prompt:
44
+ with st.expander(f"🐞 Debug: Raw LLM Input ({location})", expanded=False):
45
+ tab_p, tab_c = st.tabs(["πŸ“ Prompt", "πŸ“š Context"])
46
+
47
+ with tab_p:
48
+ st.caption(f"Length: {len(last_prompt)} chars")
49
+ st.code(last_prompt, language="text")
50
+
51
+ with tab_c:
52
+ if last_context:
53
+ st.caption("Raw retrieved chunks passed to model:")
54
+ st.text(last_context)
55
+ else:
56
+ st.info("No context used for this turn.")