shreemaan-abhishek commented on code in PR #13735:
URL: https://github.com/apache/apisix/pull/13735#discussion_r3673305624


##########
apisix/plugins/ai-aws-content-moderation.lua:
##########
@@ -257,4 +357,62 @@ function _M.access(conf, ctx)
     end
 end
 
+
+function _M.lua_body_filter(conf, ctx, headers, body)
+    if not conf.check_response then
+        core.log.info("skip response check for this request")
+        return
+    end
+
+    if ngx.status >= 400 then
+        core.log.info("skip response check because upstream returned error 
status: ", ngx.status)
+        return
+    end
+
+    local request_type = ctx.var.request_type
+
+    -- ai-proxy hands us the fully assembled completion, so one check covers 
it.
+    if request_type == "ai_chat" then
+        return moderate_response(ctx, conf, ctx.var.llm_response_text)

Review Comment:
   Fixed in 1ca4d79bc. The buffered (non-streaming) response path now fails 
closed with a 500 on a Comprehend error, mirroring the request side, since the 
body has not been sent yet. Streaming stays best-effort by necessity (once 
bytes are on the wire the response cannot be blocked), and the docs now spell 
out both. I kept `fail_mode` as-is: it governs the unsupported-protocol / 
no-ai-proxy case, not moderation-service outages, so this is really a 
request/response asymmetry rather than `fail_mode` scope.
   
   One note on syncing this to `ai-aliyun-content-moderation`: unlike AWS, 
aliyun already fails open on *both* directions on a service error, so it is 
internally symmetric. Making only its response side fail closed would introduce 
the reverse asymmetry, so I left it out of this change. Happy to align both 
plugins to fail-closed as a separate, deliberate decision if you prefer that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to