분류기 엔드포인트

분류기 엔드포인트 (Classifiers Endpoints)

Classifiers API입니다. 텍스트·대화를 안전성 기준으로 분류(모더레이션)하거나 목표별로 분류하는 엔드포인트예요.

출처: 문서

본문

입력 텍스트나 대화를 카테고리별로 점수 매겨 분류하는 API입니다. mistral-moderation-latest 같은 모델로 유해 콘텐츠를 걸러내는 모더레이션과, 커스텀 타깃 분류를 모두 지원해요.

POST /v1/moderations — Moderations (모더레이션)

텍스트를 분류합니다.

요청 본문:

  • input#string|array<string> (필수) — 분류할 텍스트.
  • model#string (필수) — 사용할 모델의 ID.
  • metadata#map<any>|null

응답 필드 (200 Successful Response):

  • id#string (필수)
  • model#string (필수)
  • results#array<ModerationObject> (필수) — 분류 결과 목록.

TypeScript:

import { Mistral } from "@mistralai/mistralai";

const mistral = new Mistral({
  apiKey: proces...EY"] ?? "",
});

async function run() {
  const result = await mistral.classifiers.moderate({
    model: "mistral-moderation-latest",
    inputs: "<value>",
  });

  console.log(result);
}

run();

Python:

from mistralai.client import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.classifiers.moderate(model="mistral-moderation-latest", inputs="<value>")

    # Handle response
    print(res)

curl:

curl https://api.mistral.ai/v1/moderations \
 -X POST \
 -H 'Authorization: Bearer ***' \
 -H 'Content-Type: application/json' \
 -d '{
  "input": "Example input.",
  "model": "mistral-moderation-latest"
}'

응답 예시 (200):

{
  "id": "4d71ae510af942108ef7344f903e2b88",
  "model": "mistral-moderation-latest",
  "results": [
    {
      "categories": {
        "sexual": false,
        "hate_and_discrimination": false,
        "violence_and_threats": false,
        "dangerous_and_criminal_content": false,
        "selfharm": false,
        "health": false,
        "financial": false,
        "law": false,
        "pii": false
      },
      "category_scores": {
        "sexual": 0.0011335690505802631,
        "hate_and_discrimination": 0.0030753696337342262,
        "violence_and_threats": 0.0003569706459529698,
        "dangerous_and_criminal_content": 0.002251847181469202,
        "selfharm": 0.00017952796770259738,
        "health": 0.0002780309587251395,
        "financial": 0.00008481103577651083,
        "law": 0.00004539786823443137,
        "pii": 0.0023967307060956955
      }
    }
  ]
}

POST /v1/chat/moderations — Chat Moderations (대화 모더레이션)

대화를 분류합니다.

요청 본문:

  • input#array<SystemMessage|UserMessage|AssistantMessage|ToolMessage>|array<array<SystemMessage|UserMessage|AssistantMessage|ToolMessage>> (필수) — 분류할 대화.
  • model#string (필수)

응답 필드 (200 Successful Response):

  • id#string (필수)
  • model#string (필수)
  • results#array<ModerationObject> (필수)

TypeScript:

import { Mistral } from "@mistralai/mistralai";

const mistral = new Mistral({
  apiKey: proces...EY"] ?? "",
});

async function run() {
  const result = await mistral.classifiers.moderateChat({
    inputs: [
      {
        role: "tool",
        content: "<value>",
      },
    ],
    model: "LeBaron",
  });

  console.log(result);
}

run();

Python:

from mistralai.client import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.classifiers.moderate_chat(inputs=[
        {
            "role": "tool",
            "content": "<value>",
        },
    ], model="LeBaron")

    # Handle response
    print(res)

curl:

curl https://api.mistral.ai/v1/chat/moderations \
 -X POST \
 -H 'Authorization: Bearer ***' \
 -H 'Content-Type: application/json' \
 -d '{
  "input": [
    {
      "content": "Example content."
    }
  ],
  "model": "mistral-small-latest"
}'

응답 예시 (200):

{
  "id": "352bce1a55814127a3b0bc4fb8f02a35",
  "model": "mistral-moderation-latest",
  "results": [
    {
      "categories": {
        "sexual": false,
        "hate_and_discrimination": false,
        "violence_and_threats": false,
        "dangerous_and_criminal_content": false,
        "selfharm": false,
        "health": false,
        "financial": false,
        "law": false,
        "pii": false
      },
      "category_scores": {
        "sexual": 0.0010322310263291001,
        "hate_and_discrimination": 0.001597845577634871,
        "violence_and_threats": 0.00020342698553577065,
        "dangerous_and_criminal_content": 0.0029810327105224133,
        "selfharm": 0.00017952796770259738,
        "health": 0.0002959570847451687,
        "financial": 0.000079673009167891,
        "law": 0.00004539786823443137,
        "pii": 0.004198795650154352
      }
    }
  ]
}

POST /v1/classifications — Classifications (분류)

텍스트를 분류합니다.

요청 본문:

  • input#string|array<string> (필수) — 분류할 텍스트.
  • model#string (필수) — 사용할 모델의 ID.
  • metadata#map<any>|null

응답 필드 (200 Successful Response):

  • id#string (필수)
  • model#string (필수)
  • results#array<map<ClassificationTargetResult>> (필수) — 타깃별 분류 결과.

TypeScript:

import { Mistral } from "@mistralai/mistralai";

const mistral = new Mistral({
  apiKey: proces...EY"] ?? "",
});

async function run() {
  const result = await mistral.classifiers.classify({
    model: "mistral-moderation-latest",
    inputs: [
      "<value 1>",
      "<value 2>",
      "<value 3>",
    ],
  });

  console.log(result);
}

run();

Python:

from mistralai.client import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.classifiers.classify(model="mistral-moderation-latest", inputs=[
        "<value 1>",
    ])

    # Handle response
    print(res)

curl:

curl https://api.mistral.ai/v1/classifications \
 -X POST \
 -H 'Authorization: Bearer ***' \
 -H 'Content-Type: application/json' \
 -d '{
  "input": "Example input.",
  "model": "mistral-moderation-latest"
}'

응답 예시 (200):

{
  "id": "mod-e5cc70bb28c444948073e77776eb30ef",
  "model": "mistral-small-latest",
  "results": [
    [
      {
        "scores": [
          87
        ]
      }
    ]
  ]
}

POST /v1/chat/classifications — Chat Classifications (대화 분류)

대화를 분류합니다.

요청 본문:

  • input#InstructRequest|array<InstructRequest> (필수) — 분류할 대화.
  • model#string (필수)

응답 필드 (200 Successful Response):

  • id#string (필수)
  • model#string (필수)
  • results#array<map<ClassificationTargetResult>> (필수)

TypeScript:

import { Mistral } from "@mistralai/mistralai";

const mistral = new Mistral({
  apiKey: proces...EY"] ?? "",
});

async function run() {
  const result = await mistral.classifiers.classifyChat({
    model: "Camry",
    input: [
      {
        messages: [
          {
            role: "system",
            content: "<value>",
          },
        ],
      },
    ],
  });

  console.log(result);
}

run();

Python:

from mistralai.client import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.classifiers.classify_chat(model="Camry", input=[
        {
            "messages": [
                {
                    "role": "system",
                    "content": "<value>",
                },
            ],
        },
    ])

    # Handle response
    print(res)

curl:

curl https://api.mistral.ai/v1/chat/classifications \
 -X POST \
 -H 'Authorization: Bearer ***' \
 -H 'Content-Type: application/json' \
 -d '{
  "input": {
    "messages": [
      {
        "content": "Example content."
      }
    ]
  },
  "model": "mistral-small-latest"
}'

응답 예시 (200):

{
  "id": "mod-e5cc70bb28c444948073e77776eb30ef",
  "model": "mistral-small-latest",
  "results": [
    [
      {
        "scores": [
          87
        ]
      }
    ]
  ]
}

더 알아보기 (Learn more)