farzai / viola
Viola CLI 是一个用于通过 ChatGPT 提问的命令行工具。
1.0.4
2023-06-23 11:18 UTC
Requires
- php: ^8.0
- doctrine/dbal: ^3.6
- farzai/transport: ^0.0.2
- symfony/cache: ^5.4.21|^6.2.10
- symfony/console: ^5.4.21|^6.2.10
Requires (Dev)
- laravel/pint: ^1.2
- mockery/mockery: ^1.6
- pestphp/pest: ^1.20
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/ray: ^1.28
README
Viola 是一个 PHP 包,允许您向 ChatGPT 提问,并使用自己的数据获得答案。
要求
- PHP >= 8.0
- OpenAI 密钥
支持的数据库
目前,Viola 支持以下数据库
等待它!我将在未来添加对其他数据库的支持。
安装
您可以通过 composer 在全局范围内安装此包
$ composer global require farzai/viola
请确保将 Composer 的系统级 vendor bin 目录添加到您的 $PATH 中,以便系统可以定位 viola 可执行文件。这个目录根据您的操作系统位于不同的位置;然而,一些常见位置包括
对于 macOS
$HOME/.composer/vendor/bin
对于 GNU / Linux 发行版
GNU / Linux Distributions: $HOME/.config/composer/vendor/bin
对于 Windows
%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
使用方法
首先,您需要设置您的 OpenAI 密钥和数据库连接。
$ viola config # API Key: <your-openai-key> # Database Connection name: <your-connection-name> # Choose database driver: <mysql|pgsql|sqlsrv> # Enter database host, port, database name, username, password
然后,您可以尝试向 ChatGPT 提问。
$ viola ask "Show me all books by J. K. Rowling."
Here, I found 2 books by J. K. Rowling: |----|------------------------------------------|---------------|------| | id | title | author | year | |----|------------------------------------------|---------------|------| | 1 | Harry Potter and the Philosopher's Stone | J. K. Rowling | 1997 | | 2 | Harry Potter and the Chamber of Secrets | J. K. Rowling | 1998 | |----|------------------------------------------|---------------|------|
命令
# Ask a question to ChatGPT. $ viola ask "<your-question>"
# Set your OpenAI key and Database Connection.
$ viola config
# Show all database connections.
$ viola config:show
# Change current connection $ viola use <connection-name>
# Clear all database connections. $ viola config:clear all # Or clear a specific connection. $ viola config:clear <connection-name>
对于开发者
安装
- 通过 composer 在项目中安装。
- 使用
Farzai\Viola\Viola
类创建一个新的实例。
use Farzai\Viola\Viola; // Setup Viola. $viola = Viola::builder() ->setApiKey(string $key) ->setDatabaseConfig(string $driver, array $databaseConfig) ->setClient(\Psr\Http\Client\ClientInterface $client) // Optional ->setLogger(\Psr\Log\LoggerInterface $logger) // Optional ->build(); // Ask a question to ChatGPT. $answer = $viola->ask('Show me all books by J. K. Rowling.'); // Get the answer. echo $answer->getAnswer(); // Or get the answer with the results. foreach ($answer->getResults() as $row) { // }
测试
$ composer test
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请审查 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。