Classifiers API.
Moderations
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)
| Parameter |
Type |
Required |
Description |
Example |
model |
str |
✔️ |
ID of the model to use. |
mistral-moderation-latest |
inputs |
models.ClassificationRequestInputs |
✔️ |
Text to classify. |
|
metadata |
Dict[str, Any] |
➖ |
N/A |
|
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
|
models.ModerationResponse
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Chat Moderations
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)
models.ModerationResponse
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Classifications
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)
| Parameter |
Type |
Required |
Description |
Example |
model |
str |
✔️ |
ID of the model to use. |
mistral-moderation-latest |
inputs |
models.ClassificationRequestInputs |
✔️ |
Text to classify. |
|
metadata |
Dict[str, Any] |
➖ |
N/A |
|
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
|
models.ClassificationResponse
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Chat Classifications
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)
models.ClassificationResponse
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |