sebacarrasco93/laravel-ask-database

Use natural language and AI to query your database from Laravel

dev-main 2024-03-03 03:22 UTC

This package is auto-updated.

Last update: 2024-05-03 03:41:25 UTC


README

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

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.