/
a11igator
/
gigachat-php-sdk
Обзор
Документация
Войти
/
a11igator
/
gigachat-php-sdk
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/GigaChatDialog.php
66 строк
1 KB
Eduard Gaynutdinov
added gigachat dialog
03 фев 2024, 16:23
03 фев 2024, 16:23
3dc7290
Код
Авторство
О чём код?
<?php declare(strict_types=1); namespace Edvardpotter\GigaChat; use Edvardpotter\GigaChat\Type\Message; use Edvardpotter\GigaChat\Type\Model; class GigaChatDialog { private GigaChat $gigaChat; /** * @var Message[] */ private array $messages; public function __construct(GigaChat $gigaChat) { $this->gigaChat = $gigaChat; } public function getAnswer( Message $message, string $model = Model::ID_GIGACHAT_LATEST, float $temperature = 1.0, float $topP = 0.1, int $n = 1, bool $stream = false, int $maxTokens = 1024, float $repetitionPenalty = 1, int $updateInterval = 0 ): Message { $this->messages[] = $message; $completion = $this->gigaChat->chatCompletions( $this->messages, $model, $temperature, $topP, $n, $stream, $maxTokens, $repetitionPenalty, $updateInterval ); $message = $completion->getChoices()[0]->getMessage(); $this->messages[] = $message; return $message; } public function reset(): void { $this->messages = []; } /** * @return Message[] */ public function getHistory(): array { return $this->messages; } }