Skip to content

Commit b6c4be1

Browse files
Merge pull request #67 from WordPress/update/readme
2 parents f22f738 + 7e4af76 commit b6c4be1

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

README.md

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,87 @@
11
# PHP AI Client
22

3-
A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.
3+
[_Part of the **AI Building Blocks for WordPress** initiative_](https://make.wordpress.org/ai/2025/07/17/ai-building-blocks)
44

5-
**This project is an early work in progress.**
5+
A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.
66

7-
## General Information
7+
## General information
88

9-
This project is a PHP SDK, which will eventually be installable as a Composer package. In WordPress, it could be bundled in plugins. It is however not a plugin itself.
9+
This project is a PHP SDK, which can be installed as a Composer package. In WordPress, it could be bundled in plugins. It is however not a plugin itself.
1010

1111
While this project is stewarded by [WordPress AI Team](https://make.wordpress.org/ai/) members and contributors, it is technically WordPress agnostic. The gap the project addresses is relevant for not only the WordPress ecosystem, but the overall PHP ecosystem, so any PHP project could benefit from it. There is also no technical reason to scope it to WordPress, as communicating with AI models and their providers is independent of WordPress's built-in APIs and paradigms.
1212

13+
## Installation
14+
15+
```
16+
composer require wordpress/php-ai-client
17+
```
18+
19+
## Code examples
20+
21+
### Text generation using a specific model
22+
23+
```php
24+
use WordPress\AiClient\AiClient;
25+
26+
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
27+
->usingModel(Google::model('gemini-2.5-flash'))
28+
->generateText();
29+
```
30+
31+
### Text generation using any compatible model from a specific provider
32+
33+
```php
34+
use WordPress\AiClient\AiClient;
35+
36+
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
37+
->usingProvider('openai')
38+
->generateText();
39+
```
40+
41+
### Text generation using any compatible model
42+
43+
```php
44+
use WordPress\AiClient\AiClient;
45+
46+
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
47+
->generateText();
48+
```
49+
50+
### Text generation with additional parameters
51+
52+
```php
53+
use WordPress\AiClient\AiClient;
54+
55+
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
56+
->usingSystemInstruction('You are a famous poet from the 17th century.')
57+
->usingTemperature(0.8)
58+
->generateText();
59+
```
60+
61+
### Text generation with multiple candidates using any compatible model
62+
63+
```php
64+
use WordPress\AiClient\AiClient;
65+
66+
$texts = AiClient::prompt('Write a 2-verse poem about PHP.')
67+
->generateTexts(4);
68+
```
69+
70+
### Image generation using any compatible model
71+
72+
```php
73+
use WordPress\AiClient\AiClient;
74+
75+
$imageFile = AiClient::prompt('Generate an illustration of the PHP elephant in the Caribbean sea.')
76+
->generateImage();
77+
```
78+
79+
See the [`PromptBuilder` class](https://github.com/WordPress/php-ai-client/blob/trunk/src/Builders/PromptBuilder.php) and its public methods for all the ways you can configure the prompt.
80+
81+
**More documentation is coming soon.**
82+
83+
## Further reading
84+
1385
For more information on the requirements and guiding principles, please review:
1486

1587
* [Glossary](./docs/GLOSSARY.md)

0 commit comments

Comments
 (0)