62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\LLM;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
class Qwen extends Base
|
|
{
|
|
protected string $model = 'qwen-max';
|
|
|
|
/**
|
|
* Create a new class instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
public function getResponse(): void
|
|
{
|
|
$client = new Client([
|
|
'headers' => [
|
|
'Content-Type' => 'application/json',
|
|
'Accept' => 'text/event-stream',
|
|
'Cache-Control' => 'no-cache',
|
|
'Authorization' => 'Bearer '.config('services.dashscope.api_key'),
|
|
],
|
|
]);
|
|
|
|
$url = config('services.dashscope.api_base').'/compatible-mode/v1/chat/completions';
|
|
|
|
$messages = [
|
|
[
|
|
'role' => 'user',
|
|
'content' => '你好',
|
|
],
|
|
];
|
|
|
|
$jsonBody = json_encode([
|
|
'model' => $this->model,
|
|
'messages' => $messages,
|
|
'stream' => true,
|
|
]);
|
|
|
|
$response = $client->request('POST', $url, [
|
|
'body' => $jsonBody,
|
|
'stream' => true,
|
|
]);
|
|
|
|
$body = $response->getBody();
|
|
// while (!$body->eof()) {
|
|
// echo $body->read(1024);
|
|
// }
|
|
|
|
while (! $body->eof()) {
|
|
// $body->read(1);
|
|
echo $body->read(1);
|
|
}
|
|
|
|
}
|
|
}
|