Skip to content

Commit

Permalink
Merge pull request #851 from 10up/feature/848
Browse files Browse the repository at this point in the history
Add OpenAI as a Provider for the Image Tags Generator and Image Text Extraction Features
  • Loading branch information
iamdharmesh authored Feb 14, 2025
2 parents 3ac7426 + 9dddb80 commit 372a8e6
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Tap into leading cloud-based services like [OpenAI](https://openai.com/), [Micro
* Find similar terms to merge together using either [OpenAI's Embedding API](https://platform.openai.com/docs/guides/embeddings) or [Microsoft Azure's OpenAI service](https://azure.microsoft.com/en-us/products/ai-services/openai-service) in combination with [ElasticPress](https://github.com/10up/ElasticPress). Note this only compares top-level terms and if you merge a term that has children, these become top-level terms as per default WordPress behavior
* BETA: Recommend content based on overall site traffic via [Microsoft Azure's AI Personalizer API](https://azure.microsoft.com/en-us/services/cognitive-services/personalizer/) *(note that this service has been [deprecated by Microsoft](https://learn.microsoft.com/en-us/azure/ai-services/personalizer/) and as such, will no longer work. We are looking to replace this with a new provider to maintain the same functionality (see [issue#392](https://github.com/10up/classifai/issues/392))*
* Generate image alt text using [Microsoft Azure's AI Vision API](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/), [OpenAI's ChatGPT API](https://platform.openai.com/docs/guides/chat), [xAI's Grok](https://x.ai/) or locally using [Ollama](https://ollama.com/)
* Generate image tags and extract text from images using [Microsoft Azure's AI Vision API](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/) or locally using [Ollama](https://ollama.com/)
* Generate image tags and extract text from images using [Microsoft Azure's AI Vision API](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/), [OpenAI's ChatGPT API](https://platform.openai.com/docs/guides/chat) or locally using [Ollama](https://ollama.com/)
* Smartly crop images using [Microsoft Azure's AI Vision API](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/)
* Scan PDF files for embedded text and save for use in post meta using [Microsoft Azure's AI Vision API](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/)
* Bulk classify content with [WP-CLI](https://wp-cli.org/)
Expand Down
11 changes: 11 additions & 0 deletions includes/Classifai/Features/ImageTagsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Classifai\Features;

use Classifai\Providers\Azure\ComputerVision;
use Classifai\Providers\OpenAI\ChatGPT;
use Classifai\Providers\Localhost\OllamaMultimodal as OllamaMM;
use Classifai\Services\ImageProcessing;
use WP_REST_Server;
Expand Down Expand Up @@ -49,6 +50,7 @@ public function __construct() {
// Contains just the providers this feature supports.
$this->supported_providers = [
ComputerVision::ID => __( 'Microsoft Azure AI Vision', 'classifai' ),
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
OllamaMM::ID => __( 'Ollama', 'classifai' ),
];
}
Expand All @@ -73,6 +75,15 @@ public function get_settings( $index = false ) {
$settings = parent::get_settings( $index );

// Keep using the original prompt from the codebase to allow updates.
if ( $settings && ! empty( $settings[ ChatGPT::ID ]['prompt'] ) ) {
foreach ( $settings[ ChatGPT::ID ]['prompt'] as $key => $prompt ) {
if ( 1 === intval( $prompt['original'] ) ) {
$settings[ ChatGPT::ID ]['prompt'][ $key ]['prompt'] = $this->prompt;
break;
}
}
}

if ( $settings && ! empty( $settings[ OllamaMM::ID ]['prompt'] ) ) {
foreach ( $settings[ OllamaMM::ID ]['prompt'] as $key => $prompt ) {
if ( 1 === intval( $prompt['original'] ) ) {
Expand Down
11 changes: 11 additions & 0 deletions includes/Classifai/Features/ImageTextExtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Classifai\Features;

use Classifai\Providers\Azure\ComputerVision;
use Classifai\Providers\OpenAI\ChatGPT;
use Classifai\Providers\Localhost\OllamaMultimodal as OllamaMM;
use Classifai\Services\ImageProcessing;
use WP_REST_Server;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function __construct() {
// Contains just the providers this feature supports.
$this->supported_providers = [
ComputerVision::ID => __( 'Microsoft Azure AI Vision', 'classifai' ),
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
OllamaMM::ID => __( 'Ollama', 'classifai' ),
];
}
Expand All @@ -67,6 +69,15 @@ public function get_settings( $index = false ) {
$settings = parent::get_settings( $index );

// Keep using the original prompt from the codebase to allow updates.
if ( $settings && ! empty( $settings[ ChatGPT::ID ]['prompt'] ) ) {
foreach ( $settings[ ChatGPT::ID ]['prompt'] as $key => $prompt ) {
if ( 1 === intval( $prompt['original'] ) ) {
$settings[ ChatGPT::ID ]['prompt'][ $key ]['prompt'] = $this->prompt;
break;
}
}
}

if ( $settings && ! empty( $settings[ OllamaMM::ID ]['prompt'] ) ) {
foreach ( $settings[ OllamaMM::ID ]['prompt'] as $key => $prompt ) {
if ( 1 === intval( $prompt['original'] ) ) {
Expand Down
Loading

0 comments on commit 372a8e6

Please sign in to comment.