Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e6c1e2c
Add a proto type for setup instructions uder the Service Provider.
BhargavBhandari90 Jul 7, 2025
ad9a9a9
Merge branch 'develop' of github.com:BhargavBhandari90/classifai into…
BhargavBhandari90 Jul 11, 2025
598ed6f
Add popup modal to display AI setup instructions to users
BhargavBhandari90 Jul 13, 2025
2a254d4
Set configuration instructions for all features
BhargavBhandari90 Jul 13, 2025
b35091b
phpcs fixes
BhargavBhandari90 Jul 13, 2025
92c9816
Add ollama instruction
BhargavBhandari90 Jul 13, 2025
4087e02
Merge branch 'develop' of github.com:BhargavBhandari90/classifai into…
BhargavBhandari90 Jul 16, 2025
451743e
Add helper component with modal for additional info for setting field
BhargavBhandari90 Jul 16, 2025
519748f
Remove debuge code
BhargavBhandari90 Jul 16, 2025
2d11e51
Add component documentation
BhargavBhandari90 Jul 16, 2025
61eebf6
Fix js lint and improve error handling
BhargavBhandari90 Jul 16, 2025
c8a6749
Merge branch 'develop' of github.com:BhargavBhandari90/classifai into…
BhargavBhandari90 Jul 18, 2025
9df3b7c
Get readme content from github
BhargavBhandari90 Jul 18, 2025
2e35bce
Use VIP function when possible
BhargavBhandari90 Jul 18, 2025
a10091c
Ignore phpcs for wp_remote_get
BhargavBhandari90 Jul 18, 2025
21dbfbf
Merge branch 'develop' of github.com:BhargavBhandari90/classifai into…
BhargavBhandari90 Jul 19, 2025
fc0acc8
Update marked package
BhargavBhandari90 Jul 19, 2025
e4cd4d8
Code improvisation as per feedback
BhargavBhandari90 Aug 20, 2025
3bd36e9
Update Marked Package
BhargavBhandari90 Aug 20, 2025
dfa5704
Merge branch 'develop' of github.com:BhargavBhandari90/classifai into…
BhargavBhandari90 Aug 20, 2025
2690e1b
Use safe_wp_remote_get for getting data from readme
BhargavBhandari90 Aug 20, 2025
6d5b9c1
Merge branch 'develop' of github.com:BhargavBhandari90/classifai into…
BhargavBhandari90 Aug 22, 2025
ba6ce18
Remove unnecessary code from package.lock
BhargavBhandari90 Aug 22, 2025
6685563
Remove unnecessary file
BhargavBhandari90 Aug 22, 2025
f818a15
Merge branch 'develop' of github.com:BhargavBhandari90/classifai into…
BhargavBhandari90 Aug 23, 2025
ceb18ed
Made change as per new folder structure for getting feature instructions
BhargavBhandari90 Sep 2, 2025
6f85c00
Fix phpcs
BhargavBhandari90 Sep 2, 2025
ed53fe9
Merge branch 'develop' into feat/925
BhargavBhandari90 Sep 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions includes/Classifai/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,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.
Expand Down
17 changes: 17 additions & 0 deletions includes/Classifai/Features/AudioTranscriptsGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
*/
const ID = 'feature_audio_transcripts_generation';

/**
* Instruction file name for the feature.
*
* @var string
*/
public $instruction_file = '08.audio-transcripts-generation.md';

/**
* Constructor.
*/
Expand All @@ -40,6 +47,16 @@
OpenAISpeechToText::ID => __( 'OpenAI Audio Transcription', 'classifai' ),
ElevenLabsSpeechToText::ID => __( 'ElevenLabs Audio Transcription', 'classifai' ),
];

// Get readme content.
$readme_content = $this->get_instruction_content();

// Contains supported providers data.
$this->supported_providers_data = [
'instruction' => [
SpeechToText::ID => preg_match( '/## Set Up via OpenAI Speech to Text(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '',

Check failure on line 57 in includes/Classifai/Features/AudioTranscriptsGeneration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Access to constant ID on an unknown class Classifai\Features\SpeechToText.
],
];
}

/**
Expand Down
20 changes: 20 additions & 0 deletions includes/Classifai/Features/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -46,6 +53,19 @@ public function __construct() {
AzureEmbeddings::ID => __( 'Azure OpenAI Embeddings', 'classifai' ),
OllamaEmbeddings::ID => __( 'Ollama', 'classifai' ),
];

// Get readme content.
$readme_content = $this->get_instruction_content();

// Contains supported providers data.
$this->supported_providers_data = [
'instruction' => [
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 => $this->get_locally_hosted_llm_instruction(),
],
];
}

/**
Expand Down
19 changes: 19 additions & 0 deletions includes/Classifai/Features/ContentGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -95,6 +102,18 @@ public function __construct() {
OpenAI::ID => __( 'Azure OpenAI', 'classifai' ),
Ollama::ID => __( 'Ollama', 'classifai' ),
];

// Get readme content.
$readme_content = $this->get_instruction_content();

// Contains supported providers data.
$this->supported_providers_data = [
'instruction' => [
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(),
],
];
}

/**
Expand Down
22 changes: 22 additions & 0 deletions includes/Classifai/Features/ContentResizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -59,6 +66,21 @@ public function __construct() {
ChromeAI::ID => __( 'Chrome AI (experimental)', 'classifai' ),
Ollama::ID => __( 'Ollama', 'classifai' ),
];

// Get readme content.
$readme_content = $this->get_instruction_content();

// Contains supported providers data.
$this->supported_providers_data = [
'instruction' => [
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 => $this->get_locally_hosted_llm_instruction(),
],
];
}

/**
Expand Down
20 changes: 20 additions & 0 deletions includes/Classifai/Features/DescriptiveTextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -47,6 +54,19 @@ public function __construct() {
Grok::ID => __( 'xAI Grok', 'classifai' ),
OllamaMM::ID => __( 'Ollama', 'classifai' ),
];

// Get readme content.
$readme_content = $this->get_instruction_content();

// Contains supported providers data.
$this->supported_providers_data = [
'instruction' => [
ComputerVision::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '',
ChatGPT::ID => '',
Grok::ID => '',
OllamaMM::ID => $this->get_locally_hosted_llm_instruction(),
],
];
}

/**
Expand Down
22 changes: 22 additions & 0 deletions includes/Classifai/Features/ExcerptGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -59,6 +66,21 @@ public function __construct() {
ChromeAI::ID => __( 'Chrome AI (experimental)', 'classifai' ),
Ollama::ID => __( 'Ollama', 'classifai' ),
];

// Get readme content.
$readme_content = $this->get_instruction_content();

// Contains supported providers data.
$this->supported_providers_data = [
'instruction' => [
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 => $this->get_locally_hosted_llm_instruction(),
],
];
}

/**
Expand Down
111 changes: 111 additions & 0 deletions includes/Classifai/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -28,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.
*
Expand Down Expand Up @@ -58,6 +73,20 @@ abstract class Feature {
*/
public $supported_providers = [];

/**
* Array of providers data supported by the feature.
*
* @var \Classifai\Providers\Provider[]
*/
public $supported_providers_data = [];

/**
* Instruction file name for the feature.
*
* @var string
*/
public $instruction_file = '';

/**
* Set up necessary hooks.
*/
Expand Down Expand Up @@ -1411,4 +1440,86 @@ public function run( ...$args ) {
$this
);
}

/**
* Get Feature Instructions from related file.
*
* @return string
*/
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 content from cache.
$locally_hosted_instruction = get_transient( $transient_key );

if ( ! empty( $locally_hosted_instruction ) ) {
return $locally_hosted_instruction;
}

$instruction_content_url = self::PLUGIN_LOCALLY_HOSTED_INSTRUCTION_URL;
$instruction_request = safe_wp_remote_get( $instruction_content_url );

if ( is_wp_error( $instruction_request ) ) {
return esc_html__( 'Instruction content cannot be downloaded.', 'classifai' );
}

$locally_hosted_instruction = wp_remote_retrieve_body( $instruction_request );

if ( empty( $locally_hosted_instruction ) || ! is_string( $locally_hosted_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 ) );

// Cache content.
set_transient( $transient_key, $locally_hosted_instruction, DAY_IN_SECONDS );

return $locally_hosted_instruction;
}
}
17 changes: 17 additions & 0 deletions includes/Classifai/Features/ImageCropping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -43,6 +50,16 @@ public function __construct() {
$this->supported_providers = [
ComputerVision::ID => __( 'Microsoft Azure AI Vision', 'classifai' ),
];

// Get readme content.
$readme_content = $this->get_instruction_content();

// Contains supported providers data.
$this->supported_providers_data = [
'instruction' => [
ComputerVision::ID => preg_match( '/## Set Up via Microsoft Azure(.*?)(?:\n## |\z)/s', $readme_content, $matches ) ? $matches[1] : '',
],
];
}

/**
Expand Down
Loading
Loading