aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-06-28 15:00:21 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-06-28 15:00:21 +0100
commitc8aca13cd459ec4c06e2ad5a6fd6c09c9d85ca81 (patch)
treec968c8126adc3f236dbaded2aa86c1d09beee41a
parent589f25254d931fd0a1b57e3fc5377956bebc0b6a (diff)
downloadrspamd-c8aca13cd459ec4c06e2ad5a6fd6c09c9d85ca81.tar.gz
rspamd-c8aca13cd459ec4c06e2ad5a6fd6c09c9d85ca81.zip
[Minor] Check words count properly
-rw-r--r--src/plugins/lua/gpt.lua16
1 files changed, 9 insertions, 7 deletions
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)