From 5da22ea3e13d693c17caac83d6cadeeedd714191 Mon Sep 17 00:00:00 2001 From: Tome Pajkovski Date: Sun, 16 Mar 2025 17:13:07 +0100 Subject: [PATCH 1/3] removing the model selection bug --- src/MCP/Client.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MCP/Client.php b/src/MCP/Client.php index f641ee5..67b7671 100644 --- a/src/MCP/Client.php +++ b/src/MCP/Client.php @@ -188,17 +188,17 @@ static function () { \WP_CLI::debug( 'Making request...' . print_r( $contents, true ), 'ai' ); - if ( $service->get_service_slug() === 'openai' ) { - $model = 'gpt-4o'; - } else { - $model = 'gemini-2.0-flash'; - } + // if ( $service->get_service_slug() === 'openai' ) { + // $model = 'gpt-4o'; + // } else { + // $model = 'gemini-2.0-flash'; + // } $candidates = $service ->get_model( [ 'feature' => 'text-generation', - 'model' => $model, + // 'model' => $model, 'tools' => $tools, 'capabilities' => [ AI_Capability::MULTIMODAL_INPUT, From 35746f2f22e9ecc1af5be8820bf3d07e8f2fb280 Mon Sep 17 00:00:00 2001 From: Tome Pajkovski Date: Sun, 16 Mar 2025 17:13:40 +0100 Subject: [PATCH 2/3] adding the media manager class --- src/MediaManager.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/MediaManager.php diff --git a/src/MediaManager.php b/src/MediaManager.php new file mode 100644 index 0000000..e1998dd --- /dev/null +++ b/src/MediaManager.php @@ -0,0 +1,38 @@ + $wp_filetype['type'], + 'post_title' => sanitize_file_name($file_name), + 'post_content' => '', + 'post_status' => 'inherit' + ); + + // Insert the attachment + $attach_id = wp_insert_attachment($attachment, $new_file_path); + + // Generate attachment metadata + require_once(ABSPATH . 'wp-admin/includes/image.php'); + $attach_data = wp_generate_attachment_metadata($attach_id, $new_file_path); + wp_update_attachment_metadata($attach_id, $attach_data); + + return $attach_id; + + } +} \ No newline at end of file From 62012c67aa838e11466572fb8c3f209d11e7762e Mon Sep 17 00:00:00 2001 From: Tome Pajkovski Date: Sun, 16 Mar 2025 17:19:45 +0100 Subject: [PATCH 3/3] returning the image generation functionality --- src/MCP/Client.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MCP/Client.php b/src/MCP/Client.php index 67b7671..8a2a07e 100644 --- a/src/MCP/Client.php +++ b/src/MCP/Client.php @@ -110,6 +110,7 @@ static function () { file_put_contents( $filename, $image_blob->get_binary_data() ); $image_url = $filename; + $image_id = \WP_CLI\AiCommand\MediaManager::upload_to_media_library($image_url); } break; @@ -120,6 +121,8 @@ static function () { // TODO: Save as file or so. break; } + + return $image_id || 'no image found'; } // See https://github.com/felixarntz/ai-services/blob/main/docs/Accessing-AI-Services-in-PHP.md for further processing.