Download the PHP package wordpress/php-ai-client without Composer

On this page you can find all versions of the php package wordpress/php-ai-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-ai-client

PHP AI Client

Part of the AI Building Blocks for WordPress initiative

A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.

General information

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.

While this project is stewarded by WordPress AI Team 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.

Installation

Code examples

Text generation using a specific model

Text generation using any compatible model from a specific provider

Text generation using any compatible model

Text generation with additional parameters

Text generation with multiple candidates using any compatible model

Text generation using max tokens

Image generation using any compatible model

Embedding generation using a specific model

Unlike the other capabilities, embedding generation always requires you to name the model. Embedding vectors are only comparable to other vectors produced by the same model, so a stored set of embeddings is permanently tied to the model that created it. If the library picked a model for you, that choice could change between requests — for example when the registered providers change — silently making new vectors incomparable to the ones you already stored. Omitting the model therefore raises an error rather than falling back to a default.

You can also pass a model instance, which is useful when you already have one or want to reference the provider class directly:

Batch embedding generation

Embedding generation with dimensions

Embedding inputs are independent MessagePart values, not a conversation. input() accepts one input or a list of inputs. Variadic withInput() accepts one or more arguments, and lists can be passed using PHP's spread syntax (withInput(...$inputs)). Each input may be a string, MessagePart, File, or message-part array shape.

The model you name is verified before any request is sent: it must support embedding generation, accept the input modalities of your inputs, and support every configuration option you set. If it does not, an InvalidArgumentException explains which capability or option is unsupported. To check without triggering an exception, call isSupported(), which returns false for any model that cannot fulfill the request — including one whose provider is not registered or configured, or a model ID the provider does not offer. Only omitting the model entirely still throws, since that is a programming error rather than an unsupported model.

Discovering available embedding models

Since no model is chosen for you, you may need to find out which embedding models the configured providers offer:

See the PromptBuilder class and the EmbeddingBuilder class and their public methods for all the ways you can configure generation.

More documentation is coming soon.

Event Dispatching

The AI Client supports PSR-14 event dispatching for prompt lifecycle events. This allows you to hook into the generation process for logging, monitoring, or other integrations.

Available Events

Important: Event listeners should not return a value, as they will be ignored. In order to modify data that is passed with the event object, you need to rely on setters on the event object. Any event data for which there are no setters on the event object is meant to be immutable or, in other words, read-only for the event listener.

Connecting Your Event Dispatcher

To enable event dispatching, pass any PSR-14 compatible EventDispatcherInterface to the client:

Example: Logging Events

Further reading

For more information on the requirements and guiding principles, please review:

See the contributing documentation for more information on how to get involved.


All versions of php-ai-client with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
nyholm/psr7 Version ^1.8
php-http/discovery Version ^1.0
php-http/httplug Version ^2.0
psr/event-dispatcher Version ^1.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0 || ^2.0
psr/simple-cache Version ^1.0 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wordpress/php-ai-client contains the following files

Loading the files please wait ...