-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eduard Gaynutdinov
committed
Feb 3, 2024
1 parent
144cd03
commit 3dc7290
Showing
2 changed files
with
104 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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; | ||
} | ||
} |