mkreftsymfonia / laravel-eloquent-ai
Laravel Eloquent AI is a Laravel package that allows asking an AI for database queries.
1.1.0
2024-11-09 19:11 UTC
Requires
- php: ^8.3
- illuminate/contracts: ^11.0
- illuminate/database: ^11.00
- openai-php/laravel: ^v0.10.2
- spatie/laravel-package-tools: ^1.14.0
- spatie/once: ^3.1
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.5
- nunomaduro/collision: ^v8.3.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.34.7
- pestphp/pest-plugin-laravel: ^2.4
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2025-05-09 20:39:09 UTC
README
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 mkreftsymfonia/laravel-eloquent-ai
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