PHP code example of lanos / laravel-open-ai-conversations
1. Go to this page and download the library: Download lanos/laravel-open-ai-conversations 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/ */
lanos / laravel-open-ai-conversations example snippets
bash
php artisan migrate
bash
php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
// CREATES THE CONVERSATION
$conversation = Conversation::create();
// ASK A NEW QUESTION
$capitalCity = $conversation->askQuestion('What is the capital city of England?');
// ASK A FOLLOW UP QUESTION
$population = $conversation->askQuestion('And what is the population of that city?');
// GETS ALL OF THE QUESTIONS AND ANSWERS UP UNTIL NOW
$messages = $conversation->messages()->get();
// GETS ALL OF THE QUESTIONS AND ANSWERS UP UNTIL NOW INCLUJDING FOROGTTEN ONES
$messages = $conversation->messages()->withTrashed()->get();
// GETS ONLY FORGOTTEN MESSAGES
$messages = $conversation->messages()->onlyTrashed()->get();