Revert "refactor: message content (#1424)" (#1442)

This reverts commit ae8497faf1.
This commit is contained in:
yetone
2025-03-01 13:25:51 +08:00
committed by GitHub
parent 5bb055795f
commit 0d592f440c
10 changed files with 124 additions and 186 deletions

View File

@@ -16,7 +16,74 @@ M.role_map = {
assistant = "assistant",
}
M.parse_messages = Claude.parse_messages
function M.parse_messages(opts)
---@type AvanteBedrockClaudeMessage[]
local messages = {}
for _, message in ipairs(opts.messages) do
table.insert(messages, {
role = M.role_map[message.role],
content = {
{
type = "text",
text = message.content,
},
},
})
end
if opts.tool_histories then
for _, tool_history in ipairs(opts.tool_histories) do
if tool_history.tool_use then
local msg = {
role = "assistant",
content = {},
}
if tool_history.tool_use.thinking_contents then
for _, thinking_content in ipairs(tool_history.tool_use.thinking_contents) do
msg.content[#msg.content + 1] = {
type = "thinking",
thinking = thinking_content.content,
signature = thinking_content.signature,
}
end
end
if tool_history.tool_use.response_contents then
for _, response_content in ipairs(tool_history.tool_use.response_contents) do
msg.content[#msg.content + 1] = {
type = "text",
text = response_content,
}
end
end
msg.content[#msg.content + 1] = {
type = "tool_use",
id = tool_history.tool_use.id,
name = tool_history.tool_use.name,
input = vim.json.decode(tool_history.tool_use.input_json),
}
messages[#messages + 1] = msg
end
if tool_history.tool_result then
messages[#messages + 1] = {
role = "user",
content = {
{
type = "tool_result",
tool_use_id = tool_history.tool_result.tool_use_id,
content = tool_history.tool_result.content,
is_error = tool_history.tool_result.is_error,
},
},
}
end
end
end
return messages
end
M.parse_response = Claude.parse_response
---@param prompt_opts AvantePromptOptions