Skip to content

Commit 870afb6

Browse files
committed
ability to add messages from base64 encoded data
1 parent 9ec5514 commit 870afb6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Messages.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@ public function addUserImageMessage(string $url, ?string $text = null): self
6060
return $this;
6161
}
6262

63+
public function addUserImageMessageFromBase64(string $base64Encoded, string $mimeType, ?string $text = null): self
64+
{
65+
$imageMessage = [
66+
'type' => 'image',
67+
'source' => [
68+
'type' => 'base64',
69+
'data' => $base64Encoded,
70+
'media_type' => $mimeType
71+
],
72+
];
73+
$message = [$imageMessage];
74+
75+
if ($text) {
76+
$textMessage = [
77+
'role' => self::ROLE_USER,
78+
'content' => $text
79+
];
80+
$message[] = $textMessage;
81+
}
82+
83+
$this->messages[] = [
84+
'role' => self::ROLE_USER,
85+
'content' => $message,
86+
];
87+
88+
return $this;
89+
}
90+
6391
public function addAssistantTextMessage(string $text): self
6492
{
6593
return $this->addMessage(self::ROLE_ASSISTANT, $text);

0 commit comments

Comments
 (0)