INNER CODE UNIT · Python
display_chat_history
business-science/free-ai-tips · 015_ai_exploratory_copilot_dtale_integration/app.py:217
def display_chat_history():
"""
Renders the entire chat history along with any artifacts attached to messages.
Artifacts (e.g., plots, dataframes, Sweetviz reports) are rendered inside expanders.
"""
for i, msg in enumerate(msgs.messages):
with st.chat_message(msg.type):
st.write(msg.content)
if (
"chat_artifacts" in st.session_state
and i in st.session_state["chat_artifacts"]
):
for artifact in st.session_state["chat_artifacts"][i]:
with st.expander(artifact["title"], expanded=True):
if artifact["render_type"] == "dataframe":
st.dataframe(artifact["data"])
elif artifact["render_type"] == "matplotlib":
st.pyplot(artifact["data"])