Download the PHP package elliotjreed/ai without Composer
On this page you can find all versions of the php package elliotjreed/ai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elliotjreed/ai
More information about elliotjreed/ai
Files in elliotjreed/ai
Package ai
Short Description A library for interacting with ChatGPT and Claude AI
License MIT
Homepage https://github.com/elliotjreed/ai
Informations about the package ai
A library for interacting with Claude AI and ChatGPT.
At present only text requests and responses are supported.
Usage
Install via Composer:
There are two classes, one for Claude AI, and one for ChatGPT.
Each take the first argument in the constructor as your API key, and the second argument as the model you want to use.
You can optionally provide a Guzzle HTTP client:
This could be useful where you are using a framework such as Symfony, you could autowire the service and reference a configured Guzzle client.
Here's an example of a Symfony integration in the services.yaml
file:
Anthropic Claude AI
For a really simple request and response:
You can provide a role too, as well as additional context, data, examples, setting the temperature (between 0 and 1, basically how "creative" you want the AI to be), and the maximum tokens to use (recommended if the user input is from a indirect source, for example an online chatbot):
If you want to keep a conversation going (like you would on ChatGPT or Claude's website or app), you can pass through the history from the previous response to a new request:
OpenAI ChatGPT
For a really simple request and response:
You can provide a role too, as well as additional context, data, examples, setting the temperature (between 0 and 1, basically how "creative" you want the AI to be), and the maximum tokens to use (recommended if the user input is from a indirect source, for example an online chatbot):
If you want to keep a conversation going (like you would on ChatGPT or Claude's website or app), you can pass through the history from the previous response to a new request:
Development
Getting Started
PHP 8.2 or above and Composer is expected to be installed.
Installing Composer
For instructions on how to install Composer visit getcomposer.org.
Installing
After cloning this repository, change into the newly created directory and run:
or if you have installed Composer locally in your current directory:
This will install all dependencies needed for the project.
Henceforth, the rest of this README will assume composer
is installed globally (ie. if you are using composer.phar
you will need to use composer.phar
instead of composer
in your terminal / command-line).
Running the Tests
Unit tests
Unit testing in this project is via PHPUnit.
All unit tests can be run by executing:
Debugging
To have PHPUnit stop and report on the first failing test encountered, run:
Code formatting
A standard for code style can be important when working in teams, as it means that less time is spent by developers processing what they are reading (as everything will be consistent).
Code formatting is automated via PHP-CS-Fixer. PHP-CS-Fixer will not format line lengths which do form part of the PSR-2 coding standards so these will product warnings when checked by PHP Code Sniffer.
These can be run by executing:
Running everything
All the tests can be run by executing:
Outdated dependencies
Checking for outdated Composer dependencies can be performed by executing:
Validating Composer configuration
Checking that the composer.json is valid can be performed by executing:
Running via GNU Make
If GNU Make is installed, you can replace the above composer
command prefixes with make
.
All the tests can be run by executing:
Running the tests on a Continuous Integration platform (eg. Github Actions)
Specific output formats better suited to CI platforms are included as Composer scripts.
To output unit test coverage in text and Clover XML format (which can be used for services such as Coveralls):
To output PHP-CS-Fixer (dry run) and PHPCS results in checkstyle format (which GitHub Actions will use to output a readable format):
Github Actions
Look at the example in .github/workflows/php.yml.
Built With
License
This project is licensed under the MIT License - see the LICENCE.md file for details.
All versions of ai with dependencies
ext-dom Version *
ext-libxml Version *
ext-simplexml Version *
guzzlehttp/guzzle Version ^7.0