modelmix 3.5.2 → 3.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -202,15 +202,8 @@ class ModelMix {
|
|
|
202
202
|
return this;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
const mimeType = mime.lookup(filePath);
|
|
208
|
-
|
|
209
|
-
if (!mimeType || !mimeType.startsWith('image/')) {
|
|
210
|
-
throw new Error('Invalid image file type');
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const data = imageBuffer.toString('base64');
|
|
205
|
+
addImageFromBuffer(buffer, { role = "user" } = {}) {
|
|
206
|
+
const data = buffer.toString('base64');
|
|
214
207
|
|
|
215
208
|
const imageMessage = {
|
|
216
209
|
...{ role },
|
|
@@ -230,6 +223,18 @@ class ModelMix {
|
|
|
230
223
|
return this;
|
|
231
224
|
}
|
|
232
225
|
|
|
226
|
+
addImage(filePath, { role = "user" } = {}) {
|
|
227
|
+
const imageBuffer = this.readFile(filePath, { encoding: null });
|
|
228
|
+
const mimeType = mime.lookup(filePath);
|
|
229
|
+
|
|
230
|
+
if (!mimeType || !mimeType.startsWith('image/')) {
|
|
231
|
+
throw new Error('Invalid image file type');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this.addImageFromBuffer(imageBuffer, { role });
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
233
238
|
addImageFromUrl(url, config = { role: "user" }) {
|
|
234
239
|
if (!this.imagesToProcess) {
|
|
235
240
|
this.imagesToProcess = [];
|
|
@@ -779,12 +784,12 @@ class MixOpenAI extends MixCustom {
|
|
|
779
784
|
for (const content of message.content) {
|
|
780
785
|
if (content.type === 'image') {
|
|
781
786
|
const { type, media_type, data } = content.source;
|
|
782
|
-
message.content = {
|
|
787
|
+
message.content = [{
|
|
783
788
|
type: 'image_url',
|
|
784
789
|
image_url: {
|
|
785
790
|
url: `data:${media_type};${type},${data}`
|
|
786
791
|
}
|
|
787
|
-
};
|
|
792
|
+
}];
|
|
788
793
|
}
|
|
789
794
|
}
|
|
790
795
|
|