Copilot commented on code in PR #13598:
URL: https://github.com/apache/apisix/pull/13598#discussion_r3457031900


##########
apisix/plugins/ai-aliyun-content-moderation.lua:
##########
@@ -113,20 +122,20 @@ end
 
 
 -- openresty ngx.escape_uri don't escape some sub-delimis in rfc 3986 but 
aliyun do it,
--- in order to we can calculate same signature with aliyun, we need escape 
those chars manually
+-- in order to we can calculate same signature with aliyun, we need escape 
those chars manually.
+-- A single JIT-compiled PCRE pass is ~20x faster than five Lua string.gsub 
passes over the
+-- encoded text, which is the hottest per-chunk operation in the signing path.

Review Comment:
   The comment has several grammar/spelling issues (e.g., “openresty”, “don't”, 
“sub-delimis”, “in order to we can”). Since this was touched in the hunk, 
please fix it for clarity.



##########
apisix/plugins/ai-aliyun-content-moderation.lua:
##########
@@ -61,11 +61,20 @@ local schema = {
         fail_mode = binding.schema_property("skip"),
         check_request = {type = "boolean", default = true},
         check_response = {type = "boolean", default = false},
+        request_check_mode = {
+            type = "string",
+            enum = {"last", "all"},
+            default = "last",
+            description = [[
+            which user messages to moderate: last (only the latest consecutive 
user
+            message block) | all (every user message). Both ignore non-user 
roles.
+            ]]
+        },
         request_check_service = {type = "string", minLength = 1, default = 
"llm_query_moderation"},
-        request_check_length_limit = {type = "number", default = 2000},
+        request_check_length_limit = {type = "number", minimum = 1, default = 
2000},
         response_check_service = {type = "string", minLength = 1,
                                   default = "llm_response_moderation"},
-        response_check_length_limit = {type = "number", default = 5000},
+        response_check_length_limit = {type = "number", minimum = 1, default = 
5000},

Review Comment:
   `request_check_length_limit`/`response_check_length_limit` are used as 
character counts (passed to `utf8.offset` and used in arithmetic), so allowing 
non-integer values via `type = "number"` can lead to runtime errors (e.g., 
passing a fractional value). Tighten the schema to `integer` to reject invalid 
configs at validation time.



-- 
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