PHP code example of hesamrad / laravel-chatgpt

1. Go to this page and download the library: Download hesamrad/laravel-chatgpt 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/ */

    

hesamrad / laravel-chatgpt example snippets


composer 

// This is the chatgpt.php config file. -> (app/config/chatgpt.php)

'internal_api_route' => '/api/chatgpt/ask'



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;

class ImaginaryController extends Controller
{
    /**
     * This method connects to ChatGPT servers
     * and asks the given question.
     *
     * @param  \Illuminate\Http\Response  $request
     * @return \Illuminate\Http\Response
     */
    public function ImaginaryMethod(Request $request)
    {
        $answer = chatgpt($request->input('question'));

        return response($answer, Response::HTTP_OK);
    }
}



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use HesamRad\LaravelChatGpt\ChatGptFacade as ChatGpt;

class ImaginaryController extends Controller
{
    /**
     * This method connects to ChatGPT servers
     * and asks the given question.
     *
     * @param  \Illuminate\Http\Response  $request
     * @return \Illuminate\Http\Response
     */
    public function ImaginaryMethod(Request $request)
    {
        $answer = chatgpt($request->input('question'));

        return response($answer, Response::HTTP_OK);
    }
}

php artisan vendor:publish --provider="HesamRad\LaravelChatGpt\LaravelChatGptServiceProvider" --tag="chatgpt-config"