Skip to content

Commit 1e9e116

Browse files
committed
[Add] : add HyDE RAG Fusion mid context
1 parent 294bc0b commit 1e9e116

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,27 @@ def invoke(query, streaming_callback, parent, reranker, hyde, ragfusion, alpha):
117117
)
118118
response, pretty_contexts, similar_docs, augmentation = qa.invoke(query = query, complex_doc = True)
119119
print("-------> response")
120-
print(response)
120+
# print(response)
121121
print("-------> pretty_contexts -> 모든 컨텍스트 포함된 자료")
122122

123123
def extract_elements_and_print(pretty_contexts):
124124
for context in pretty_contexts:
125125
print("context: \n")
126-
print(context)
126+
# print(context)
127127

128-
print("######### SEMANTIC #########")
129-
extract_elements_and_print(pretty_contexts[0])
130-
print("######### KEYWORD #########")
131-
extract_elements_and_print(pretty_contexts[1])
132-
print("######### WITHOUT_RERANKER #########")
133-
extract_elements_and_print(pretty_contexts[2])
134-
print("######## SIMILAR_DOCS ##########")
135-
extract_elements_and_print(pretty_contexts[3])
128+
# print("######### SEMANTIC #########")
129+
# extract_elements_and_print(pretty_contexts[0])
130+
# print("######### KEYWORD #########")
131+
# extract_elements_and_print(pretty_contexts[1])
132+
# print("######### WITHOUT_RERANKER #########")
133+
# extract_elements_and_print(pretty_contexts[2])
134+
# print("######## SIMILAR_DOCS ##########")
135+
# extract_elements_and_print(pretty_contexts[3])
136+
# if hyde or ragfusion:
137+
# print("######## 중간답변 ##########")
138+
# print(augmentation)
136139
if hyde or ragfusion:
137-
print("######## 중간답변 ##########")
138-
print(augmentation)
140+
return response, pretty_contexts, augmentation
141+
139142

140143
return response, pretty_contexts

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ def show_answer_with_multi_columns(answers):
156156
with st.chat_message("assistant"):
157157
with st.expander("Context 확인하기 ⬇️"):
158158
show_context_with_tab(contexts=msg["content"])
159+
160+
elif msg["role"] == "hyde_or_fusion":
161+
with st.chat_message("assistant"):
162+
with st.expander("중간 답변 확인하기 ⬇️"):
163+
msg["content"]
164+
159165
elif msg["role"] == "assistant_column":
160166
# 'Separately' 옵션일 경우 multi column 으로 보여주지 않고 첫 번째 답변만 출력
161167
st.chat_message(msg["role"]).write(msg["content"][0])
@@ -188,19 +194,34 @@ def show_answer_with_multi_columns(answers):
188194
)
189195
# response 로 메세지, 링크, 레퍼런스(source_documents) 받아오게 설정된 것을 변수로 저장
190196
answer = response[0]
191-
contexts = response[1]
197+
contexts = response[1]
198+
if hyde or ragfusion:
199+
mid_answer = response[2]
192200

193201
# UI 출력
194202
st.chat_message("assistant").write(answer)
195203

204+
205+
if hyde:
206+
with st.chat_message("assistant"):
207+
with st.expander("HyDE 중간 생성 답변 ⬇️"):
208+
mid_answer
209+
210+
if ragfusion:
211+
with st.chat_message("assistant"):
212+
with st.expander("RAG-Fusion 중간 생성 쿼리 ⬇️"):
213+
mid_answer
196214
with st.chat_message("assistant"):
197-
with st.expander("정확도 별 답변 보기 ⬇️"):
215+
with st.expander("정확도 별 컨텍스트 보기 ⬇️"):
198216
show_context_with_tab(contexts)
199-
217+
200218
# Session 메세지 저장
201219
st.session_state.messages.append({"role": "assistant", "content": answer})
202-
st.session_state.messages.append({"role": "assistant_context", "content": contexts})
203220

221+
if hyde or ragfusion:
222+
st.session_state.messages.append({"role": "hyde_or_fusion", "content": mid_answer})
223+
224+
st.session_state.messages.append({"role": "assistant_context", "content": contexts})
204225
# Thinking을 complete로 수동으로 바꾸어 줌
205226
st_cb._complete_current_thought()
206227

0 commit comments

Comments
 (0)