()
| 182 | # Main |
| 183 | # ───────────────────────────────────────────────────────────── |
| 184 | def main(): |
| 185 | init_session() |
| 186 | sidebar() |
| 187 | |
| 188 | st.info("**Try:** *Analyze backend pod logs and detect issues*") |
| 189 | display_history() |
| 190 | |
| 191 | if prompt := st.chat_input("Ask about backend logs, database issues, or pod status..."): |
| 192 | # Save and show user message |
| 193 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| 194 | with st.chat_message("user"): |
| 195 | st.markdown(prompt) |
| 196 | |
| 197 | # Generate assistant response |
| 198 | with st.chat_message("assistant"): |
| 199 | status = st.status("Analyzing...", expanded=True) |
| 200 | progress = StreamlitProgress(status) |
| 201 | |
| 202 | history = to_langchain(st.session_state.messages[:-1]) |
| 203 | |
| 204 | try: |
| 205 | response = st.session_state.agent.process_query( |
| 206 | user_input=prompt, |
| 207 | chat_history=history, |
| 208 | callbacks=progress, |
| 209 | ) |
| 210 | if not response or not response.strip(): |
| 211 | response = "No response generated. Try a different question." |
| 212 | progress.complete() |
| 213 | except Exception as e: |
| 214 | progress.error(str(e)) |
| 215 | response = f"Error: {e}" |
| 216 | |
| 217 | st.markdown(response) |
| 218 | |
| 219 | st.session_state.messages.append({ |
| 220 | "role": "assistant", |
| 221 | "content": response, |
| 222 | "steps": progress.steps, |
| 223 | }) |
| 224 | |
| 225 | |
| 226 | if __name__ == "__main__": |
no test coverage detected