Update app.py
Browse files
app.py
CHANGED
@@ -364,11 +364,16 @@ def main():
|
|
364 |
</div>
|
365 |
""", unsafe_allow_html=True)
|
366 |
else:
|
367 |
-
|
|
|
|
|
|
|
|
|
|
|
368 |
assistant_response = content.get('answer', '❌ ไม่มีข้อมูลคำตอบ')
|
369 |
-
|
370 |
-
assistant_response = content
|
371 |
|
|
|
372 |
st.markdown(f"""
|
373 |
<div class="chat-message assistant-message">
|
374 |
<strong>🤖 คำตอบ:</strong><br>
|
@@ -376,16 +381,18 @@ def main():
|
|
376 |
</div>
|
377 |
""", unsafe_allow_html=True)
|
378 |
|
379 |
-
|
|
|
380 |
with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=False):
|
381 |
-
for
|
|
|
382 |
st.markdown(f"""
|
383 |
-
<div style="padding: 1rem; background-color: #
|
384 |
-
<strong>เอกสารที่ {
|
385 |
-
{
|
386 |
</div>
|
387 |
""", unsafe_allow_html=True)
|
388 |
-
|
389 |
# Create chat input using the new implementation
|
390 |
create_chat_input()
|
391 |
|
|
|
364 |
</div>
|
365 |
""", unsafe_allow_html=True)
|
366 |
else:
|
367 |
+
# Handle both string and dictionary responses
|
368 |
+
assistant_response = content
|
369 |
+
reference_docs = None
|
370 |
+
|
371 |
+
# Check if the response is a dictionary with both answer and documents
|
372 |
+
if isinstance(content, dict):
|
373 |
assistant_response = content.get('answer', '❌ ไม่มีข้อมูลคำตอบ')
|
374 |
+
reference_docs = content.get('documents', [])
|
|
|
375 |
|
376 |
+
# Display the assistant's response
|
377 |
st.markdown(f"""
|
378 |
<div class="chat-message assistant-message">
|
379 |
<strong>🤖 คำตอบ:</strong><br>
|
|
|
381 |
</div>
|
382 |
""", unsafe_allow_html=True)
|
383 |
|
384 |
+
# Display reference documents if available
|
385 |
+
if reference_docs:
|
386 |
with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=False):
|
387 |
+
for idx, doc in enumerate(reference_docs, 1):
|
388 |
+
doc_content = doc.get('content', '') if isinstance(doc, dict) else str(doc)
|
389 |
st.markdown(f"""
|
390 |
+
<div style="padding: 1rem; background-color: #F3F4F6; border-radius: 8px; margin: 0.5rem 0; border: 1px solid #E5E7EB;">
|
391 |
+
<strong>เอกสารที่ {idx}:</strong><br>
|
392 |
+
{doc_content}
|
393 |
</div>
|
394 |
""", unsafe_allow_html=True)
|
395 |
+
|
396 |
# Create chat input using the new implementation
|
397 |
create_chat_input()
|
398 |
|