amohamed / database-ai
使用自然语言和AI从Laravel查询您的数据库
dev-main
2024-03-16 17:29 UTC
Requires
- php: >=7.2
- doctrine/dbal: >=3.2
- illuminate/contracts: >=11.0
- openai-php/laravel: >=0.6.0
- spatie/laravel-package-tools: >=1.0
- spatie/once: >=3.0
This package is auto-updated.
Last update: 2024-09-16 18:38:18 UTC
README
Ask DB 允许您使用OpenAI的GPT-3构建自然语言数据库查询。
DB::ask('How many users do we have on the "pro" plan?');
安装
您可以通过composer安装此包
composer require amohamed/database-ai
您可以使用以下命令发布配置文件
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
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件。