PHP code example of webboy / laravel-open-ai-api-client
1. Go to this page and download the library: Download webboy/laravel-open-ai-api-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webboy / laravel-open-ai-api-client example snippets
namespace App\Console\Commands;
use Illuminate\Console\Command;
use OpenAIClient;
class OpenAIChatCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'open-ai:chat-answer {question}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Answers a question using ChatGPT Chat API endpoint';
/**
* Execute the console command.
*/
public function handle(): void
{
$question = $this->argument('question');
$data['model'] = 'gpt-3.5-turbo';
$data['messages'] = [
[
'role' => 'system',
'content' => 'You are a good and all knowing assistant'
],
[
'role' => 'user',
'content' => $question
]
];
$response = OpenAIClient::chat()->create($data);
$this->info($response['choices'][0]['message']['content']);
}
}
text
php artisan vendor:publish --tag=openai-config