refactor: message content (#1424)

This commit is contained in:
yetone
2025-02-28 14:43:39 +08:00
committed by GitHub
parent ebadba7420
commit ae8497faf1
10 changed files with 187 additions and 125 deletions

View File

@@ -392,6 +392,7 @@ local function transform_result_content(selected_files, result_content, prev_fil
elseif line_content == "<think>" then
is_thinking = true
last_think_tag_start_line = i
last_think_tag_end_line = 0
elseif line_content == "</think>" then
is_thinking = false
last_think_tag_end_line = i
@@ -2356,6 +2357,7 @@ function Sidebar:create_input_container(opts)
end
end
---@type AvanteLLMMessage[]
local history_messages = {}
for i = #chat_history, 1, -1 do
local entry = chat_history[i]
@@ -2368,11 +2370,9 @@ function Sidebar:create_input_container(opts)
then
break
end
table.insert(
history_messages,
1,
{ role = "assistant", content = Utils.trim_think_content(entry.original_response) }
)
local assistant_content = {}
table.insert(assistant_content, { type = "text", text = Utils.trim_think_content(entry.original_response) })
table.insert(history_messages, 1, { role = "assistant", content = assistant_content })
local user_content = ""
if entry.selected_file ~= nil then
user_content = user_content .. "SELECTED FILE: " .. entry.selected_file.filepath .. "\n\n"
@@ -2386,9 +2386,18 @@ function Sidebar:create_input_container(opts)
.. "\n```\n\n"
end
user_content = user_content .. "USER PROMPT:\n\n" .. entry.request
table.insert(history_messages, 1, { role = "user", content = user_content })
table.insert(history_messages, 1, {
role = "user",
content = {
{
type = "text",
text = user_content,
},
},
})
end
---@type AvanteGeneratePromptsOptions
return {
ask = opts.ask or true,
project_context = vim.json.encode(project_context),