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 | :heavy_check_mark: | ID of the model to use. | mistral-moderation-latest |
inputs | models.ClassificationRequestInputs | :heavy_check_mark: | Text to classify. | |
metadata | Dict[str, Any] | :heavy_minus_sign: | N/A | |
retries | Optional[utils.RetryConfig] | :heavy_minus_sign: | 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 | :heavy_check_mark: | ID of the model to use. | mistral-moderation-latest |
inputs | models.ClassificationRequestInputs | :heavy_check_mark: | Text to classify. | |
metadata | Dict[str, Any] | :heavy_minus_sign: | N/A | |
retries | Optional[utils.RetryConfig] | :heavy_minus_sign: | 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)
| Parameter | Type | Required | Description |
|---|
model | str | :heavy_check_mark: | N/A |
input | models.Inputs | :heavy_check_mark: | Chat to classify |
retries | Optional[utils.RetryConfig] | :heavy_minus_sign: | 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 | */* |