Skip to content

Commit 2a59e42

Browse files
authored
Merge pull request #700 from 10up/enhacement/google-ai
Add Google AI (Gemini API) Provider for the Title Generation, Excerpt Generation and Content resizing.
2 parents 5685687 + fb952b4 commit 2a59e42

19 files changed

+1447
-95
lines changed

README.md

+78-35
Large diffs are not rendered by default.

includes/Classifai/Features/ContentResizing.php

+8-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Classifai\Features;
44

5+
use Classifai\Providers\GoogleAI\GeminiAPI;
56
use Classifai\Providers\OpenAI\ChatGPT;
67
use Classifai\Services\LanguageProcessing;
78
use WP_REST_Server;
@@ -48,7 +49,8 @@ public function __construct() {
4849

4950
// Contains just the providers this feature supports.
5051
$this->supported_providers = [
51-
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
52+
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
53+
GeminiAPI::ID => __( 'Google AI (Gemini API)', 'classifai' ),
5254
];
5355
}
5456

@@ -234,22 +236,6 @@ public function get_enable_description(): string {
234236
public function add_custom_settings_fields() {
235237
$settings = $this->get_settings();
236238

237-
add_settings_field(
238-
'number_of_suggestions',
239-
esc_html__( 'Number of suggestions', 'classifai' ),
240-
[ $this, 'render_input' ],
241-
$this->get_option_name(),
242-
$this->get_option_name() . '_section',
243-
[
244-
'label_for' => 'number_of_suggestions',
245-
'input_type' => 'number',
246-
'min' => 1,
247-
'step' => 1,
248-
'default_value' => $settings['number_of_suggestions'],
249-
'description' => esc_html__( 'Number of suggestions that will be generated in one request.', 'classifai' ),
250-
]
251-
);
252-
253239
add_settings_field(
254240
'condense_text_prompt',
255241
esc_html__( 'Condense text prompt', 'classifai' ),
@@ -286,22 +272,21 @@ public function add_custom_settings_fields() {
286272
*/
287273
public function get_feature_default_settings(): array {
288274
return [
289-
'number_of_suggestions' => 1,
290-
'condense_text_prompt' => [
275+
'condense_text_prompt' => [
291276
[
292277
'title' => esc_html__( 'ClassifAI default', 'classifai' ),
293278
'prompt' => $this->condense_prompt,
294279
'original' => 1,
295280
],
296281
],
297-
'expand_text_prompt' => [
282+
'expand_text_prompt' => [
298283
[
299284
'title' => esc_html__( 'ClassifAI default', 'classifai' ),
300285
'prompt' => $this->expand_prompt,
301286
'original' => 1,
302287
],
303288
],
304-
'provider' => ChatGPT::ID,
289+
'provider' => ChatGPT::ID,
305290
];
306291
}
307292

@@ -314,9 +299,8 @@ public function get_feature_default_settings(): array {
314299
public function sanitize_default_feature_settings( array $new_settings ): array {
315300
$settings = $this->get_settings();
316301

317-
$new_settings['number_of_suggestions'] = sanitize_number_of_responses_field( 'number_of_suggestions', $new_settings, $settings );
318-
$new_settings['condense_text_prompt'] = sanitize_prompts( 'condense_text_prompt', $new_settings );
319-
$new_settings['expand_text_prompt'] = sanitize_prompts( 'expand_text_prompt', $new_settings );
302+
$new_settings['condense_text_prompt'] = sanitize_prompts( 'condense_text_prompt', $new_settings );
303+
$new_settings['expand_text_prompt'] = sanitize_prompts( 'expand_text_prompt', $new_settings );
320304

321305
return $new_settings;
322306
}

includes/Classifai/Features/ExcerptGeneration.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Classifai\Features;
44

5+
use Classifai\Providers\GoogleAI\GeminiAPI;
56
use Classifai\Services\LanguageProcessing;
67
use Classifai\Providers\OpenAI\ChatGPT;
78
use WP_REST_Server;
@@ -40,7 +41,8 @@ public function __construct() {
4041

4142
// Contains just the providers this feature supports.
4243
$this->supported_providers = [
43-
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
44+
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
45+
GeminiAPI::ID => __( 'Google AI (Gemini API)', 'classifai' ),
4446
];
4547
}
4648

@@ -263,7 +265,7 @@ public function enqueue_admin_assets( string $hook_suffix ) {
263265
* @return string
264266
*/
265267
public function get_enable_description(): string {
266-
return esc_html__( 'A button will be added to the status panel that can be used to generate titles.', 'classifai' );
268+
return esc_html__( 'A button will be added to the excerpt panel that can be used to generate an excerpt.', 'classifai' );
267269
}
268270

269271
/**
@@ -320,7 +322,7 @@ public function add_custom_settings_fields() {
320322
'min' => 1,
321323
'step' => 1,
322324
'default_value' => $settings['length'],
323-
'description' => __( 'How many words should the excerpt be? Note that the final result may not exactly match this. In testing, ChatGPT tended to exceed this number by 10-15 words.', 'classifai' ),
325+
'description' => __( 'How many words should the excerpt be? Note that the final result may not exactly match this, it often tends to exceed this number by 10-15 words.', 'classifai' ),
324326
]
325327
);
326328
}

includes/Classifai/Features/TitleGeneration.php

+3-22
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Classifai\Features;
44

5+
use Classifai\Providers\GoogleAI\GeminiAPI;
56
use Classifai\Services\LanguageProcessing;
67
use Classifai\Providers\OpenAI\ChatGPT;
78
use WP_REST_Server;
89
use WP_REST_Request;
910
use WP_Error;
1011

1112
use function Classifai\sanitize_prompts;
12-
use function Classifai\sanitize_number_of_responses_field;
1313
use function Classifai\get_asset_info;
1414

1515
/**
@@ -41,7 +41,8 @@ public function __construct() {
4141

4242
// Contains just the providers this feature supports.
4343
$this->supported_providers = [
44-
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
44+
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
45+
GeminiAPI::ID => __( 'Google AI (Gemini API)', 'classifai' ),
4546
];
4647
}
4748

@@ -315,22 +316,6 @@ public function get_enable_description(): string {
315316
public function add_custom_settings_fields() {
316317
$settings = $this->get_settings();
317318

318-
add_settings_field(
319-
'number_of_titles',
320-
esc_html__( 'Number of titles', 'classifai' ),
321-
[ $this, 'render_input' ],
322-
$this->get_option_name(),
323-
$this->get_option_name() . '_section',
324-
[
325-
'label_for' => 'number_of_titles',
326-
'input_type' => 'number',
327-
'min' => 1,
328-
'step' => 1,
329-
'default_value' => $settings['number_of_titles'],
330-
'description' => esc_html__( 'Number of titles that will be generated in one request.', 'classifai' ),
331-
]
332-
);
333-
334319
add_settings_field(
335320
'generate_title_prompt',
336321
esc_html__( 'Prompt', 'classifai' ),
@@ -353,7 +338,6 @@ public function add_custom_settings_fields() {
353338
*/
354339
public function get_feature_default_settings(): array {
355340
return [
356-
'number_of_titles' => 1,
357341
'generate_title_prompt' => [
358342
[
359343
'title' => esc_html__( 'ClassifAI default', 'classifai' ),
@@ -372,9 +356,6 @@ public function get_feature_default_settings(): array {
372356
* @return array
373357
*/
374358
public function sanitize_default_feature_settings( array $new_settings ): array {
375-
$settings = $this->get_settings();
376-
377-
$new_settings['number_of_titles'] = sanitize_number_of_responses_field( 'number_of_titles', $new_settings, $settings );
378359
$new_settings['generate_title_prompt'] = sanitize_prompts( 'generate_title_prompt', $new_settings );
379360

380361
return $new_settings;

0 commit comments

Comments
 (0)