membphis commented on code in PR #11541:
URL: https://github.com/apache/apisix/pull/11541#discussion_r1774358396


##########
apisix/plugins/ai-content-moderation.lua:
##########
@@ -0,0 +1,175 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local aws = require("resty.aws")
+local http = require("resty.http")
+local fetch_secrets = require("apisix.secret").fetch_secrets
+
+local aws_instance = aws()

Review Comment:
   ```suggestion
   local aws_instance = require("resty.aws")()
   ```
   
   then we can remove `local aws = require("resty.aws")`



##########
apisix/plugins/ai-content-moderation.lua:
##########
@@ -0,0 +1,175 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local aws = require("resty.aws")
+local http = require("resty.http")
+local fetch_secrets = require("apisix.secret").fetch_secrets
+
+local aws_instance = aws()
+local next = next
+local pairs = pairs
+local unpack = unpack
+local type = type
+local ipairs = ipairs
+local require = require
+local INTERNAL_SERVER_ERROR = ngx.HTTP_INTERNAL_SERVER_ERROR

Review Comment:
   I think we should keep the prefix `HTTP_`, they were meaningful for me



##########
apisix/plugins/ai-content-moderation.lua:
##########
@@ -0,0 +1,175 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local aws = require("resty.aws")
+local http = require("resty.http")
+local fetch_secrets = require("apisix.secret").fetch_secrets
+
+local aws_instance = aws()
+local next = next
+local pairs = pairs
+local unpack = unpack
+local type = type
+local ipairs = ipairs
+local require = require
+local INTERNAL_SERVER_ERROR = ngx.HTTP_INTERNAL_SERVER_ERROR
+local BAD_REQUEST = ngx.HTTP_BAD_REQUEST

Review Comment:
   ditto



##########
docs/en/latest/plugins/ai-content-moderation.md:
##########
@@ -0,0 +1,218 @@
+---
+title: ai-content-moderation
+keywords:
+  - Apache APISIX
+  - API Gateway
+  - Plugin
+  - ai-content-moderation
+description: This document contains information about the Apache APISIX 
ai-content-moderation Plugin.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## Description
+
+The `ai-content-moderation` plugin processes the request body to check for 
toxicity and rejects the request if it exceeds the configured threshold.
+
+**_This plugin must be used in routes that proxy requests to LLMs only._**
+
+## Plugin Attributes
+
+| **Field**                                 | **Required** | **Type** | 
**Description**                                                                 
                                                         |
+| ----------------------------------------- | ------------ | -------- | 
----------------------------------------------------------------------------------------------------------------------------------------
 |
+| provider.aws_comprehend.access_key_id     | Yes          | String   | AWS 
access key ID                                                                   
                                                     |
+| provider.aws_comprehend.secret_access_key | Yes          | String   | AWS 
secret access key                                                               
                                                     |
+| provider.aws_comprehend.region            | Yes          | String   | AWS 
region                                                                          
                                                     |
+| provider.aws_comprehend.endpoint          | No           | String   | AWS 
Comprehend service endpoint. Must match the pattern `^https?://`                
                                                     |
+| moderation_categories                     | No           | Object   | 
Configuration for moderation categories. Must be one of: PROFANITY, 
HATE_SPEECH, INSULT, HARASSMENT_OR_ABUSE, SEXUAL, VIOLENCE_OR_THREAT |
+| toxicity_level                            | No           | Number   | 
Threshold for overall toxicity detection. Range: 0 - 1. Default: 0.5            
                                                         |
+| llm_provider                              | Yes          | String   | Name 
of the LLM provider that this route will proxy requests to.                     
                                                    |
+
+## Example usage
+
+Create a route with the `ai-content-moderation` and `ai-proxy` plugin like so:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes/1"; -X PUT \
+  -H "X-API-KEY: ${ADMIN_API_KEY}" \
+  -d '{
+    "uri": "/post",
+    "plugins": {
+      "ai-content-moderation": {
+        "provider": {
+          "aws_comprehend": {

Review Comment:
   this plugin supports `aws_comprehend` as provider now, will it support 
different providers in the future?



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