/moderations
用法
- LiteLLM Python SDK
- LiteLLM 代理服务器
from litellm import moderation
response = moderation(
input="hello from litellm",
model="text-moderation-stable"
)
对于 /moderations
端点,无需在请求或 litellm config.yaml 中指定 model
启动 litellm 代理服务器
litellm
- OpenAI Python SDK
- Curl 请求
from openai import OpenAI
# set base_url to your proxy server
# set api_key to send to proxy server
client = OpenAI(api_key="<proxy-api-key>", base_url="http://0.0.0.0:4000")
response = client.moderations.create(
input="hello from litellm",
model="text-moderation-stable" # optional, defaults to `omni-moderation-latest`
)
print(response)
curl --location 'http://0.0.0.0:4000/moderations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-1234' \
--data '{"input": "Sample text goes here", "model": "text-moderation-stable"}'
输入参数
LiteLLM 接受并翻译所有支持提供商的OpenAI Moderation 参数。
必填字段
input
: string 或 array - 要分类的输入(或多个输入)。可以是单个字符串、字符串数组或类似于其他模型的多种模态输入对象数组。- 如果是字符串:要分类的文本字符串用于审核
- 如果是字符串数组:要分类的字符串数组用于审核
- 如果是对象数组:用于审核模型的多种模态输入数组,其中每个对象可以是
- 描述要分类图像的对象
type
: string,必填 - 始终为image_url
image_url
: object,必填 - 包含图像 URL 或用于 base64 编码图像的数据 URL
- 描述要分类文本的对象
type
: string,必填 - 始终为text
text
: string,必填 - 要分类的文本字符串
- 描述要分类图像的对象
可选字段
model
: string (可选) - 要使用的审核模型。默认为omni-moderation-latest
。
输出格式
以下是您可以从所有审核调用中获得的精确 json 输出和类型
{
"id": "modr-AB8CjOTu2jiq12hp1AQPfeqFWaORR",
"model": "text-moderation-007",
"results": [
{
"flagged": true,
"categories": {
"sexual": false,
"hate": false,
"harassment": true,
"self-harm": false,
"sexual/minors": false,
"hate/threatening": false,
"violence/graphic": false,
"self-harm/intent": false,
"self-harm/instructions": false,
"harassment/threatening": true,
"violence": true
},
"category_scores": {
"sexual": 0.000011726012417057063,
"hate": 0.22706663608551025,
"harassment": 0.5215635299682617,
"self-harm": 2.227119921371923e-6,
"sexual/minors": 7.107352217872176e-8,
"hate/threatening": 0.023547329008579254,
"violence/graphic": 0.00003391829886822961,
"self-harm/intent": 1.646940972932498e-6,
"self-harm/instructions": 1.1198755256458526e-9,
"harassment/threatening": 0.5694745779037476,
"violence": 0.9971134662628174
}
}
]
}
支持的提供商
提供商 |
---|
OpenAI |