From 96ca4b0e9e9b4aff473eb98e1c4c4a502589e409 Mon Sep 17 00:00:00 2001 From: schilkp Date: Wed, 8 Jan 2025 10:58:39 +0100 Subject: [PATCH] fix(chat): Error if changing adapter in empty chat w/o system prompt. --- lua/codecompanion/strategies/chat/keymaps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/codecompanion/strategies/chat/keymaps.lua b/lua/codecompanion/strategies/chat/keymaps.lua index 4ad050be..421619a9 100644 --- a/lua/codecompanion/strategies/chat/keymaps.lua +++ b/lua/codecompanion/strategies/chat/keymaps.lua @@ -461,7 +461,7 @@ M.change_adapter = { -- Update the system prompt local system_prompt = config.opts.system_prompt if type(system_prompt) == "function" then - if chat.messages[1].role == "system" then + if chat.messages[1] and chat.messages[1].role == "system" then chat.messages[1].content = system_prompt(chat.adapter) end end