This package is meant to be a learning resource for prompt engineering and how to achieve AI-generated query generation with PHP/Laravel. You should probably not use this in production
The original package created by Beyond Code has been archived, also, it uses hardcoded text-davinci-003 model, and has been deprecated. However, this version supports custom specific models. You can change it into
config/ask-database.php
file, or into your.env
Ask DB allows you to use OpenAI's GPT to build natural language database queries.
DB::ask('How many users do we have on the "pro" plan?');
// We have 23 users with "pro" plan.
Install the package via composer:
composer require sebacarrasco93/laravel-ask-database
Publish the config files with:
php artisan vendor:publish --tag="ask-database-config"
php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
What about accidental deletions, updates or inserts? By default it's protecting by enabling strict mode. You can disable it. Do this at your own risk
// config/ask-database.php
'strict_mode' => env('ASK_DATABASE_STRICT_MODE', true),
First, you to configure your OpenAI API key in your .env
file:
OPENAI_API_KEY=sk-...
By default it's using gpt-3.5-turbo-instruct
. Optionally you can customize it
ASK_DATABASE_MODEL=gpt-3.5-turbo-instruct
Then, you can use the DB::ask()
method to ask the database:
$response = DB::ask('How many users are there?');
// We have 100 users
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.