beyondcode / laravel-ask-database
此包已被弃用且不再维护。未建议替代包。
使用自然语言和AI从Laravel查询您的数据库
1.0.0
2023-02-21 12:39 UTC
Requires
- php: ^8.1
- doctrine/dbal: ^3.6
- illuminate/contracts: ^9.0|^10.0
- openai-php/laravel: ^0.3.1
- spatie/laravel-package-tools: ^1.14.0
- spatie/once: ^3.1
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.5
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- 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
README
备注
此包旨在作为提示工程的学习资源,以及如何使用PHP/Laravel实现AI生成的查询生成。你可能不应当在生产环境中使用此包。
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)。请参阅 许可证文件 了解更多信息。