| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Archived: This package is superseded by WordPress core's wp-ai-client APIs. Data Machine no longer uses this runtime dependency; provider/model/key administration and image generation have moved to wp-ai-client-shaped capabilities. This repository remains available for historical reference only and should not be used for new work.
A professional WordPress library for unified AI provider communication. Supports OpenAI, Anthropic, Google Gemini, Grok, and OpenRouter with standardized request/response formats.
Key Features:
Composer (recommended for standalone use):
composer require chubes4/ai-http-clientGit Subtree (recommended for plugin embedding):
git subtree add --prefix=lib/ai-http-client https://github.com/chubes4/ai-http-client.git main --squashManual Installation: Download and include in your WordPress plugin or theme
Requirements: PHP 7.4+, WordPress environment
Breaking Changes: All filter/action hooks renamed from ai_* to chubes_ai_* for WordPress.org compliance.
API keys are automatically migrated on first admin page load:
Update all references in your code:
// OLD (v1.x)
apply_filters('ai_providers', [])
apply_filters('ai_provider_api_keys', null)
apply_filters('ai_models', $provider)
apply_filters('ai_tools', [])
apply_filters('ai_request', $request)
apply_filters('ai_file_to_base64', '', $path)
apply_filters('ai_http', [], $method, $url, $args)
// NEW (v2.0)
apply_filters('chubes_ai_providers', [])
apply_filters('chubes_ai_provider_api_keys', null)
apply_filters('chubes_ai_models', $provider)
apply_filters('chubes_ai_tools', [])
apply_filters('chubes_ai_request', $request)
apply_filters('chubes_ai_file_to_base64', '', $path)
apply_filters('chubes_ai_http', [], $method, $url, $args)See docs/CHANGELOG.md for complete migration details.
Include Library:
// Composer: Auto-loads via Composer (no includes needed)
// Git Subtree/Manual: Include in your plugin
require_once plugin_dir_path(__FILE__) . 'lib/ai-http-client/ai-http-client.php';Basic Request:
$response = apply_filters('chubes_ai_request', [
'messages' => [['role' => 'user', 'content' => 'Hello AI!']]
], 'openai'); // Provider name is now requiredAdvanced Options:
// Specific provider (required parameter)
$response = apply_filters('chubes_ai_request', $request, 'anthropic');
// With streaming callback
$response = apply_filters('chubes_ai_request', $request, 'openai', $streaming_callback);
// With function calling tools
$response = apply_filters('chubes_ai_request', $request, 'openai', null, $tools);
// With conversation continuation
$response = apply_filters('chubes_ai_request', $request, 'openai', null, $tools, $conversation_data);Comprehensive AI provider support with dynamic model discovery:
// Provider Discovery
$providers = apply_filters('chubes_ai_providers', []);
// API Keys Management
$keys = apply_filters('chubes_ai_provider_api_keys', null); // Get all keys
apply_filters('chubes_ai_provider_api_keys', $new_keys); // Update all keys
// Dynamic Model Fetching (with 24-hour cache)
$models = apply_filters('chubes_ai_models', $provider_name, $config);
// AI Tools Registration
$tools = apply_filters('chubes_ai_tools', []);
// File Operations
$base64 = apply_filters('chubes_ai_file_to_base64', '', $file_path, $options);
// HTTP Requests (internal use)
$result = apply_filters('chubes_ai_http', [], 'POST', $url, $args, 'Context');The library provides REST API endpoints for configuration and management:
// Configure API keys via REST API
wp_remote_post('/wp-json/ai-http-client/v1/api-keys/openai', [
'body' => wp_json_encode([
'api_key' => 'your-api-key'
]),
'headers' => [
'Content-Type' => 'application/json',
'X-WP-Nonce' => wp_create_nonce('wp_rest')
]
]);
// Get provider configuration
$config = wp_remote_get('/wp-json/ai-http-client/v1/api-keys/openai', [
'headers' => [
'X-WP-Nonce' => wp_create_nonce('wp_rest')
]
]);
// Get available models for a provider
$models = wp_remote_get('/wp-json/ai-http-client/v1/models/openai', [
'headers' => [
'X-WP-Nonce' => wp_create_nonce('wp_rest')
]
]);
// Get all available providers
$providers = wp_remote_get('/wp-json/ai-http-client/v1/providers', [
'headers' => [
'X-WP-Nonce' => wp_create_nonce('wp_rest')
]
]);Available Endpoints:
Shared API Keys Storage:
// WordPress option: 'chubes_ai_http_shared_api_keys'
$shared_keys = apply_filters('chubes_ai_provider_api_keys', null);
// Returns: ['openai' => 'sk-...', 'anthropic' => 'sk-ant-...', ...]Provider Configuration:
// Each provider accepts configuration in constructor
$provider = new AI_HTTP_OpenAI_Provider([
'api_key' => 'sk-...',
'organization' => 'org-...',
'base_url' => 'https://api.openai.com/v1' // Optional custom endpoint
]);Tool Registration:
add_filter('chubes_ai_tools', function($tools) {
$tools['file_processor'] = [
'class' => 'FileProcessor_Tool',
'category' => 'file_handling',
'description' => 'Process files and extract content',
'parameters' => [
'file_path' => [
'type' => 'string',
'required' => true,
'description' => 'Path to file to process'
]
]
];
return $tools;
});Tool Discovery and Usage:
// Get all registered tools
$all_tools = apply_filters('chubes_ai_tools', []);
// Pass tools to AI request
$response = apply_filters('chubes_ai_request', $request, 'openai', null, $tools);
// Note: Tool execution is handled by consuming pluginsclass AI_HTTP_MyProvider {
public function __construct($config = []) { /* Provider setup */ }
public function is_configured() { /* Check if ready */ }
public function request($standard_request) { /* Standard → Provider → Standard */ }
public function streaming_request($standard_request, $callback) { /* Streaming support */ }
public function get_normalized_models() { /* Get models for UI */ }
public function get_raw_models() { /* Get raw API response */ }
}
// Self-register via filter
add_filter('chubes_ai_providers', function($providers) {
$providers['myprovider'] = [
'class' => 'AI_HTTP_MyProvider',
'type' => 'llm',
'name' => 'My Provider'
];
return $providers;
});WordPress.org Compliance:
Core Architecture:
AI Provider Support:
WordPress Integration:
This library is actively used in production WordPress plugins:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);Debug Logging Covers:
Pull requests welcome for:
GNU GPL v3 - Chris Huber
| Back | FazBrowse Home | New Git URL |