34 lines
813 B
Plaintext
34 lines
813 B
Plaintext
/**
|
|
* Classify if text violates OpenAI's Content Policy.
|
|
* API Ref: https://platform.openai.com/docs/api-reference/moderations/create
|
|
*
|
|
* @param string|array $input The input text to classify.
|
|
* @param string|null $model The moderation model (optional).
|
|
*
|
|
* @return object|null
|
|
* @since 3.2.0
|
|
**/
|
|
public function text(
|
|
$input,
|
|
?string $model = null
|
|
): ?object
|
|
{
|
|
// Build the request path.
|
|
$path = "/moderations";
|
|
|
|
// Set the moderation data.
|
|
$data = new \stdClass();
|
|
$data->input = $input;
|
|
|
|
if ($model !== null)
|
|
{
|
|
$data->model = $model;
|
|
}
|
|
|
|
// Send the post request.
|
|
return $this->response->get(
|
|
$this->http->post(
|
|
$this->uri->get($path), json_encode($data)
|
|
)
|
|
);
|
|
} |