From e6c1e2c0549395d585667c9af6440a506204f813 Mon Sep 17 00:00:00 2001 From: Bunty Date: Mon, 7 Jul 2025 15:05:25 +0530 Subject: [PATCH 01/20] Add a proto type for setup instructions uder the Service Provider. --- includes/Classifai/Plugin.php | 52 +++++++++++++++++++ package-lock.json | 21 ++++++-- package.json | 1 + .../provider-settings/azure-openai.js | 2 + .../provider-settings/google-gemini-api.js | 2 + .../provider-settings/ibm-watson-nlu.js | 2 + .../provider-settings/ollama-embeddings.js | 14 +++-- .../components/provider-settings/ollama.js | 14 +++-- .../provider-settings/openai-chatgpt.js | 26 ++++++---- .../provider-settings/openai-embeddings.js | 12 +++-- .../provider-settings/setup-instruction.js | 46 ++++++++++++++++ .../components/provider-settings/xai-grok.js | 26 ++++++---- 12 files changed, 179 insertions(+), 39 deletions(-) create mode 100644 src/js/settings/components/provider-settings/setup-instruction.js diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index 3f6d2d50c..f218c8473 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -186,6 +186,13 @@ public function enqueue_admin_assets() { true ); + $readme_path = trailingslashit( CLASSIFAI_PLUGIN_DIR ) . 'README.md'; + $readme_content = ''; + + if ( file_exists( $readme_path ) ) { + $readme_content = file_get_contents( $readme_path ); + } + $localize_data = [ 'api_password' => __( 'API Password', 'classifai' ), 'api_key' => __( 'API Key', 'classifai' ), @@ -195,6 +202,51 @@ public function enqueue_admin_assets() { 'opt_out_enabled_features' => array_keys( $allowed_features ), 'profile_url' => esc_url( get_edit_profile_url( get_current_user_id() ) . '#classifai-profile-features-section' ), 'plugin_url' => CLASSIFAI_PLUGIN_URL, + 'instruction' => array( + 'feature_classification' => array( + 'ibm_watson_nlu' => preg_match('/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + 'openai_embeddings' => preg_match('/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + 'azure_openai_embeddings' => '', + 'ollama_embeddings' => '', + ), + 'feature_title_generation' => array( + 'openai_chatgpt' => '', + 'googleai_gemini_api' => '', + 'azure_openai' => '', + 'xai_grok' => '', + 'ollama' => '', + ), + 'feature_excerpt_generation' => array( + 'openai_chatgpt' => '', + 'googleai_gemini_api' => '', + 'azure_openai' => '', + 'xai_grok' => '', + 'ollama' => '', + ), + 'feature_content_generation' => array( + 'openai_chatgpt' => '', + 'azure_openai' => '', + 'ollama' => '', + ), + 'feature_content_resizing' => array( + 'openai_chatgpt' => '', + 'googleai_gemini_api' => '', + 'azure_openai' => '', + 'xai_grok' => '', + 'ollama' => '', + ), + 'feature_key_takeaways' => array(), + 'feature_text_to_speech_generation' => array(), + 'feature_smart_404' => array(), + 'feature_term_cleanup' => array(), + 'feature_descriptive_text_generator' => array(), + 'feature_image_tags_generator' => array(), + 'feature_image_to_text_generator' => array(), + 'feature_image_cropping' => array(), + 'feature_pdf_to_text_generation' => array(), + 'feature_moderation' => array(), + 'feature_recommended_content' => array(), + ), ]; wp_localize_script( diff --git a/package-lock.json b/package-lock.json index 2f836e16d..62f91a0bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@wordpress/icons": "^10.17.0", "choices.js": "^11.1.0", "classnames": "^2.5.1", + "marked": "^16.0.0", "motion": "^12.4.10", "react-router-dom": "^7.5.2", "tippy.js": "^6.3.7" @@ -15736,6 +15737,19 @@ "markdown-it": "bin/markdown-it.mjs" } }, + "node_modules/jsdoc/node_modules/marked": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz", + "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==", + "dev": true, + "license": "MIT", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 12" + } + }, "node_modules/jsdoc/node_modules/mdurl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", @@ -17175,14 +17189,15 @@ "license": "MIT" }, "node_modules/marked": { - "version": "4.3.0", - "dev": true, + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-16.0.0.tgz", + "integrity": "sha512-MUKMXDjsD/eptB7GPzxo4xcnLS6oo7/RHimUMHEDRhUooPwmN9BEpMl7AEOJv3bmso169wHI2wUF9VQgL7zfmA==", "license": "MIT", "bin": { "marked": "bin/marked.js" }, "engines": { - "node": ">= 12" + "node": ">= 20" } }, "node_modules/marky": { diff --git a/package.json b/package.json index b161bc17d..723ee85de 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "@wordpress/icons": "^10.17.0", "choices.js": "^11.1.0", "classnames": "^2.5.1", + "marked": "^16.0.0", "motion": "^12.4.10", "react-router-dom": "^7.5.2", "tippy.js": "^6.3.7" diff --git a/src/js/settings/components/provider-settings/azure-openai.js b/src/js/settings/components/provider-settings/azure-openai.js index 9a6b9b016..9c6ee5cdf 100644 --- a/src/js/settings/components/provider-settings/azure-openai.js +++ b/src/js/settings/components/provider-settings/azure-openai.js @@ -12,6 +12,7 @@ import { __ } from '@wordpress/i18n'; import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { useFeatureContext } from '../feature-settings/context'; +import { SetupInstruction } from './setup-instruction'; /** * Component for Azure OpenAI Provider settings. @@ -52,6 +53,7 @@ export const AzureOpenAISettings = ( { <> { ! isConfigured && ( <> + } diff --git a/src/js/settings/components/provider-settings/google-gemini-api.js b/src/js/settings/components/provider-settings/google-gemini-api.js index 5ac90eeb3..98beac087 100644 --- a/src/js/settings/components/provider-settings/google-gemini-api.js +++ b/src/js/settings/components/provider-settings/google-gemini-api.js @@ -11,6 +11,7 @@ import { __ } from '@wordpress/i18n'; */ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; +import { SetupInstruction } from './setup-instruction'; /** * Component for Google AI (Gemini API) Provider settings. @@ -50,6 +51,7 @@ export const GoogleAIGeminiAPISettings = ( { isConfigured = false } ) => { return ( <> + } diff --git a/src/js/settings/components/provider-settings/ibm-watson-nlu.js b/src/js/settings/components/provider-settings/ibm-watson-nlu.js index fb70ff79d..b7b5d8aeb 100644 --- a/src/js/settings/components/provider-settings/ibm-watson-nlu.js +++ b/src/js/settings/components/provider-settings/ibm-watson-nlu.js @@ -14,6 +14,7 @@ import { __ } from '@wordpress/i18n'; */ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; +import { SetupInstruction } from './setup-instruction'; /** * Component for IBM Watson NLU Provider settings. @@ -60,6 +61,7 @@ export const IBMWatsonNLUSettings = ( { isConfigured = false } ) => { return ( <> + { } return ( - + <> + + + ); }; diff --git a/src/js/settings/components/provider-settings/ollama.js b/src/js/settings/components/provider-settings/ollama.js index 7f0e0401c..ae27438b9 100644 --- a/src/js/settings/components/provider-settings/ollama.js +++ b/src/js/settings/components/provider-settings/ollama.js @@ -8,6 +8,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; */ import { STORE_NAME } from '../../data/store'; import { OllamaBaseSettings } from './ollama-base'; +import { SetupInstruction } from './setup-instruction'; /** * Component for Ollama Provider settings. @@ -34,10 +35,13 @@ export const OllamaSettings = ( { isConfigured = false } ) => { } return ( - + <> + + + ); }; diff --git a/src/js/settings/components/provider-settings/openai-chatgpt.js b/src/js/settings/components/provider-settings/openai-chatgpt.js index f1f2c8b86..73e48c264 100644 --- a/src/js/settings/components/provider-settings/openai-chatgpt.js +++ b/src/js/settings/components/provider-settings/openai-chatgpt.js @@ -13,6 +13,7 @@ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { useFeatureContext } from '../feature-settings/context'; import { PromptRepeater } from '../feature-additional-settings/prompt-repeater'; +import { SetupInstruction } from './setup-instruction'; /** * Component for OpenAI ChatGPT Provider settings. @@ -71,17 +72,20 @@ export const OpenAIChatGPTSettings = ( { isConfigured = false } ) => { return ( <> { ! isConfigured && ( - } - > - onChange( { api_key: value } ) } - /> - + <> + + } + > + onChange( { api_key: value } ) } + /> + + ) } { [ 'feature_content_resizing', diff --git a/src/js/settings/components/provider-settings/openai-embeddings.js b/src/js/settings/components/provider-settings/openai-embeddings.js index b695c7734..1530d57e1 100644 --- a/src/js/settings/components/provider-settings/openai-embeddings.js +++ b/src/js/settings/components/provider-settings/openai-embeddings.js @@ -14,6 +14,7 @@ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { OpenAISettings } from './openai'; import { useFeatureContext } from '../feature-settings/context'; +import { SetupInstruction } from './setup-instruction'; /** * React Component for OpenAI Embeddings settings. @@ -38,10 +39,13 @@ export const OpenAIEmbeddingsSettings = ( { isConfigured = false } ) => { return ( <> { ! isConfigured && ( - + <> + + + ) } { [ 'feature_recommended_content' ].includes( featureName ) && ( diff --git a/src/js/settings/components/provider-settings/setup-instruction.js b/src/js/settings/components/provider-settings/setup-instruction.js new file mode 100644 index 000000000..8da3177a8 --- /dev/null +++ b/src/js/settings/components/provider-settings/setup-instruction.js @@ -0,0 +1,46 @@ +/** + * WordPress dependencies + */ +import { Panel, PanelBody } from '@wordpress/components'; +import { useState } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import { SettingsRow } from '../settings-row'; +import { useFeatureContext } from '../feature-settings/context'; + +/** + * External Dependencies + */ +import { marked } from 'marked'; + +export const SetupInstruction = ( { provider } ) => { + const { featureName } = useFeatureContext(); + const [ readmeContent ] = useState( + ClassifAI.instruction[ featureName ][ provider ] || '' + ); + const instruction = marked.parse( readmeContent || '' ); + + return ( + + + + { instruction ? ( +
+ ) : ( +

+ { __( 'No instructions available.', 'classifai' ) } +

+ ) } + + + + ); +}; diff --git a/src/js/settings/components/provider-settings/xai-grok.js b/src/js/settings/components/provider-settings/xai-grok.js index 74eeeaa6b..619e2a63a 100644 --- a/src/js/settings/components/provider-settings/xai-grok.js +++ b/src/js/settings/components/provider-settings/xai-grok.js @@ -13,6 +13,7 @@ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { useFeatureContext } from '../feature-settings/context'; import { PromptRepeater } from '../feature-additional-settings/prompt-repeater'; +import { SetupInstruction } from './setup-instruction'; /** * Component for xAI Grok Provider settings. @@ -71,17 +72,20 @@ export const XAIGrokSettings = ( { isConfigured = false } ) => { return ( <> { ! isConfigured && ( - } - > - onChange( { api_key: value } ) } - /> - + <> + + } + > + onChange( { api_key: value } ) } + /> + + ) } { [ 'feature_content_resizing', From 598ed6f50e3ce26155cef6f0f33878a80074da41 Mon Sep 17 00:00:00 2001 From: Bunty Date: Sun, 13 Jul 2025 14:40:53 +0530 Subject: [PATCH 02/20] Add popup modal to display AI setup instructions to users - A question mark icon beside "Select a Provider" label - When we click on the icon, instruction of specific AI configuration will be displayed in a popup modal - Used "Modal" component from @wordpress/components --- .../provider-settings/azure-openai.js | 2 - .../provider-settings/google-gemini-api.js | 2 - .../provider-settings/ibm-watson-nlu.js | 2 - .../components/provider-settings/index.js | 1 + .../provider-settings/ollama-embeddings.js | 14 ++-- .../components/provider-settings/ollama.js | 14 ++-- .../provider-settings/openai-chatgpt.js | 26 ++++---- .../provider-settings/openai-embeddings.js | 12 ++-- .../provider-settings/setup-instruction.js | 64 ++++++++++++------- .../components/provider-settings/xai-grok.js | 26 ++++---- .../settings/components/settings-row/index.js | 8 ++- src/scss/settings.scss | 25 ++++++++ 12 files changed, 110 insertions(+), 86 deletions(-) diff --git a/src/js/settings/components/provider-settings/azure-openai.js b/src/js/settings/components/provider-settings/azure-openai.js index 9c6ee5cdf..9a6b9b016 100644 --- a/src/js/settings/components/provider-settings/azure-openai.js +++ b/src/js/settings/components/provider-settings/azure-openai.js @@ -12,7 +12,6 @@ import { __ } from '@wordpress/i18n'; import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { useFeatureContext } from '../feature-settings/context'; -import { SetupInstruction } from './setup-instruction'; /** * Component for Azure OpenAI Provider settings. @@ -53,7 +52,6 @@ export const AzureOpenAISettings = ( { <> { ! isConfigured && ( <> - } diff --git a/src/js/settings/components/provider-settings/google-gemini-api.js b/src/js/settings/components/provider-settings/google-gemini-api.js index 98beac087..5ac90eeb3 100644 --- a/src/js/settings/components/provider-settings/google-gemini-api.js +++ b/src/js/settings/components/provider-settings/google-gemini-api.js @@ -11,7 +11,6 @@ import { __ } from '@wordpress/i18n'; */ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; -import { SetupInstruction } from './setup-instruction'; /** * Component for Google AI (Gemini API) Provider settings. @@ -51,7 +50,6 @@ export const GoogleAIGeminiAPISettings = ( { isConfigured = false } ) => { return ( <> - } diff --git a/src/js/settings/components/provider-settings/ibm-watson-nlu.js b/src/js/settings/components/provider-settings/ibm-watson-nlu.js index b7b5d8aeb..fb70ff79d 100644 --- a/src/js/settings/components/provider-settings/ibm-watson-nlu.js +++ b/src/js/settings/components/provider-settings/ibm-watson-nlu.js @@ -14,7 +14,6 @@ import { __ } from '@wordpress/i18n'; */ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; -import { SetupInstruction } from './setup-instruction'; /** * Component for IBM Watson NLU Provider settings. @@ -61,7 +60,6 @@ export const IBMWatsonNLUSettings = ( { isConfigured = false } ) => { return ( <> - { { ! configured && ( { } return ( - <> - - - + ); }; diff --git a/src/js/settings/components/provider-settings/ollama.js b/src/js/settings/components/provider-settings/ollama.js index ae27438b9..7f0e0401c 100644 --- a/src/js/settings/components/provider-settings/ollama.js +++ b/src/js/settings/components/provider-settings/ollama.js @@ -8,7 +8,6 @@ import { useSelect, useDispatch } from '@wordpress/data'; */ import { STORE_NAME } from '../../data/store'; import { OllamaBaseSettings } from './ollama-base'; -import { SetupInstruction } from './setup-instruction'; /** * Component for Ollama Provider settings. @@ -35,13 +34,10 @@ export const OllamaSettings = ( { isConfigured = false } ) => { } return ( - <> - - - + ); }; diff --git a/src/js/settings/components/provider-settings/openai-chatgpt.js b/src/js/settings/components/provider-settings/openai-chatgpt.js index 73e48c264..f1f2c8b86 100644 --- a/src/js/settings/components/provider-settings/openai-chatgpt.js +++ b/src/js/settings/components/provider-settings/openai-chatgpt.js @@ -13,7 +13,6 @@ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { useFeatureContext } from '../feature-settings/context'; import { PromptRepeater } from '../feature-additional-settings/prompt-repeater'; -import { SetupInstruction } from './setup-instruction'; /** * Component for OpenAI ChatGPT Provider settings. @@ -72,20 +71,17 @@ export const OpenAIChatGPTSettings = ( { isConfigured = false } ) => { return ( <> { ! isConfigured && ( - <> - - } - > - onChange( { api_key: value } ) } - /> - - + } + > + onChange( { api_key: value } ) } + /> + ) } { [ 'feature_content_resizing', diff --git a/src/js/settings/components/provider-settings/openai-embeddings.js b/src/js/settings/components/provider-settings/openai-embeddings.js index 1530d57e1..b695c7734 100644 --- a/src/js/settings/components/provider-settings/openai-embeddings.js +++ b/src/js/settings/components/provider-settings/openai-embeddings.js @@ -14,7 +14,6 @@ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { OpenAISettings } from './openai'; import { useFeatureContext } from '../feature-settings/context'; -import { SetupInstruction } from './setup-instruction'; /** * React Component for OpenAI Embeddings settings. @@ -39,13 +38,10 @@ export const OpenAIEmbeddingsSettings = ( { isConfigured = false } ) => { return ( <> { ! isConfigured && ( - <> - - - + ) } { [ 'feature_recommended_content' ].includes( featureName ) && ( diff --git a/src/js/settings/components/provider-settings/setup-instruction.js b/src/js/settings/components/provider-settings/setup-instruction.js index 8da3177a8..bcb5ad417 100644 --- a/src/js/settings/components/provider-settings/setup-instruction.js +++ b/src/js/settings/components/provider-settings/setup-instruction.js @@ -1,46 +1,64 @@ +/* global ClassifAI */ /** * WordPress dependencies */ -import { Panel, PanelBody } from '@wordpress/components'; +import { Button, Modal } from '@wordpress/components'; import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import { SettingsRow } from '../settings-row'; import { useFeatureContext } from '../feature-settings/context'; /** * External Dependencies */ import { marked } from 'marked'; +import { useEffect } from 'react'; +import { getFeature } from '../../utils/utils'; export const SetupInstruction = ( { provider } ) => { const { featureName } = useFeatureContext(); - const [ readmeContent ] = useState( - ClassifAI.instruction[ featureName ][ provider ] || '' - ); - const instruction = marked.parse( readmeContent || '' ); + const [ isOpen, setOpen ] = useState( false ); + const [ readmeContent, setReadmeContent ] = useState( '' ); + const [ instructionTitle, setInstructionTitle ] = useState( '' ); + const openModal = () => setOpen( true ); + const closeModal = () => setOpen( false ); + const feature = getFeature( featureName ); + + useEffect( () => { + setReadmeContent( + ClassifAI.instruction[ featureName ][ provider ] || + 'No Instruction found' + ); + setInstructionTitle( feature.providers[ provider ] || '' ); + }, [ provider, featureName, feature.providers ] ); + + const instruction = marked.parse( readmeContent ); return ( - - - + + { isOpen && ( + - { instruction ? ( -
- ) : ( -

- { __( 'No instructions available.', 'classifai' ) } -

- ) } - - - +
+ + ) } + ); }; diff --git a/src/js/settings/components/provider-settings/xai-grok.js b/src/js/settings/components/provider-settings/xai-grok.js index 619e2a63a..74eeeaa6b 100644 --- a/src/js/settings/components/provider-settings/xai-grok.js +++ b/src/js/settings/components/provider-settings/xai-grok.js @@ -13,7 +13,6 @@ import { SettingsRow } from '../settings-row'; import { STORE_NAME } from '../../data/store'; import { useFeatureContext } from '../feature-settings/context'; import { PromptRepeater } from '../feature-additional-settings/prompt-repeater'; -import { SetupInstruction } from './setup-instruction'; /** * Component for xAI Grok Provider settings. @@ -72,20 +71,17 @@ export const XAIGrokSettings = ( { isConfigured = false } ) => { return ( <> { ! isConfigured && ( - <> - - } - > - onChange( { api_key: value } ) } - /> - - + } + > + onChange( { api_key: value } ) } + /> + ) } { [ 'feature_content_resizing', diff --git a/src/js/settings/components/settings-row/index.js b/src/js/settings/components/settings-row/index.js index 341d65999..e2af89388 100644 --- a/src/js/settings/components/settings-row/index.js +++ b/src/js/settings/components/settings-row/index.js @@ -2,6 +2,7 @@ * External dependencies */ import classNames from 'classnames'; +import { SetupInstruction } from '../provider-settings/setup-instruction'; /** * Settings row component. @@ -13,7 +14,12 @@ import classNames from 'classnames'; export const SettingsRow = ( props ) => { return (
-
{ props.label }
+
+ { props.label } + { props.instructionProvider && ( + + ) } +
{ props.children }
diff --git a/src/scss/settings.scss b/src/scss/settings.scss index 35fe31414..578efebd7 100644 --- a/src/scss/settings.scss +++ b/src/scss/settings.scss @@ -95,11 +95,25 @@ } .settings-label { + display: flex; align-items: center; font-weight: bold; flex-shrink: 0; flex: 20%; padding: 12px 0px; + + .settings-info-button { + + &:hover { + background: none; + outline: none; + } + + &:focus { + box-shadow: none; + outline: none; + } + } } .settings-control { @@ -634,3 +648,14 @@ .classifai-settings__main-title { margin-top: 2.5rem; } + +.tools_page_classifai { + + .settings-instruction-modal { + + ul { + list-style: unset; + padding: revert; + } + } +} From 2a254d46169f9aaac8093f99adde8ecee8f99699 Mon Sep 17 00:00:00 2001 From: Bunty Date: Sun, 13 Jul 2025 20:26:42 +0530 Subject: [PATCH 03/20] Set configuration instructions for all features --- includes/Classifai/Admin/Settings.php | 1 + .../Features/AudioTranscriptsGeneration.php | 10 ++++ .../Classifai/Features/Classification.php | 13 +++++ .../Classifai/Features/ContentGeneration.php | 12 +++++ .../Classifai/Features/ContentResizing.php | 15 ++++++ .../Features/DescriptiveTextGenerator.php | 13 +++++ .../Classifai/Features/ExcerptGeneration.php | 15 ++++++ includes/Classifai/Features/Feature.php | 29 +++++++++++ includes/Classifai/Features/ImageCropping.php | 10 ++++ .../Classifai/Features/ImageGeneration.php | 11 ++++ .../Classifai/Features/ImageTagsGenerator.php | 12 +++++ .../Features/ImageTextExtraction.php | 12 +++++ includes/Classifai/Features/KeyTakeaways.php | 12 +++++ includes/Classifai/Features/Moderation.php | 10 ++++ .../Classifai/Features/PDFTextExtraction.php | 10 ++++ .../Classifai/Features/RecommendedContent.php | 11 ++++ includes/Classifai/Features/Smart404.php | 11 ++++ includes/Classifai/Features/TermCleanup.php | 11 ++++ includes/Classifai/Features/TextToSpeech.php | 12 +++++ .../Classifai/Features/TitleGeneration.php | 15 ++++++ includes/Classifai/Plugin.php | 52 ------------------- .../provider-settings/setup-instruction.js | 16 ++++-- 22 files changed, 256 insertions(+), 57 deletions(-) diff --git a/includes/Classifai/Admin/Settings.php b/includes/Classifai/Admin/Settings.php index 3a9934bdc..078438496 100644 --- a/includes/Classifai/Admin/Settings.php +++ b/includes/Classifai/Admin/Settings.php @@ -170,6 +170,7 @@ public function get_features( bool $with_instance = false ): array { 'roles' => $feature->get_roles(), 'enable_description' => $feature->get_enable_description(), 'taxonomies' => $feature->get_taxonomies(), + 'providers_data' => $feature->supported_providers_data, ); // Add taxonomies under post types for language processing features to allow filtering by post type. diff --git a/includes/Classifai/Features/AudioTranscriptsGeneration.php b/includes/Classifai/Features/AudioTranscriptsGeneration.php index f1c26ecc4..726b63ff5 100644 --- a/includes/Classifai/Features/AudioTranscriptsGeneration.php +++ b/includes/Classifai/Features/AudioTranscriptsGeneration.php @@ -36,6 +36,16 @@ public function __construct() { $this->supported_providers = [ SpeechToText::ID => __( 'OpenAI Audio Transcription', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + SpeechToText::ID => preg_match('/## Set Up Audio Transcripts Generation \(via OpenAI Speech to Text\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index e765ae4ef..13b4d9d51 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -46,6 +46,19 @@ public function __construct() { AzureEmbeddings::ID => __( 'Azure OpenAI Embeddings', 'classifai' ), OllamaEmbeddings::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + NLU::ID => preg_match('/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAIEmbeddings::ID => preg_match('/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + AzureEmbeddings::ID => '', + OllamaEmbeddings::ID => '', + ], + ]; } /** diff --git a/includes/Classifai/Features/ContentGeneration.php b/includes/Classifai/Features/ContentGeneration.php index 76667ff12..d8c62dcc4 100644 --- a/includes/Classifai/Features/ContentGeneration.php +++ b/includes/Classifai/Features/ContentGeneration.php @@ -95,6 +95,18 @@ public function __construct() { OpenAI::ID => __( 'Azure OpenAI', 'classifai' ), Ollama::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index f97a4b0f5..6cfe63cc1 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -59,6 +59,21 @@ public function __construct() { ChromeAI::ID => __( 'Chrome AI (experimental)', 'classifai' ), Ollama::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + GeminiAPI::ID => preg_match('/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Grok::ID => '', + ChromeAI::ID => '', + Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index d49b3f9ba..08003382a 100644 --- a/includes/Classifai/Features/DescriptiveTextGenerator.php +++ b/includes/Classifai/Features/DescriptiveTextGenerator.php @@ -47,6 +47,19 @@ public function __construct() { Grok::ID => __( 'xAI Grok', 'classifai' ), OllamaMM::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ChatGPT::ID => '', + Grok::ID => '', + OllamaMM::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index e0bea64d0..37c8959ec 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -59,6 +59,21 @@ public function __construct() { ChromeAI::ID => __( 'Chrome AI (experimental)', 'classifai' ), Ollama::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + GeminiAPI::ID => preg_match('/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Grok::ID => '', + ChromeAI::ID => '', + Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index c63e74cb8..3489a6a47 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -58,6 +58,13 @@ abstract class Feature { */ public $supported_providers = []; + /** + * Array of providers data supported by the feature. + * + * @var \Classifai\Providers\Provider[] + */ + public $supported_providers_data = []; + /** * Set up necessary hooks. */ @@ -1411,4 +1418,26 @@ public function run( ...$args ) { $this ); } + + /** + * Get content from README.md file. + * + * @return string|WP_Error + */ + public function get_readme_content(): string | WP_Error { + + $readme_path = trailingslashit( CLASSIFAI_PLUGIN_DIR ) . 'README.md'; + + if ( ! file_exists( $readme_path ) ) { + return __return_empty_string(); + } + + $readme_content = file_get_contents( $readme_path ); // phpcs:ignore + + if ( false === $readme_content || ! is_string( $readme_content ) ) { + return new WP_Error( 'invalid', esc_html__( 'Readme cannot be downloaded.', 'classifai' ) ); + } + + return $readme_content; + } } diff --git a/includes/Classifai/Features/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index 766de5117..62c4ddd1a 100644 --- a/includes/Classifai/Features/ImageCropping.php +++ b/includes/Classifai/Features/ImageCropping.php @@ -43,6 +43,16 @@ public function __construct() { $this->supported_providers = [ ComputerVision::ID => __( 'Microsoft Azure AI Vision', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/ImageGeneration.php b/includes/Classifai/Features/ImageGeneration.php index 62cde445a..a4580cd9f 100644 --- a/includes/Classifai/Features/ImageGeneration.php +++ b/includes/Classifai/Features/ImageGeneration.php @@ -37,6 +37,17 @@ public function __construct() { OpenAIImages::ID => __( 'OpenAI Images', 'classifai' ), GoogleAIImagen::ID => __( 'Google AI Imagen', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + OpenAIImages::ID => preg_match('/## Set Up Image Generation \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + GoogleAIImagen::ID => preg_match('/## Set Up Image Generation \(via Google AI Imagen\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/ImageTagsGenerator.php b/includes/Classifai/Features/ImageTagsGenerator.php index faff4cc2e..866a9e24b 100644 --- a/includes/Classifai/Features/ImageTagsGenerator.php +++ b/includes/Classifai/Features/ImageTagsGenerator.php @@ -53,6 +53,18 @@ public function __construct() { ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ), OllamaMM::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ChatGPT::ID => '', + OllamaMM::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index 4d026688b..c316e06bd 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -47,6 +47,18 @@ public function __construct() { ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ), OllamaMM::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ChatGPT::ID => '', + OllamaMM::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/KeyTakeaways.php b/includes/Classifai/Features/KeyTakeaways.php index 57387ea9f..37c2a790e 100644 --- a/includes/Classifai/Features/KeyTakeaways.php +++ b/includes/Classifai/Features/KeyTakeaways.php @@ -47,6 +47,18 @@ public function __construct() { OpenAI::ID => __( 'Azure OpenAI', 'classifai' ), Ollama::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ChatGPT::ID => '', + OpenAI::ID => '', + Ollama::ID => '', + ], + ]; } /** diff --git a/includes/Classifai/Features/Moderation.php b/includes/Classifai/Features/Moderation.php index 3ce97190f..73f50c09d 100644 --- a/includes/Classifai/Features/Moderation.php +++ b/includes/Classifai/Features/Moderation.php @@ -33,6 +33,16 @@ public function __construct() { $this->supported_providers = [ ModerationProvider::ID => __( 'OpenAI Moderation', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ModerationProvider::ID => preg_match('/## Set Up Comment Moderation \(via OpenAI Moderation\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/PDFTextExtraction.php b/includes/Classifai/Features/PDFTextExtraction.php index d2f4e4e80..d5be9e97b 100644 --- a/includes/Classifai/Features/PDFTextExtraction.php +++ b/includes/Classifai/Features/PDFTextExtraction.php @@ -35,6 +35,16 @@ public function __construct() { $this->supported_providers = [ ComputerVision::ID => __( 'Microsoft Azure AI Vision', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/RecommendedContent.php b/includes/Classifai/Features/RecommendedContent.php index 248388335..f13c783a7 100644 --- a/includes/Classifai/Features/RecommendedContent.php +++ b/includes/Classifai/Features/RecommendedContent.php @@ -34,6 +34,17 @@ public function __construct() { OpenAIEmbeddings::ID => __( 'OpenAI Embeddings', 'classifai' ), PersonalizerProvider::ID => __( 'Microsoft Azure AI Personalizer', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + OpenAIEmbeddings::ID => preg_match('/## Set Up Recommended Content \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + PersonalizerProvider::ID => '', + ], + ]; } /** diff --git a/includes/Classifai/Features/Smart404.php b/includes/Classifai/Features/Smart404.php index c0a5283ef..83edb28bf 100644 --- a/includes/Classifai/Features/Smart404.php +++ b/includes/Classifai/Features/Smart404.php @@ -36,6 +36,17 @@ public function __construct() { OpenAIEmbeddings::ID => __( 'OpenAI Embeddings', 'classifai' ), AzureEmbeddings::ID => __( 'Azure OpenAI Embeddings', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + OpenAIEmbeddings::ID => preg_match('/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + AzureEmbeddings::ID => preg_match('/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/TermCleanup.php b/includes/Classifai/Features/TermCleanup.php index 76fc794ca..11bc624c2 100644 --- a/includes/Classifai/Features/TermCleanup.php +++ b/includes/Classifai/Features/TermCleanup.php @@ -66,6 +66,17 @@ public function __construct() { OpenAIEmbeddings::ID => __( 'OpenAI Embeddings', 'classifai' ), AzureEmbeddings::ID => __( 'Azure OpenAI Embeddings', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + OpenAIEmbeddings::ID => preg_match('/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + AzureEmbeddings::ID => preg_match('/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index 8b1be189d..b61829ec3 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -69,6 +69,18 @@ public function __construct() { Speech::ID => __( 'Microsoft Azure AI Speech', 'classifai' ), OpenAITTS::ID => __( 'OpenAI Text to Speech', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + AmazonPolly::ID => preg_match('/## Set Up Text to Speech \(via Amazon Polly\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Speech::ID => preg_match('/## Set Up Text to Speech \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAITTS::ID => preg_match('/## Set Up Text to Speech \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Features/TitleGeneration.php b/includes/Classifai/Features/TitleGeneration.php index 2f73c803c..6070f4721 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -59,6 +59,21 @@ public function __construct() { ChromeAI::ID => __( 'Chrome AI (experimental)', 'classifai' ), Ollama::ID => __( 'Ollama', 'classifai' ), ]; + + // Get readme content. + $readme_content = $this->get_readme_content(); + + // Contains supported providers data. + $this->supported_providers_data = [ + 'instructions' => [ + ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + GeminiAPI::ID => preg_match('/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Grok::ID => '', + ChromeAI::ID => '', + Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ], + ]; } /** diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index f218c8473..3f6d2d50c 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -186,13 +186,6 @@ public function enqueue_admin_assets() { true ); - $readme_path = trailingslashit( CLASSIFAI_PLUGIN_DIR ) . 'README.md'; - $readme_content = ''; - - if ( file_exists( $readme_path ) ) { - $readme_content = file_get_contents( $readme_path ); - } - $localize_data = [ 'api_password' => __( 'API Password', 'classifai' ), 'api_key' => __( 'API Key', 'classifai' ), @@ -202,51 +195,6 @@ public function enqueue_admin_assets() { 'opt_out_enabled_features' => array_keys( $allowed_features ), 'profile_url' => esc_url( get_edit_profile_url( get_current_user_id() ) . '#classifai-profile-features-section' ), 'plugin_url' => CLASSIFAI_PLUGIN_URL, - 'instruction' => array( - 'feature_classification' => array( - 'ibm_watson_nlu' => preg_match('/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - 'openai_embeddings' => preg_match('/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - 'azure_openai_embeddings' => '', - 'ollama_embeddings' => '', - ), - 'feature_title_generation' => array( - 'openai_chatgpt' => '', - 'googleai_gemini_api' => '', - 'azure_openai' => '', - 'xai_grok' => '', - 'ollama' => '', - ), - 'feature_excerpt_generation' => array( - 'openai_chatgpt' => '', - 'googleai_gemini_api' => '', - 'azure_openai' => '', - 'xai_grok' => '', - 'ollama' => '', - ), - 'feature_content_generation' => array( - 'openai_chatgpt' => '', - 'azure_openai' => '', - 'ollama' => '', - ), - 'feature_content_resizing' => array( - 'openai_chatgpt' => '', - 'googleai_gemini_api' => '', - 'azure_openai' => '', - 'xai_grok' => '', - 'ollama' => '', - ), - 'feature_key_takeaways' => array(), - 'feature_text_to_speech_generation' => array(), - 'feature_smart_404' => array(), - 'feature_term_cleanup' => array(), - 'feature_descriptive_text_generator' => array(), - 'feature_image_tags_generator' => array(), - 'feature_image_to_text_generator' => array(), - 'feature_image_cropping' => array(), - 'feature_pdf_to_text_generation' => array(), - 'feature_moderation' => array(), - 'feature_recommended_content' => array(), - ), ]; wp_localize_script( diff --git a/src/js/settings/components/provider-settings/setup-instruction.js b/src/js/settings/components/provider-settings/setup-instruction.js index bcb5ad417..1b9b0130a 100644 --- a/src/js/settings/components/provider-settings/setup-instruction.js +++ b/src/js/settings/components/provider-settings/setup-instruction.js @@ -1,4 +1,3 @@ -/* global ClassifAI */ /** * WordPress dependencies */ @@ -29,11 +28,18 @@ export const SetupInstruction = ( { provider } ) => { useEffect( () => { setReadmeContent( - ClassifAI.instruction[ featureName ][ provider ] || - 'No Instruction found' + feature.providers_data.instructions[ provider ] || + __( 'No Instruction found', 'classifai' ) ); - setInstructionTitle( feature.providers[ provider ] || '' ); - }, [ provider, featureName, feature.providers ] ); + setInstructionTitle( + `${ feature.label + ' - ' + feature.providers[ provider ] }` || '' + ); + }, [ + provider, + feature.providers, + feature.providers_data.instructions, + feature.label, + ] ); const instruction = marked.parse( readmeContent ); From b35091b1d291daf0e49bc5332f9c81995b367365 Mon Sep 17 00:00:00 2001 From: Bunty Date: Sun, 13 Jul 2025 20:55:59 +0530 Subject: [PATCH 04/20] phpcs fixes --- .../Classifai/Features/AudioTranscriptsGeneration.php | 2 +- includes/Classifai/Features/Classification.php | 4 ++-- includes/Classifai/Features/ContentGeneration.php | 6 +++--- includes/Classifai/Features/ContentResizing.php | 8 ++++---- includes/Classifai/Features/DescriptiveTextGenerator.php | 4 ++-- includes/Classifai/Features/ExcerptGeneration.php | 8 ++++---- includes/Classifai/Features/Feature.php | 2 +- includes/Classifai/Features/ImageCropping.php | 2 +- includes/Classifai/Features/ImageGeneration.php | 4 ++-- includes/Classifai/Features/ImageTagsGenerator.php | 4 ++-- includes/Classifai/Features/ImageTextExtraction.php | 4 ++-- includes/Classifai/Features/Moderation.php | 2 +- includes/Classifai/Features/PDFTextExtraction.php | 2 +- includes/Classifai/Features/RecommendedContent.php | 2 +- includes/Classifai/Features/Smart404.php | 4 ++-- includes/Classifai/Features/TermCleanup.php | 4 ++-- includes/Classifai/Features/TextToSpeech.php | 6 +++--- includes/Classifai/Features/TitleGeneration.php | 8 ++++---- 18 files changed, 38 insertions(+), 38 deletions(-) diff --git a/includes/Classifai/Features/AudioTranscriptsGeneration.php b/includes/Classifai/Features/AudioTranscriptsGeneration.php index 726b63ff5..3b6a31123 100644 --- a/includes/Classifai/Features/AudioTranscriptsGeneration.php +++ b/includes/Classifai/Features/AudioTranscriptsGeneration.php @@ -43,7 +43,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - SpeechToText::ID => preg_match('/## Set Up Audio Transcripts Generation \(via OpenAI Speech to Text\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + SpeechToText::ID => preg_match( '/## Set Up Audio Transcripts Generation \(via OpenAI Speech to Text\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index 13b4d9d51..33a20f0aa 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -53,8 +53,8 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - NLU::ID => preg_match('/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - OpenAIEmbeddings::ID => preg_match('/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + NLU::ID => preg_match( '/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAIEmbeddings::ID => preg_match( '/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => '', OllamaEmbeddings::ID => '', ], diff --git a/includes/Classifai/Features/ContentGeneration.php b/includes/Classifai/Features/ContentGeneration.php index d8c62dcc4..b446689cd 100644 --- a/includes/Classifai/Features/ContentGeneration.php +++ b/includes/Classifai/Features/ContentGeneration.php @@ -102,9 +102,9 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index 6cfe63cc1..08fe880ac 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -66,12 +66,12 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - GeminiAPI::ID => preg_match('/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Grok::ID => '', ChromeAI::ID => '', - Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index 08003382a..8d9233a03 100644 --- a/includes/Classifai/Features/DescriptiveTextGenerator.php +++ b/includes/Classifai/Features/DescriptiveTextGenerator.php @@ -54,10 +54,10 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', Grok::ID => '', - OllamaMM::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index 37c8959ec..1044fc629 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -66,12 +66,12 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - GeminiAPI::ID => preg_match('/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Grok::ID => '', ChromeAI::ID => '', - Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 3489a6a47..82a67f7a1 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1424,7 +1424,7 @@ public function run( ...$args ) { * * @return string|WP_Error */ - public function get_readme_content(): string | WP_Error { + public function get_readme_content() { $readme_path = trailingslashit( CLASSIFAI_PLUGIN_DIR ) . 'README.md'; diff --git a/includes/Classifai/Features/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index 62c4ddd1a..233bf52b9 100644 --- a/includes/Classifai/Features/ImageCropping.php +++ b/includes/Classifai/Features/ImageCropping.php @@ -50,7 +50,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/ImageGeneration.php b/includes/Classifai/Features/ImageGeneration.php index a4580cd9f..ce37a9bbf 100644 --- a/includes/Classifai/Features/ImageGeneration.php +++ b/includes/Classifai/Features/ImageGeneration.php @@ -44,8 +44,8 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - OpenAIImages::ID => preg_match('/## Set Up Image Generation \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - GoogleAIImagen::ID => preg_match('/## Set Up Image Generation \(via Google AI Imagen\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAIImages::ID => preg_match( '/## Set Up Image Generation \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GoogleAIImagen::ID => preg_match( '/## Set Up Image Generation \(via Google AI Imagen\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/ImageTagsGenerator.php b/includes/Classifai/Features/ImageTagsGenerator.php index 866a9e24b..198844a7d 100644 --- a/includes/Classifai/Features/ImageTagsGenerator.php +++ b/includes/Classifai/Features/ImageTagsGenerator.php @@ -60,9 +60,9 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', - OllamaMM::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index c316e06bd..1e9f2e65c 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -54,9 +54,9 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', - OllamaMM::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/Moderation.php b/includes/Classifai/Features/Moderation.php index 73f50c09d..f748dbde3 100644 --- a/includes/Classifai/Features/Moderation.php +++ b/includes/Classifai/Features/Moderation.php @@ -40,7 +40,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ModerationProvider::ID => preg_match('/## Set Up Comment Moderation \(via OpenAI Moderation\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ModerationProvider::ID => preg_match( '/## Set Up Comment Moderation \(via OpenAI Moderation\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/PDFTextExtraction.php b/includes/Classifai/Features/PDFTextExtraction.php index d5be9e97b..51d373015 100644 --- a/includes/Classifai/Features/PDFTextExtraction.php +++ b/includes/Classifai/Features/PDFTextExtraction.php @@ -42,7 +42,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ComputerVision::ID => preg_match('/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/RecommendedContent.php b/includes/Classifai/Features/RecommendedContent.php index f13c783a7..07ad219ea 100644 --- a/includes/Classifai/Features/RecommendedContent.php +++ b/includes/Classifai/Features/RecommendedContent.php @@ -41,7 +41,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - OpenAIEmbeddings::ID => preg_match('/## Set Up Recommended Content \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAIEmbeddings::ID => preg_match( '/## Set Up Recommended Content \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', PersonalizerProvider::ID => '', ], ]; diff --git a/includes/Classifai/Features/Smart404.php b/includes/Classifai/Features/Smart404.php index 83edb28bf..19d5adf1d 100644 --- a/includes/Classifai/Features/Smart404.php +++ b/includes/Classifai/Features/Smart404.php @@ -43,8 +43,8 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - OpenAIEmbeddings::ID => preg_match('/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - AzureEmbeddings::ID => preg_match('/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAIEmbeddings::ID => preg_match( '/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + AzureEmbeddings::ID => preg_match( '/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/TermCleanup.php b/includes/Classifai/Features/TermCleanup.php index 11bc624c2..af1b60567 100644 --- a/includes/Classifai/Features/TermCleanup.php +++ b/includes/Classifai/Features/TermCleanup.php @@ -73,8 +73,8 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - OpenAIEmbeddings::ID => preg_match('/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - AzureEmbeddings::ID => preg_match('/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + OpenAIEmbeddings::ID => preg_match( '/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + AzureEmbeddings::ID => preg_match( '/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index b61829ec3..b98b14ada 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -76,9 +76,9 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - AmazonPolly::ID => preg_match('/## Set Up Text to Speech \(via Amazon Polly\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - Speech::ID => preg_match('/## Set Up Text to Speech \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - OpenAITTS::ID => preg_match('/## Set Up Text to Speech \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + AmazonPolly::ID => preg_match( '/## Set Up Text to Speech \(via Amazon Polly\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Speech::ID => preg_match( '/## Set Up Text to Speech \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAITTS::ID => preg_match( '/## Set Up Text to Speech \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/TitleGeneration.php b/includes/Classifai/Features/TitleGeneration.php index 6070f4721..0c9e4a0a0 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -66,12 +66,12 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ 'instructions' => [ - ChatGPT::ID => preg_match('/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - GeminiAPI::ID => preg_match('/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', - OpenAI::ID => preg_match('/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Grok::ID => '', ChromeAI::ID => '', - Ollama::ID => preg_match('/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches) ? $matches[1] : '', + Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } From 92c9816fe4c83b466b9b3b771d6caf2ab60b623e Mon Sep 17 00:00:00 2001 From: Bunty Date: Sun, 13 Jul 2025 22:15:05 +0530 Subject: [PATCH 05/20] Add ollama instruction --- includes/Classifai/Features/Classification.php | 2 +- includes/Classifai/Features/KeyTakeaways.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index 33a20f0aa..8fffc7126 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -56,7 +56,7 @@ public function __construct() { NLU::ID => preg_match( '/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', OpenAIEmbeddings::ID => preg_match( '/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => '', - OllamaEmbeddings::ID => '', + OllamaEmbeddings::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/KeyTakeaways.php b/includes/Classifai/Features/KeyTakeaways.php index 37c2a790e..4f4188698 100644 --- a/includes/Classifai/Features/KeyTakeaways.php +++ b/includes/Classifai/Features/KeyTakeaways.php @@ -56,7 +56,7 @@ public function __construct() { 'instructions' => [ ChatGPT::ID => '', OpenAI::ID => '', - Ollama::ID => '', + Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } From 451743e4447f97446abe6d9b312d76aa48e23a79 Mon Sep 17 00:00:00 2001 From: Bunty Date: Wed, 16 Jul 2025 14:02:41 +0530 Subject: [PATCH 06/20] Add helper component with modal for additional info for setting field - Displays an icon next to fields as helper text - Opens a modal with detailed information when clicked --- .../Features/AudioTranscriptsGeneration.php | 2 +- .../Classifai/Features/Classification.php | 2 +- .../Classifai/Features/ContentGeneration.php | 2 +- .../Classifai/Features/ContentResizing.php | 2 +- .../Features/DescriptiveTextGenerator.php | 2 +- .../Classifai/Features/ExcerptGeneration.php | 2 +- includes/Classifai/Features/ImageCropping.php | 2 +- .../Classifai/Features/ImageGeneration.php | 2 +- .../Classifai/Features/ImageTagsGenerator.php | 2 +- .../Features/ImageTextExtraction.php | 2 +- includes/Classifai/Features/KeyTakeaways.php | 2 +- includes/Classifai/Features/Moderation.php | 2 +- .../Classifai/Features/PDFTextExtraction.php | 2 +- .../Classifai/Features/RecommendedContent.php | 2 +- includes/Classifai/Features/Smart404.php | 2 +- includes/Classifai/Features/TermCleanup.php | 2 +- includes/Classifai/Features/TextToSpeech.php | 2 +- .../Classifai/Features/TitleGeneration.php | 2 +- .../components/provider-settings/index.js | 5 +- .../field-info.js} | 50 ++++++++++++------- .../settings/components/settings-row/index.js | 7 +-- src/scss/settings.scss | 2 +- 22 files changed, 60 insertions(+), 40 deletions(-) rename src/js/settings/components/{provider-settings/setup-instruction.js => settings-row/field-info.js} (57%) diff --git a/includes/Classifai/Features/AudioTranscriptsGeneration.php b/includes/Classifai/Features/AudioTranscriptsGeneration.php index 3b6a31123..377a85b85 100644 --- a/includes/Classifai/Features/AudioTranscriptsGeneration.php +++ b/includes/Classifai/Features/AudioTranscriptsGeneration.php @@ -42,7 +42,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ SpeechToText::ID => preg_match( '/## Set Up Audio Transcripts Generation \(via OpenAI Speech to Text\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index 8fffc7126..d65dc3073 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -52,7 +52,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ NLU::ID => preg_match( '/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', OpenAIEmbeddings::ID => preg_match( '/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => '', diff --git a/includes/Classifai/Features/ContentGeneration.php b/includes/Classifai/Features/ContentGeneration.php index b446689cd..41892973e 100644 --- a/includes/Classifai/Features/ContentGeneration.php +++ b/includes/Classifai/Features/ContentGeneration.php @@ -101,7 +101,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index 08fe880ac..fc7d7112d 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -65,7 +65,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index 8d9233a03..b89825b50 100644 --- a/includes/Classifai/Features/DescriptiveTextGenerator.php +++ b/includes/Classifai/Features/DescriptiveTextGenerator.php @@ -53,7 +53,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', Grok::ID => '', diff --git a/includes/Classifai/Features/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index 1044fc629..7ac9dce85 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -65,7 +65,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/includes/Classifai/Features/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index 233bf52b9..ee68d8bf8 100644 --- a/includes/Classifai/Features/ImageCropping.php +++ b/includes/Classifai/Features/ImageCropping.php @@ -49,7 +49,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; diff --git a/includes/Classifai/Features/ImageGeneration.php b/includes/Classifai/Features/ImageGeneration.php index ce37a9bbf..dce1e8f17 100644 --- a/includes/Classifai/Features/ImageGeneration.php +++ b/includes/Classifai/Features/ImageGeneration.php @@ -43,7 +43,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ OpenAIImages::ID => preg_match( '/## Set Up Image Generation \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', GoogleAIImagen::ID => preg_match( '/## Set Up Image Generation \(via Google AI Imagen\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], diff --git a/includes/Classifai/Features/ImageTagsGenerator.php b/includes/Classifai/Features/ImageTagsGenerator.php index 198844a7d..998c44383 100644 --- a/includes/Classifai/Features/ImageTagsGenerator.php +++ b/includes/Classifai/Features/ImageTagsGenerator.php @@ -59,7 +59,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index 1e9f2e65c..81cc70937 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -53,7 +53,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/includes/Classifai/Features/KeyTakeaways.php b/includes/Classifai/Features/KeyTakeaways.php index 4f4188698..586f07107 100644 --- a/includes/Classifai/Features/KeyTakeaways.php +++ b/includes/Classifai/Features/KeyTakeaways.php @@ -53,7 +53,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ChatGPT::ID => '', OpenAI::ID => '', Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/includes/Classifai/Features/Moderation.php b/includes/Classifai/Features/Moderation.php index f748dbde3..3aa9ec8d4 100644 --- a/includes/Classifai/Features/Moderation.php +++ b/includes/Classifai/Features/Moderation.php @@ -39,7 +39,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ModerationProvider::ID => preg_match( '/## Set Up Comment Moderation \(via OpenAI Moderation\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; diff --git a/includes/Classifai/Features/PDFTextExtraction.php b/includes/Classifai/Features/PDFTextExtraction.php index 51d373015..6187a77e5 100644 --- a/includes/Classifai/Features/PDFTextExtraction.php +++ b/includes/Classifai/Features/PDFTextExtraction.php @@ -41,7 +41,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; diff --git a/includes/Classifai/Features/RecommendedContent.php b/includes/Classifai/Features/RecommendedContent.php index 07ad219ea..fe928b3c2 100644 --- a/includes/Classifai/Features/RecommendedContent.php +++ b/includes/Classifai/Features/RecommendedContent.php @@ -40,7 +40,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ OpenAIEmbeddings::ID => preg_match( '/## Set Up Recommended Content \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', PersonalizerProvider::ID => '', ], diff --git a/includes/Classifai/Features/Smart404.php b/includes/Classifai/Features/Smart404.php index 19d5adf1d..b904a8731 100644 --- a/includes/Classifai/Features/Smart404.php +++ b/includes/Classifai/Features/Smart404.php @@ -42,7 +42,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ OpenAIEmbeddings::ID => preg_match( '/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => preg_match( '/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], diff --git a/includes/Classifai/Features/TermCleanup.php b/includes/Classifai/Features/TermCleanup.php index af1b60567..7792a1ae6 100644 --- a/includes/Classifai/Features/TermCleanup.php +++ b/includes/Classifai/Features/TermCleanup.php @@ -72,7 +72,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ OpenAIEmbeddings::ID => preg_match( '/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => preg_match( '/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], diff --git a/includes/Classifai/Features/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index b98b14ada..8d82694da 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -75,7 +75,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ AmazonPolly::ID => preg_match( '/## Set Up Text to Speech \(via Amazon Polly\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Speech::ID => preg_match( '/## Set Up Text to Speech \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', OpenAITTS::ID => preg_match( '/## Set Up Text to Speech \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/includes/Classifai/Features/TitleGeneration.php b/includes/Classifai/Features/TitleGeneration.php index 0c9e4a0a0..85afbd821 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -65,7 +65,7 @@ public function __construct() { // Contains supported providers data. $this->supported_providers_data = [ - 'instructions' => [ + 'instruction' => [ ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', diff --git a/src/js/settings/components/provider-settings/index.js b/src/js/settings/components/provider-settings/index.js index 29dee4381..47f12cc3d 100644 --- a/src/js/settings/components/provider-settings/index.js +++ b/src/js/settings/components/provider-settings/index.js @@ -189,7 +189,10 @@ export const ProviderSettings = () => { { ! configured && ( { +export const FieldInfo = ( props ) => { const { featureName } = useFeatureContext(); const [ isOpen, setOpen ] = useState( false ); - const [ readmeContent, setReadmeContent ] = useState( '' ); - const [ instructionTitle, setInstructionTitle ] = useState( '' ); + const [ icon, setIcon ] = useState( 'info' ); + const [ fieldInfoContent, setFieldInfoContent ] = useState( '' ); + const [ infoTitle, setInfoTitle ] = useState( '' ); const openModal = () => setOpen( true ); const closeModal = () => setOpen( false ); const feature = getFeature( featureName ); useEffect( () => { - setReadmeContent( - feature.providers_data.instructions[ provider ] || - __( 'No Instruction found', 'classifai' ) - ); - setInstructionTitle( - `${ feature.label + ' - ' + feature.providers[ provider ] }` || '' - ); + switch ( props.fieldInfo.type ) { + case 'instruction': + setFieldInfoContent( + feature.providers_data[ props.fieldInfo.type ][ + props.fieldInfo.provider + ] || __( 'No info found.', 'classifai' ) + ); + setInfoTitle( + `${ + feature.label + + ' - ' + + feature.providers[ props.fieldInfo.provider ] + }` || '' + ); + setIcon( 'editor-help' ); + break; + + default: + break; + } }, [ - provider, + props.fieldInfo, feature.providers, feature.providers_data.instructions, feature.label, ] ); - const instruction = marked.parse( readmeContent ); - return ( <> { isOpen && ( -
+
) } diff --git a/src/js/settings/components/settings-row/index.js b/src/js/settings/components/settings-row/index.js index e2af89388..341f98cfc 100644 --- a/src/js/settings/components/settings-row/index.js +++ b/src/js/settings/components/settings-row/index.js @@ -2,7 +2,7 @@ * External dependencies */ import classNames from 'classnames'; -import { SetupInstruction } from '../provider-settings/setup-instruction'; +import { FieldInfo } from './field-info'; /** * Settings row component. @@ -12,12 +12,13 @@ import { SetupInstruction } from '../provider-settings/setup-instruction'; * @param {Object} props.children The children of the component. */ export const SettingsRow = ( props ) => { + console.log('props', props); return (
{ props.label } - { props.instructionProvider && ( - + { props.fieldInfo && ( + ) }
diff --git a/src/scss/settings.scss b/src/scss/settings.scss index 578efebd7..8c9f414ac 100644 --- a/src/scss/settings.scss +++ b/src/scss/settings.scss @@ -651,7 +651,7 @@ .tools_page_classifai { - .settings-instruction-modal { + .settings-info-modal { ul { list-style: unset; From 519748fd30aa4bc1b17400f2b50c779da5d9a7a8 Mon Sep 17 00:00:00 2001 From: Bunty Date: Wed, 16 Jul 2025 14:08:57 +0530 Subject: [PATCH 07/20] Remove debuge code --- src/js/settings/components/settings-row/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/settings/components/settings-row/index.js b/src/js/settings/components/settings-row/index.js index 341f98cfc..a08cd0703 100644 --- a/src/js/settings/components/settings-row/index.js +++ b/src/js/settings/components/settings-row/index.js @@ -12,7 +12,6 @@ import { FieldInfo } from './field-info'; * @param {Object} props.children The children of the component. */ export const SettingsRow = ( props ) => { - console.log('props', props); return (
From 2d11e51e903db2b7ad1a7ae34bd4a382bfee3252 Mon Sep 17 00:00:00 2001 From: Bunty Date: Wed, 16 Jul 2025 14:21:06 +0530 Subject: [PATCH 08/20] Add component documentation --- .../components/settings-row/field-info.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/js/settings/components/settings-row/field-info.js b/src/js/settings/components/settings-row/field-info.js index 7ebd0bf8c..acb375c23 100644 --- a/src/js/settings/components/settings-row/field-info.js +++ b/src/js/settings/components/settings-row/field-info.js @@ -17,6 +17,34 @@ import { marked } from 'marked'; import { useEffect } from 'react'; import { getFeature } from '../../utils/utils'; +/** + * FieldInfo Component + * + * This component displays a small helper icon button (e.g., an "info" icon) next to a field or label. + * When clicked, it opens a modal displaying detailed information specific to the field. + * + * @summary Shows a helper icon button that opens a modal with detailed information. + * + * @param {Object} props Component props. + * @param {Object} props.fieldInfo Field information object. + * @param {string} props.fieldInfo.type Type of information to display (e.g., 'instruction'). + * @param {string} props.fieldInfo.provider Provider type to look up data. + * + * @example + * + * + * @return {JSX.Element} The rendered FieldInfo button and modal. + * + * Notes: + * - The modal content is loaded dynamically from feature context data. + * - The icon can be customized based on info type. + * - Uses `dangerouslySetInnerHTML` to render content. + */ export const FieldInfo = ( props ) => { const { featureName } = useFeatureContext(); const [ isOpen, setOpen ] = useState( false ); From 61eebf602293e342714bdbf51f0d2bf224112c6a Mon Sep 17 00:00:00 2001 From: Bunty Date: Wed, 16 Jul 2025 14:45:34 +0530 Subject: [PATCH 09/20] Fix js lint and improve error handling --- includes/Classifai/Features/Feature.php | 4 ++-- src/js/settings/components/settings-row/field-info.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 82a67f7a1..6ba314dc4 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1422,7 +1422,7 @@ public function run( ...$args ) { /** * Get content from README.md file. * - * @return string|WP_Error + * @return string */ public function get_readme_content() { @@ -1435,7 +1435,7 @@ public function get_readme_content() { $readme_content = file_get_contents( $readme_path ); // phpcs:ignore if ( false === $readme_content || ! is_string( $readme_content ) ) { - return new WP_Error( 'invalid', esc_html__( 'Readme cannot be downloaded.', 'classifai' ) ); + return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); } return $readme_content; diff --git a/src/js/settings/components/settings-row/field-info.js b/src/js/settings/components/settings-row/field-info.js index acb375c23..8691c19e0 100644 --- a/src/js/settings/components/settings-row/field-info.js +++ b/src/js/settings/components/settings-row/field-info.js @@ -79,7 +79,7 @@ export const FieldInfo = ( props ) => { }, [ props.fieldInfo, feature.providers, - feature.providers_data.instructions, + feature.providers_data, feature.label, ] ); @@ -92,7 +92,7 @@ export const FieldInfo = ( props ) => { onClick={ openModal } size="small" icon={ icon } - label={ __( 'AI Configuration Instruction', 'classifai' ) } + label={ infoTitle } > { isOpen && ( Date: Fri, 18 Jul 2025 13:43:15 +0530 Subject: [PATCH 10/20] Get readme content from github - As readme.md is not included in plugin's zip - So getting it from raw readme.md from github --- config.php | 1 + includes/Classifai/Features/Feature.php | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/config.php b/config.php index eb65e0608..dddf4d8f7 100644 --- a/config.php +++ b/config.php @@ -11,6 +11,7 @@ classifai_define( 'CLASSIFAI_PLUGIN_VERSION', $plugin_version ); classifai_define( 'CLASSIFAI_PLUGIN_DIR', __DIR__ ); classifai_define( 'CLASSIFAI_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); classifai_define( 'CLASSIFAI_PLUGIN_BASENAME', plugin_basename( __DIR__ . '/classifai.php' ) ); +classifai_define( 'CLASSIFAI_PLUGIN_README_URL', 'https://raw.githubusercontent.com/10up/classifai/refs/heads/develop/README.md' ); // IBM Watson constants diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 6ba314dc4..6457bd264 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1426,18 +1426,29 @@ public function run( ...$args ) { */ public function get_readme_content() { - $readme_path = trailingslashit( CLASSIFAI_PLUGIN_DIR ) . 'README.md'; + // Get readme content from cache. + $readme_content = get_transient( 'classifai_readme_content' ); - if ( ! file_exists( $readme_path ) ) { - return __return_empty_string(); + if ( ! empty( $readme_content ) ) { + return $readme_content; } - $readme_content = file_get_contents( $readme_path ); // phpcs:ignore + // Get readme content. + $readme_request = wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); - if ( false === $readme_content || ! is_string( $readme_content ) ) { + if ( is_wp_error( $readme_request ) ) { return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); } + $readme_content = wp_remote_retrieve_body( $readme_request ); + + if ( empty( $readme_content ) || ! is_string( $readme_content ) ) { + return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); + } + + // Cache readme content. + set_transient( 'classifai_readme_content', $readme_content, DAY_IN_SECONDS ); + return $readme_content; } } From 2e35bced14f73a7158edcf312f6453918af3ddac Mon Sep 17 00:00:00 2001 From: Bunty Date: Fri, 18 Jul 2025 14:05:04 +0530 Subject: [PATCH 11/20] Use VIP function when possible --- includes/Classifai/Features/Feature.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 6457bd264..2f5a2bbf0 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1434,7 +1434,9 @@ public function get_readme_content() { } // Get readme content. - $readme_request = wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); + $readme_request = function_exists( 'vip_safe_wp_remote_get' ) + ? vip_safe_wp_remote_get( CLASSIFAI_PLUGIN_README_URL ) + : wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); if ( is_wp_error( $readme_request ) ) { return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); From a10091c5f3d345412f07e2938bfdf18dd89b0b93 Mon Sep 17 00:00:00 2001 From: Bunty Date: Fri, 18 Jul 2025 14:08:24 +0530 Subject: [PATCH 12/20] Ignore phpcs for wp_remote_get --- includes/Classifai/Features/Feature.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 2f5a2bbf0..597714352 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1436,7 +1436,7 @@ public function get_readme_content() { // Get readme content. $readme_request = function_exists( 'vip_safe_wp_remote_get' ) ? vip_safe_wp_remote_get( CLASSIFAI_PLUGIN_README_URL ) - : wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); + : wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get if ( is_wp_error( $readme_request ) ) { return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); From fc0acc8f0d981b008623f4d427028860a04fe39d Mon Sep 17 00:00:00 2001 From: Bunty Date: Sat, 19 Jul 2025 12:06:13 +0530 Subject: [PATCH 13/20] Update marked package --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 90b01c7cc..fce8fe51a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@wordpress/icons": "^10.17.0", "choices.js": "^11.1.0", "classnames": "^2.5.1", - "marked": "^16.0.0", + "marked": "^16.1.1", "motion": "^12.23.6", "react-router-dom": "^7.5.2", "tippy.js": "^6.3.7" @@ -17738,9 +17738,9 @@ "license": "MIT" }, "node_modules/marked": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-16.0.0.tgz", - "integrity": "sha512-MUKMXDjsD/eptB7GPzxo4xcnLS6oo7/RHimUMHEDRhUooPwmN9BEpMl7AEOJv3bmso169wHI2wUF9VQgL7zfmA==", + "version": "16.1.1", + "resolved": "https://registry.npmjs.org/marked/-/marked-16.1.1.tgz", + "integrity": "sha512-ij/2lXfCRT71L6u0M29tJPhP0bM5shLL3u5BePhFwPELj2blMJ6GDtD7PfJhRLhJ/c2UwrK17ySVcDzy2YHjHQ==", "license": "MIT", "bin": { "marked": "bin/marked.js" diff --git a/package.json b/package.json index aec571509..dd827d23d 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@wordpress/icons": "^10.17.0", "choices.js": "^11.1.0", "classnames": "^2.5.1", - "marked": "^16.0.0", + "marked": "^16.1.1", "motion": "^12.23.6", "react-router-dom": "^7.5.2", "tippy.js": "^6.3.7" From e4cd4d8b09963bcd2f3666203b369cbc163d7311 Mon Sep 17 00:00:00 2001 From: Bunty Date: Wed, 20 Aug 2025 13:30:55 +0530 Subject: [PATCH 14/20] Code improvisation as per feedback --- includes/Classifai/Features/Feature.php | 6 +++--- src/js/settings/components/settings-row/field-info.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 597714352..a5c612a0c 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1434,9 +1434,7 @@ public function get_readme_content() { } // Get readme content. - $readme_request = function_exists( 'vip_safe_wp_remote_get' ) - ? vip_safe_wp_remote_get( CLASSIFAI_PLUGIN_README_URL ) - : wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get + $readme_request = wp_safe_remote_get( CLASSIFAI_PLUGIN_README_URL ); if ( is_wp_error( $readme_request ) ) { return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); @@ -1448,6 +1446,8 @@ public function get_readme_content() { return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); } + $readme_content = wp_kses_post( $readme_content ); + // Cache readme content. set_transient( 'classifai_readme_content', $readme_content, DAY_IN_SECONDS ); diff --git a/src/js/settings/components/settings-row/field-info.js b/src/js/settings/components/settings-row/field-info.js index 8691c19e0..f210113c9 100644 --- a/src/js/settings/components/settings-row/field-info.js +++ b/src/js/settings/components/settings-row/field-info.js @@ -44,6 +44,7 @@ import { getFeature } from '../../utils/utils'; * - The modal content is loaded dynamically from feature context data. * - The icon can be customized based on info type. * - Uses `dangerouslySetInnerHTML` to render content. + * - The content rendering here has already been sanitized on the server. */ export const FieldInfo = ( props ) => { const { featureName } = useFeatureContext(); From 3bd36e981554253c9551c06ccd720707901e6c6a Mon Sep 17 00:00:00 2001 From: Bunty Date: Wed, 20 Aug 2025 13:53:29 +0530 Subject: [PATCH 15/20] Update Marked Package --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index fce8fe51a..2c2cf3a73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@wordpress/icons": "^10.17.0", "choices.js": "^11.1.0", "classnames": "^2.5.1", - "marked": "^16.1.1", + "marked": "^16.2.0", "motion": "^12.23.6", "react-router-dom": "^7.5.2", "tippy.js": "^6.3.7" @@ -17738,9 +17738,9 @@ "license": "MIT" }, "node_modules/marked": { - "version": "16.1.1", - "resolved": "https://registry.npmjs.org/marked/-/marked-16.1.1.tgz", - "integrity": "sha512-ij/2lXfCRT71L6u0M29tJPhP0bM5shLL3u5BePhFwPELj2blMJ6GDtD7PfJhRLhJ/c2UwrK17ySVcDzy2YHjHQ==", + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-16.2.0.tgz", + "integrity": "sha512-LbbTuye+0dWRz2TS9KJ7wsnD4KAtpj0MVkWc90XvBa6AslXsT0hTBVH5k32pcSyHH1fst9XEFJunXHktVy0zlg==", "license": "MIT", "bin": { "marked": "bin/marked.js" diff --git a/package.json b/package.json index dd827d23d..e78040edb 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@wordpress/icons": "^10.17.0", "choices.js": "^11.1.0", "classnames": "^2.5.1", - "marked": "^16.1.1", + "marked": "^16.2.0", "motion": "^12.23.6", "react-router-dom": "^7.5.2", "tippy.js": "^6.3.7" From 2690e1b51af33d360a01667357ce1e9cab521773 Mon Sep 17 00:00:00 2001 From: Bunty Date: Wed, 20 Aug 2025 14:54:27 +0530 Subject: [PATCH 16/20] Use safe_wp_remote_get for getting data from readme --- includes/Classifai/Features/Feature.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index a5c612a0c..14254f363 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -7,6 +7,7 @@ use function Classifai\find_provider_class; use function Classifai\should_use_legacy_settings_panel; use function Classifai\get_asset_info; +use function Classifai\safe_wp_remote_get; abstract class Feature { /** @@ -1434,7 +1435,7 @@ public function get_readme_content() { } // Get readme content. - $readme_request = wp_safe_remote_get( CLASSIFAI_PLUGIN_README_URL ); + $readme_request = safe_wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); if ( is_wp_error( $readme_request ) ) { return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); From ba6ce1871ea4dfb8cf14ba4edccf08db0844402c Mon Sep 17 00:00:00 2001 From: Bunty Date: Fri, 22 Aug 2025 13:13:51 +0530 Subject: [PATCH 17/20] Remove unnecessary code from package.lock --- package-lock.json | 81 ----------------------------------------------- 1 file changed, 81 deletions(-) diff --git a/package-lock.json b/package-lock.json index 76f2360bc..4f34b7d85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16289,87 +16289,6 @@ "node": ">=12.0.0" } }, - "node_modules/jsdoc/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true, - "license": "Python-2.0" - }, - "node_modules/jsdoc/node_modules/escape-string-regexp": { - "version": "2.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/jsdoc/node_modules/linkify-it": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", - "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "uc.micro": "^2.0.0" - } - }, - "node_modules/jsdoc/node_modules/markdown-it": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz", - "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", - "dev": true, - "license": "MIT", - "dependencies": { - "argparse": "^2.0.1", - "entities": "^4.4.0", - "linkify-it": "^5.0.0", - "mdurl": "^2.0.0", - "punycode.js": "^2.3.1", - "uc.micro": "^2.1.0" - }, - "bin": { - "markdown-it": "bin/markdown-it.mjs" - } - }, - "node_modules/jsdoc/node_modules/marked": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz", - "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==", - "dev": true, - "license": "MIT", - "bin": { - "marked": "bin/marked.js" - }, - "engines": { - "node": ">= 12" - } - }, - "node_modules/jsdoc/node_modules/mdurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==", - "dev": true, - "license": "MIT" - }, - "node_modules/jsdoc/node_modules/mkdirp": { - "version": "1.0.4", - "dev": true, - "license": "MIT", - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/jsdoc/node_modules/uc.micro": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", - "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", - "dev": true, - "license": "MIT" - }, "node_modules/jsdom": { "version": "20.0.3", "dev": true, From 6685563dcbb3737f7ee90806fa2a6294ed18f52a Mon Sep 17 00:00:00 2001 From: Bunty Date: Fri, 22 Aug 2025 13:21:48 +0530 Subject: [PATCH 18/20] Remove unnecessary file --- .../provider-settings/google-gemini-api.js | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/js/settings/components/provider-settings/google-gemini-api.js diff --git a/src/js/settings/components/provider-settings/google-gemini-api.js b/src/js/settings/components/provider-settings/google-gemini-api.js deleted file mode 100644 index 5ac90eeb3..000000000 --- a/src/js/settings/components/provider-settings/google-gemini-api.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * WordPress dependencies - */ -import { useSelect, useDispatch } from '@wordpress/data'; -// eslint-disable-next-line @wordpress/no-unsafe-wp-apis -import { __experimentalInputControl as InputControl } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies - */ -import { SettingsRow } from '../settings-row'; -import { STORE_NAME } from '../../data/store'; - -/** - * Component for Google AI (Gemini API) Provider settings. - * - * This component is used within the ProviderSettings component to allow users to configure the Google AI (Gemini API) Provider settings. - * - * @param {Object} props Component props. - * @param {boolean} props.isConfigured Whether the provider is configured. - * - * @return {React.ReactElement} GoogleAIGeminiAPISettings component. - */ -export const GoogleAIGeminiAPISettings = ( { isConfigured = false } ) => { - const providerName = 'googleai_gemini_api'; - const providerSettings = useSelect( - ( select ) => - select( STORE_NAME ).getFeatureSettings( providerName ) || {} - ); - const { setProviderSettings } = useDispatch( STORE_NAME ); - const onChange = ( data ) => setProviderSettings( providerName, data ); - - if ( isConfigured ) { - return null; - } - - const Description = () => ( - <> - { __( "Don't have an Google AI (Gemini API) key?", 'classifai' ) }{ ' ' } - - { __( 'Get an API key', 'classifai' ) } - { ' ' } - { __( 'now.', 'classifai' ) } - - ); - - return ( - <> - } - > - onChange( { api_key: value } ) } - /> - - - ); -}; From ceb18ed0a1147380f0723b02c3db0a79bdc016ed Mon Sep 17 00:00:00 2001 From: Bunty Date: Tue, 2 Sep 2025 17:32:01 +0530 Subject: [PATCH 19/20] Made change as per new folder structure for getting feature instructions --- config.php | 1 - .../Features/AudioTranscriptsGeneration.php | 11 +- .../Classifai/Features/Classification.php | 15 ++- .../Classifai/Features/ContentGeneration.php | 15 ++- .../Classifai/Features/ContentResizing.php | 17 ++- .../Features/DescriptiveTextGenerator.php | 13 ++- .../Classifai/Features/ExcerptGeneration.php | 17 ++- includes/Classifai/Features/Feature.php | 102 +++++++++++++++--- includes/Classifai/Features/ImageCropping.php | 11 +- .../Classifai/Features/ImageGeneration.php | 13 ++- .../Classifai/Features/ImageTagsGenerator.php | 13 ++- .../Features/ImageTextExtraction.php | 13 ++- includes/Classifai/Features/KeyTakeaways.php | 15 ++- includes/Classifai/Features/Moderation.php | 11 +- .../Classifai/Features/PDFTextExtraction.php | 11 +- .../Classifai/Features/RecommendedContent.php | 11 +- includes/Classifai/Features/Smart404.php | 10 +- includes/Classifai/Features/TermCleanup.php | 10 +- includes/Classifai/Features/TextToSpeech.php | 15 ++- .../Classifai/Features/TitleGeneration.php | 17 ++- 20 files changed, 268 insertions(+), 73 deletions(-) diff --git a/config.php b/config.php index 655f63e56..d3f435d2f 100644 --- a/config.php +++ b/config.php @@ -11,7 +11,6 @@ classifai_define( 'CLASSIFAI_PLUGIN_VERSION', $plugin_version ); classifai_define( 'CLASSIFAI_PLUGIN_DIR', __DIR__ ); classifai_define( 'CLASSIFAI_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); classifai_define( 'CLASSIFAI_PLUGIN_BASENAME', plugin_basename( __DIR__ . '/classifai.php' ) ); -classifai_define( 'CLASSIFAI_PLUGIN_README_URL', 'https://raw.githubusercontent.com/10up/classifai/refs/heads/develop/README.md' ); // IBM Watson constants diff --git a/includes/Classifai/Features/AudioTranscriptsGeneration.php b/includes/Classifai/Features/AudioTranscriptsGeneration.php index 4cc9c0c11..bbce2f0de 100644 --- a/includes/Classifai/Features/AudioTranscriptsGeneration.php +++ b/includes/Classifai/Features/AudioTranscriptsGeneration.php @@ -23,6 +23,13 @@ class AudioTranscriptsGeneration extends Feature { */ const ID = 'feature_audio_transcripts_generation'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '08.audio-transcripts-generation.md'; + /** * Constructor. */ @@ -38,12 +45,12 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - SpeechToText::ID => preg_match( '/## Set Up Audio Transcripts Generation \(via OpenAI Speech to Text\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + SpeechToText::ID => preg_match( '/## Set Up via OpenAI Speech to Text(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index ce3b07879..2ab6fdd00 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -30,6 +30,13 @@ class Classification extends Feature { */ const ID = 'feature_classification'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '01.classification.md'; + /** * Constructor. */ @@ -48,15 +55,15 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - NLU::ID => preg_match( '/## Set Up Classification \(via IBM Watson\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - OpenAIEmbeddings::ID => preg_match( '/## Set Up Classification \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + NLU::ID => preg_match( '/## Set Up via IBM Watson(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAIEmbeddings::ID => preg_match( '/## Set Up via OpenAI Embeddings(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => '', - OllamaEmbeddings::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OllamaEmbeddings::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/ContentGeneration.php b/includes/Classifai/Features/ContentGeneration.php index 41892973e..ed0760e4f 100644 --- a/includes/Classifai/Features/ContentGeneration.php +++ b/includes/Classifai/Features/ContentGeneration.php @@ -27,6 +27,13 @@ class ContentGeneration extends Feature { */ const ID = 'feature_content_generation'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '04.content-generation.md'; + /** * Prompt for creating content. * @@ -97,14 +104,14 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up via OpenAI ChatGPT(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up via Azure OpenAI(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Ollama::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index fc7d7112d..432320bad 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -41,6 +41,13 @@ class ContentResizing extends Feature { */ public $expand_prompt = 'Increase the content length no more than 2 to 4 sentences.'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '05.content-resizing.md'; + /** * Constructor. */ @@ -61,17 +68,17 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up via OpenAI ChatGPT(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GeminiAPI::ID => preg_match( '/## Set Up via Google AI \(Gemini API\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up via Azure OpenAI(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Grok::ID => '', ChromeAI::ID => '', - Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Ollama::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index bbadef8ab..a4da441fa 100644 --- a/includes/Classifai/Features/DescriptiveTextGenerator.php +++ b/includes/Classifai/Features/DescriptiveTextGenerator.php @@ -31,6 +31,13 @@ class DescriptiveTextGenerator extends Feature { */ public $prompt = 'You are an assistant that generates descriptions of images that are used on a website. You will be provided with an image and will describe the main item you see in the image, giving details but staying concise. There is no need to say "the image contains" or similar, just describe what is actually in the image. This text will be important for screen readers, so make sure it is descriptive and accurate but not overly verbose. Before returning the text, re-evaluate your response and ensure you are following the above points, in particular ensuring the text is concise.'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '12.descriptive-text-generator.md'; + /** * Constructor. */ @@ -49,15 +56,15 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', Grok::ID => '', - OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OllamaMM::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index 3920d2bfe..91acf07c1 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -41,6 +41,13 @@ class ExcerptGeneration extends Feature { */ public $woo_prompt = 'Create a concise, compelling summary for an ecommerce product that highlights key features, benefits, and unique selling points. Keep it within {{WORDS}} words and ensure it pairs well with the product title: {{TITLE}}.'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '03.excerpt-generation.md'; + /** * Constructor. */ @@ -61,17 +68,17 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up via OpenAI ChatGPT(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GeminiAPI::ID => preg_match( '/## Set Up via Google AI \(Gemini API\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up via Azure OpenAI(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Grok::ID => '', ChromeAI::ID => '', - Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Ollama::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 6a531d9f7..5e9414b22 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -29,6 +29,20 @@ abstract class Feature { */ const PLUGIN_AREA_SCRIPT = 'classifai-plugin-fill-js'; + /** + * Plugin feature instruction directory URL. + * + * @var string + */ + const PLUGIN_FEATURE_INSTRUCTION_DIR = 'https://raw.githubusercontent.com/10up/classifai/refs/heads/develop/wp-hooks-docs/docs/02.feature-configuration'; + + /** + * Locally hosted instruction file. + * + * @var string + */ + const PLUGIN_LOCALLY_HOSTED_INSTRUCTION_URL = 'https://raw.githubusercontent.com/10up/classifai/refs/heads/develop/wp-hooks-docs/docs/03.advanced-docs/06.run-locally-hosted-llms.md'; + /** * Feature label. * @@ -66,6 +80,13 @@ abstract class Feature { */ public $supported_providers_data = []; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = ''; + /** * Set up necessary hooks. */ @@ -1421,37 +1442,84 @@ public function run( ...$args ) { } /** - * Get content from README.md file. + * Get Feature Instructions from related file. * * @return string */ - public function get_readme_content() { + public function get_instruction_content() { + $instruction_file = $this->instruction_file ?? ''; + $provider = static::ID; + + if ( empty( $instruction_file ) || empty( $provider ) ) { + return; + } + + $transient_key = 'classifai_instruction_' . $provider; + + // Get content from cache. + $feature_instruction = get_transient( $transient_key ); + + if ( ! empty( $feature_instruction ) ) { + return $feature_instruction; + } + + $instruction_content_url = trailingslashit( self::PLUGIN_FEATURE_INSTRUCTION_DIR ) . $instruction_file; + + // Get content. + $instruction_request = safe_wp_remote_get( $instruction_content_url ); + + if ( is_wp_error( $instruction_request ) ) { + return esc_html__( 'Instruction content cannot be downloaded.', 'classifai' ); + } + + $feature_instruction = wp_remote_retrieve_body( $instruction_request ); + + if ( empty( $feature_instruction ) || ! is_string( $feature_instruction ) ) { + return esc_html__( 'Instruction content cannot be downloaded.', 'classifai' ); + } + + $feature_instruction = wp_kses_post( $feature_instruction ); + + // Cache content. + set_transient( $transient_key, $feature_instruction, DAY_IN_SECONDS ); + + return $feature_instruction; + } + + /** + * Get Feature Instructions for locally hosted LLMs. + * + * @return string + */ + public function get_locally_hosted_llm_instruction() { + + $transient_key = 'classifai_instruction_locally_hosted_llm'; - // Get readme content from cache. - $readme_content = get_transient( 'classifai_readme_content' ); + // Get content from cache. + $locally_hosted_instruction = get_transient( $transient_key ); - if ( ! empty( $readme_content ) ) { - return $readme_content; + if ( ! empty( $locally_hosted_instruction ) ) { + return $locally_hosted_instruction; } - // Get readme content. - $readme_request = safe_wp_remote_get( CLASSIFAI_PLUGIN_README_URL ); + $instruction_content_url = self::PLUGIN_LOCALLY_HOSTED_INSTRUCTION_URL; + $instruction_request = safe_wp_remote_get( $instruction_content_url ); - if ( is_wp_error( $readme_request ) ) { - return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); + if ( is_wp_error( $instruction_request ) ) { + return esc_html__( 'Instruction content cannot be downloaded.', 'classifai' ); } - $readme_content = wp_remote_retrieve_body( $readme_request ); + $locally_hosted_instruction = wp_remote_retrieve_body( $instruction_request ); - if ( empty( $readme_content ) || ! is_string( $readme_content ) ) { - return esc_html__( 'Readme cannot be downloaded.', 'classifai' ); + if ( empty( $locally_hosted_instruction ) || ! is_string( $locally_hosted_instruction ) ) { + return esc_html__( 'Instruction content cannot be downloaded.', 'classifai' ); } - $readme_content = wp_kses_post( $readme_content ); + $locally_hosted_instruction = wp_kses_post( preg_replace('/^---\s*[\s\S]*?\s*---\s*/', '', $locally_hosted_instruction) ); - // Cache readme content. - set_transient( 'classifai_readme_content', $readme_content, DAY_IN_SECONDS ); + // Cache content. + set_transient( $transient_key, $locally_hosted_instruction, DAY_IN_SECONDS ); - return $readme_content; + return $locally_hosted_instruction; } } diff --git a/includes/Classifai/Features/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index 1c2f360f4..37e56c85b 100644 --- a/includes/Classifai/Features/ImageCropping.php +++ b/includes/Classifai/Features/ImageCropping.php @@ -21,6 +21,13 @@ class ImageCropping extends Feature { */ const ID = 'feature_image_cropping'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '14.image-cropping.md'; + /** * WP_Filesystem_Base instance. * @@ -45,12 +52,12 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/ImageGeneration.php b/includes/Classifai/Features/ImageGeneration.php index e1e6d1024..2ba42ae2c 100644 --- a/includes/Classifai/Features/ImageGeneration.php +++ b/includes/Classifai/Features/ImageGeneration.php @@ -25,6 +25,13 @@ class ImageGeneration extends Feature { */ const ID = 'feature_image_generation'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '16.image-generation.md'; + /** * Constructor. */ @@ -43,13 +50,13 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - OpenAIImages::ID => preg_match( '/## Set Up Image Generation \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - GoogleAIImagen::ID => preg_match( '/## Set Up Image Generation \(via Google AI Imagen\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAIImages::ID => preg_match( '/## Set Up via OpenAI(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GoogleAIImagen::ID => preg_match( '/## Set Up via Google AI Imagen(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/ImageTagsGenerator.php b/includes/Classifai/Features/ImageTagsGenerator.php index 2dfe601ff..4092f8707 100644 --- a/includes/Classifai/Features/ImageTagsGenerator.php +++ b/includes/Classifai/Features/ImageTagsGenerator.php @@ -38,6 +38,13 @@ class ImageTagsGenerator extends Feature { EOD; // phpcs:enable Squiz.PHP.Heredoc.NotAllowed + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '13.image-tags-generator.md'; + /** * Constructor. */ @@ -55,14 +62,14 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', - OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OllamaMM::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index 1eecfdb43..3972c79b8 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -32,6 +32,13 @@ class ImageTextExtraction extends Feature { */ public $prompt = 'You are an assistant that extracts text from images. You will be provided with an image and will return whatever text is in the image. Return only the text, nothing else. If there is no text present, return the word none.'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '15.image-text-extraction.md'; + /** * Constructor. */ @@ -49,14 +56,14 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ChatGPT::ID => '', - OllamaMM::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OllamaMM::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/KeyTakeaways.php b/includes/Classifai/Features/KeyTakeaways.php index 305f986f2..e990e79e4 100644 --- a/includes/Classifai/Features/KeyTakeaways.php +++ b/includes/Classifai/Features/KeyTakeaways.php @@ -32,6 +32,13 @@ class KeyTakeaways extends Feature { */ public $prompt = 'The content you will be provided with is from an already written article. This article has the title of: {{TITLE}}. Your task is to carefully read through this article and provide a summary that captures all the important points. This summary should be concise and limited to about 2-4 points but should also be detailed enough to allow someone to quickly grasp the full article. Read the article a few times before providing the summary and trim each point down to be as concise as possible.'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '06.key-takeaways.md'; + /** * Constructor. */ @@ -49,14 +56,14 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ChatGPT::ID => '', - OpenAI::ID => '', - Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up via OpenAI ChatGPT(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up via Azure OpenAI(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Ollama::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/Moderation.php b/includes/Classifai/Features/Moderation.php index 3aa9ec8d4..a637fb0dd 100644 --- a/includes/Classifai/Features/Moderation.php +++ b/includes/Classifai/Features/Moderation.php @@ -20,6 +20,13 @@ class Moderation extends Feature { */ const ID = 'feature_moderation'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '09.moderation.md'; + /** * Constructor. */ @@ -35,12 +42,12 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ModerationProvider::ID => preg_match( '/## Set Up Comment Moderation \(via OpenAI Moderation\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ModerationProvider::ID => preg_match( '/## Set Up via OpenAI Moderation(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/PDFTextExtraction.php b/includes/Classifai/Features/PDFTextExtraction.php index a3e6e427a..ad9f84c4b 100644 --- a/includes/Classifai/Features/PDFTextExtraction.php +++ b/includes/Classifai/Features/PDFTextExtraction.php @@ -22,6 +22,13 @@ class PDFTextExtraction extends Feature { */ const ID = 'feature_pdf_to_text_generation'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '17.pdf-text-extraction.md'; + /** * Constructor. */ @@ -37,12 +44,12 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ComputerVision::ID => preg_match( '/## Set Up Image Processing features \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ComputerVision::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/RecommendedContent.php b/includes/Classifai/Features/RecommendedContent.php index fe928b3c2..ae43c9262 100644 --- a/includes/Classifai/Features/RecommendedContent.php +++ b/includes/Classifai/Features/RecommendedContent.php @@ -20,6 +20,13 @@ class RecommendedContent extends Feature { */ const ID = 'feature_recommended_content'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '18.recommended-content.md'; + /** * Constructor. */ @@ -36,12 +43,12 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - OpenAIEmbeddings::ID => preg_match( '/## Set Up Recommended Content \(via OpenAI Embeddings\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAIEmbeddings::ID => preg_match( '/## Set Up via OpenAI Embeddings(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', PersonalizerProvider::ID => '', ], ]; diff --git a/includes/Classifai/Features/Smart404.php b/includes/Classifai/Features/Smart404.php index 1c2c487ba..e4dc2225e 100644 --- a/includes/Classifai/Features/Smart404.php +++ b/includes/Classifai/Features/Smart404.php @@ -23,6 +23,13 @@ class Smart404 extends Feature { */ const ID = 'feature_smart_404'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '10.smart-404.md'; + /** * Constructor. */ @@ -40,13 +47,14 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ OpenAIEmbeddings::ID => preg_match( '/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => preg_match( '/## Set Up the Smart 404 Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OllamaEmbeddings::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/TermCleanup.php b/includes/Classifai/Features/TermCleanup.php index 08ccb4713..83d92962f 100644 --- a/includes/Classifai/Features/TermCleanup.php +++ b/includes/Classifai/Features/TermCleanup.php @@ -25,6 +25,13 @@ class TermCleanup extends Feature { */ const ID = 'feature_term_cleanup'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '11.term-cleanup.md'; + /** * Setting page URL. * @@ -70,13 +77,14 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ OpenAIEmbeddings::ID => preg_match( '/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', AzureEmbeddings::ID => preg_match( '/## Set Up the Term Cleanup Feature(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OllamaEmbeddings::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } diff --git a/includes/Classifai/Features/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index 97c1e304a..248c1b1de 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -54,6 +54,13 @@ class TextToSpeech extends Feature { */ const AUDIO_HASH_KEY = '_classifai_post_audio_hash'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '07.text-to-speech.md'; + /** * Constructor. */ @@ -71,14 +78,14 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - AmazonPolly::ID => preg_match( '/## Set Up Text to Speech \(via Amazon Polly\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - Speech::ID => preg_match( '/## Set Up Text to Speech \(via Microsoft Azure\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - OpenAITTS::ID => preg_match( '/## Set Up Text to Speech \(via OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + AmazonPolly::ID => preg_match( '/## Set Up via Amazon Polly(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Speech::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAITTS::ID => preg_match( '/## Set Up via OpenAI(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', ], ]; } diff --git a/includes/Classifai/Features/TitleGeneration.php b/includes/Classifai/Features/TitleGeneration.php index 85afbd821..1dac32f53 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -41,6 +41,13 @@ class TitleGeneration extends Feature { */ public $woo_prompt = 'Write an SEO-friendly, engaging product title that encourages clicks and purchases. Use key details like product type, attributes, and categories while keeping it within 40 to 60 characters and format it in sentence case.'; + /** + * Instruction file name for the feature. + * + * @var string + */ + public $instruction_file = '02.title-generation.md'; + /** * Constructor. */ @@ -61,17 +68,17 @@ public function __construct() { ]; // Get readme content. - $readme_content = $this->get_readme_content(); + $readme_content = $this->get_instruction_content(); // Contains supported providers data. $this->supported_providers_data = [ 'instruction' => [ - ChatGPT::ID => preg_match( '/## Set Up Language Processing Features \(via OpenAI ChatGPT\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - GeminiAPI::ID => preg_match( '/## Set Up Language Processing Features \(via Google AI \(Gemini API\)\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', - OpenAI::ID => preg_match( '/## Set Up Language Processing Features \(via Azure OpenAI\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + ChatGPT::ID => preg_match( '/## Set Up via OpenAI ChatGPT(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + GeminiAPI::ID => preg_match( '/## Set Up via Google AI \(Gemini API\)(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + OpenAI::ID => preg_match( '/## Set Up via Azure OpenAI(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', Grok::ID => '', ChromeAI::ID => '', - Ollama::ID => preg_match( '/## Run locally hosted LLMs(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '', + Ollama::ID => $this->get_locally_hosted_llm_instruction(), ], ]; } From 6f85c0085d6c5a3af221f61c932ce8cdf65ae913 Mon Sep 17 00:00:00 2001 From: Bunty Date: Tue, 2 Sep 2025 17:37:53 +0530 Subject: [PATCH 20/20] Fix phpcs --- includes/Classifai/Features/Feature.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 5e9414b22..457bc16b5 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1515,7 +1515,7 @@ public function get_locally_hosted_llm_instruction() { return esc_html__( 'Instruction content cannot be downloaded.', 'classifai' ); } - $locally_hosted_instruction = wp_kses_post( preg_replace('/^---\s*[\s\S]*?\s*---\s*/', '', $locally_hosted_instruction) ); + $locally_hosted_instruction = wp_kses_post( preg_replace( '/^---\s*[\s\S]*?\s*---\s*/', '', $locally_hosted_instruction ) ); // Cache content. set_transient( $transient_key, $locally_hosted_instruction, DAY_IN_SECONDS );