mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-24 01:36:37 +03:00
added option to remove conversations
This commit is contained in:
parent
3f49f18e07
commit
1379ec96b9
@ -38,6 +38,17 @@ def save_conversations(conversations, current_conversation):
|
|||||||
|
|
||||||
os.replace(temp_conversations_file, conversations_file)
|
os.replace(temp_conversations_file, conversations_file)
|
||||||
|
|
||||||
|
def delete_conversation(conversations, current_conversation):
|
||||||
|
for idx, conversation in enumerate(conversations):
|
||||||
|
conversations[idx] = current_conversation
|
||||||
|
break
|
||||||
|
conversations.remove(current_conversation)
|
||||||
|
|
||||||
|
temp_conversations_file = "temp_" + conversations_file
|
||||||
|
with open(temp_conversations_file, "wb") as f:
|
||||||
|
pickle.dump(conversations, f)
|
||||||
|
|
||||||
|
os.replace(temp_conversations_file, conversations_file)
|
||||||
|
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
print("Exiting, saving data...")
|
print("Exiting, saving data...")
|
||||||
@ -118,17 +129,22 @@ if search_query:
|
|||||||
|
|
||||||
sidebar_header = f"Search Results ({len(conversations)})"
|
sidebar_header = f"Search Results ({len(conversations)})"
|
||||||
else:
|
else:
|
||||||
conversations = enumerate(st.session_state.conversations)
|
conversations = st.session_state.conversations
|
||||||
sidebar_header = "Conversation History"
|
sidebar_header = "Conversation History"
|
||||||
|
|
||||||
# Sidebar
|
# Sidebar
|
||||||
st.sidebar.header(sidebar_header)
|
st.sidebar.header(sidebar_header)
|
||||||
|
sidebar_col1, sidebar_col2 = st.sidebar.columns([5,1])
|
||||||
for idx, conversation in conversations:
|
for idx, conversation in enumerate(conversations):
|
||||||
if st.sidebar.button(f"Conversation {idx + 1}: {conversation['user_inputs'][0]}", key=f"sidebar_btn_{idx}"):
|
if sidebar_col1.button(f"Conversation {idx + 1}: {conversation['user_inputs'][0]}", key=f"sidebar_btn_{idx}"):
|
||||||
st.session_state['selected_conversation'] = idx
|
st.session_state['selected_conversation'] = idx
|
||||||
st.session_state['current_conversation'] = conversation
|
st.session_state['current_conversation'] = conversation
|
||||||
|
if sidebar_col2.button('🗑️', key=f"sidebar_btn_delete_{idx}"):
|
||||||
|
if st.session_state['selected_conversation'] == idx:
|
||||||
|
st.session_state['selected_conversation'] = None
|
||||||
|
st.session_state['current_conversation'] = {'user_inputs': [], 'generated_responses': []}
|
||||||
|
delete_conversation(conversations, conversation)
|
||||||
|
st.experimental_rerun()
|
||||||
if st.session_state['selected_conversation'] is not None:
|
if st.session_state['selected_conversation'] is not None:
|
||||||
conversation_to_display = conversations[st.session_state['selected_conversation']]
|
conversation_to_display = conversations[st.session_state['selected_conversation']]
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user