Skip to content

Application Laravel integrated with OpenAI's ChatGPT, with Authentication and Cache.

Notifications You must be signed in to change notification settings

urnauzao/laravel-chatgpt-application

Repository files navigation

Laravel ChatGPT

Application Laravel integrated with OpenAI's ChatGPT, with Authentication and Cache.

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.

Get Started

Required:

  • PHP 8.1+
  • Docker
  • WSL2 (recommended)
  • OpenAI account for API Key

Installation

  • 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

Tutorial

...

How this project was made!

  • 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

Inspirations

  • About OpenAI models

Openai Models

  • OpenAI-PHP Dependencies

Nuno Maduro - OpenAI-PHP dependecy

  • OpenAI ChatGPT

OpenAI ChatGTP

  • App Node.js with ChatGPT and WhatsApp

Victor Harray - Guide integration ChatGPT with WhatsApp

About

Application Laravel integrated with OpenAI's ChatGPT, with Authentication and Cache.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages