Skip to content

Scaffold initial implementation #2

@swissspidy

Description

@swissspidy

https://github.com/WordPress/wp-ai-client is an AI client and API for WordPress to communicate with any generative AI models of various capabilities using a uniform API.

Built on top of the PHP AI Client, adapted for the WordPress ecosystem.

It's proposed to be included in WordPress 7.0. Right now it's bundled with the AI Experiments plugin, but others can use it too via Composer. Its features:

  • WordPress-native Prompt Builder: Fluent API for building and configuring AI prompts
  • Automatic Credential Wiring: Automatic wiring up of AI provider API credentials based on storage in a WordPress database option.
  1. Credentials Management
    Command: wp ai credentials
    Manage the API keys stored in the wp_ai_client_provider_credentials option. See API_Credentials_Settings_Screen and API_Credentials_Manager.

    Note: this may be replaced with wp option * family of commands instead, but dedicated ones for AI might be easiest to get started

  • 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.

Notes: There are some open questions regarding output formats. Perhaps we start with dedicated wp ai generate-text and then later add wp ai generate-image. And wp ai generate could output whatever. Need to decide how to return images. Should they be saved to disk?

Also: when --debug=ai is used, we should print some addition debugging information such as model used, tokens used, etc. As provided by GenerativeAiResult from the PHP AI Client

  • Arguments:
    • : The text prompt to send.
  • Options (Flags mapping to Prompt_Builder methods):
    • --model=: Maps to using_model(). Should support a comma-separated list of models in order of preference
    • --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).

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