Skip to content

Commit

Permalink
toxicity_level -> moderation_threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
shreemaan-abhishek committed Oct 9, 2024
1 parent a3e47b2 commit 81958e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apisix/plugins/ai-content-moderation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ local schema = {
},
additionalProperties = false
},
toxicity_level = {
moderation_threshold = {
type = "number",
minimum = 0,
maximum = 1,
Expand Down Expand Up @@ -170,7 +170,7 @@ function _M.rewrite(conf, ctx)
end
end

if result.Toxicity > conf.toxicity_level then
if result.Toxicity > conf.moderation_threshold then
return HTTP_BAD_REQUEST, "request body exceeds toxicity threshold"
end
end
Expand Down
6 changes: 3 additions & 3 deletions docs/en/latest/plugins/ai-content-moderation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The `ai-content-moderation` plugin processes the request body to check for toxic
| 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 | Key-value pairs of moderation category and their score. In each pair, the key should be one of the `PROFANITY`, `HATE_SPEECH`, `INSULT`, `HARASSMENT_OR_ABUSE`, `SEXUAL`, or `VIOLENCE_OR_THREAT`; and the value should be between 0 and 1 (inclusive). |
| toxicity_level | No | Number | The degree to which content is harmful, offensive, or inappropriate. A higher value indicates more toxic content allowed. Range: 0 - 1. Default: 0.5 |
| moderation_threshold | No | Number | The degree to which content is harmful, offensive, or inappropriate. A higher value indicates more toxic content allowed. Range: 0 - 1. Default: 0.5 |
| llm_provider | Yes | String | Name of the LLM provider that this route will proxy requests to. |

## Example usage
Expand Down Expand Up @@ -208,7 +208,7 @@ curl "http://127.0.0.1:9180/apisix/admin/routes/1" -X PUT \
```

If none of the `moderation_categories` are configured, request bodies will be moderated on the basis of overall toxicity.
The default `toxicity_level` is 0.5, it can be configured like so.
The default `moderation_threshold` is 0.5, it can be configured like so.

```shell
curl "http://127.0.0.1:9180/apisix/admin/routes/1" -X PUT \
Expand All @@ -224,7 +224,7 @@ curl "http://127.0.0.1:9180/apisix/admin/routes/1" -X PUT \
"region": "us-east-1"
}
},
"toxicity_level": 0.7,
"moderation_threshold": 0.7,
"llm_provider": "openai"
},
"ai-proxy": {
Expand Down

0 comments on commit 81958e4

Please sign in to comment.