fix: summarize memory failed (#1731)
This commit is contained in:
@@ -43,7 +43,7 @@ function M.summarize_chat_thread_title(content, cb)
|
|||||||
end,
|
end,
|
||||||
on_stop = function(stop_opts)
|
on_stop = function(stop_opts)
|
||||||
if stop_opts.error ~= nil then
|
if stop_opts.error ~= nil then
|
||||||
Utils.error(string.format("summarize failed: %s", vim.inspect(stop_opts.error)))
|
Utils.error(string.format("summarize chat thread title failed: %s", vim.inspect(stop_opts.error)))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if stop_opts.reason == "complete" then
|
if stop_opts.reason == "complete" then
|
||||||
@@ -58,6 +58,30 @@ function M.summarize_chat_thread_title(content, cb)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param messages AvanteLLMMessage[]
|
||||||
|
---@return AvanteLLMMessage[]
|
||||||
|
local function filter_out_tool_use_messages(messages)
|
||||||
|
local filtered_messages = {}
|
||||||
|
for _, message in ipairs(messages) do
|
||||||
|
local content = message.content
|
||||||
|
if type(content) == "table" then
|
||||||
|
local new_content = {}
|
||||||
|
for _, item in ipairs(content) do
|
||||||
|
if item.type == "tool_use" or item.type == "tool_result" then goto continue end
|
||||||
|
table.insert(new_content, item)
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
content = new_content
|
||||||
|
end
|
||||||
|
if type(content) == "table" then
|
||||||
|
if #content > 0 then table.insert(filtered_messages, { role = message.role, content = content }) end
|
||||||
|
else
|
||||||
|
table.insert(filtered_messages, { role = message.role, content = content })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return filtered_messages
|
||||||
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param history avante.ChatHistory
|
---@param history avante.ChatHistory
|
||||||
---@param entries? avante.ChatHistoryEntry[]
|
---@param entries? avante.ChatHistoryEntry[]
|
||||||
@@ -80,6 +104,7 @@ function M.summarize_memory(bufnr, history, entries, cb)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local history_messages = Utils.history.entries_to_llm_messages(entries)
|
local history_messages = Utils.history.entries_to_llm_messages(entries)
|
||||||
|
history_messages = filter_out_tool_use_messages(history_messages)
|
||||||
history_messages = vim.list_slice(history_messages, 1, 4)
|
history_messages = vim.list_slice(history_messages, 1, 4)
|
||||||
if #history_messages == 0 then
|
if #history_messages == 0 then
|
||||||
cb(history.memory)
|
cb(history.memory)
|
||||||
@@ -109,7 +134,7 @@ function M.summarize_memory(bufnr, history, entries, cb)
|
|||||||
end,
|
end,
|
||||||
on_stop = function(stop_opts)
|
on_stop = function(stop_opts)
|
||||||
if stop_opts.error ~= nil then
|
if stop_opts.error ~= nil then
|
||||||
Utils.error(string.format("summarize failed: %s", vim.inspect(stop_opts.error)))
|
Utils.error(string.format("summarize memory failed: %s", vim.inspect(stop_opts.error)))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if stop_opts.reason == "complete" then
|
if stop_opts.reason == "complete" then
|
||||||
|
|||||||
Reference in New Issue
Block a user