PluginProbe
AI / 0.2.0
AI v0.2.0
1.3.0 1.2.0 1.1.0 1.0.2 1.0.1 1.0.0 0.9.0 trunk 0.1.1 0.2.0 0.2.1 0.3.0 0.3.1 0.4.0 0.4.1 0.5.0 0.6.0 0.7.0 0.8.0
ai / includes / Experiments / Image_Generation / Image_Generation.php

Image_Generation.php in AI 0.2.0, at includes/Experiments/Image_Generation/Image_Generation.php

76 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Image generation experiment implementation.
4 *
5 * @package WordPress\AI
6 */
7
8 declare( strict_types=1 );
9
10 namespace WordPress\AI\Experiments\Image_Generation;
11
12 use WordPress\AI\Abilities\Image\Generate_Image as Image_Generation_Ability;
13 use WordPress\AI\Abilities\Image\Import_Base64_Image as Image_Import_Ability;
14 use WordPress\AI\Abstracts\Abstract_Experiment;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * Image generation experiment.
22 *
23 * @since 0.2.0
24 */
25 class Image_Generation extends Abstract_Experiment {
26
27 /**
28 * {@inheritDoc}
29 *
30 * @since 0.2.0
31 *
32 * @return array{id: string, label: string, description: string} Experiment metadata.
33 */
34 protected function load_experiment_metadata(): array {
35 return array(
36 'id' => 'image-generation',
37 'label' => __( 'Image Generation', 'ai' ),
38 'description' => __( 'Generates an image from a passed in prompt', 'ai' ),
39 );
40 }
41
42 /**
43 * {@inheritDoc}
44 *
45 * @since 0.2.0
46 */
47 public function register(): void {
48 add_action( 'wp_abilities_api_init', array( $this, 'register_abilities' ) );
49 }
50
51 /**
52 * Registers any needed abilities.
53 *
54 * @since 0.2.0
55 */
56 public function register_abilities(): void {
57 wp_register_ability(
58 'ai/' . $this->get_id(),
59 array(
60 'label' => $this->get_label(),
61 'description' => $this->get_description(),
62 'ability_class' => Image_Generation_Ability::class,
63 ),
64 );
65
66 wp_register_ability(
67 'ai/image-import',
68 array(
69 'label' => __( 'Base64 Image Import', 'ai' ),
70 'description' => __( 'Imports a base64 encoded image into the media library', 'ai' ),
71 'ability_class' => Image_Import_Ability::class,
72 ),
73 );
74 }
75 }
76