From 5db2a0f92ff0ac4cfde27266cbc91eabdc2bb7f5 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 4 Nov 2024 16:39:50 +0800 Subject: [PATCH] fix: filter out empty history (#794) --- lua/avante/sidebar.lua | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index d280fbd..0cfd126 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1392,17 +1392,26 @@ function Sidebar:create_input(opts) local project_context = mentions.enable_project_context and RepoMap.get_repo_map(file_ext) or nil - local history_messages = vim.tbl_map( - function(history) - return { - { role = "user", content = history.request }, - { role = "assistant", content = history.original_response }, - } - end, - chat_history - ) - - history_messages = vim.iter(history_messages):flatten():totable() + local history_messages = vim + .iter(chat_history) + :filter( + function(history) + return history.request ~= nil + and history.original_response ~= nil + and history.request ~= "" + and history.original_response ~= "" + end + ) + :map( + function(history) + return { + { role = "user", content = history.request }, + { role = "assistant", content = history.original_response }, + } + end + ) + :flatten() + :totable() Llm.stream({ bufnr = self.code.bufnr,