fix: tokens usage is nil (#2322)
This commit is contained in:
@@ -335,7 +335,7 @@ function M.generate_prompts(opts)
|
||||
Utils.debug("Context window", context_window)
|
||||
if opts.get_tokens_usage then
|
||||
local tokens_usage = opts.get_tokens_usage()
|
||||
if tokens_usage then
|
||||
if tokens_usage and tokens_usage.prompt_tokens ~= nil and tokens_usage.completion_tokens ~= nil then
|
||||
local target_tokens = context_window * 0.9
|
||||
local tokens_count = tokens_usage.prompt_tokens + tokens_usage.completion_tokens
|
||||
Utils.debug("Tokens count", tokens_count)
|
||||
|
||||
@@ -2782,7 +2782,11 @@ function Sidebar:create_input_container()
|
||||
return history and history.todos or {}
|
||||
end,
|
||||
session_ctx = {},
|
||||
---@param usage avante.LLMTokenUsage
|
||||
update_tokens_usage = function(usage)
|
||||
if not usage then return end
|
||||
if usage.completion_tokens == nil then return end
|
||||
if usage.prompt_tokens == nil then return end
|
||||
self.chat_history.tokens_usage = usage
|
||||
self:save_history()
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user