OpenAI for Laravel | Laravel News

Back in October, Nuno Maduro released an OpenAI PHP Client and this week he announced a brand Laravel integration called OpenAPI Laravel.

On Twitter Nuno said, “OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API, with this integration, developers can now easily use OpenAI’s powerful natural language processing capabilities in their Laravel applications.”

Getting started with the package is pretty straightforward and you can see the guide here:

First, install OpenAI:

1composer require openai-php/laravel

Next, publish the configuration file:

1php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"

This will create a config/openai.php configuration file in your project, which you can modify to your needs
using environment variables:


Finally, you may use the OpenAI facade to access the OpenAI API:

1use OpenAI\Laravel\Facades\OpenAI;


3$result = OpenAI::completions()->create([

4 'model' => 'text-davinci-003',

5 'prompt' => 'PHP is',



8echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.

Check out the repo for full instructions and for usage examples, take a look at the openai-php/client repository.

Source link


Leave a Reply

Your email address will not be published. Required fields are marked *