Add shared chat actions menu, rename functionality, and debug logging
This commit is contained in:
parent
33465ea337
commit
e6ff68b962
1 changed files with 74 additions and 8 deletions
|
|
@ -136,6 +136,12 @@ with col_sessions:
|
|||
if st.session_state.get("chat_action_menu") == chat['id']:
|
||||
st.markdown("**Actions:**")
|
||||
|
||||
# Rename
|
||||
if st.button("✏️ Rename", key=f"rename_{chat['id']}", use_container_width=True):
|
||||
st.session_state.renaming_chat_id = chat['id']
|
||||
st.session_state.chat_action_menu = None
|
||||
st.rerun()
|
||||
|
||||
# Share toggle
|
||||
share_status = "🤝 Shared" if chat['is_shared'] else "🔒 Private"
|
||||
if st.button(f"{share_status}", key=f"toggle_share_{chat['id']}", use_container_width=True):
|
||||
|
|
@ -157,6 +163,29 @@ with col_sessions:
|
|||
del st.session_state.chat_action_menu
|
||||
st.rerun()
|
||||
|
||||
# Rename form
|
||||
if st.session_state.get("renaming_chat_id") == chat['id']:
|
||||
new_title = st.text_input("New name:", value=chat['title'], key=f"rename_input_{chat['id']}")
|
||||
col_r1, col_r2 = st.columns(2)
|
||||
with col_r1:
|
||||
if st.button("Save", key=f"save_rename_{chat['id']}", type="primary", use_container_width=True):
|
||||
from database import ChatSession
|
||||
db = get_db()
|
||||
try:
|
||||
session = db.query(ChatSession).filter(ChatSession.id == chat['id']).first()
|
||||
if session:
|
||||
session.title = new_title
|
||||
db.commit()
|
||||
st.success("Renamed!")
|
||||
del st.session_state.renaming_chat_id
|
||||
st.rerun()
|
||||
finally:
|
||||
db.close()
|
||||
with col_r2:
|
||||
if st.button("Cancel", key=f"cancel_rename_{chat['id']}", use_container_width=True):
|
||||
del st.session_state.renaming_chat_id
|
||||
st.rerun()
|
||||
|
||||
# Shared Chats
|
||||
if shared_chats:
|
||||
st.markdown("---")
|
||||
|
|
@ -168,14 +197,45 @@ with col_sessions:
|
|||
chat_label = chat['title'] or f"Chat {chat['created_at'].strftime('%m/%d %H:%M')}"
|
||||
owner_name = chat.get('username', 'Unknown') if not is_mine else "You"
|
||||
|
||||
if st.button(
|
||||
f"{'▶ ' if is_current else '🤝 '}{chat_label}\n*by {owner_name}*",
|
||||
key=f"load_shared_{chat['id']}",
|
||||
use_container_width=True,
|
||||
disabled=is_current
|
||||
):
|
||||
st.session_state.selected_chat_id = chat['id']
|
||||
st.rerun()
|
||||
col_s1, col_s2 = st.columns([3, 1])
|
||||
with col_s1:
|
||||
if st.button(
|
||||
f"{'▶ ' if is_current else '🤝 '}{chat_label}\n*by {owner_name}*",
|
||||
key=f"load_shared_{chat['id']}",
|
||||
use_container_width=True,
|
||||
disabled=is_current
|
||||
):
|
||||
st.session_state.selected_chat_id = chat['id']
|
||||
st.rerun()
|
||||
|
||||
with col_s2:
|
||||
# Only show actions if it's your chat
|
||||
if is_mine and st.button("⋮", key=f"shared_actions_{chat['id']}"):
|
||||
st.session_state.chat_action_menu = chat['id']
|
||||
|
||||
# Action menu for shared chats
|
||||
if is_mine and st.session_state.get("chat_action_menu") == chat['id']:
|
||||
st.markdown("**Actions:**")
|
||||
|
||||
# Unshare (make private again)
|
||||
if st.button("🔒 Make Private", key=f"unshare_{chat['id']}", use_container_width=True):
|
||||
toggle_chat_sharing(chat['id'])
|
||||
st.success("Chat is now private!")
|
||||
del st.session_state.chat_action_menu
|
||||
st.rerun()
|
||||
|
||||
# Delete
|
||||
if st.button("🗑️ Delete", key=f"delete_shared_{chat['id']}", use_container_width=True):
|
||||
if delete_chat_session(chat['id'], user.id):
|
||||
if st.session_state.get("selected_chat_id") == chat['id']:
|
||||
st.session_state.selected_chat_id = None
|
||||
st.success("Chat deleted!")
|
||||
del st.session_state.chat_action_menu
|
||||
st.rerun()
|
||||
|
||||
if st.button("✕ Close", key=f"close_shared_menu_{chat['id']}", use_container_width=True):
|
||||
del st.session_state.chat_action_menu
|
||||
st.rerun()
|
||||
|
||||
with col_chat:
|
||||
# Header
|
||||
|
|
@ -248,9 +308,15 @@ with col_chat:
|
|||
with st.chat_message("assistant"):
|
||||
with st.spinner("Thinking..."):
|
||||
try:
|
||||
# Debug output
|
||||
print(f"About to query pipeline: {notebook.pipeline_id}")
|
||||
print(f"Question: {prompt}")
|
||||
|
||||
# Query using notebook's dedicated pipeline
|
||||
response = sync_chat(prompt, notebook.pipeline_id)
|
||||
|
||||
print(f"Got response: {type(response)}")
|
||||
|
||||
if "## Sources" in response:
|
||||
parts = response.split("## Sources", 1)
|
||||
main_response = parts[0].strip()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue