Created
March 31, 2026 13:28
-
-
Save niraj-shah/a2cd6536508ec331da693937bc2f65fe to your computer and use it in GitHub Desktop.
WordPress AI Client example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| include 'vendor/autoload.php'; | |
| use WordPress\AiClient\AiClient; | |
| use WordPress\GoogleAiProvider\Provider\GoogleProvider; | |
| // 1. Set your API key securely | |
| putenv('GOOGLE_API_KEY=YOUR-GOOGLE-AI-API-KEY'); | |
| // 2. Register the provider with the default registry | |
| $registry = AiClient::defaultRegistry(); | |
| $registry->registerProvider(GoogleProvider::class); | |
| // 3. Simple text generation | |
| $result = AiClient::prompt('Write a short intro about PHP and AI.') | |
| ->usingProvider('google') | |
| ->usingModelPreference('gemini-2.5-flash') | |
| ->generateTextResult(); | |
| $Parsedown = new Parsedown(); | |
| // Convert and echo the rendered HTML | |
| echo $Parsedown->text($result->toText()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment