-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChat.php
More file actions
49 lines (41 loc) · 1012 Bytes
/
Copy pathChat.php
File metadata and controls
49 lines (41 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace fholbrook\Openrouter\DTO;
class Chat
{
public function __construct(
/**
* Implementation specific chat Id.
*
* @var string|null
*/
public ?string $id = null,
/**
* The messages in the chat.
*
* @var Message[]
*/
public array $messages = []
) {}
public function toArray(bool $includeMetadata = false): array
{
$a['messages'] = array_map(
fn (Message $message) => $message->toArray($includeMetadata),
$this->messages
);
if ($includeMetadata) {
$a['id'] = $this->id;
}
return array_filter($a);
}
public static function fromArray(array $data): self
{
return new self(
$data['id'],
array_map(
fn (array $message) => Message::fromArray($message),
$data['messages']
)
);
}
}