cboettig commited on
Commit
83df5bc
·
1 Parent(s): e0fc76b

option b: cleaner flow but hides 'thinking' after answer succeeds.

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -48,13 +48,13 @@ agent = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True)
48
  def handle_user_input(user_query):
49
  with history:
50
  st.session_state.messages.append({"role": "user", "content": user_query})
51
- st.chat_message("user").write(user_query)
52
 
53
  with st.chat_message("assistant"):
54
  st_cb = StreamlitCallbackHandler(st.container())
55
  response = agent.run(user_query, callbacks=[st_cb])
56
  st.session_state.messages.append({"role": "assistant", "content": response})
57
- st.write(response)
58
 
59
 
60
  if "messages" not in st.session_state:
@@ -63,9 +63,10 @@ if "messages" not in st.session_state:
63
  main = st.container()
64
  with main:
65
  history = st.container(height=400)
66
- #with history:
67
- # for msg in st.session_state.messages:
68
- # st.chat_message(msg["role"]).write(msg["content"])
 
69
  if user_query := st.chat_input(placeholder="Ask me about US Protected areas!"):
70
  handle_user_input(user_query)
71
 
 
48
  def handle_user_input(user_query):
49
  with history:
50
  st.session_state.messages.append({"role": "user", "content": user_query})
51
+ #st.chat_message("user").write(user_query)
52
 
53
  with st.chat_message("assistant"):
54
  st_cb = StreamlitCallbackHandler(st.container())
55
  response = agent.run(user_query, callbacks=[st_cb])
56
  st.session_state.messages.append({"role": "assistant", "content": response})
57
+ # st.write(response) # thinking is only shown transiently this way
58
 
59
 
60
  if "messages" not in st.session_state:
 
63
  main = st.container()
64
  with main:
65
  history = st.container(height=400)
66
+ # stores all questions and responses, but not the 'thinking'
67
+ with history:
68
+ for msg in st.session_state.messages:
69
+ st.chat_message(msg["role"]).write(msg["content"])
70
  if user_query := st.chat_input(placeholder="Ask me about US Protected areas!"):
71
  handle_user_input(user_query)
72