天际/laravel-ask-database

使用自然语言和AI从Laravel查询数据库

1.0.2 2023-08-31 10:40 UTC

This package is auto-updated.

Last update: 2024-08-30 01:44:27 UTC


README

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

Ask DB 允许您使用 OpenAI 的 GPT-3 来构建自然语言数据库查询。

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

安装

您可以通过 composer 安装此包

composer require beyondcode/laravel-ask-database

您可以使用以下命令发布配置文件

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

这是发布配置文件的内容

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),
];

用法

首先,您需要在您的 .env 文件中配置您的 OpenAI API 密钥

OPENAI_API_KEY=sk-...

然后,您可以使用 DB::ask() 方法来查询数据库

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

测试

composer test

更新日志

请参阅 更新日志 以获取最近更改的更多信息。

贡献

请参阅 贡献指南 以获取详细信息。

鸣谢

许可证

MIT 许可证(MIT)。请参阅 许可证文件 以获取更多信息。