Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@

require_once __DIR__ . '/vendor/autoload.php';

use Symfony\Component\Dotenv\Dotenv;
use WordPress\AnthropicAiProvider\Provider\AnthropicProvider;
use WordPress\GoogleAiProvider\Provider\GoogleProvider;
use WordPress\OpenAiAiProvider\Provider\OpenAiProvider;

// Load .env file if it exists (same approach as integration test bootstrap).
$envFile = __DIR__ . '/.env';
if (file_exists($envFile)) {
$dotenv = new Dotenv();
$dotenv->usePutenv(true);
$dotenv->load($envFile);
}

// Register provider packages so the registry can discover them.
$registry = AiClient::defaultRegistry();
if (class_exists(AnthropicProvider::class)) {
$registry->registerProvider(AnthropicProvider::class);
}
if (class_exists(GoogleProvider::class)) {
$registry->registerProvider(GoogleProvider::class);
}
if (class_exists(OpenAiProvider::class)) {
$registry->registerProvider(OpenAiProvider::class);
}
Comment on lines +39 to +49

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not ideal to hard-code specific providers here. What if you want to test the CLI with other ones?

I think this should be removed. It would be better to instead support a simple system where another user-controlled file handles the registration of providers. Could look like this:

  1. check if the file (e.g. __DIR__ . '/cli-providers.php) exists
  2. if so, implement a closure here in which that file is loaded, with only access to the $registry instance so that it cannot do anything else

The cli-providers.php file would be git-ignored. It would need to look something like this (with $registry being in the local scope of where it is required):

use WordPress\AnthropicAiProvider\Provider\AnthropicProvider;
use WordPress\GoogleAiProvider\Provider\GoogleProvider;
use WordPress\OpenAiAiProvider\Provider\OpenAiProvider;

$registry->registerProvider(AnthropicProvider::class);
$registry->registerProvider(GoogleProvider::class);
$registry->registerProvider(OpenAiProvider::class);


/**
* Prints the output to stdout.
*
Expand Down
Loading