fix: copilot tool histories (#1197)

This commit is contained in:
yetone 2025-02-06 19:19:50 +08:00 committed by GitHub
parent 1ec12907a2
commit 402c7f9665
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -215,26 +215,29 @@ M.parse_messages = function(opts)
vim vim
.iter(opts.messages) .iter(opts.messages)
:each(function(msg) table.insert(messages, { role = M.role_map[msg.role], content = msg.content }) end) :each(function(msg) table.insert(messages, { role = M.role_map[msg.role], content = msg.content }) end)
if opts.tool_result then
table.insert(messages, { if opts.tool_histories then
role = M.role_map["assistant"], for _, tool_history in ipairs(opts.tool_histories) do
tool_calls = { table.insert(messages, {
{ role = M.role_map["assistant"],
id = opts.tool_use.id, tool_calls = {
type = "function", {
["function"] = { id = tool_history.tool_use.id,
name = opts.tool_use.name, type = "function",
arguments = opts.tool_use.input_json, ["function"] = {
name = tool_history.tool_use.name,
arguments = tool_history.tool_use.input_json,
},
}, },
}, },
}, })
}) local result_content = tool_history.tool_result.content or ""
local result_content = opts.tool_result.content or "" table.insert(messages, {
table.insert(messages, { role = "tool",
role = "tool", tool_call_id = tool_history.tool_result.tool_use_id,
tool_call_id = opts.tool_result.tool_use_id, content = tool_history.tool_result.is_error and "Error: " .. result_content or result_content,
content = opts.tool_result.is_error and "Error: " .. result_content or result_content, })
}) end
end end
return messages return messages
end end