From a138532d0dc7f71ba3b9eb4ead9576ea87707761 Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Sat, 22 Apr 2023 11:48:44 +0200 Subject: recover for unfinished chat --- py/chat.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'py/chat.py') diff --git a/py/chat.py b/py/chat.py index 93a8664..6054484 100644 --- a/py/chat.py +++ b/py/chat.py @@ -27,6 +27,13 @@ def initialize_chat_window(): vim_break_undo_sequence() vim.command("redraw") + file_content = vim.eval('trim(join(getline(1, "$"), "\n"))') + role_lines = re.findall(r'(^>>> user|^>>> system|^<<< assistant).*', file_content, flags=re.MULTILINE) + if not role_lines[-1].startswith(">>> user"): + # last role is not user, most likely completion was cancelled before + vim.command("normal! o") + vim.command("normal! i\n>>> user\n\n") + if prompt: vim.command("normal! a" + prompt) vim_break_undo_sequence() -- cgit v1.2.3