Skip to content

Commit 5b76466

Browse files
author
Yoonseo Kim
committed
Implement maintaining columns for previous chat of 'All at once' option
1 parent 272555a commit 5b76466

File tree

1 file changed

+32
-16
lines changed
  • genai/aws-gen-ai-kr/20_applications/02_qa_chatbot/04_web_ui

1 file changed

+32
-16
lines changed

genai/aws-gen-ai-kr/20_applications/02_qa_chatbot/04_web_ui/streamlit.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,24 @@ def context_showing_tab(contexts):
129129
]
130130
# 지난 답변 출력
131131
for msg in st.session_state.messages:
132-
# 지난 답변에 대한 컨텍스트 출력
133-
st.chat_message(msg["role"]).write(msg["content"])
132+
if msg["role"] == "assistant_column":
133+
answers = msg["content"]
134+
col1, col2, col3, col4 = st.columns(4)
135+
with col1:
136+
st.markdown('''### option 1 ''')
137+
st.write(answers[0])
138+
with col2:
139+
st.markdown('''### option 2 ''')
140+
st.write(answers[1])
141+
with col3:
142+
st.markdown('''### option 3 ''')
143+
st.write(answers[2])
144+
with col4:
145+
st.markdown('''### option 4 ''')
146+
st.write(answers[3])
147+
148+
else:
149+
st.chat_message(msg["role"]).write(msg["content"])
134150

135151
# 유저가 쓴 chat을 query라는 변수에 담음
136152
query = st.chat_input("Search documentation")
@@ -143,74 +159,74 @@ def context_showing_tab(contexts):
143159

144160
col1, col2, col3, col4 = st.columns(4)
145161
with col1:
146-
st.markdown('''#### parent=:red[False], reranker=:red[False]''')
162+
st.markdown('''### option 1 ''')
147163
with col2:
148-
st.markdown('''#### parent=:green[True], reranker=:red[False]''')
164+
st.markdown('''### option 2 ''')
149165
with col3:
150-
st.markdown('''#### parent=:red[False], reranker=:green[True]''')
166+
st.markdown('''### option 3 ''')
151167
with col4:
152-
st.markdown('''#### parent=:green[True], reranker=:green[True]''')
168+
st.markdown('''### option 4 ''')
153169

154170
with col1:
155171
# Streamlit callback handler로 bedrock streaming 받아오는 컨테이너 설정
156172
st_cb = StreamlitCallbackHandler(
157173
st.chat_message("assistant"),
158174
collapse_completed_thoughts=True
159175
)
160-
answer = glib.invoke(
176+
answer1 = glib.invoke(
161177
query=query,
162178
streaming_callback=st_cb,
163179
parent=False,
164180
reranker=False
165181
)[0]
166-
st.write(answer)
182+
st.write(answer1)
167183
st_cb._complete_current_thought() # Thinking을 complete로 수동으로 바꾸어 줌
168184
with col2:
169185
# Streamlit callback handler로 bedrock streaming 받아오는 컨테이너 설정
170186
st_cb = StreamlitCallbackHandler(
171187
st.chat_message("assistant"),
172188
collapse_completed_thoughts=True
173189
)
174-
answer = glib.invoke(
190+
answer2 = glib.invoke(
175191
query=query,
176192
streaming_callback=st_cb,
177193
parent=True,
178194
reranker=False
179195
)[0]
180-
st.write(answer)
196+
st.write(answer2)
181197
st_cb._complete_current_thought() # Thinking을 complete로 수동으로 바꾸어 줌
182198
with col3:
183199
# Streamlit callback handler로 bedrock streaming 받아오는 컨테이너 설정
184200
st_cb = StreamlitCallbackHandler(
185201
st.chat_message("assistant"),
186202
collapse_completed_thoughts=True
187203
)
188-
answer = glib.invoke(
204+
answer3 = glib.invoke(
189205
query=query,
190206
streaming_callback=st_cb,
191207
parent=False,
192208
reranker=True
193209
)[0]
194-
st.write(answer)
210+
st.write(answer3)
195211
st_cb._complete_current_thought() # Thinking을 complete로 수동으로 바꾸어 줌
196212
with col4:
197213
# Streamlit callback handler로 bedrock streaming 받아오는 컨테이너 설정
198214
st_cb = StreamlitCallbackHandler(
199215
st.chat_message("assistant"),
200216
collapse_completed_thoughts=True
201217
)
202-
answer = glib.invoke(
218+
answer4 = glib.invoke(
203219
query=query,
204220
streaming_callback=st_cb,
205221
parent=True,
206222
reranker=True
207223
)[0]
208-
st.write(answer)
224+
st.write(answer4)
209225
st_cb._complete_current_thought() # Thinking을 complete로 수동으로 바꾸어 줌
210226

211227
# Session 메세지 저장
212-
st.session_state.messages.append({"role": "assistant", "content": answer})
213-
# st.session_state.messages.append({"role": "assistant", "content": contexts})
228+
answer = [answer1, answer2, answer3, answer4]
229+
st.session_state.messages.append({"role": "assistant_column", "content": answer})
214230

215231
# UI 출력
216232
# st.chat_message("assistant").write(answer)

0 commit comments

Comments
 (0)