PHPackages                             lanos/laravel-open-ai-conversations - 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. lanos/laravel-open-ai-conversations

ActiveLibrary

lanos/laravel-open-ai-conversations
===================================

Adds persistent conversation functionality to the existing Laravel OpenAI Package

v1.2(2y ago)17MITPHP

Since Aug 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/l4nos/laravel-open-ai-conversations)[ Packagist](https://packagist.org/packages/lanos/laravel-open-ai-conversations)[ RSS](/packages/lanos-laravel-open-ai-conversations/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (12)Versions (6)Used By (0)

 Laravel GPT Conversations
===========================

[](#laravel-gpt-conversations-)

Intro
-----

[](#intro)

This package is built on top of the [openai-php/laravel](https://github.com/openai-php/laravel) package to allow you to build conversation sessions where context is preserved using a database.

This package is just an extra layer on top of the amazing package developed by:

- Nuno Maduro: **[github.com/sponsors/nunomaduro](https://github.com/sponsors/nunomaduro)**
- Sandro Gehri: **[github.com/sponsors/gehrisandro](https://github.com/sponsors/gehrisandro)**

The openai-php/laravel is required and should be installed as part of this install.

### Setup

[](#setup)

> **Requires [PHP 8.1+](https://php.net/releases/)**

Really simple. Install our package (if you don't have the openai-php/laravel installed, composer should try to install it)

```
composer require lanos/laravel-open-ai-conversations
```

Then you need to just run the migrations

```
php artisan migrate
```

If you haven't set up the OpenAI-PHP Laravel package you can publish their config like so:

```
php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
```

Then add the environment variables as needed.

```
OPENAI_API_KEY=sk-...
```

You can also override some of the default config variables in the .env for my plugin, such as setting the default model for a conversation.

```
OPENAI_DEFAULT_MODEL=gpt-4-32k
OPENAI_TOKEN_LIMIT=4096
```

### Examples

[](#examples)

Once you have fully configured both plugins you simply create a conversation using the eloquent interface.

The defaults are filled in for you, but you can override upon creation.

Once you have created the conversation you can ask questions. The plugin will automatically append all previous responses so that the model has consciousness of previous messages in the conversation. It also automatically ensures no token limits are hit by "forgetting" older messages as needed.

```
