Spaces:
Sleeping
Sleeping
| #!/usr/bin/python3 | |
| from langchain_core.messages import SystemMessage, HumanMessage | |
| def analyze_error(kali_command: str, kali_output: str, llm_with_tools, system_prompt: str) -> str: | |
| """ | |
| Analyze kali_linux or fortinet_monitor output for errors and suggest fixes using LLM reasoning. | |
| Args: | |
| kali_command (str): The executed command. | |
| kali_output (str): The command’s output. | |
| llm_with_tools: The initialized LLM instance with bound tools. | |
| system_prompt (str): The system prompt for context. | |
| Returns: | |
| str: Analysis with status, message, and suggested fix. | |
| """ | |
| prompt = f""" | |
| Analyze the following command and its output for errors. Suggest a fix or next steps based on the error context. Detect if it's from Kali (e.g., Linux errors) or Fortinet (e.g., 'Command fail. Return code'). If no error, confirm validity. If unclear, recommend human_assistance. | |
| Command: {kali_command} | |
| Output: {kali_output} | |
| Provide a concise response with: | |
| - [Status]: Output valid | |
| - [Message]: Explanation of the error or confirmation | |
| - [Suggested Fix]: Fix or next steps (if applicable) | |
| """ | |
| messages = [SystemMessage(content=system_prompt), HumanMessage(content=prompt)] | |
| analysis = llm_with_tools.invoke(messages).content # Use llm_with_tools instead of llm | |
| return analysis | |