dneustadt/ openai-client
OpenAI API 客户端
0.2.2
2022-11-05 20:03 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.12
- phpunit/phpunit: ^8.0 || ^9.0
- symfony/dotenv: ^6.0
README
OpenAI 是一家 AI 研究和部署公司。我们的使命是确保通用人工智能造福全人类。
安装与使用
要求
PHP 7.2 及以上版本。
Composer
通过Composer安装
composer require dneustadt/openai-client
入门指南
请按照安装过程进行操作,然后运行以下命令
<?php require_once(__DIR__ . '/vendor/autoload.php'); // Configure API key authorization: api_key $config = OpenAI\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY'); $apiInstance = new OpenAI\Client\Api\AnswerApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new GuzzleHttp\Client(), $config ); $open_ai_organization = 'open_ai_organization_example'; // optional $answer_payload = new \OpenAI\Client\Model\AnswerPayload(); // \OpenAI\Client\Model\AnswerPayload try { $result = $apiInstance->postAnswer($open_ai_organization, $answer_payload); print_r($result); } catch (Exception $e) { echo 'Exception when calling AnswerApi->postAnswer: ', $e->getMessage(), PHP_EOL; }
API 端点
所有 URI 都相对于 https://api.openai.com/v1
模型
请求负载
- AnswerPayload
- ClassificationPayload
- CompletionPayload
- ImagesGenerationsPayload
- SearchPayload
- EmbeddingsPayload
- FineTunesPayload
- ModerationsPayload