if chat: with st.container(): st.header("Chat with GPT")
for message in st.session_state["messages"]: ifisinstance(message, HumanMessage): with st.chat_message("user"): st.markdown(message.content) elifisinstance(message, AIMessage): with st.chat_message("assistant"): st.markdown(message.content) prompt = st.chat_input("Type something...") if prompt: st.session_state["messages"].append(HumanMessage(content=prompt)) with st.chat_message("user"): st.markdown(prompt) ai_message = chat([HumanMessage(content=prompt)]) st.session_state["messages"].append(ai_message) with st.chat_message("assistant"): st.markdown(ai_message.content) else: with st.container(): st.warning("Please set your OpenAI API key in the settings page.")