Skip to content

Conversation

@Jameswlepage
Copy link
Contributor

@Jameswlepage Jameswlepage commented Dec 19, 2025

CleanShot 2025-12-19 at 09 15 39@2x

What?

Adds a new Extended Providers experiment that registers 9 additional AI provider integrations:

  • Cloudflare Workers AI
  • Cohere
  • DeepSeek
  • Fal.ai (image generation)
  • Grok (xAI)
  • Groq
  • HuggingFace
  • Ollama (local)
  • OpenRouter

Also includes provider credentials UI enhancements and a metadata registry for custom branding per provider.

Why?

The core wp-ai-client package ships with OpenAI, Anthropic, and Google. Users want access to additional providers—especially local options like Ollama and cost-effective alternatives like Groq and DeepSeek.

How?

  • Adds Extended_Providers experiment class that registers all 9 providers with the wp-ai-client registry
  • Each provider includes a Provider class, TextGenerationModel (or ImageGenerationModel for Fal.ai), and ModelMetadataDirectory
  • Adds Provider_Metadata_Registry for custom branding (icons, colors, API key URLs)
  • Adds Provider_Credentials_UI initialization to display enhanced credentials screen
  • Works around provider registration timing issue (see Add hook for registering providers before metadata collection wp-ai-client#43)

Testing Instructions

  1. Enable the Extended Providers experiment in Settings → AI → Experiments
  2. Navigate to Settings → AI and verify all 9 providers appear on the credentials screen
  3. Add an API key for at least one cloud provider (e.g., Groq, DeepSeek) and verify it saves
  4. If you have Ollama running locally, verify it appears and connects
Open WordPress Playground Preview

Adds additional AI provider integrations:
- Cloudflare Workers AI
- Cohere
- DeepSeek
- Fal.ai
- HuggingFace
- Ollama
- OpenRouter
- xAI (Grok)

Includes provider credentials UI and metadata registry.
- Initialize HTTP discovery strategy before experiments load
- Register extended providers immediately instead of on late init hook
- Initialize Provider_Credentials_UI for enhanced credentials display
- Reorder initialization: HTTP client → experiments → AI_Client

The wp-ai-client package collects providers during AI_Client::init().
Extended providers must be registered before that collection occurs.
- Add phpcs:disable/enable blocks for exception escaping false positives
- Add phpcs:ignore for DisallowMultiConstantDefinition false positives
- Update @return annotations to use fully qualified class names
- Fix variable alignment spacing issues
- Add missing translators comment for placeholder
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 0.44477% with 1343 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.98%. Comparing base (7dbbc44) to head (f99595c).
⚠️ Report is 20 commits behind head on develop.

Files with missing lines Patch % Lines
includes/Admin/Provider_Metadata_Registry.php 0.00% 164 Missing ⚠️
...des/Providers/Cohere/CohereTextGenerationModel.php 0.00% 142 Missing ⚠️
...eriments/Extended_Providers/Extended_Providers.php 3.44% 140 Missing ⚠️
...udes/Providers/Grok/GrokModelMetadataDirectory.php 0.00% 86 Missing ⚠️
...udflare/CloudflareWorkersAiTextGenerationModel.php 0.00% 80 Missing ⚠️
...udes/Providers/FalAi/FalAiImageGenerationModel.php 0.00% 77 Missing ⚠️
...des/Providers/Ollama/OllamaTextGenerationModel.php 0.00% 65 Missing ⚠️
...udes/Providers/Groq/GroqModelMetadataDirectory.php 0.00% 56 Missing ⚠️
.../Providers/Cohere/CohereModelMetadataDirectory.php 0.00% 45 Missing ⚠️
...oviders/Cloudflare/CloudflareWorkersAiProvider.php 0.00% 39 Missing ⚠️
... and 21 more
Additional details and impacted files
@@              Coverage Diff               @@
##             develop     #148       +/-   ##
==============================================
- Coverage      46.89%   22.98%   -23.91%     
- Complexity       208      543      +335     
==============================================
  Files             19       49       +30     
  Lines           1271     2619     +1348     
==============================================
+ Hits             596      602        +6     
- Misses           675     2017     +1342     
Flag Coverage Δ
unit 22.98% <0.44%> (-23.91%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an Extended Providers experiment that registers 9 additional AI provider integrations (Cloudflare, Cohere, DeepSeek, Fal.ai, Grok, Groq, HuggingFace, Ollama, OpenRouter) alongside the core providers (OpenAI, Anthropic, Google). It includes enhanced UI for provider credentials with custom branding, icons, and tooltips.

Key changes:

  • New Extended Providers experiment with provider class registration system
  • Enhanced credentials UI with React components for provider icons and interactive tooltips
  • Provider implementations for 9 additional AI services
  • Provider metadata registry for custom branding per provider
  • Bootstrap initialization reordered to register providers before AI Client initialization

Reviewed changes

Copilot reviewed 54 out of 54 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
webpack.config.js Adds provider-credentials entry point for admin UI assets
src/admin/provider-credentials/* React components and styles for enhanced credentials screen with provider icons and tooltips
src/admin/components/provider-icons.tsx Icon component registry mapping provider IDs to SVG icon components
src/admin/components/icons/* SVG icon components for all providers (Anthropic, OpenAI, Google, etc.)
src/admin/components/ProviderTooltipContent.tsx Tooltip component displaying provider metadata and available models
includes/bootstrap.php Reorders initialization to register extended providers before AI Client init
includes/Providers/*/ Provider implementations for OpenRouter, Ollama, HuggingFace, Groq, Grok, FalAi, DeepSeek, Cohere, and Cloudflare
includes/Experiments/Extended_Providers/* Experiment class implementing provider registration with filtering and selection UI
includes/Experiment_Loader.php Registers Extended_Providers experiment in default list
includes/Admin/Provider_Metadata_Registry.php Central registry providing structured metadata and branding for all providers
includes/Admin/Provider_Credentials_UI.php Initializes enhanced credentials UI assets
docs/experiments/extended-providers.md Documentation for Extended Providers experiment features and usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*/
private static function get_initials( string $name ): string {
$parts = preg_split( '/\s+/', trim( $name ) );
if ( empty( $parts ) ) {
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The preg_split function should have its return value validated. If preg_split fails (returns false), it should be handled to prevent type errors. Consider adding error handling or using an alternative approach with explode.

Suggested change
if ( empty( $parts ) ) {
if ( false === $parts || empty( $parts ) ) {

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +42
$request = new Request(
HttpMethodEnum::POST(),
rtrim( OllamaProvider::get_base_url(), '/api' ) . '/api/chat',
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The URL construction logic using rtrim to remove '/api' and then appending '/api/chat' is fragile. If the base URL doesn't end with '/api', this will result in an incorrect URL. Consider using a more robust URL construction approach or documenting the expected format of the base URL.

Suggested change
$request = new Request(
HttpMethodEnum::POST(),
rtrim( OllamaProvider::get_base_url(), '/api' ) . '/api/chat',
$base_url = rtrim( OllamaProvider::get_base_url(), '/' );
if ( preg_match( '#/api/?$#', $base_url ) === 1 ) {
$base_url = preg_replace( '#/api/?$#', '', $base_url );
}
$endpoint = $base_url . '/api/chat';
$request = new Request(
HttpMethodEnum::POST(),
$endpoint,

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +34
$request = new Request(
HttpMethodEnum::GET(),
rtrim( OllamaProvider::get_base_url(), '/api' ) . '/api/tags'
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The URL construction logic using rtrim to remove '/api' and then appending '/api/tags' is fragile and duplicates the same pattern from OllamaTextGenerationModel. If the base URL doesn't end with '/api', this will result in an incorrect URL. Consider extracting this logic to a helper method in the OllamaProvider class.

Suggested change
$request = new Request(
HttpMethodEnum::GET(),
rtrim( OllamaProvider::get_base_url(), '/api' ) . '/api/tags'
$base_url = rtrim( OllamaProvider::get_base_url(), '/' );
// Ensure the base URL ends with '/api' exactly once before appending '/tags'.
if ( substr( $base_url, -4 ) !== '/api' ) {
$base_url .= '/api';
}
$request = new Request(
HttpMethodEnum::GET(),
$base_url . '/tags'

Copilot uses AI. Check for mistakes.
*/
import domReady from '@wordpress/dom-ready';
import { Popover } from '@wordpress/components';
import { useRef, useState, useEffect } from '@wordpress/element';
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

Unused import useEffect.

Copilot uses AI. Check for mistakes.
@Jameswlepage Jameswlepage changed the title Add Extended Providers experiment with support for Cloudflare, Cohere, DeepSeek, Fal.ai, Grok, Groq, HuggingFace, Ollama, and OpenRouter Add Extended Providers experiment Dec 19, 2025
@jeffpaul
Copy link
Member

@jeffpaul
Copy link
Member

  • Reminder for us to add a screenshot gif and entry in the readme.txt for this feature before merging/releasing.

@JasonTheAdams JasonTheAdams removed their request for review December 21, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

2 participants