Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the new OpenAI Moderation model #811

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading