From 0eb4fca4f1072b46b94276a9a5438568cffce5de Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Fri, 27 Sep 2024 12:24:47 -0600 Subject: [PATCH] Add the new OpenAI Moderation model and ensure we use this in our API requests. Add a helper method to get this model which makes it easy for others to override this --- .../Classifai/Providers/OpenAI/Moderation.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/includes/Classifai/Providers/OpenAI/Moderation.php b/includes/Classifai/Providers/OpenAI/Moderation.php index 0dd7bd17b..82e104370 100644 --- a/includes/Classifai/Providers/OpenAI/Moderation.php +++ b/includes/Classifai/Providers/OpenAI/Moderation.php @@ -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. * @@ -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. */ @@ -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 );