mpsk commited on
Commit
5ee41cc
Β·
1 Parent(s): 06665fc

fix session id selection bug

Browse files
Files changed (1) hide show
  1. chat.py +5 -5
chat.py CHANGED
@@ -107,10 +107,9 @@ def refresh_sessions():
107
  st.session_state[
108
  "current_sessions"
109
  ] = st.session_state.session_manager.list_sessions(st.session_state.user_name)
 
110
  try:
111
- dfl_indx = [
112
- x["session_id"] for x in st.session_state.current_sessions
113
- ].index("default")
114
  except ValueError:
115
  dfl_indx = 0
116
  st.session_state.sel_sess = st.session_state.current_sessions[dfl_indx]
@@ -143,7 +142,8 @@ def chat_page():
143
  st.session_state["session_manager"] = build_session_manager()
144
  with st.sidebar:
145
  with st.expander("Session Management"):
146
- refresh_sessions()
 
147
  st.info("Here you can set up your session! \n\nYou can **change your prompt** here!",
148
  icon="πŸ€–")
149
  st.info(("**Add columns by clicking the empty row**.\n"
@@ -163,7 +163,7 @@ def chat_page():
163
  try:
164
  dfl_indx = [
165
  x["session_id"] for x in st.session_state.current_sessions
166
- ].index("default")
167
  except Exception as e:
168
  print("*** ", str(e))
169
  dfl_indx = 0
 
107
  st.session_state[
108
  "current_sessions"
109
  ] = st.session_state.session_manager.list_sessions(st.session_state.user_name)
110
+
111
  try:
112
+ dfl_indx = [x["session_id"] for x in st.session_state.current_sessions].index("default" if "" not in st.session_state else st.session_state.sel_session["session_id"])
 
 
113
  except ValueError:
114
  dfl_indx = 0
115
  st.session_state.sel_sess = st.session_state.current_sessions[dfl_indx]
 
142
  st.session_state["session_manager"] = build_session_manager()
143
  with st.sidebar:
144
  with st.expander("Session Management"):
145
+ if "current_sessions" not in st.session_state:
146
+ refresh_sessions()
147
  st.info("Here you can set up your session! \n\nYou can **change your prompt** here!",
148
  icon="πŸ€–")
149
  st.info(("**Add columns by clicking the empty row**.\n"
 
163
  try:
164
  dfl_indx = [
165
  x["session_id"] for x in st.session_state.current_sessions
166
+ ].index("default" if "" not in st.session_state else st.session_state.sel_session["session_id"])
167
  except Exception as e:
168
  print("*** ", str(e))
169
  dfl_indx = 0