From 503249a9ac3259fa84be7d741074040c00728bd6 Mon Sep 17 00:00:00 2001 From: dougollerenshaw Date: Fri, 27 Sep 2024 08:45:48 -0700 Subject: [PATCH] More method cleanup --- codeaide/logic/chat_handler.py | 2 +- codeaide/ui/chat_window.py | 34 +++++++++++++++------------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/codeaide/logic/chat_handler.py b/codeaide/logic/chat_handler.py index 210dec8..420c024 100644 --- a/codeaide/logic/chat_handler.py +++ b/codeaide/logic/chat_handler.py @@ -389,7 +389,7 @@ def add_error_prompt_to_history(self, error_message): Returns: None """ - error_prompt = f"\n\nThere was an error in your last response: {error_message}. Please ensure you're using proper JSON formatting to avoid this error and others like it." + error_prompt = f"\n\nThere was an error in your last response: {error_message}. Please ensure you're using proper JSON formatting to avoid this error and others like it. Please don't apologize for the error because it will be hidden from the end user." self.conversation_history[-1]["content"] += error_prompt def handle_unexpected_error(self, e): diff --git a/codeaide/ui/chat_window.py b/codeaide/ui/chat_window.py index 2039c2b..67c724b 100644 --- a/codeaide/ui/chat_window.py +++ b/codeaide/ui/chat_window.py @@ -1,7 +1,7 @@ import signal import sys import traceback - +import time from PyQt5.QtCore import Qt, QTimer from PyQt5.QtGui import QColor from PyQt5.QtWidgets import ( @@ -151,6 +151,9 @@ def on_submit(self): if not user_input: return + # Clear the input field immediately + self.input_text.clear() + if self.waiting_for_api_key: ( success, @@ -162,9 +165,18 @@ def on_submit(self): if success: self.enable_ui_elements() else: - self.process_input(user_input) + # Immediately display user input and "Thinking..." message + self.add_to_chat("User", user_input) + self.disable_ui_elements() + self.add_to_chat("AI", "Thinking... 🤔") - self.input_text.clear() + # Use QTimer to process the input after the UI has updated + QTimer.singleShot(100, lambda: self.call_process_input_async(user_input)) + + def call_process_input_async(self, user_input): + # Process the input + response = self.chat_handler.process_input(user_input) + self.handle_response(response) def on_modify(self): self.input_text.ensureCursorVisible() @@ -180,18 +192,6 @@ def add_to_chat(self, sender, message): def display_thinking(self): self.add_to_chat("AI", "Thinking... 🤔") - def process_input(self, user_input): - try: - response = self.chat_handler.process_input(user_input) - self.handle_response(response) - except Exception as e: - error_message = f"An unexpected error occurred: {str(e)}. Please check the console window for the full traceback." - self.add_to_chat("AI", error_message) - print("Unexpected error in ChatWindow process_input:", file=sys.stderr) - traceback.print_exc() - finally: - self.enable_ui_elements() - def handle_response(self, response): self.enable_ui_elements() self.remove_thinking_messages() @@ -333,7 +333,3 @@ def update_chat_handler(self): {'='*50} """, ) - - def increment_version(self, version): - major, minor = map(int, version.split(".")) - return f"{major}.{minor + 1}"