In this project, we have a Laravel 9 application with PHP 8.2, with a login session and access to OpenAI's ChatGPT API, in addition, there is a cache application to avoid the consumption of recently performed queries. The entire Laravel project also has TailwindCSS themes, Vite.js to compile scripts, docker-compose file with PHP 8.2, MySQL and Redis. Furthermore, the entire project runs easily with Laravel Sail, requiring only a docker environment to run.
- PHP 8.1+
- Docker
- WSL2 (recommended)
- OpenAI account for API Key
- Clone this repository
- Run
composer update - Into folder, run
./vendor/bin/sail build - After build, run
./vendor/bin/sail up -d - Done, access on browser
http://localhost
- Create a new project with Laravel Sail template
curl -s "https://laravel.build/example-app?with=mysql,redis" | bash- Running the project with Laravel Sail
sail up -d- Require laravel breeze for gerante auth sessions pages
composer require laravel/breeze --dev- Install Laravel Breeze, apply generate auth session pages on project
php artisan breeze:install- Run all migrations, including migrations of breeze
php artisan migrate- Install npm dependencies
npm install- Run npm to test application are stared
npm run dev- If your application not found scripts will be set configuration into ./vite.config.js file add after
plugins: [...]
watch: {
usePolling: true,
origin: 'http://localhost'
},
server: {
hmr: {
host: 'localhost'
}
}- To add authentication session on application
php artisan breeze:install --dark- Install Nuno Maduro dependencies for supporting at OpenAI, with all api resources.
composer require openai-php/client- Add into .env OpenAI key
echo -e '\nOPEN_AI_KEY="CHANGE_TO_YOUR_KEY..."' >> .env- Genertate OpenAIController
sail artisan make:controller OpenAIController- Run again NPM for auto builds scripts after changes
npm run dev- New Route on web.php file, into session auth, add route:
Route::get('/openai', [OpenAIController::class, 'index'])->name('openai.index');-
New Link for menu access, on file ./resources/views/layouts/navigation.blade.php add:
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex"> <x-nav-link :href="route('openai.index')" :active="request()->routeIs('openai.index')" > {{ __('OpenAI') }} </x-nav-link> </div>
-
New file ./app/Http/Controllers/OpenAIController.php
-
New file ./resources/views/openai/index.blade.php
- About OpenAI models
- OpenAI-PHP Dependencies
Nuno Maduro - OpenAI-PHP dependecy
- OpenAI ChatGPT
- App Node.js with ChatGPT and WhatsApp