/moderations
使用方式
- LiteLLM Python SDK
- LiteLLM Proxy Server
from litellm import moderation
response = moderation(
input="hello from litellm",
model="text-moderation-stable"
)
對於 /moderations 端點,不需要在請求中或 litellm config.yaml 中指定 model
- 設定 config.yaml
model_list:
- model_name: text-moderation-stable
litellm_params:
model: openai/omni-moderation-latest
- 啟動 litellm proxy server
litellm --config /path/to/config.yaml
- OpenAI Python SDK
- Curl Request
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"
)
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 - 要分類的輸入(或多個輸入)。可以是單一字串、字串陣列,或類似其他模型的多模態輸入物件陣列。- 如果是字串:要進行 moderation 分類的文字字串
- 如果是字串陣列:要進行 moderation 分類的字串陣列
- 如果是物件陣列:送入 moderation model 的多模態輸入陣列,其中每個物件可以是:
- 描述要分類的圖片之物件:
type: string, required - 一律為image_urlimage_url: object, required - 包含圖片 URL 或 base64 編碼圖片的 data URL
- 描述要分類的文字之物件:
type: string, required - 一律為texttext: string, required - 要分類的文字字串
- 描述要分類的圖片之物件:
選填欄位
model: string (optional) - 要使用的 moderation model。預設為omni-moderation-latest。
輸出格式
以下是您可以從所有 moderation 請求預期得到的完整 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
}
}
]
}
支援的提供者
⚡️請前往 models.litellm.ai 查看所有支援的模型與提供者
| 提供者 |
|---|
| OpenAI |