Skip to content

Commit

Permalink
chat history bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chinesewebman committed May 19, 2023
1 parent 107d555 commit 7813f66
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ cython_debug/
*.pkl
*.csv
src/pages/3_Robby-Youtube.py
*.zip
*.docx
embeddings/.gitkeep
6 changes: 3 additions & 3 deletions src/modules/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions src/modules/sidebar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from math import e
import streamlit as st
import os

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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)
self.temperature_slider()

0 comments on commit 7813f66

Please sign in to comment.