Skip to content

Commit 6c5e1d4

Browse files
committed
Disable sending messages until response/error received
1 parent 4ebe473 commit 6c5e1d4

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/chatgpt_gui/gui/widgets/conversation_view.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from PySide6.QtGui import *
1212
from PySide6.QtWidgets import *
1313

14+
from ...models import DistributedCallable
1415
from ...network.client import Conversation
1516
from ...network.client import Message
1617
from ...utils import init_layouts
@@ -29,6 +30,7 @@ def __init__(self, conversation: Conversation | None = None, *args, **kwargs) ->
2930
super().__init__(*args, **kwargs)
3031
self.conversation = conversation if conversation is not None else Conversation()
3132

33+
self.is_waiting: bool = False
3234
self._init_ui()
3335

3436
def _init_ui(self) -> None:
@@ -111,6 +113,10 @@ def toggle_multiline():
111113
self.output.setPlaceholderText(tr('gui.output_text.placeholder'))
112114

113115
app().client.receivedMessage.connect(self.receive_message)
116+
app().client.receivedError.connect(DistributedCallable((
117+
lambda _: setattr(self, 'is_waiting', False),
118+
lambda _: self.send_button.setDisabled(False)
119+
)))
114120

115121
def append_to_view(self, text: str) -> None:
116122
"""Append some new text to the output.
@@ -128,13 +134,15 @@ def send_message(self) -> None:
128134
129135
Clears the input and disables after sending.
130136
"""
131-
message: str = self.input_line.text() or self.input_multi.toPlainText()
132-
self.input_line.clear()
133-
self.input_multi.clear()
134-
self.send_button.setDisabled(True)
135-
self.append_to_view(tr('gui.output_text.you_prompt', message, key_eval=False)) # type: ignore
137+
if not self.is_waiting:
138+
message: str = self.input_line.text() or self.input_multi.toPlainText()
139+
self.input_line.clear()
140+
self.input_multi.clear()
141+
self.is_waiting = True
142+
self.send_button.setDisabled(True)
143+
self.append_to_view(tr('gui.output_text.you_prompt', message, key_eval=False)) # type: ignore
136144

137-
app().client.send_message(message, self.conversation) # type: ignore
145+
app().client.send_message(message, self.conversation) # type: ignore
138146

139147
def receive_message(self, message: Message, conversation: Conversation) -> None:
140148
"""Receive a response from the client.
@@ -143,5 +151,6 @@ def receive_message(self, message: Message, conversation: Conversation) -> None:
143151
:param conversation: Conversation received in.
144152
"""
145153
if conversation is self.conversation:
154+
self.is_waiting = False
146155
self.send_button.setDisabled(False)
147156
self.append_to_view(tr('gui.output_text.ai_prompt', message.text, key_eval=False))

src/chatgpt_gui/resources/lang/en.default.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"warnings.empty_token.title": "No Session",
2929
"errors.authentication_failed.description": "Failed to login to <b>%s</b>.<br><br>Error: %s",
3030
"errors.authentication_failed.title": "Authentication Failed",
31+
"errors.client_http_error.description": "Error %i: %s",
32+
"errors.client_http_error.title": "Client HTTP Error: %s",
3133
"errors.missing_package.cancel": "Cancel",
3234
"errors.missing_package.description": "The action \"%s\" requires the \"{0}\" package, which is not currently installed.\n\nPressing \"{errors.missing_package.install}\" will install it using the following command:\n\n\"%s -m pip install {0}\"",
3335
"errors.missing_package.install": "Install",
@@ -85,6 +87,8 @@
8587
"gui.menus.account.sign_in": "Sign In...",
8688
"gui.menus.account.sign_out": "Sign Out...",
8789
"gui.menus.account.signed_in_as": " Signed-in as: %s",
90+
"gui.menus.conversations.import": "Import Conversation From...",
91+
"gui.menus.conversations.export": "Export Conversation To...",
8892
"gui.menus.help": "Help",
8993
"gui.menus.help.about": "About",
9094
"gui.menus.help.about_qt": "About Qt",
@@ -129,6 +133,7 @@
129133
"network.http.codes.403.description": "Request forbidden -- You cannot get this resource with or without an access token.",
130134
"network.http.codes.404.description": "No resource found at the given location.",
131135
"network.http.codes.405.description": "Invalid method -- GET requests are not accepted for this resource.",
132-
"network.http.codes.406.description": "Client does not support the given resource format."
136+
"network.http.codes.406.description": "Client does not support the given resource format.",
137+
"network.http.codes.429.description": "You have sent too many requests, and have been rate limited by OpenAI."
133138
}
134139
}

0 commit comments

Comments
 (0)