Vigiar
1
0
Derivar
Você já tinha feito uma derivação do repositório api-php-sdk, anteriormente
0
api-php-sdk/examples/ai-chat.php
2026-11-27 22:29:26 +02:00

29 linhas
911 B
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/../autoload.php'; // with Composer: require 'vendor/autoload.php';
use MozOutMz\Client;
use MozOutMz\ApiException;
// Key from MOZOUT_API_KEY.
$client = new Client();
// Chat with an AI model, then the same with streaming.
$answer = $client->ai->chatCreate([
'model' => 'deepseek-ai/deepseek-v4-flash',
'messages' => [['role' => 'user', 'content' => 'Write a two-sentence welcome message for our website.']],
'max_tokens' => 200,
]);
echo $answer['choices'][0]['message']['content'], "\n";
$client->ai->chatCreate([
'model' => 'deepseek-ai/deepseek-v4-flash',
'messages' => [['role' => 'user', 'content' => 'Say hello.']],
'stream' => true,
], ['on_event' => static function ($event): void {
foreach ((is_array($event) ? ($event['choices'] ?? []) : []) as $c) {
echo $c['delta']['content'] ?? '';
}
}]);
echo "\n";