Skip to content

Commit

Permalink
Merge pull request #166 from jber18/main
Browse files Browse the repository at this point in the history
[ Add ] Added imageBase64 capability instead of Image URL only for gpt-4-vision
  • Loading branch information
anasfik authored May 8, 2024
2 parents dfce769 + f7e4c88 commit 4b281d6
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class OpenAIChatCompletionChoiceMessageContentItemModel {
/// The image url content of the item.
final String? imageUrl;

final String? imageBase64;

@override
int get hashCode => type.hashCode ^ text.hashCode ^ imageUrl.hashCode;

Expand All @@ -20,6 +22,7 @@ class OpenAIChatCompletionChoiceMessageContentItemModel {
required this.type,
this.text,
this.imageUrl,
this.imageBase64,
});

/// This is used to convert a [Map<String, dynamic>] object to a [OpenAIChatCompletionChoiceMessageContentItemModel] object.
Expand All @@ -30,6 +33,7 @@ class OpenAIChatCompletionChoiceMessageContentItemModel {
type: asMap['type'],
text: asMap['text'],
imageUrl: asMap['image_url'],
imageBase64: asMap['imageBase64'],
);
}

Expand All @@ -51,12 +55,22 @@ class OpenAIChatCompletionChoiceMessageContentItemModel {
);
}

factory OpenAIChatCompletionChoiceMessageContentItemModel.imageBase64(
String imageBase64,
) {
return OpenAIChatCompletionChoiceMessageContentItemModel._(
type: 'image_base64',
imageBase64: imageBase64,
);
}

/// This method used to convert the [OpenAIChatCompletionChoiceMessageContentItemModel] to a [Map<String, dynamic>] object.
Map<String, dynamic> toMap() {
return {
"type": type,
if (text != null) "text": text,
if (imageUrl != null) "image_url": imageUrl,
if (imageBase64 != null) "image_url": {"url": "data:image/jpeg;base64,${imageBase64}"}
};
}

Expand All @@ -68,7 +82,8 @@ class OpenAIChatCompletionChoiceMessageContentItemModel {

return other.type == type &&
other.text == text &&
other.imageUrl == imageUrl;
other.imageUrl == imageUrl &&
other.imageBase64 == imageBase64;
}

@override
Expand All @@ -77,6 +92,8 @@ class OpenAIChatCompletionChoiceMessageContentItemModel {
'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type, text: $text)',
'image' =>
'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type, imageUrl: $imageUrl)',
'image_base64' =>
'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type, imageBase64: $imageBase64)',
_ => 'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type)',
};
}

0 comments on commit 4b281d6

Please sign in to comment.