Revert "refactor: message content (#1424)" (#1442)

This reverts commit ae8497faf1.
This commit is contained in:
yetone
2025-03-01 13:25:51 +08:00
committed by GitHub
parent 5bb055795f
commit 0d592f440c
10 changed files with 124 additions and 186 deletions

View File

@@ -9,21 +9,6 @@ local cost_per_token = {
davinci = 0.000002,
}
---@param content AvanteLLMMessageContent
---@return integer
function Tokens.calculate_message_content_tokens(content)
if type(content) == "string" then return Tokens.calculate_tokens(content) end
local tokens = 0
for _, item in ipairs(content) do
if type(item) == "string" then
tokens = tokens + Tokens.calculate_tokens(item)
elseif item.type == "text" then
tokens = tokens + Tokens.calculate_tokens(item.text)
end
end
return tokens
end
--- Calculate the number of tokens in a given text.
---@param text string The text to calculate the number of tokens for.
---@return integer The number of tokens in the given text.