From eff69df65a2fd67e329f4d5d7992c5ad8b827ca2 Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Thu, 10 Aug 2023 16:33:17 +0300 Subject: [PATCH 01/13] Update the Computer Vision API Image analysis API endpoint version --- includes/Classifai/Providers/Azure/ComputerVision.php | 4 +++- tests/test-plugin/e2e-test-plugin.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index 2a9555610..857e53490 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -21,7 +21,7 @@ class ComputerVision extends Provider { /** * @var string URL fragment to the analyze API endpoint */ - protected $analyze_url = 'vision/v3.0/analyze'; + protected $analyze_url = 'vision/v3.2/analyze'; /** * ComputerVision constructor. @@ -1323,6 +1323,8 @@ public function rest_endpoint_callback( $post_id, $route_to_call, $args = [] ) { $image_scan_results = $this->scan_image( $image_url, [ $route_to_call ] ); + print_r( $image_scan_results ); + if ( is_wp_error( $image_scan_results ) ) { return $image_scan_results; } diff --git a/tests/test-plugin/e2e-test-plugin.php b/tests/test-plugin/e2e-test-plugin.php index f993da6de..c345a8d13 100644 --- a/tests/test-plugin/e2e-test-plugin.php +++ b/tests/test-plugin/e2e-test-plugin.php @@ -43,7 +43,7 @@ function classifai_test_mock_http_requests( $preempt, $parsed_args, $url ) { ); } elseif ( strpos( $url, 'https://api.openai.com/v1/embeddings' ) !== false ) { $response = file_get_contents( __DIR__ . '/embeddings.json' ); - } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.0/analyze' ) !== false ) { + } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.2/analyze' ) !== false ) { $response = file_get_contents( __DIR__ . '/image_analyze.json' ); } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.2/ocr' ) !== false ) { $response = file_get_contents( __DIR__ . '/ocr.json' ); From 12069a6c6b4025effc4c802adba817ee201abae3 Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Thu, 10 Aug 2023 16:33:53 +0300 Subject: [PATCH 02/13] Update the Computer Vision API thumbnail generation service API endpoint version --- includes/Classifai/Providers/Azure/SmartCropping.php | 2 +- tests/Classifai/Providers/Azure/SmartCroppingTest.php | 2 +- tests/test-plugin/e2e-test-plugin.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Classifai/Providers/Azure/SmartCropping.php b/includes/Classifai/Providers/Azure/SmartCropping.php index c46f86419..a3c3686d3 100644 --- a/includes/Classifai/Providers/Azure/SmartCropping.php +++ b/includes/Classifai/Providers/Azure/SmartCropping.php @@ -26,7 +26,7 @@ class SmartCropping { * * @var string */ - const API_PATH = 'vision/v3.1/generateThumbnail/'; + const API_PATH = 'vision/v3.2/generateThumbnail/'; /** * ComputerVisition settings. diff --git a/tests/Classifai/Providers/Azure/SmartCroppingTest.php b/tests/Classifai/Providers/Azure/SmartCroppingTest.php index 23d241581..6a08a479a 100644 --- a/tests/Classifai/Providers/Azure/SmartCroppingTest.php +++ b/tests/Classifai/Providers/Azure/SmartCroppingTest.php @@ -188,7 +188,7 @@ public function test_get_cropped_thumbnail() { */ public function test_get_api_url() { $this->assertEquals( - 'my-api-url.com/vision/v3.1/generateThumbnail/', + 'my-api-url.com/vision/v3.2/generateThumbnail/', $this->get_smart_cropping()->get_api_url() ); } diff --git a/tests/test-plugin/e2e-test-plugin.php b/tests/test-plugin/e2e-test-plugin.php index c345a8d13..1b13d7c1b 100644 --- a/tests/test-plugin/e2e-test-plugin.php +++ b/tests/test-plugin/e2e-test-plugin.php @@ -47,7 +47,7 @@ function classifai_test_mock_http_requests( $preempt, $parsed_args, $url ) { $response = file_get_contents( __DIR__ . '/image_analyze.json' ); } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.2/ocr' ) !== false ) { $response = file_get_contents( __DIR__ . '/ocr.json' ); - } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.1/generateThumbnail' ) !== false ) { + } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.2/generateThumbnail' ) !== false ) { $response = file_get_contents( __DIR__ . '../classifai/assets/img/icon256x256.png' ); } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/pdf-read-result' ) !== false ) { $response = file_get_contents( __DIR__ . '/pdf.json' ); From df4eee229b23a62a825cfa12b9f59a7d54fd6525 Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Fri, 11 Aug 2023 08:54:00 +0300 Subject: [PATCH 03/13] Remove debugging leftover code --- includes/Classifai/Providers/Azure/ComputerVision.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index 857e53490..d73c94eef 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -1323,8 +1323,6 @@ public function rest_endpoint_callback( $post_id, $route_to_call, $args = [] ) { $image_scan_results = $this->scan_image( $image_url, [ $route_to_call ] ); - print_r( $image_scan_results ); - if ( is_wp_error( $image_scan_results ) ) { return $image_scan_results; } From fd219ee44cfd168cc11102951d6912cb0f2370b1 Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Fri, 11 Aug 2023 09:56:44 +0300 Subject: [PATCH 04/13] Adust the error handling for the responses of Azure AI Vision API that changed after v3.2 --- includes/Classifai/Providers/Azure/ComputerVision.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index d73c94eef..b7578e832 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -719,8 +719,14 @@ protected function scan_image( $image_url, array $routes = [] ) { if ( ! is_wp_error( $request ) ) { $body = json_decode( wp_remote_retrieve_body( $request ) ); - if ( 200 !== wp_remote_retrieve_response_code( $request ) && isset( $body->message ) ) { - $rtn = new WP_Error( $body->code ?? 'error', $body->message, $body ); + if ( 200 !== wp_remote_retrieve_response_code( $request ) ) { + if ( isset( $body->error ) ) { + $rtn = new WP_Error( $body->error->code ?? 'error', $body->error->message ?? esc_html__( 'An error occurred.', 'classifai' ), $body ); + } elseif ( isset( $body->message ) ) { + $rtn = new WP_Error( $body->code ?? 'error', $body->message, $body ); + } else { + $rtn = new WP_Error( 'error', esc_html__( 'An error occurred.', 'classifai' ), $body ); + } } else { $rtn = $body; } From 7458543780807f61685147b2a1f6124e5d20d0ea Mon Sep 17 00:00:00 2001 From: sksaju Date: Thu, 23 Nov 2023 02:39:08 +0600 Subject: [PATCH 05/13] update watson nlu default thresholds value from 70 to 55 --- config.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.php b/config.php index 1e24861db..e7ef77541 100644 --- a/config.php +++ b/config.php @@ -29,10 +29,10 @@ classifai_define( 'WATSON_CONCEPT_TAXONOMY', 'watson-concept' ); classifai_define( 'WATSON_TIMEOUT', 60 ); // seconds // Default Thresholds -classifai_define( 'WATSON_CATEGORY_THRESHOLD', 70 ); -classifai_define( 'WATSON_KEYWORD_THRESHOLD', 70 ); -classifai_define( 'WATSON_ENTITY_THRESHOLD', 70 ); -classifai_define( 'WATSON_CONCEPT_THRESHOLD', 70 ); +classifai_define( 'WATSON_CATEGORY_THRESHOLD', 55 ); +classifai_define( 'WATSON_KEYWORD_THRESHOLD', 55 ); +classifai_define( 'WATSON_ENTITY_THRESHOLD', 55 ); +classifai_define( 'WATSON_CONCEPT_THRESHOLD', 55 ); classifai_define( 'WATSON_KEYWORD_LIMIT', 10 ); From c9de51e527b32f0cbda7c036c264aba5f2a5e2d5 Mon Sep 17 00:00:00 2001 From: sksaju Date: Thu, 23 Nov 2023 03:50:59 +0600 Subject: [PATCH 06/13] added thresholds_update_notice callback function --- includes/Classifai/Providers/Watson/NLU.php | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/includes/Classifai/Providers/Watson/NLU.php b/includes/Classifai/Providers/Watson/NLU.php index 0d30e9115..0d4238b8d 100644 --- a/includes/Classifai/Providers/Watson/NLU.php +++ b/includes/Classifai/Providers/Watson/NLU.php @@ -88,7 +88,6 @@ public function __construct( $service ) { // translators: %s is the post type label. $this->onboarding_options['features'][ 'post_types__' . $post_type->name ] = sprintf( __( 'Automatically tag %s', 'classifai' ), $post_type->label ); } - } /** @@ -128,6 +127,7 @@ public function reset_settings() { public function register() { add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_assets' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); + add_action( 'admin_notices', [ $this, 'thresholds_update_notice' ] ); // Add classifai meta box to classic editor. add_action( 'add_meta_boxes', [ $this, 'add_classifai_meta_box' ], 10, 2 ); @@ -913,6 +913,42 @@ public function add_process_content_meta_to_rest_api() { ); } + /** + * Display a dismissable admin notice when a threshold still at the default 70% and IBM Watson NLU active + */ + public function thresholds_update_notice() { + $config = $this->is_configured(); + + $thresholds = [ + $config['features']['category_threshold'] ?? 55, + $config['features']['keyword_threshold'] ?? 55, + $config['features']['entity_threshold'] ?? 55, + $config['features']['concept_threshold'] ?? 55, + ]; + + if ( ! in_array( 70, $thresholds, true ) ) { + return; + } + + ?> +
+

+ %s', + esc_url( admin_url( 'tools.php?page=classifai&tab=language_processing&provider=watson_nlu' ) ), + esc_html__( 'Click here to adjust those settings.', 'text-domain' ) + ) + ); + ?> +

+
+ Date: Mon, 27 Nov 2023 21:24:00 +0600 Subject: [PATCH 07/13] fix classify-content-ibm-watson.test cypress test case --- .../language-processing/classify-content-ibm-watson.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js b/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js index 52f8333f3..24ae0f575 100644 --- a/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js +++ b/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js @@ -219,7 +219,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); it( 'Can create post and taxonomy terms get created by ClassifAI (with default threshold)', () => { - const threshold = 0.7; + const threshold = 55; // Create Test Post cy.createPost( { title: 'Test NLU post', From aca5c990bd23701e834fc8e15476619847db495d Mon Sep 17 00:00:00 2001 From: sksaju Date: Mon, 27 Nov 2023 21:45:22 +0600 Subject: [PATCH 08/13] fix classify-content-ibm-watson.test cypress test case --- .../classify-content-ibm-watson.test.js | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js b/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js index 24ae0f575..08d8b3e0a 100644 --- a/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js +++ b/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js @@ -220,10 +220,30 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () it( 'Can create post and taxonomy terms get created by ClassifAI (with default threshold)', () => { const threshold = 55; + + // Update Threshold to 55. + cy.visit( + '/wp-admin/tools.php?page=classifai&tab=language_processing' + ); + + cy.get( '#classifai-settings-category_threshold' ) + .clear() + .type( threshold ); + cy.get( '#classifai-settings-keyword_threshold' ) + .clear() + .type( threshold ); + cy.get( '#classifai-settings-entity_threshold' ) + .clear() + .type( threshold ); + cy.get( '#classifai-settings-concept_threshold' ) + .clear() + .type( threshold ); + cy.get( '#submit' ).click(); + // Create Test Post cy.createPost( { - title: 'Test NLU post', - content: 'Test NLU Content', + title: 'Test NLU post with 55 Threshold', + content: 'Test NLU Content with 55 Threshold', } ); // Close post publish panel @@ -240,7 +260,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () // Verify Each Created taxonomies. [ 'categories', 'keywords', 'concepts', 'entities' ].forEach( ( taxonomy ) => { - cy.verifyPostTaxonomyTerms( taxonomy, threshold ); + cy.verifyPostTaxonomyTerms( taxonomy, threshold / 100 ); } ); } ); From 1b732e2fe0685e640983bf04c5a757c664b28779 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 1 Feb 2024 10:47:55 -0700 Subject: [PATCH 09/13] Remove any changes made to the NLU code, as that isn't the provider we're changing here. Move admin notice into our Notifications class --- includes/Classifai/Admin/Notifications.php | 69 +++++++++++++++++++ includes/Classifai/Providers/Watson/NLU.php | 37 ---------- .../classify-content-ibm-watson.test.js | 27 ++------ 3 files changed, 73 insertions(+), 60 deletions(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index 307d06865..e088fe945 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -2,6 +2,9 @@ namespace Classifai\Admin; +use Classifai\Features\DescriptiveTextGenerator; +use Classifai\Features\ImageTagsGenerator; + class Notifications { /** @@ -24,6 +27,7 @@ public function can_register(): bool { public function register() { add_action( 'classifai_activation_hook', [ $this, 'add_activation_notice' ] ); add_action( 'admin_notices', [ $this, 'maybe_render_notices' ], 0 ); + add_action( 'admin_notices', [ $this, 'thresholds_update_notice' ] ); } /** @@ -76,4 +80,69 @@ public function maybe_render_notices() { delete_transient( 'classifai_activation_notice' ); } } + + /** + * Display a dismissable admin notice when a threshold may need updating. + * + * We used to recommend thresholds between 70-75% but in the latest + * version of the AI Vision API, seems 55% is a better threshold. + */ + public function thresholds_update_notice() { + $features = [ + 'feature_descriptive_text_generator' => 'Classifai\Features\DescriptiveTextGenerator', + 'feature_image_tags_generator' => 'Classifai\Features\ImageTagsGenerator', + ]; + + foreach ( $features as $name => $feature_class ) { + if ( ! class_exists( $feature_class ) ) { + continue; + } + + $feature_instance = new $feature_class(); + + if ( ! $feature_instance->is_feature_enabled() ) { + continue; + } + + // TODO: add a check where we don't show the notice if it's already been dismissed + + $settings = $feature_instance->get_settings( 'ms_computer_vision' ); + $key = ''; + $message = ''; + + switch ( $feature_instance::ID ) { + case DescriptiveTextGenerator::ID: + $key = 'descriptive_confidence_threshold'; + $message = __( 'The previous recommended threshold for descriptive text generation was 75% but we find better results now at around 55%.', 'classifai' ); + break; + + case ImageTagsGenerator::ID: + $key = 'tag_confidence_threshold'; + $message = __( 'The previous recommended threshold for image tagging was 70% but we find better results now at around 55%.', 'classifai' ); + break; + } + + if ( $key && isset( $settings[ $key ] ) && $settings[ $key ] <= 55 ) { + continue; + } + ?> + +
+

+ Click here to adjust those settings.', 'classifai' ), + esc_html( $message ), + esc_url( admin_url( "tools.php?page=classifai&tab=image_processing&feature=$name" ) ) + ) + ); + ?> +

+
+ + is_feature_enabled() && $feature->get_feature_provider_instance()::ID === static::ID ) { add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_assets' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); - add_action( 'admin_notices', [ $this, 'thresholds_update_notice' ] ); // Add classifai meta box to classic editor. add_action( 'add_meta_boxes', [ $this, 'add_classifai_meta_box' ], 10, 2 ); @@ -819,42 +818,6 @@ public function add_process_content_meta_to_rest_api() { ); } - /** - * Display a dismissable admin notice when a threshold still at the default 70% and IBM Watson NLU active - */ - public function thresholds_update_notice() { - $config = $this->is_configured(); - - $thresholds = [ - $config['features']['category_threshold'] ?? 55, - $config['features']['keyword_threshold'] ?? 55, - $config['features']['entity_threshold'] ?? 55, - $config['features']['concept_threshold'] ?? 55, - ]; - - if ( ! in_array( 70, $thresholds, true ) ) { - return; - } - - ?> -
-

- %s', - esc_url( admin_url( 'tools.php?page=classifai&tab=language_processing&provider=watson_nlu' ) ), - esc_html__( 'Click here to adjust those settings.', 'text-domain' ) - ) - ); - ?> -

-
- { - const threshold = 55; - - // Update Threshold to 55. - cy.visit( - '/wp-admin/tools.php?page=classifai&tab=language_processing' - ); - - cy.get( '#classifai-settings-category_threshold' ) - .clear() - .type( threshold ); - cy.get( '#classifai-settings-keyword_threshold' ) - .clear() - .type( threshold ); - cy.get( '#classifai-settings-entity_threshold' ) - .clear() - .type( threshold ); - cy.get( '#classifai-settings-concept_threshold' ) - .clear() - .type( threshold ); - cy.get( '#submit' ).click(); + const threshold = 0.7; // Create Test Post cy.createPost( { - title: 'Test NLU post with 55 Threshold', - content: 'Test NLU Content with 55 Threshold', + title: 'Test NLU post', + content: 'Test NLU Content', } ); // Close post publish panel @@ -277,7 +258,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () // Verify Each Created taxonomies. [ 'categories', 'keywords', 'concepts', 'entities' ].forEach( ( taxonomy ) => { - cy.verifyPostTaxonomyTerms( taxonomy, threshold / 100 ); + cy.verifyPostTaxonomyTerms( taxonomy, threshold ); } ); } ); From 1372f17ff721abc76880609f111a081884bc01bd Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 1 Feb 2024 10:50:05 -0700 Subject: [PATCH 10/13] Update default thresholds to 55 --- includes/Classifai/Providers/Azure/ComputerVision.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index b1772736b..f7e0620b9 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -126,7 +126,7 @@ public function add_descriptive_text_generation_fields() { 'min' => 1, 'step' => 1, 'default_value' => $settings['descriptive_confidence_threshold'], - 'description' => esc_html__( 'Minimum confidence score for automatically added generated text, numeric value from 0-100. Recommended to be set to at least 75.', 'classifai' ), + 'description' => esc_html__( 'Minimum confidence score for automatically added generated text, numeric value from 0-100. Recommended to be set to at least 55.', 'classifai' ), 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. ] ); @@ -151,7 +151,7 @@ public function add_image_tags_generation_fields() { 'min' => 1, 'step' => 1, 'default_value' => $settings['tag_confidence_threshold'], - 'description' => esc_html__( 'Minimum confidence score for automatically added image tags, numeric value from 0-100. Recommended to be set to at least 70.', 'classifai' ), + 'description' => esc_html__( 'Minimum confidence score for automatically added image tags, numeric value from 0-100. Recommended to be set to at least 55.', 'classifai' ), 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. ] ); @@ -175,7 +175,7 @@ public function get_default_provider_settings(): array { return array_merge( $common_settings, [ - 'descriptive_confidence_threshold' => 75, + 'descriptive_confidence_threshold' => 55, ] ); @@ -183,7 +183,7 @@ public function get_default_provider_settings(): array { return array_merge( $common_settings, [ - 'tag_confidence_threshold' => 70, + 'tag_confidence_threshold' => 55, ] ); } From 15e44c2aeaa414823f3ece7bc51372bffc6c5a26 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 1 Feb 2024 11:21:36 -0700 Subject: [PATCH 11/13] Output an inline script that fires when the dismiss button is clicked. This sends an ajax request that we listen for and store some data in user meta, which we then use to not show the notice again --- includes/Classifai/Admin/Notifications.php | 80 +++++++++++++++++++++- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index e088fe945..3d9ce314a 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -28,6 +28,8 @@ public function register() { add_action( 'classifai_activation_hook', [ $this, 'add_activation_notice' ] ); add_action( 'admin_notices', [ $this, 'maybe_render_notices' ], 0 ); add_action( 'admin_notices', [ $this, 'thresholds_update_notice' ] ); + add_action( 'admin_enqueue_scripts', [ $this, 'add_dismiss_script' ] ); + add_action( 'wp_ajax_classifai_dismiss_notice', [ $this, 'ajax_maybe_dismiss_notice' ] ); } /** @@ -81,6 +83,73 @@ public function maybe_render_notices() { } } + /** + * Print out a script to dismiss a notice. + * + * This allows us to save that a user has dismissed a notice. + * + * Influenced by https://github.com/WPTT/admin-notices/blob/af52f563398b42cff82d38eefa55c8121d698ebe/src/Dismiss.php#L77 + */ + public function add_dismiss_script() { + $nonce = wp_create_nonce( 'classifai_dismissible_notice' ); + $admin_ajax_url = esc_url( admin_url( 'admin-ajax.php' ) ); + + $script = <<is_feature_enabled() ) { continue; } - // TODO: add a check where we don't show the notice if it's already been dismissed - $settings = $feature_instance->get_settings( 'ms_computer_vision' ); $key = ''; $message = ''; @@ -122,12 +190,18 @@ public function thresholds_update_notice() { break; } + // Don't show the notice if the user has already dismissed it. + if ( get_user_meta( get_current_user_id(), "classifai_dismissed_{$key}", true ) ) { + continue; + } + + // Don't show the notice if the threshold is already at 55% or lower. if ( $key && isset( $settings[ $key ] ) && $settings[ $key ] <= 55 ) { continue; } ?> -
+

Date: Thu, 1 Feb 2024 11:40:36 -0700 Subject: [PATCH 12/13] Fix tests. Change defaults for image tagging back as they seem to give similar results --- includes/Classifai/Admin/Notifications.php | 6 ------ includes/Classifai/Providers/Azure/ComputerVision.php | 4 ++-- tests/Classifai/Azure/ComputerVisionTest.php | 2 +- tests/Classifai/Providers/Azure/ComputerVisionTest.php | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index 3d9ce314a..1e92ee88f 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -159,7 +159,6 @@ public function ajax_maybe_dismiss_notice() { public function thresholds_update_notice() { $features = [ 'feature_descriptive_text_generator' => 'Classifai\Features\DescriptiveTextGenerator', - 'feature_image_tags_generator' => 'Classifai\Features\ImageTagsGenerator', ]; foreach ( $features as $name => $feature_class ) { @@ -183,11 +182,6 @@ public function thresholds_update_notice() { $key = 'descriptive_confidence_threshold'; $message = __( 'The previous recommended threshold for descriptive text generation was 75% but we find better results now at around 55%.', 'classifai' ); break; - - case ImageTagsGenerator::ID: - $key = 'tag_confidence_threshold'; - $message = __( 'The previous recommended threshold for image tagging was 70% but we find better results now at around 55%.', 'classifai' ); - break; } // Don't show the notice if the user has already dismissed it. diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index f7e0620b9..57929a1cf 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -151,7 +151,7 @@ public function add_image_tags_generation_fields() { 'min' => 1, 'step' => 1, 'default_value' => $settings['tag_confidence_threshold'], - 'description' => esc_html__( 'Minimum confidence score for automatically added image tags, numeric value from 0-100. Recommended to be set to at least 55.', 'classifai' ), + 'description' => esc_html__( 'Minimum confidence score for automatically added image tags, numeric value from 0-100. Recommended to be set to at least 70.', 'classifai' ), 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. ] ); @@ -183,7 +183,7 @@ public function get_default_provider_settings(): array { return array_merge( $common_settings, [ - 'tag_confidence_threshold' => 55, + 'tag_confidence_threshold' => 70, ] ); } diff --git a/tests/Classifai/Azure/ComputerVisionTest.php b/tests/Classifai/Azure/ComputerVisionTest.php index 867bf5cef..1abb424e1 100644 --- a/tests/Classifai/Azure/ComputerVisionTest.php +++ b/tests/Classifai/Azure/ComputerVisionTest.php @@ -42,7 +42,7 @@ public function test_get_debug_information() { $this->assertEquals( [ 'Generate descriptive text' => '0, 0, 0', - 'Confidence threshold' => 75, + 'Confidence threshold' => 55, 'Latest response:' => 'N/A', ], $this->provider->get_debug_information( diff --git a/tests/Classifai/Providers/Azure/ComputerVisionTest.php b/tests/Classifai/Providers/Azure/ComputerVisionTest.php index 4f0f61890..af842a89c 100644 --- a/tests/Classifai/Providers/Azure/ComputerVisionTest.php +++ b/tests/Classifai/Providers/Azure/ComputerVisionTest.php @@ -87,7 +87,7 @@ public function test_no_computer_vision_option_set() { 'endpoint_url' => '', 'api_key' => '', 'authenticated' => false, - 'descriptive_confidence_threshold' => 75, + 'descriptive_confidence_threshold' => 55, ], ] ); From 674ca8ac06968f9f099a8936020a5807ca7515c8 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 1 Feb 2024 11:42:00 -0700 Subject: [PATCH 13/13] Remove unecessary line of code --- includes/Classifai/Admin/Notifications.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index 1e92ee88f..75a5292bf 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -3,7 +3,6 @@ namespace Classifai\Admin; use Classifai\Features\DescriptiveTextGenerator; -use Classifai\Features\ImageTagsGenerator; class Notifications {