sebacarrasco93 / laravel-ask-database
Use natural language and AI to query your database from Laravel
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- illuminate/database: ^10.43
- openai-php/laravel: ^0.3.1
- spatie/laravel-package-tools: ^1.14.0
- spatie/once: ^3.1
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.0
- mockery/mockery: ^1.5
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0|^8.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-03 04:45:13 UTC
README
Notes
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.
Installation
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),
Usage
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
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.