Main application logic
()
| 107 | |
| 108 | |
| 109 | def main(): |
| 110 | """Main application logic""" |
| 111 | # Initialize session state |
| 112 | initialize_session_state() |
| 113 | |
| 114 | # Display sidebar |
| 115 | display_sidebar() |
| 116 | |
| 117 | # Main content area |
| 118 | st.title("Chat with AI Log Analyzer") |
| 119 | st.markdown("Ask me anything about your log files!") |
| 120 | |
| 121 | # Display chat messages |
| 122 | display_chat_messages() |
| 123 | |
| 124 | # Chat input |
| 125 | if prompt := st.chat_input("Ask about your logs..."): |
| 126 | # Add user message to chat |
| 127 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| 128 | |
| 129 | # Display user message |
| 130 | with st.chat_message("user"): |
| 131 | st.markdown(prompt) |
| 132 | |
| 133 | # Get agent response |
| 134 | with st.chat_message("assistant"): |
| 135 | with st.spinner("Analyzing..."): |
| 136 | # Convert chat history to LangChain format |
| 137 | chat_history = convert_to_langchain_messages( |
| 138 | st.session_state.messages[:-1] # Exclude the current message |
| 139 | ) |
| 140 | |
| 141 | # Get response from agent |
| 142 | response = st.session_state.agent.process_query( |
| 143 | user_input=prompt, |
| 144 | chat_history=chat_history |
| 145 | ) |
| 146 | |
| 147 | # Display response |
| 148 | st.markdown(response) |
| 149 | |
| 150 | # Add assistant response to chat history |
| 151 | st.session_state.messages.append({"role": "assistant", "content": response}) |
| 152 | |
| 153 | |
| 154 | if __name__ == "__main__": |
no test coverage detected