A PHP wrapper for the OpenAI API
GPT-3 lets you inject a little bit of AI magic into your apps, and this PHP wrapper makes it even easier to access. Covers the entire OpenAI API, in a familiar PHP way, without limiting any functionality.
use SiteOrigin\OpenAI\Client;
$client = new Client($_ENV['OPENAI_API_KEY']);
$completions = $client->completions('davinci')->complete("The most important technology for humanity is", [
'max_tokens' => 32,
'temperature' => 0.8,
'n' => 4,
'stop' => ["\n", '.']
]);
foreach($completions as $c) {
echo $c->text . "\n";
}Read more on the documentation wiki.
Installation
You can install the package via composer:
composer require siteorigin/openai-apiUsage
For most of the features of this wrapper, you should have an understanding of the OpenAI API.
// Set up a client with your API key.
use SiteOrigin\OpenAI\Client;
use SiteOrigin\OpenAI\Models;
$client = new Client($_ENV['OPENAI_API_KEY']);
// Create a completion call
$c = $client->completions(Models::BABBAGE)->complete('The meaning of life is: ', [ /* ... */]);
// List all the available engines
$e = $client->engines()->list();
// Classify safe/unsafe content
$f = $client->filter()->classify('ponies are fantastic!'); // 'safe'Testing
composer testChangelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please email greg@siteorigin.com if you find any security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.