Skip to content

A laravel package that allows you to interact with your database using natural language

License

Notifications You must be signed in to change notification settings

masrimohammad/laravel-database-ask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Database Ask:

Interact with your database using natural language

Database Ask allows you to use OpenAI's GPT-3 to build natural language database queries.

$dbAsk = new DatabaseAsk();
$dbAsk->prompt('How many users do we have on the "pro" plan?');

Installation

You can install the package via composer. By default, Composer pulls in packages from Packagist, so you’ll have to make a slight adjustment to your new project composer.json file. Open the file and update include the following array somewhere in the object:

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/masrimohammad/laravel-database-ask"
    }
]
composer require database/ask

You can publish the config file with:

php artisan vendor:publish --tag="database-ask"

This is the contents of the published config file:

return [
    /**
     * Package name
     */
    'name' => 'Database Ask',

    /**
     * Open AI api key
     */
    'open_ai_api_key' => env('DATABASE_ASK_OPEN_AI_API_KEY'),

    /**
     * Database connection type
     */
    'connection' => env('DATABASE_ASK_CONNECTION'),

    /**
     * Strict mode will throw an exception when the query
     * would perform a write/alter operation on the database.
     *
     * If you want to allow write operations - or if you are using a read-only
     * database user - you may disable strict mode.
     */
    'strict_mode' => env('DATABASE_ASK_STRICT_MODE'),
];

Usage

First, you need to configure your OpenAI API key in your .env file:

DATABASE_ASK_OPEN_AI_API_KEY=sk-...
DATABASE_ASK_CONNECTION=mysql
DATABASE_ASK_STRICT_MODE=true

Then, you can use the DatabaseAsk::prompt() method to ask the database:

$dbAsk = new DatabaseAsk();
$dbAsk->prompt('How many users do we have on the "pro" plan?');

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A laravel package that allows you to interact with your database using natural language

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published