feat: bedrock use tools (#1184)

This commit is contained in:
yetone 2025-02-06 00:03:49 +08:00 committed by GitHub
parent 3aaf7dad77
commit e1125fca54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,6 +32,40 @@ M.parse_messages = function(opts)
})
end
if opts.tool_use then
local msg = {
role = "assistant",
content = {},
}
if opts.response_content then
msg.content[#msg.content + 1] = {
type = "text",
text = opts.response_content,
}
end
msg.content[#msg.content + 1] = {
type = "tool_use",
id = opts.tool_use.id,
name = opts.tool_use.name,
input = vim.json.decode(opts.tool_use.input_json),
}
messages[#messages + 1] = msg
end
if opts.tool_result then
messages[#messages + 1] = {
role = "user",
content = {
{
type = "tool_result",
tool_use_id = opts.tool_result.tool_use_id,
content = opts.tool_result.content,
is_error = opts.tool_result.is_error,
},
},
}
end
return messages
end