Skip to content

Commit

Permalink
ability to add messages from base64 encoded data
Browse files Browse the repository at this point in the history
  • Loading branch information
nunodonato committed Jul 19, 2024
1 parent 9ec5514 commit 870afb6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ public function addUserImageMessage(string $url, ?string $text = null): self
return $this;
}

public function addUserImageMessageFromBase64(string $base64Encoded, string $mimeType, ?string $text = null): self
{
$imageMessage = [
'type' => 'image',
'source' => [
'type' => 'base64',
'data' => $base64Encoded,
'media_type' => $mimeType
],
];
$message = [$imageMessage];

if ($text) {
$textMessage = [
'role' => self::ROLE_USER,
'content' => $text
];
$message[] = $textMessage;
}

$this->messages[] = [
'role' => self::ROLE_USER,
'content' => $message,
];

return $this;
}

public function addAssistantTextMessage(string $text): self
{
return $this->addMessage(self::ROLE_ASSISTANT, $text);
Expand Down

0 comments on commit 870afb6

Please sign in to comment.