71 lines
1.4 KiB
PHP
71 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Domain\Chat;
|
|
|
|
final class ChatResult
|
|
{
|
|
/**
|
|
* @param list<Choice> $choices
|
|
* @param list<Message> $messageHistory
|
|
*/
|
|
public function __construct(
|
|
private readonly array $choices = [],
|
|
private readonly array $messageHistory = [],
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return list<Choice>
|
|
*/
|
|
public function getChoices(): array
|
|
{
|
|
return $this->choices;
|
|
}
|
|
|
|
/**
|
|
* @return list<Message>
|
|
*/
|
|
public function getMessageHistory(): array
|
|
{
|
|
return $this->messageHistory;
|
|
}
|
|
|
|
public function getFirstChoice(): ?Choice
|
|
{
|
|
if (empty($this->choices)) {
|
|
return null;
|
|
}
|
|
|
|
return $this->choices[0];
|
|
}
|
|
|
|
public function getContent(): ?string
|
|
{
|
|
$firstChoice = $this->getFirstChoice();
|
|
if ($firstChoice === null) {
|
|
return null;
|
|
}
|
|
|
|
return $firstChoice->getContent();
|
|
}
|
|
|
|
/**
|
|
* @return list<ToolCall>
|
|
*/
|
|
public function getToolCalls(): array
|
|
{
|
|
$toolCalls = [];
|
|
foreach ($this->choices as $choice) {
|
|
if (!empty($choice->getToolCalls())) {
|
|
foreach ($choice->getToolCalls() as $toolCall) {
|
|
$toolCalls[] = $toolCall;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $toolCalls;
|
|
}
|
|
}
|