Skip to content

feat: add ai-aliyun-content-moderation plugin #12530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ dependencies = {
"jsonpath = 1.0-1",
"api7-lua-resty-aws == 2.0.2-1",
"multipart = 0.5.9-1",
"luautf8 = 0.1.6-1",
}

build = {
Expand Down
1 change: 1 addition & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ http {
set $dubbo_method '';
{% end %}

set $llm_content_risk_level '';
access_by_lua_block {
apisix.http_access_phase()
}
Expand Down
1 change: 1 addition & 0 deletions apisix/core/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ do
upstream_upgrade = true,
upstream_connection = true,
upstream_uri = true,
llm_content_risk_level = true,

upstream_mirror_host = true,
upstream_mirror_uri = true,
Expand Down
37 changes: 37 additions & 0 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ local expr = require("resty.expr.v1")
local apisix_ssl = require("apisix.ssl")
local re_split = require("ngx.re").split
local ngx = ngx
local ngx_ok = ngx.OK
local ngx_print = ngx.print
local crc32 = ngx.crc32_short
local ngx_exit = ngx.exit
local pkg_loaded = package.loaded
Expand Down Expand Up @@ -1270,5 +1272,40 @@ function _M.run_global_rules(api_ctx, global_rules, phase_name)
end
end

function _M.lua_response_filter(api_ctx, headers, body)
local plugins = api_ctx.plugins
if not plugins or #plugins == 0 then
-- if there is no any plugin, just print the original body to downstream
ngx_print(body)
return
end
for i = 1, #plugins, 2 do
local phase_func = plugins[i]["lua_body_filter"]
if phase_func then
local conf = plugins[i + 1]
if not meta_filter(api_ctx, plugins[i]["name"], conf)then
goto CONTINUE
end

run_meta_pre_function(conf, api_ctx, plugins[i]["name"])
local code, new_body = phase_func(conf, api_ctx, headers, body)
if code then
if code ~= ngx_ok then
ngx.status = code
end

ngx_print(new_body)
ngx_exit(ngx_ok)
end
if new_body then
body = new_body
end
end

::CONTINUE::
end
ngx_print(body)
end


return _M
Loading
Loading