Skip to content

Commit 9c7d13a

Browse files
committed
Enter sends message
1 parent 770137f commit 9c7d13a

5 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/llm_qlient/shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"center_conversation_view": False,
123123
"ui_font_scale": 1.0,
124124
"editor_auto_pair": True,
125+
"editor_enter_sends": True,
125126

126127
"system_metrics_show": True,
127128
"system_metrics_interval": 2.0,

src/llm_qlient/ui/pages/chats/conversation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ def __init__(self, view: ConversationView, history: ChatHistory) -> None:
275275
self.view.input_composer.continue_btn.clicked.connect(self.continue_last)
276276
self.view.input_composer.stop_btn.clicked.connect(shared.gen.stop_gen)
277277

278+
self.view.input_composer.editor.return_pressed.connect(self._input_return_pressed)
279+
278280
self.change_conversation_index(0)
279281

280282
shared.gen.generation_started.connect(self._generation_started)
@@ -399,6 +401,16 @@ def get_last_assistant_message(self) -> None:
399401
self.stream_msg = last_msg
400402
self.stream_bubble = self.view.get_bubble_by_message(last_msg)
401403

404+
@pyqtSlot(bool)
405+
def _input_return_pressed(self, shift: bool) -> None:
406+
if shift:
407+
return
408+
409+
if not shared.settings["editor_enter_sends"]:
410+
return
411+
412+
self.send_new()
413+
402414
@pyqtSlot(str)
403415
def _generation_started(self, mode: str) -> None:
404416
if mode not in {"new", "retry", "continue"}:

src/llm_qlient/ui/pages/playground/view.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def __init__(self) -> None:
4747
QSizePolicy.Policy.Expanding
4848
)
4949
layout.addWidget(self.editor)
50+
self.editor.setPlaceholderText(
51+
"Write anything...\n\n"
52+
"The text you write here is purely passed down to the model as the initial prompt when generating.\n"
53+
"No chat templates or formatting is applied."
54+
)
5055

5156
layout.addSpacing(20)
5257

src/llm_qlient/ui/pages/settings/view.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ def __init__(self) -> None:
107107
"editor_auto_pair"
108108
)
109109

110+
self.add_setting(
111+
"Enter sends message",
112+
"Send new message in the text conversation with 'enter' or 'return' key.",
113+
"editor_enter_sends"
114+
)
115+
110116
hdivider(3, self.content_lyt)
111117

112118
self.add_setting("Show system metrics", "", "system_metrics_show")

src/llm_qlient/ui/widgets/auto_pair_editor.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
"""
1212

13+
from PyQt6.QtCore import Qt, pyqtSignal
1314
from PyQt6.QtWidgets import QPlainTextEdit
1415

1516
from llm_qlient import shared
@@ -18,7 +19,15 @@
1819
class AutoPairEditor(QPlainTextEdit):
1920
"""
2021
Plain text editor with auto-pairing.
22+
23+
Signals
24+
-------
25+
only_return_pressed
26+
Return or enter key is pressed.
27+
shift_return_pressed
2128
"""
29+
30+
return_pressed = pyqtSignal(bool)
2231

2332
PAIRS = {
2433
"\"": "\"",
@@ -29,11 +38,20 @@ class AutoPairEditor(QPlainTextEdit):
2938
}
3039

3140
def keyPressEvent(self, e) -> None:
41+
if e.key() == Qt.Key.Key_Return or e.key() == Qt.Key.Key_Enter:
42+
if e.modifiers() == Qt.KeyboardModifier.ShiftModifier:
43+
self.return_pressed.emit(True)
44+
45+
else:
46+
self.return_pressed.emit(False)
47+
if shared.settings["editor_enter_sends"]:
48+
return
49+
3250
super().keyPressEvent(e)
3351

3452
if not shared.settings["editor_auto_pair"]:
3553
return
36-
54+
3755
key = e.text()
3856

3957
if key in AutoPairEditor.PAIRS:

0 commit comments

Comments
 (0)