laswitchtech / php-openai
PHP应用程序的OpenAI库
v1.0.3
2023-03-02 17:19 UTC
This package is auto-updated.
Last update: 2024-09-30 01:46:58 UTC
README
phpOpenAI
功能
- 易于使用的OpenAI cURL库
你可能为什么需要它
如果你在寻找一种简单的方法将OpenAI集成到你的项目中,这个PHP类就是为你准备的。
我能使用这个吗?
当然可以!
许可证
本软件根据GNU通用公共许可证v3.0分发。请阅读LICENSE以获取有关软件可用性和分发的信息。
要求
- PHP >= 5.6.0
安全
请负责任地披露发现的任何漏洞 - 私下向维护者报告安全问题。
安装
使用Composer
composer require laswitchtech/php-openai
我如何使用它?
在本文档中,我们将使用名为users的表作为我们的示例。
示例
初始化phpOpenAI
//Import phpOpenAI class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpOpenAI\phpOpenAI; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate phpOpenAI $phpOpenAI = new phpOpenAI('YOUR_API_KEY');
完成
//Import phpOpenAI class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpOpenAI\phpOpenAI; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate phpOpenAI $phpOpenAI = new phpOpenAI('YOUR_API_KEY'); //Request $phpOpenAI->completions([ 'model' => 'text-davinci-003', 'prompt' => 'Say this is a test', 'temperature' => 0, 'max_tokens' => 7, 'top_p' => 1, 'n' => 1, 'stream' => false, 'logprobs' => null, 'stop' => '\n', ]); // Returns an array
编辑
//Import phpOpenAI class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpOpenAI\phpOpenAI; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate phpOpenAI $phpOpenAI = new phpOpenAI('YOUR_API_KEY'); //Request $phpOpenAI->edits([ 'model' => 'text-davinci-edit-001', 'input' => 'What day of the wek is it?', 'instruction' => 'Fix the spelling mistakes', ]); // Returns an array
审核
//Import phpOpenAI class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpOpenAI\phpOpenAI; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate phpOpenAI $phpOpenAI = new phpOpenAI('YOUR_API_KEY'); //Request $phpOpenAI->moderations([ 'model' => 'text-moderation-stable', 'input' => 'I want to kill them.', ]); // Returns an array