fix: claude assistant content cannot end with trailing whitespace (#2186)
This commit is contained in:
@@ -77,15 +77,19 @@ function M:parse_messages(opts)
|
|||||||
local content_items = message.content
|
local content_items = message.content
|
||||||
local message_content = {}
|
local message_content = {}
|
||||||
if type(content_items) == "string" then
|
if type(content_items) == "string" then
|
||||||
|
if message.role == "assistant" then content_items = content_items:gsub("%s+$", "") end
|
||||||
|
if content_items ~= "" then
|
||||||
table.insert(message_content, {
|
table.insert(message_content, {
|
||||||
type = "text",
|
type = "text",
|
||||||
text = message.content,
|
text = content_items,
|
||||||
cache_control = top_two[idx] and { type = "ephemeral" } or nil,
|
cache_control = top_two[idx] and { type = "ephemeral" } or nil,
|
||||||
})
|
})
|
||||||
|
end
|
||||||
elseif type(content_items) == "table" then
|
elseif type(content_items) == "table" then
|
||||||
---@cast content_items AvanteLLMMessageContentItem[]
|
---@cast content_items AvanteLLMMessageContentItem[]
|
||||||
for _, item in ipairs(content_items) do
|
for _, item in ipairs(content_items) do
|
||||||
if type(item) == "string" then
|
if type(item) == "string" then
|
||||||
|
if message.role == "assistant" then item = item:gsub("%s+$", "") end
|
||||||
table.insert(
|
table.insert(
|
||||||
message_content,
|
message_content,
|
||||||
{ type = "text", text = item, cache_control = top_two[idx] and { type = "ephemeral" } or nil }
|
{ type = "text", text = item, cache_control = top_two[idx] and { type = "ephemeral" } or nil }
|
||||||
|
|||||||
Reference in New Issue
Block a user