Skip to content

Commit

Permalink
Merge pull request #811 from 10up/feature/openai-moderation-model
Browse files Browse the repository at this point in the history
Add the new OpenAI Moderation model
  • Loading branch information
dkotter authored Dec 11, 2024
2 parents 43991a9 + a0f0199 commit 7641a92
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions includes/Classifai/Providers/OpenAI/Moderation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class Moderation extends Provider {
*/
protected $moderation_url = 'https://api.openai.com/v1/moderations';

/**
* OpenAI Moderation model
*
* @var string
*/
protected $model = 'omni-moderation-latest';

/**
* OpenAI Moderation constructor.
*
Expand All @@ -31,6 +38,28 @@ public function __construct( $feature_instance = null ) {
$this->feature_instance = $feature_instance;
}

/**
* Get the model name.
*
* @return string
*/
public function get_model(): string {
/**
* Filter the model name.
*
* Useful if you want to use a different model, like
* text-moderation-latest.
*
* @since x.x.x
* @hook classifai_openai_moderation_model
*
* @param {string} $model The default model to use.
*
* @return {string} The model to use.
*/
return apply_filters( 'classifai_openai_moderation_model', $this->model );
}

/**
* Register what we need for the provider.
*/
Expand Down Expand Up @@ -191,6 +220,7 @@ public function moderate_comment( int $comment_id = 0 ) {
'classifai_openai_moderation_request_body',
[
'input' => $comment->comment_content,
'model' => $this->get_model(),
],
$comment_id
);
Expand Down

0 comments on commit 7641a92

Please sign in to comment.