aboutsummaryrefslogtreecommitdiffstats
path: root/test/functional/lua/neural.lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2020-12-17 11:28:09 +0200
committerAndrew Lewis <nerf@judo.za.org>2020-12-17 11:28:09 +0200
commit960b608d352e8c820b0725d898d78959ca59ee7d (patch)
tree9d9f192e1c3161a804e94e1aed1c0a63b77929c0 /test/functional/lua/neural.lua
parent5ce6a2d97ff655651e4bba7737b834d866b94c94 (diff)
downloadrspamd-960b608d352e8c820b0725d898d78959ca59ee7d.tar.gz
rspamd-960b608d352e8c820b0725d898d78959ca59ee7d.zip
[Feature] Add controller endpoint for training neural
- Move neural functions to library - Parameterise spawn_train - neural plugin: Fix store_pool_only when autotrain is true - neural plugin: Use cache_set instead of mempool - Add test
Diffstat (limited to 'test/functional/lua/neural.lua')
-rw-r--r--test/functional/lua/neural.lua39
1 files changed, 38 insertions, 1 deletions
diff --git a/test/functional/lua/neural.lua b/test/functional/lua/neural.lua
index 70857d429..ccdad1b68 100644
--- a/test/functional/lua/neural.lua
+++ b/test/functional/lua/neural.lua
@@ -1,3 +1,5 @@
+local logger = require "rspamd_logger"
+
rspamd_config:register_symbol({
name = 'SPAM_SYMBOL',
score = 5.0,
@@ -21,4 +23,39 @@ rspamd_config:register_symbol({
callback = function()
return true, 'Fires always'
end
-}) \ No newline at end of file
+})
+
+rspamd_config.SAVE_NN_ROW = {
+ callback = function(task)
+ local fname = os.tmpname()
+ task:cache_set('nn_row_tmpfile', fname)
+ return true, 1.0, fname
+ end
+}
+
+rspamd_config.SAVE_NN_ROW_IDEMPOTENT = {
+ callback = function(task)
+ local function tohex(str)
+ return (str:gsub('.', function (c)
+ return string.format('%02X', string.byte(c))
+ end))
+ end
+ local fname = task:cache_get('nn_row_tmpfile')
+ if not fname then
+ return
+ end
+ local f, err = io.open(fname, 'w')
+ if not f then
+ logger.errx(task, err)
+ return
+ end
+ f:write(tohex(task:cache_get('neural_vec_mpack') or ''))
+ f:close()
+ return
+ end,
+ type = 'idempotent',
+ flags = 'explicit_disable',
+ priority = 10,
+}
+
+dofile(rspamd_env.INSTALLROOT .. "/share/rspamd/rules/controller/init.lua")