import streamlit as st from backend.managers.chat_manager import ChatManager from backend.managers.system_prompter import SystemPrompter def render_chat(): st.subheader("Chat with AI Assistant") chat_section = st.container() setup_section = st.container() with chat_section: if st.session_state.chat_history: for message in st.session_state.chat_history: st.markdown(f"**{message['role'].capitalize()}:** {message['content']}") # Clear the input field before the widget is rendered (Streamlit requirement) if st.session_state.get("_clear_chat_input"): st.session_state.chat_input = "" st.session_state._clear_chat_input = False user_input = st.text_input("Type your message here:", key="chat_input") if st.button("Send", key="send_button") and user_input: chat_manager = st.session_state.chat_manager # Inject system prompt on the first message if not chat_manager.get_history(): system_prompt = SystemPrompter.generate_prompt() chat_manager.add_message("system", system_prompt) st.session_state.chat_history.append({"role": "user", "content": user_input}) try: ai_response = chat_manager.send_message(user_input) except Exception as e: ai_response = f"Error: {e}" st.session_state.chat_history.append({"role": "assistant", "content": ai_response}) st.session_state._clear_chat_input = True # Clear input on next rerun st.rerun() with setup_section: st.info("This is where you can set up your AI assistant. For now, this section is just a placeholder.") st.toggle("Use debug system prompt", key="use_system_prompt", value=True) # Here you could add options to configure the AI assistant, such as selecting a model, setting parameters, etc. if __name__ == "__main__": render_chat()