1tomany / php-ai
A single, unified, framework-independent library for integration with many popular AI providers and large language models
Requires
- php: >=8.5
- symfony/http-client: ^7.2|^8.0|^8.1
- symfony/serializer: ^7.2|^8.0|^8.1
- symfony/validator: ^7.2|^8.0|^8.1
Requires (Dev)
- fakerphp/faker: ^1.24
- friendsofphp/php-cs-fixer: ^3.93
- phpstan/phpstan: ^2.1.55
- phpunit/phpunit: ^13.1.11
README
This library provides a single, unified, framework-independent library for integration with several popular AI providers and large language models.
Installation
Install the library using Composer:
composer require 1tomany/php-ai
Symfony Bundle
A Symfony bundle is available if you wish to integrate this library into your Symfony applications with autowiring and configuration support.
Supported platforms
- Gemini
- OpenAI
Platform features
| Feature | Gemini | OpenAI |
|---|---|---|
| Files | ||
| Upload | ✅ | ✅ |
| Delete | ✅ | ✅ |
| Queries | ||
| Compile | ✅ | ✅ |
| Run | ✅ | ✅ |
Note: Each platform refers to generating output - inference - differently: OpenAI uses "Response", Gemini uses "Interaction", and Anthropic uses "Message". I've decided the word "Query" best represents how you interact with a generative LLM: you compile a query and then run the query to generate a response. The word "Embedding" will continue to be used for embedding models.
To generate a response, you must first compile a query. A query is made up of different input components: text prompts, files, a JSON schema, and/or system instructions. Once the query is compiled, it can be sent to the LLM for inference.
This library allows you to compile a query before sending it to the model for two reasons:
- You can log/analyze the request payload before sending it.
- You can compile individual requests for batching.
Credits
License
The MIT License