From: Vsevolod Stakhov Date: Fri, 28 Jun 2024 14:00:21 +0000 (+0100) Subject: [Minor] Check words count properly X-Git-Tag: 3.9.0~13^2~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c8aca13cd459ec4c06e2ad5a6fd6c09c9d85ca81;p=rspamd.git [Minor] Check words count properly --- diff --git a/src/plugins/lua/gpt.lua b/src/plugins/lua/gpt.lua index 7f4d55b17..dee83416d 100644 --- a/src/plugins/lua/gpt.lua +++ b/src/plugins/lua/gpt.lua @@ -133,16 +133,18 @@ local function default_condition(task) end if nwords > settings.max_tokens then - -- We need to truncate words + -- We need to truncate words (sometimes get_words_count returns a different number comparing to `get_words`) local words = sel_part:get_words('norm') - -- Trim something that does not fit - for i = nwords, settings.max_tokens, -1 do - rawset(words, i, nil) + nwords = #words + if nwords > settings.max_tokens then + -- Trim something that does not fit + for i = nwords, settings.max_tokens, -1 do + rawset(words, i, nil) + end + return true, table.concat(words, ' ') end - return true, table.concat(words, ' ') - else - return true, sel_part:get_content_oneline() end + return true, sel_part:get_content_oneline() end local function default_conversion(task, input)