xheaven/laravel-ask-database

Use natural language and AI to query your database from Laravel
1,655
Install
composer require xheaven/laravel-ask-database
Latest Version:1.0.2
PHP:^8.1
Laravel:9 · 10
License:MIT
Last Updated:Aug 31, 2023
Links: GitHub  ·  Packagist
Maintainer: xHeaven

Laravel Ask DB: Natural Language Database Query Builder

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

DB::ask('How many users do we have on the "pro" plan?');

Installation

You can install the package via composer:

composer require beyondcode/laravel-ask-database

You can publish the config file with:

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

This is the contents of the published config file:

return [
    /**
     * The database connection name to use. Depending on your
     * use case, you might want to limit the database user
     * to have read-only access to the database.
     */
    'connection' => env('ASK_DATABASE_DB_CONNECTION', 'mysql'),

    /**
     * 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('ASK_DATABASE_STRICT_MODE', true),

    /**
     * The maximum number of tables to use before performing an additional
     * table name lookup call to OpenAI.
     * If you have a lot of database tables and columns, they might not fit
     * into a single request to OpenAI. In that case, we will perform a
     * lookup call to OpenAI to get the matching table names for the
     * provided question.
     */
    'max_tables_before_performing_lookup' => env('ASK_DATABASE_MAXIMUM_TABLES', 15),
];

Usage

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

OPENAI_API_KEY=sk-...

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

$response = DB::ask('How many users are there?');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

Related Packages

beyondcode/laravel-self-diagnosis

Perform various self diagnosis tests on your Laravel application.

1,220,056 1,449
beyondcode/laravel-er-diagram-generator

Generate ER diagrams from your Laravel models.

1,692,238 2,024
beyondcode/laravel-dump-server

Symfony Var-Dump Server for Laravel

45,625,618 1,556
beyondcode/laravel-query-detector

Laravel N+1 Query Detector

8,403,950 2,060
beyondcode/laravel-confirm-email

Add email verification to your Laravel projects.

58,047 553

Version History

Version Released PHP Laravel License
1.0.2 ^8.1 ^9.0|^10.0 MIT
1.0.1 ^8.1 ^9.0|^10.0 MIT
1.0.0 ^8.1 ^9.0|^10.0 MIT