Skip to content

Leverage WP AI Client #71

@swissspidy

Description

@swissspidy

Refactor wp ai to use https://github.com/WordPress/wp-ai-client, which is proposed for WP 7.0. Right now it's bundled with the AI plugin at https://github.com/WordPress/ai

This package here should be rewritten to use that AI client if it's available.

We can include it as a dev-dependency (composer require wordpress/wp-ai-client) for PHPStan stubs perhaps.

  1. Credentials Management
    Command: wp ai credentials
    Manage the API keys stored in the wp_ai_client_provider_credentials option.
  • wp ai credentials list
    • Description: Lists all configured providers and their status (masked key).
    • Implementation: Fetch wp_ai_client_provider_credentials option. Use
      API_Credentials_Manager::get_all_cloud_providers_metadata() to cross-reference available providers vs. configured ones.
  • wp ai credentials get <provider_id>
    • Description: Get the API key for a specific provider.
    • Example: wp ai credentials get openai
  • wp ai credentials set <provider_id> <api_key>
    • Description: Set or update the API key for a provider.
    • Implementation: Fetch the option array, update the key for the provider ID, and write it back using update_option.
  • wp ai credentials delete <provider_id>
    • Description: Remove an API key.
  1. AI Generation
    Command: wp ai generate
    Execute a prompt using the AI_Client::prompt() fluent interface.
  • Arguments:
    • : The text prompt to send.
  • Options (Flags mapping to Prompt_Builder methods):
    • --model=: Maps to using_model().
    • --provider=: Maps to using_provider().
    • --temperature=: Maps to using_temperature().
    • --max-tokens=: Maps to using_max_tokens().
    • --system-instruction=: Maps to using_system_instruction().
    • --format=<json|text>: Maps to as_json_response() or defaults to text.
  • Example:

1 wp ai generate "Write a haiku about WordPress" --provider=openai --temperature=0.7

  • Implementation:
    1. Call AI_Client::prompt( $prompt_arg ).
    2. Iterate over flags. If --temperature is set, call $builder->using_temperature( $val ).
    3. Call $builder->generate_text() and output the result.
  1. System Status & Diagnostics
    Command: wp ai status
    Check if the environment is ready for AI operations.
  • Description: Checks which capabilities are currently supported based on the environment and credentials.
  • Implementation:
    • Instantiate a builder: $builder = AI_Client::prompt();
    • Run checks:
      • Text Generation: + $builder->is_supported_for_text_generation()
      • Image Generation: + $builder->is_supported_for_image_generation()
    • Output a table of supported capabilities (Yes/No).

All the wp mcp commands are not really needed anymore

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions