fix: cache prompt count (#1499)

This commit is contained in:
yetone
2025-03-06 00:08:59 +08:00
committed by GitHub
parent cad42ac00f
commit 662b6a547b

View File

@@ -49,9 +49,9 @@ function M.parse_messages(opts)
table.sort(messages_with_length, function(a, b) return a.length > b.length end) table.sort(messages_with_length, function(a, b) return a.length > b.length end)
---@type table<integer, boolean> ---@type table<integer, boolean>
local top_three = {} local top_two = {}
for i = 1, math.min(3, #messages_with_length) do for i = 1, math.min(2, #messages_with_length) do
top_three[messages_with_length[i].idx] = true top_two[messages_with_length[i].idx] = true
end end
for idx, message in ipairs(opts.messages) do for idx, message in ipairs(opts.messages) do
@@ -61,7 +61,7 @@ function M.parse_messages(opts)
{ {
type = "text", type = "text",
text = message.content, text = message.content,
cache_control = top_three[idx] and { type = "ephemeral" } or nil, cache_control = top_two[idx] and { type = "ephemeral" } or nil,
}, },
}, },
}) })