]> git.ipfire.org Git - thirdparty/rspamd.git/commit
Refactor: Move request content generation into gpt_check function 6159/head
authorMoritz Friedrich <mf@cyon.ch>
Tue, 28 Jul 2026 07:47:57 +0000 (09:47 +0200)
committerMoritz Friedrich <mf@cyon.ch>
Tue, 28 Jul 2026 07:47:57 +0000 (09:47 +0200)
commitc5ee174959b88479ae0a56159de94082be748a4c
treec830f5460cf879d110c6e63d64e09dd6c84e507c
parent193dd277eaf8c1b558814bb56694b879a3b4ed33
Refactor: Move request content generation into gpt_check function

The Condition option was previously expected to return both a boolean decision and the content for the LLM request. This behavior was non-obvious and only discovered through extensive debugging and code analysis (confirmed by rspamd#5857).

The condition setting now only returns a boolean for the decision (true/false) and an optional reason. Generating the request content has been moved into the gpt_check function, making the condition callback simpler to implement.

Example condition:
```
condition = <<EOD
return function(task)
  local result = task:get_metric_result()
  if result then
    local score = result.score
    if score < 2.0 or score > 8.0 then
      return false, ‘outside the range’
    end
  end

  return true, nil
end
EOD
```
src/plugins/lua/gpt.lua