# components/styled_response.py import streamlit as st from utils.response_formatter import display_formatted_response def add_custom_styles(): """Add custom CSS styles for response formatting.""" st.markdown(""" """, unsafe_allow_html=True) def display_styled_chat_message(message, is_user=False): """ Display a styled chat message with formatting. Args: message: The chat message to display is_user (bool): Whether the message is from the user """ # Add custom styles add_custom_styles() if is_user: st.chat_message("user").write(message) else: with st.chat_message("assistant"): display_formatted_response( message.content, metadata=getattr(message, 'metadata', None) ) def display_copyable_sections(content: str): """ Display content in copyable sections. Args: content (str): The content to display """ sections = content.split("###")[1:] # Skip the first empty section for section in sections: if section.strip(): lines = section.strip().split("\n") title = lines[0].strip() content = "\n".join(lines[1:]).strip() with st.expander(f"{title}", expanded=False): st.markdown(f"### {title}") st.markdown(content) # Add copy button if st.button(f"Copy {title}", key=f"copy_{title}"): st.code(content, language="text") st.success(f"{title} content copied to clipboard!")