Skip to content

Commit f807a05

Browse files
Copilotswissspidy
andcommitted
Address code review feedback
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent c195bc1 commit f807a05

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

ai-command.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
require_once __DIR__ . '/vendor/autoload.php';
1313
}
1414

15-
WP_CLI::add_command( 'ai', AiCommand::class );
16-
WP_CLI::add_command( 'ai credentials', CredentialsCommand::class );
17-
WP_CLI::add_command( 'mcp prompt', AiCommand::class );
18-
WP_CLI::add_command( 'mcp', McpCommand::class );
19-
WP_CLI::add_command( 'mcp server', McpServerCommand::class );
15+
WP_CLI::add_command( 'ai', \McpWp\AiCommand\AiCommand::class );
16+
WP_CLI::add_command( 'ai credentials', \McpWp\AiCommand\CredentialsCommand::class );
17+
WP_CLI::add_command( 'mcp prompt', \McpWp\AiCommand\AiCommand::class );
18+
WP_CLI::add_command( 'mcp', \McpWp\AiCommand\McpCommand::class );
19+
WP_CLI::add_command( 'mcp server', \McpWp\AiCommand\McpServerCommand::class );

src/AI/WpAiClient.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ public function call_ai_service_with_prompt( string $prompt ): void {
8787
if ( $this->service && $this->model ) {
8888
$prompt_builder = $prompt_builder->using_model_preference( [ $this->service, $this->model ] );
8989
} elseif ( $this->model ) {
90-
// If only model is specified, try to use it as a preference.
91-
$prompt_builder = $prompt_builder->using_model_preference( [ 'anthropic', $this->model ], [ 'openai', $this->model ], [ 'google', $this->model ] );
90+
// If only model is specified without a service, try common providers.
91+
// This provides a reasonable fallback that works with most configurations.
92+
// The WP AI Client will automatically use the first available provider
93+
// that has the specified model and is properly configured.
94+
$prompt_builder = $prompt_builder->using_model_preference(
95+
[ 'anthropic', $this->model ],
96+
[ 'openai', $this->model ],
97+
[ 'google', $this->model ]
98+
);
9299
}
93100

94101
// Generate text response.

src/AiCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Mcp\Client\ClientSession;
66
use McpWp\AiCommand\AI\AiClient;
7+
use McpWp\AiCommand\AI\WpAiClient;
78
use McpWp\AiCommand\MCP\Client;
89
use McpWp\AiCommand\Utils\CliLogger;
910
use McpWp\AiCommand\Utils\McpConfig;
@@ -87,7 +88,7 @@ public function __invoke( array $args, array $assoc_args ): void {
8788
$skip_builtin_servers = Utils\get_flag_value( $assoc_args, 'skip-builtin-servers' );
8889
// Only use WP AI Client if MCP servers are skipped.
8990
if ( $skip_builtin_servers ) {
90-
$ai_client = new AI\WpAiClient( [], $approval_mode, $service, $model );
91+
$ai_client = new WpAiClient( [], $approval_mode, $service, $model );
9192
$ai_client->call_ai_service_with_prompt( $args[0] );
9293
return;
9394
}

src/CredentialsCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class CredentialsCommand extends WP_CLI_Command {
2020
*
2121
* # List all credentials
2222
* $ wp ai credentials list
23-
* +----------+------------+
24-
* | Provider | Status |
25-
* +----------+------------+
26-
* | openai | configured |
27-
* | anthropic| configured |
28-
* +----------+------------+
23+
* +-----------+------------+
24+
* | Provider | Status |
25+
* +-----------+------------+
26+
* | openai | configured |
27+
* | anthropic | configured |
28+
* +-----------+------------+
2929
*
3030
* @when before_wp_load
3131
*

0 commit comments

Comments
 (0)