modelmix 3.5.4 → 3.5.8

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.
Files changed (2) hide show
  1. package/index.js +12 -8
  2. 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 mime = require('mime-types');
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');
@@ -202,15 +202,14 @@ class ModelMix {
202
202
  return this;
203
203
  }
204
204
 
205
- addImage(filePath, { role = "user" } = {}) {
206
- const imageBuffer = this.readFile(filePath, { encoding: null });
207
- const mimeType = mime.lookup(filePath);
205
+ addImageFromBuffer(buffer, { role = "user" } = {}) {
208
206
 
209
- if (!mimeType || !mimeType.startsWith('image/')) {
210
- throw new Error('Invalid image file type');
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');
211
210
  }
212
211
 
213
- const data = imageBuffer.toString('base64');
212
+ const data = buffer.toString('base64');
214
213
 
215
214
  const imageMessage = {
216
215
  ...{ role },
@@ -219,7 +218,7 @@ class ModelMix {
219
218
  type: "image",
220
219
  "source": {
221
220
  type: "base64",
222
- media_type: mimeType,
221
+ media_type: fileType.mime,
223
222
  data
224
223
  }
225
224
  }
@@ -230,6 +229,11 @@ class ModelMix {
230
229
  return this;
231
230
  }
232
231
 
232
+ addImage(filePath, { role = "user" } = {}) {
233
+ const imageBuffer = this.readFile(filePath, { encoding: null });
234
+ return this.addImageFromBuffer(imageBuffer, { role });
235
+ }
236
+
233
237
  addImageFromUrl(url, config = { role: "user" }) {
234
238
  if (!this.imagesToProcess) {
235
239
  this.imagesToProcess = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modelmix",
3
- "version": "3.5.4",
3
+ "version": "3.5.8",
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": "^21.0.0",
56
57
  "lemonlog": "^1.1.2"
57
58
  }
58
59
  }