- Easy to use OpenAI cURL Library
If you are looking for an easy way to integrate OpenAI in your project. This PHP Class is for you.
Sure!
This software is distributed under the GNU General Public License v3.0 license. Please read LICENSE for information on the software availability and distribution.
- PHP >= 5.6.0
Please disclose any vulnerabilities found responsibly – report security issues to the maintainers privately.
Using Composer:
composer require laswitchtech/php-openai
In this documentations, we will use a table called users for our examples.
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;
//Load Composer's autoloader
require 'vendor/autoload.php';
//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;
//Load Composer's autoloader
require 'vendor/autoload.php';
//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');
//Request
$phpOpenAI->completions([
'model' => 'text-davinci-003',
'prompt' => 'Say this is a test',
'temperature' => 0,
'max_tokens' => 7,
'top_p' => 1,
'n' => 1,
'stream' => false,
'logprobs' => null,
'stop' => '\n',
]); // Returns an array
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;
//Load Composer's autoloader
require 'vendor/autoload.php';
//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');
//Request
$phpOpenAI->edits([
'model' => 'text-davinci-edit-001',
'input' => 'What day of the wek is it?',
'instruction' => 'Fix the spelling mistakes',
]); // Returns an array
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;
//Load Composer's autoloader
require 'vendor/autoload.php';
//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');
//Request
$phpOpenAI->moderations([
'model' => 'text-moderation-stable',
'input' => 'I want to kill them.',
]); // Returns an array