Skip to content

Conversation

Copy link

Copilot AI commented Dec 7, 2025

Integrates WordPress AI Client (proposed for WP 7.0) as the required backend for AI functionality.

Implementation

  • WP AI Client only: Command requires WP AI Client (WordPress 7.0+ or AI plugin)
  • Credentials management: New wp ai credentials subcommand with list/set/delete operations
  • Simplified approach: Focused on core text generation functionality

Changes

  • Added wordpress/wp-ai-client: ^0.2.1 as dev-dependency for PHPStan stubs
  • Created CredentialsCommand for managing provider API keys via WordPress options
  • Created WpAiClient wrapper implementing conversational prompt interface
  • Modified AiCommand to require WP AI Client (no fallback)
  • Removed AI Services plugin dependency and backward compatibility
  • Updated README with WP AI Client-only configuration
  • Simplified command documentation and removed MCP tool references

Usage

# Configure credentials
wp ai credentials set openai sk-proj-...
wp ai credentials list

# Simple prompts
wp ai "Explain WordPress in one sentence"

# Use specific model
wp ai "Summarize WordPress history" --model=gpt-4o

Credentials stored in wp_ai_client_provider_credentials option, compatible with WP AI Client's admin settings screen.

Notes

MCP tool integration has been temporarily removed as WP AI Client doesn't support function calling yet. This can be added in a future update when the capability becomes available.

Original prompt

This section details on the original issue you should resolve

<issue_title>Leverage WP AI Client</issue_title>
<issue_description>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</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 7, 2025 15:05
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor wp ai to leverage WP AI Client Leverage WP AI Client Dec 7, 2025
Copilot AI requested a review from swissspidy December 7, 2025 15:12
@swissspidy
Copy link
Collaborator

@copilot No backward compatibility, remove that fallback.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 7, 2025

@copilot No backward compatibility, remove that fallback.

Removed AI Services fallback. The command now requires WP AI Client exclusively. Changes in commit ca652fc:

  • Removed all AI Services plugin dependencies and fallback code
  • Simplified to use only WP AI Client
  • Updated documentation and tests to reflect WP AI Client as the sole backend
  • Removed MCP tool integration (can be added later when WP AI Client supports function calling)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leverage WP AI Client

2 participants