From 4844b7c92993bd77c79e2e6f38a4d7c6b0e9b295 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 15 Mar 2025 16:54:09 +0100 Subject: [PATCH 1/2] Keep prompt open --- src/MCP/Client.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/MCP/Client.php b/src/MCP/Client.php index 39d74e2..7ebda84 100644 --- a/src/MCP/Client.php +++ b/src/MCP/Client.php @@ -172,12 +172,19 @@ static function () { ] ); - \WP_CLI::log( 'Making request...' . print_r( $contents, true ) ); +// \WP_CLI::log( 'Making request...' . print_r( $contents, true ) ); + + if( $service->get_service_slug() === 'openai' ) { + $model = 'gpt-4o'; + } else { + $model = 'gemini-2.0-flash'; + } $candidates = $service ->get_model( [ 'feature' => 'text-generation', + 'model' => $model, 'tools' => $tools, 'capabilities' => [ AI_Capability::MULTIMODAL_INPUT, @@ -196,7 +203,7 @@ static function () { } $text .= $part->get_text(); } elseif ( $part instanceof Function_Call_Part ) { - var_dump( 'call function', $part ); +// var_dump( 'call function', $part ); $function_result = $this->{$part->get_name()}( $part->get_args() ); // Odd limitation of add_function_response_part(). @@ -221,7 +228,15 @@ static function () { return $this->call_ai_service( $new_contents ); } - return $text; + // Keep the session open to continue chatting. + + $response = \cli\prompt( 'Continue' ); + + $parts = new Parts(); + $parts->add_text_part( $response ); + $content = new Content( Content_Role::USER, $parts ); + $new_contents[] = $content; + return $this->call_ai_service( $new_contents ); } catch ( Exception $e ) { WP_CLI::error( $e->getMessage() ); } From aae64aabf48dbfc658fec74a3d3bcb51366c4223 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 15 Mar 2025 16:54:46 +0100 Subject: [PATCH 2/2] Fix formatting --- src/MCP/Client.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/MCP/Client.php b/src/MCP/Client.php index 7ebda84..462b2a5 100644 --- a/src/MCP/Client.php +++ b/src/MCP/Client.php @@ -172,9 +172,9 @@ static function () { ] ); -// \WP_CLI::log( 'Making request...' . print_r( $contents, true ) ); + \WP_CLI::log( 'Making request...' . print_r( $contents, true ) ); - if( $service->get_service_slug() === 'openai' ) { + if ( $service->get_service_slug() === 'openai' ) { $model = 'gpt-4o'; } else { $model = 'gemini-2.0-flash'; @@ -203,7 +203,6 @@ static function () { } $text .= $part->get_text(); } elseif ( $part instanceof Function_Call_Part ) { -// var_dump( 'call function', $part ); $function_result = $this->{$part->get_name()}( $part->get_args() ); // Odd limitation of add_function_response_part().