Skip to content

Commit

Permalink
fix: filter out empty history (yetone#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Nov 4, 2024
1 parent 1e8abbf commit 5db2a0f
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5db2a0f

Please sign in to comment.