PHP code example of yven / openai-php-client
1. Go to this page and download the library: Download yven/openai-php-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yven / openai-php-client example snippets
$apiKeys = "sk-xxx...";
$service = \OpenAI\Client::build(\OpenAI\constant\LLM::QWEN_ALI, $apiKeys);
// HTTP 请求
$data = $service->query("你好,请问你可以做什么?")->send();
echo $data->getContent();
// SSE 请求
$data = $service->query("你好,请问你可以做什么?")->stream();
$content = '';
/** @var \OpenAI\response\Response $item */
foreach ($data as $item) {
$content .= $item->getContent();
}
echo $content;
shell
composer