Skip to content

Commit e6300fd

Browse files
committed
2 parents 7f8a2cc + 61b6f40 commit e6300fd

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

ai-command.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
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

src/ImageTools.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

src/MCP/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)