PHPackages                             trinavo/laravel-chatgpt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. trinavo/laravel-chatgpt

ActiveLibrary[API Development](/categories/api)

trinavo/laravel-chatgpt
=======================

A lightweight library to integrate chatGpt into your Laravel application!

11PHP

Since Apr 19Pushed 1y agoCompare

[ Source](https://github.com/doonfrs/laravel-chatgpt)[ Packagist](https://packagist.org/packages/trinavo/laravel-chatgpt)[ RSS](/packages/trinavo-laravel-chatgpt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Laravel ChatGPT Cover](https://raw.githubusercontent.com/hesamzakerirad/laravel-chatgpt/main/media/cover.png "Laravel ChatGPT Cover")](https://raw.githubusercontent.com/hesamzakerirad/laravel-chatgpt/main/media/cover.png)

Laravel ChatGPT
===============

[](#laravel-chatgpt)

Bring ChatGPT to your Laravel application with a few simple steps!

How to install it?
------------------

[](#how-to-install-it)

Take these steps to install ChatGPT.

### Step #1

[](#step-1)

Install the package using Composer.

```
composer require hesamrad/laravel-chatgpt
```

### Step #2

[](#step-2)

Publish congifuration file.

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

```

### Step #3

[](#step-3)

Generate an API key inside your OpenAI account, and copy it into your .env file. (Generate your own API key.)

```
CHATGPT_API_KEY="xx-xxxx"

```

And that's it! You now have ChatGPT inside your application.

---

How to use it?
--------------

[](#how-to-use-it)

It really is up to you! You could use the built-in routes to ask your questions, or even use the global helper function inside your controllers to do the job.

### Method #1 - Using built-in routes.

[](#method-1---using-built-in-routes)

The package comes with a built-in route so you can send a request from anywhere inside your client application; whether it's a separate JavaScript-powered front-end, or anything else.

Simply send a `POST` request to `/api/chatgpt/ask` with a body parameter `question` to get your answer.

Note that you could easily change this route to whatever you want! You could do so by editing the `internal_api_route` key inside `chatgpt.php` config file under `app/config`.

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

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

### Method #2 - Using global helper function.

[](#method-2---using-global-helper-function)

There is a `chatgpt()` global helper function which takes one parameter as the question you want to ask. You could use this method anywhere you like.

If you want to use this package inside any controller you could go about it like this:

```
