laravel ask database
1.0.0
筆記
該軟件包旨在成為迅速工程的學習資源,以及如何使用PHP/Laravel實現AI生成的查詢產生。您可能不應該在生產中使用它
詢問數據庫允許您使用OpenAI的GPT-3來構建自然語言數據庫查詢。
DB :: ask ( ' How many users do we have on the "pro" plan? ' );您可以通過作曲家安裝軟件包:
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 有關最近發生了變化的更多信息,請參見ChangElog。
請有關詳細信息,請參閱貢獻。
麻省理工學院許可證(麻省理工學院)。請參閱許可證文件以獲取更多信息。