diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2025-02-24 17:12:09 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2025-02-24 17:12:09 +0000 |
commit | 7414eea791ecb8dba7ce7f50945caba0e42f3363 (patch) | |
tree | ab646efa11893692108d43725f1db15e324c7475 /src | |
parent | 4aa341918bfe89162c6812669fa07111447080d4 (diff) | |
download | rspamd-7414eea791ecb8dba7ce7f50945caba0e42f3363.tar.gz rspamd-7414eea791ecb8dba7ce7f50945caba0e42f3363.zip |
[Minor] GPT: Allow to trigger on specific symbols
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/gpt.lua | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/src/plugins/lua/gpt.lua b/src/plugins/lua/gpt.lua index 971bfbd29..0fb6123e1 100644 --- a/src/plugins/lua/gpt.lua +++ b/src/plugins/lua/gpt.lua @@ -48,8 +48,6 @@ gpt { allow_passthrough = false; # Check messages that are apparent ham (no action and negative score) allow_ham = false; - # default send response_format field { type = "json_object" } - include_response_format = true, # Add header with reason (null to disable) reason_header = "X-GPT-Reason"; } @@ -88,6 +86,7 @@ local settings = { reason_header = nil, url = 'https://api.openai.com/v1/chat/completions', symbols_to_except = nil, + symbols_to_trigger = nil, -- Exclude/include logic allow_passthrough = false, allow_ham = false, } @@ -113,22 +112,44 @@ local function default_condition(task) return false, 'negative score, already decided as ham' end end - -- We also exclude some symbols - for s, required_weight in pairs(settings.symbols_to_except) do - if task:has_symbol(s) then - if required_weight > 0 then - -- Also check score - local sym = task:get_symbol(s) or E - -- Must exist as we checked it before with `has_symbol` - if sym.weight then - if math.abs(sym.weight) >= required_weight then - return false, 'skip as "' .. s .. '" is found (weight: ' .. sym.weight .. ')' + + if settings.symbols_to_except then + for s, required_weight in pairs(settings.symbols_to_except) do + if task:has_symbol(s) then + if required_weight > 0 then + -- Also check score + local sym = task:get_symbol(s) or E + -- Must exist as we checked it before with `has_symbol` + if sym.weight then + if math.abs(sym.weight) >= required_weight then + return false, 'skip as "' .. s .. '" is found (weight: ' .. sym.weight .. ')' + end + end + lua_util.debugm(N, task, 'symbol %s has weight %s, but required %s', s, + sym.weight, required_weight) + else + return false, 'skip as "' .. s .. '" is found' + end + end + end + end + if settings.symbols_to_trigger then + for s, required_weight in pairs(settings.symbols_to_trigger) do + if task:has_symbol(s) then + if required_weight > 0 then + -- Also check score + local sym = task:get_symbol(s) or E + -- Must exist as we checked it before with `has_symbol` + if sym.weight then + if math.abs(sym.weight) < required_weight then + return false, 'skip as "' .. s .. '" is found with low weight (weight: ' .. sym.weight .. ')' + end end + lua_util.debugm(N, task, 'symbol %s has weight %s, but required %s', s, + sym.weight, required_weight) end - lua_util.debugm(N, task, 'symbol %s has weight %s, but required %s', s, - sym.weight, required_weight) else - return false, 'skip as "' .. s .. '" is found' + return false, 'skip as "' .. s .. '" is not found' end end end |