Skip to content

Commit ad022da

Browse files
committed
retry: Delete from the end until reaching an assistant message, then send. This improves functionality of the retry command when using LLMProvider implementations that support a custom assistant prefix.
1 parent 0795b99 commit ad022da

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/gptcmd/cli.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
file, You can obtain one at https://mozilla.org/MPL/2.0/.
88
"""
99

10-
1110
import argparse
1211
import cmd
1312
import dataclasses
@@ -615,8 +614,8 @@ def do_copy(self, arg):
615614

616615
def do_retry(self, arg):
617616
"""
618-
Resend up through the last non-assistant, non-sticky message to the
619-
language model. This command takes no arguments.
617+
Delete up to the last non-sticky assistant message, then send the
618+
conversation to the language model. This command takes no arguments.
620619
"""
621620
if not any(
622621
m.role != MessageRole.ASSISTANT for m in self._current_thread
@@ -639,17 +638,14 @@ def do_retry(self, arg):
639638
while basename + str(num) in self._threads:
640639
num += 1
641640
self.do_thread(basename + str(num))
642-
while self._current_thread[-1].role == MessageRole.ASSISTANT:
643-
try:
644-
self._current_thread.pop()
645-
except PopStickyMessageError:
646-
print(
647-
self.__class__._fragment(
648-
"Sending up to sticky message {msg}",
649-
self._current_thread[-1],
650-
)
651-
)
652-
break
641+
for i in range(len(self._current_thread) - 1, -1, -1):
642+
role = self._current_thread[i].role
643+
if role == MessageRole.ASSISTANT:
644+
try:
645+
self._current_thread.pop(i)
646+
break
647+
except PopStickyMessageError:
648+
continue
653649
self.do_send(None)
654650

655651
def do_model(self, arg, _print_on_success=True):

0 commit comments

Comments
 (0)