From 4029d16d1fb58e56b7eb67bb037e9644838fef24 Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Mon, 3 Apr 2023 00:25:59 +0200 Subject: trim newlines from the prompt, fixes #5 --- py/chat.py | 4 ++++ py/complete.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'py') diff --git a/py/chat.py b/py/chat.py index 0104014..f8345b4 100644 --- a/py/chat.py +++ b/py/chat.py @@ -30,6 +30,10 @@ if not messages: file_content = ">>> user\n\n" + file_content messages.append({"role": "user", "content": file_content }) +for message in messages: + # strip newlines from the content as it causes empty responses + message["content"] = message["content"].strip() + try: if messages[-1]["content"].strip(): vim.command("normal! Go\n<<< assistant\n\n") diff --git a/py/complete.py b/py/complete.py index e474580..14667b0 100644 --- a/py/complete.py +++ b/py/complete.py @@ -4,13 +4,13 @@ import openai plugin_root = vim.eval("s:plugin_root") vim.command(f"py3file {plugin_root}/py/utils.py") -prompt = vim.eval("prompt") +prompt = vim.eval("prompt").strip() options = make_options() openai.api_key = load_api_key() try: - if prompt.strip(): + if prompt: print('Completing...') vim.command("redraw") -- cgit v1.2.3