fix: missing tool use (#1610)

This commit is contained in:
yetone
2025-03-17 05:00:03 +08:00
committed by GitHub
parent 63605a55a3
commit eb5a2f6cca
2 changed files with 12 additions and 2 deletions

View File

@@ -77,6 +77,7 @@ function M:parse_messages(opts)
end
end
local has_tool_use = false
for idx, message in ipairs(opts.messages) do
local content_items = message.content
local message_content = {}
@@ -102,8 +103,14 @@ function M:parse_messages(opts)
elseif type(item) == "table" and item.type == "image" then
table.insert(message_content, { type = "image", source = item.source })
elseif not provider_conf.disable_tools and type(item) == "table" and item.type == "tool_use" then
has_tool_use = true
table.insert(message_content, { type = "tool_use", name = item.name, id = item.id, input = item.input })
elseif not provider_conf.disable_tools and type(item) == "table" and item.type == "tool_result" then
elseif
not provider_conf.disable_tools
and type(item) == "table"
and item.type == "tool_result"
and has_tool_use
then
table.insert(
message_content,
{ type = "tool_result", tool_use_id = item.tool_use_id, content = item.content, is_error = item.is_error }