Skip to content

Commit

Permalink
More method cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dougollerenshaw committed Sep 27, 2024
1 parent 879334f commit 503249a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion codeaide/logic/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 15 additions & 19 deletions codeaide/ui/chat_window.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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}"

0 comments on commit 503249a

Please sign in to comment.