From 7813f6669102bfe2a4143b83c73f5134548f0fb9 Mon Sep 17 00:00:00 2001 From: chinesewebman Date: Sat, 20 May 2023 07:30:46 +0800 Subject: [PATCH] chat history bug fix --- .gitignore | 3 +++ src/modules/history.py | 6 +++--- src/modules/sidebar.py | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 3f09851..0af35eb 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,6 @@ cython_debug/ *.pkl *.csv src/pages/3_Robby-Youtube.py +*.zip +*.docx +embeddings/.gitkeep diff --git a/src/modules/history.py b/src/modules/history.py index 3833d0d..07183e9 100644 --- a/src/modules/history.py +++ b/src/modules/history.py @@ -22,14 +22,14 @@ def initialize_assistant_history(self, selected_file): st.session_state["assistant"] = [self.default_prompt(selected_file)] def initialize(self, selected_file): - if "assistant" not in st.session_state: + if 'assistant' not in st.session_state: self.initialize_assistant_history(selected_file) - if "user" not in st.session_state: + if 'user' not in st.session_state: self.initialize_user_history() def reset(self, selected_file): + st.balloons() st.session_state["history"] = [] - self.initialize_user_history() self.initialize_assistant_history(selected_file) st.session_state["reset_chat"] = False diff --git a/src/modules/sidebar.py b/src/modules/sidebar.py index 92ab535..4343b46 100644 --- a/src/modules/sidebar.py +++ b/src/modules/sidebar.py @@ -1,3 +1,4 @@ +from math import e import streamlit as st import os @@ -27,7 +28,8 @@ def about(): def reset_chat_button(): if st.button("重置聊天"): st.session_state["reset_chat"] = True - st.session_state.setdefault("reset_chat", False) + else: + st.session_state["reset_chat"] = False def delemiter_selector(self): text_delimiter = st.selectbox( @@ -80,9 +82,9 @@ def temperature_slider(self): def show_file_selecotr(self, data_directory, history): def reset_history(): + st.success("文件已选择") history.reset(st.session_state["selected_file"]) history.initialize_assistant_history(st.session_state["selected_file"]) - st.success("聊天已重置!") filelist=[] for root, dirs, files in os.walk(data_directory): for file in files: @@ -92,15 +94,15 @@ def reset_history(): def show_options(self): with st.sidebar.expander("🛠️ 小维摩的设置", expanded=True): - + st.session_state.setdefault("model", self.MODEL_OPTIONS[0]) + st.session_state.setdefault("temperature", self.TEMPERATURE_DEFAULT_VALUE) + st.session_state.setdefault("top_k", 3) + st.session_state.setdefault("text_delimiter", "###") + st.session_state.setdefault("chunk_size_limit", 1100) + st.session_state.setdefault("reset_chat", False) self.reset_chat_button() self.chunk_size_slider() self.delemiter_selector() self.top_k_slider() self.model_selector() - self.temperature_slider() - st.session_state.setdefault("model", self.MODEL_OPTIONS[0]) - st.session_state.setdefault("temperature", self.TEMPERATURE_DEFAULT_VALUE) - st.session_state.setdefault("top_k", 3) - st.session_state.setdefault("text_delimiter", "###") - st.session_state.setdefault("chunk_size_limit", 1100) \ No newline at end of file + self.temperature_slider() \ No newline at end of file