29 lines
911 B
PHP
29 lines
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";
|