fix: openai tool histories (#1606)

This commit is contained in:
yetone
2025-03-17 03:06:26 +08:00
committed by GitHub
parent 078f06320c
commit dfdab1d41f

View File

@@ -113,7 +113,7 @@ function M:parse_messages(opts)
)
end
end
table.insert(messages, { role = self.role_map[msg.role], content = content })
if #content > 0 then table.insert(messages, { role = self.role_map[msg.role], content = content }) end
if not provider_conf.disable_tools then
if #tool_calls > 0 then
table.insert(messages, { role = self.role_map["assistant"], tool_calls = tool_calls })
@@ -150,14 +150,14 @@ function M:parse_messages(opts)
vim.iter(messages):each(function(message)
local role = message.role
if role == prev_role then
if role == self.role_map["user"] then
table.insert(final_messages, { role = self.role_map["assistant"], content = "Ok, I understand." })
else
if role == self.role_map["assistant"] then
table.insert(final_messages, { role = self.role_map["user"], content = "Ok" })
else
table.insert(final_messages, { role = self.role_map["assistant"], content = "Ok, I understand." })
end
end
prev_role = role
table.insert(final_messages, { role = self.role_map[role] or role, content = message.content })
table.insert(final_messages, message)
end)
if opts.tool_histories then