modelmix 3.5.6 → 3.6.0
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 +9 -10
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const axios = require('axios');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
const
|
|
3
|
+
const { fileTypeFromBuffer } = require('file-type');
|
|
4
4
|
const log = require('lemonlog')('ModelMix');
|
|
5
5
|
const Bottleneck = require('bottleneck');
|
|
6
6
|
const path = require('path');
|
|
@@ -203,6 +203,12 @@ class ModelMix {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
addImageFromBuffer(buffer, { role = "user" } = {}) {
|
|
206
|
+
|
|
207
|
+
const fileType = fileTypeFromBuffer(buffer);
|
|
208
|
+
if (!fileType || !fileType.mime.startsWith('image/')) {
|
|
209
|
+
throw new Error('Invalid image buffer - unable to detect valid image format');
|
|
210
|
+
}
|
|
211
|
+
|
|
206
212
|
const data = buffer.toString('base64');
|
|
207
213
|
|
|
208
214
|
const imageMessage = {
|
|
@@ -212,7 +218,7 @@ class ModelMix {
|
|
|
212
218
|
type: "image",
|
|
213
219
|
"source": {
|
|
214
220
|
type: "base64",
|
|
215
|
-
media_type:
|
|
221
|
+
media_type: fileType.mime,
|
|
216
222
|
data
|
|
217
223
|
}
|
|
218
224
|
}
|
|
@@ -225,14 +231,7 @@ class ModelMix {
|
|
|
225
231
|
|
|
226
232
|
addImage(filePath, { role = "user" } = {}) {
|
|
227
233
|
const imageBuffer = this.readFile(filePath, { encoding: null });
|
|
228
|
-
|
|
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;
|
|
234
|
+
return this.addImageFromBuffer(imageBuffer, { role });
|
|
236
235
|
}
|
|
237
236
|
|
|
238
237
|
addImageFromUrl(url, config = { role: "user" }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modelmix",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "🧬 ModelMix - Unified API for Diverse AI LLM.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"mixtral",
|
|
24
24
|
"chat",
|
|
25
25
|
"opus",
|
|
26
|
-
"sonnet",
|
|
26
|
+
"sonnet",
|
|
27
27
|
"multimodal",
|
|
28
28
|
"groq",
|
|
29
29
|
"gemini",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@modelcontextprotocol/sdk": "^1.11.2",
|
|
54
54
|
"axios": "^1.8.4",
|
|
55
55
|
"bottleneck": "^2.19.5",
|
|
56
|
+
"file-type": "^16.5.4",
|
|
56
57
|
"lemonlog": "^1.1.2"
|
|
57
58
|
}
|
|
58
59
|
}
|