github-actions commited on
Commit
fe4e974
1 Parent(s): 1f16a4c

Sync updates from source repository

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -33,6 +33,7 @@ def launch_bot():
33
  'examples': os.environ.get('examples', '')
34
  })
35
  st.session_state.cfg = cfg
 
36
  st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_ids, cfg.prompt_name)
37
 
38
  cfg = st.session_state.cfg
@@ -61,11 +62,12 @@ def launch_bot():
61
  if "messages" not in st.session_state.keys():
62
  st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
63
 
 
64
  example_messages = [example.strip() for example in cfg.examples.split(",")]
65
- example_messages = [em for em in example_messages if len(em)>0]
66
  if len(example_messages) > 0:
67
  st.markdown("<h6>Queries To Try:</h6>", unsafe_allow_html=True)
68
- ex_cols = st.columns(4)
69
 
70
  # Display chat messages
71
  for message in st.session_state.messages:
@@ -73,7 +75,12 @@ def launch_bot():
73
  st.write(message["content"])
74
 
75
  # User-provided prompt
76
- if prompt := st.chat_input():
 
 
 
 
 
77
  st.session_state.messages.append({"role": "user", "content": prompt})
78
  with st.chat_message("user"):
79
  st.write(prompt)
@@ -83,8 +90,7 @@ def launch_bot():
83
  button_pressed = False
84
  with ex_cols[i]:
85
  if st.button(example):
86
- prompt = example
87
- button_pressed = True
88
 
89
  if button_pressed:
90
  st.session_state.messages.append({"role": "user", "content": prompt})
 
33
  'examples': os.environ.get('examples', '')
34
  })
35
  st.session_state.cfg = cfg
36
+ st.session_state.ex_prompt = None
37
  st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_ids, cfg.prompt_name)
38
 
39
  cfg = st.session_state.cfg
 
62
  if "messages" not in st.session_state.keys():
63
  st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
64
 
65
+ max_examples = 4
66
  example_messages = [example.strip() for example in cfg.examples.split(",")]
67
+ example_messages = [em for em in example_messages if len(em)>0][:max_examples]
68
  if len(example_messages) > 0:
69
  st.markdown("<h6>Queries To Try:</h6>", unsafe_allow_html=True)
70
+ ex_cols = st.columns(max_examples)
71
 
72
  # Display chat messages
73
  for message in st.session_state.messages:
 
75
  st.write(message["content"])
76
 
77
  # User-provided prompt
78
+ if st.session_state.ex_prompt:
79
+ prompt = st.session_state.ex_prompt
80
+ st.session_state.ex_prompt = None
81
+ else:
82
+ prompt = st.chat_input()
83
+ if prompt:
84
  st.session_state.messages.append({"role": "user", "content": prompt})
85
  with st.chat_message("user"):
86
  st.write(prompt)
 
90
  button_pressed = False
91
  with ex_cols[i]:
92
  if st.button(example):
93
+ st.session_state.ex_prompt = example
 
94
 
95
  if button_pressed:
96
  st.session_state.messages.append({"role": "user", "content": prompt})