please revise and upgrade, this is meant for the generation of vector networks to represent GPON fibre network planning: import sys
import os
import traceback
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QTextEdit, QPushButton, QLabel, QMessageBox, QHBoxLayout
from PyQt6.QtCore import Qt
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import huggingface_hub

# Initialize the LLM client
client = huggingface_hub.InferenceClient(
    "mistralai/Mistral-7B-Instruct-v0.3",
    token="<TRUFFLEHOG_REDACTED_HUGGINGFACE>"
)

# Define the folder where outputs will be saved
output_folder = "AutoMist"

# Create the output folder if it doesn't exist
if not os.path.exists(output_folder):
    os.makedirs(output_folder)


class LLMInteractionGUI(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        """Initializes the user interface."""
        self.setWindowTitle("AutoMist - Autonomous LLM Assistant")
        self.setGeometry(100, 100, 900, 700)

        self.layout = QVBoxLayout()

        # Input box for user request
        self.inputBox = QTextEdit(self)
        self.inputBox.setPlaceholderText("Enter your request here...")
        self.layout.addWidget(self.inputBox)

        # Output text boxes
        self.logBox = QTextEdit(self)
        self.logBox.setReadOnly(True)
        self.logBox.setPlaceholderText("Log output will be displayed here...")
        self.layout.addWidget(self.logBox)

        # Control buttons
        self.sendBtn = QPushButton("Submit Request", self)
        self.sendBtn.clicked.connect(self.process_request)
        self.layout.addWidget(self.sendBtn)

        # Set the layout for the main window
        self.setLayout(self.layout)

    def log(self, message):
        """Logs the message to the log box with a timestamp."""
        timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.logBox.append(f"[{timestamp}] {message}")
        self.logBox.repaint()  # Ensure UI is updated immediately

    def process_request(self):
        """Main function to handle the user's request and process it."""
        user_input = self.inputBox.toPlainText().strip()

        if not user_input:
            QMessageBox.warning(self, "Input Error", "Please enter a request.")
            return

        # Log user request
        self.log("User request received.")

        try:
            # Step 1: Research the topic
            self.log("Starting research...")
            knowledge_base = self.research_topic(user_input)
            self.log(f"Research complete. Knowledge base:\n{knowledge_base}")

            # Step 2: Generate Python script based on the research
            self.log("Generating Python script based on research...")
            script_code = self.generate_script(knowledge_base)
            self.log(f"Script generation complete:\n{script_code}")

            # Step 3: Save the generated script
            script_path = os.path.join(output_folder, "generated_script.py")
            with open(script_path, "w") as script_file:
                script_file.write(script_code)
            self.log(f"Script saved to: {script_path}")

            # Step 4: Execute the generated script
            self.log("Executing the script...")
            execution_result = self.execute_script(script_code)
            self.log(f"Execution result:\n{execution_result}")

            # Step 5: Save execution results
            result_path = os.path.join(output_folder, "execution_result.txt")
            with open(result_path, "w") as result_file:
                result_file.write(execution_result)
            self.log(f"Execution results saved to: {result_path}")

            # Step 6: Evaluate the script output
            self.log("Evaluating the script output...")
            evaluation_result = self.evaluate_script(execution_result, user_input)
            self.log(f"Evaluation result:\n{evaluation_result}")

            # Step 7: Save evaluation results
            evaluation_path = os.path.join(output_folder, "evaluation_result.txt")
            with open(evaluation_path, "w") as evaluation_file:
                evaluation_file.write(evaluation_result)
            self.log(f"Evaluation results saved to: {evaluation_path}")

        except Exception as e:
            self.log(f"Error during process: {e}")
            self.log(traceback.format_exc())

    def research_topic(self, topic):
        """Research a topic using the LLM."""
        query = f"Research the topic: {topic} and provide key details."
        self.log(f"Sending research query to LLM: {query}")
        response = self.get_llm_response(query)
        self.log(f"LLM response received for research.")
        return response

    def generate_script(self, knowledge_base):
        """Generate a Python script based on the knowledge base."""
        prompt = f"Based on the following information: {knowledge_base}, generate a Python script that solves the problem."
        self.log(f"Sending script generation request to LLM: {prompt}")
        response = self.get_llm_response(prompt)
        self.log(f"LLM response received for script generation.")
        return response

    def execute_script(self, script_code):
        """Execute the generated Python script and handle potential errors."""
        self.log(f"Attempting to execute the generated script.")
        try:
            exec(script_code, globals())
            self.log("Script executed successfully.")
            return "Script executed successfully."
        except Exception as e:
            error_message = f"Script execution failed with error: {e}"
            self.log(error_message)
            debugged_script = self.debug_script(script_code, str(e))
            return self.execute_script(debugged_script)

    def debug_script(self, script_code, error_message):
        """Use the LLM to debug the Python script."""
        prompt = f"The following Python script threw an error: {error_message}. Fix the code: {script_code}."
        self.log(f"Sending debug request to LLM: {prompt}")
        response = self.get_llm_response(prompt)
        self.log(f"LLM response received for script debugging.")
        return response

    def evaluate_script(self, script_output, user_request):
        """Evaluate the script output to ensure it meets the user's request."""
        prompt = f"Check if the following output matches the user request: '{script_output}'. The user request was: '{user_request}'. Is the output correct?"
        self.log(f"Sending evaluation request to LLM: {prompt}")
        response = self.get_llm_response(prompt)
        self.log(f"LLM response received for evaluation.")
        return response

    def get_llm_response(self, prompt):
    """Send a prompt to the LLM and get the full response at once."""
    try:
        self.log(f"Sending prompt to LLM...")
    
        # Send the prompt and get a full response without streaming
        response = client.chat_completion(
            messages=[{"role": "user", "content": prompt}],
            max_tokens=4096,  # Adjust token limit as needed
            stream=False  # Disable streaming
        )
        
        # Retrieve the full response content
        response_text = response['choices'][0]['message']['content']
        self.log(f"LLM response received.")
    
        return response_text
    except Exception as e:
        self.log(f"Error interacting with LLM: {e}")
        return f"Error interacting with LLM: {e}"



if __name__ == "__main__":
    app = QApplication(sys.argv)
    gui = LLMInteractionGUI()
    gui.show()
    sys.exit(app.exec())