File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 2323
2424 // TODO Register your tool here and add it to the collection
2525
26+ $ image_tools = new ImageTools ($ client );
27+
28+ foreach ($ image_tools ->get_tools () as $ tool ){
29+ $ tools ->add ($ tool );
30+ }
31+
32+
2633 // WordPress REST calls
2734 $ rest_tools = new MapRESTtoMCP ();
2835
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace WP_CLI \AiCommand ;
4+ use WP_CLI \AiCommand \Entity \Tool ;
5+
6+ class ImageTools {
7+
8+ private $ client ;
9+
10+ public function __construct ($ client ) {
11+ $ this ->client = $ client ;
12+ }
13+
14+ public function get_tools (){
15+ return [
16+ $ this ->image_generation_tool ()
17+ ];
18+ }
19+
20+ public function image_generation_tool () {
21+ return new Tool (
22+ [
23+ 'name ' => 'generate_image ' ,
24+ 'description ' => 'Generates an image ' ,
25+ 'inputSchema ' => [
26+ 'type ' => 'object ' ,
27+ 'properties ' => [
28+ 'prompt ' => [
29+ 'type ' => 'string ' ,
30+ 'description ' => 'The prompt for generating the image. ' ,
31+ ],
32+ ],
33+ 'required ' => [ 'prompt ' ],
34+ ],
35+ 'callable ' => function ( $ params ) {
36+
37+ return $ this ->client ->get_image_from_ai_service ( $ params ['prompt ' ] );
38+ },
39+ ]
40+ );
41+ }
42+
43+
44+
45+ }
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ static function () {
107107 rename ( $ filename , $ filename . '. ' . $ extension );
108108 $ filename .= '. ' . $ extension ;
109109
110- file_put_contents ( $ filename , $ image_blob ->get_binary_data () );
110+ // file_put_contents( $filename, $image_blob->get_binary_data() );
111111
112112 $ image_url = $ filename ;
113113 $ image_id = \WP_CLI \AiCommand \MediaManager::upload_to_media_library ($ image_url );
You can’t perform that action at this time.
0 commit comments