INNER CODE UNIT · Python
display_chat_history
business-science/free-ai-tips · 014_ai_exploratory_copilot_app/app.py:122
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"])
elif artifact["render_type"] == "plotly":
st.plotly_chart(artifact["data"])
elif artifact["render_type"] == "sweetviz":