modelmix 4.4.22 → 4.4.24

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  const axios = require('axios');
2
2
  const fs = require('fs');
3
- const { fromBuffer } = require('file-type');
3
+ const fileType = require('file-type');
4
+ const detectFileTypeFromBuffer = fileType.fileTypeFromBuffer || fileType.fromBuffer;
4
5
  const { inspect } = require('util');
5
6
  const log = require('lemonlog')('ModelMix');
6
7
  const Bottleneck = require('bottleneck');
@@ -633,11 +634,14 @@ class ModelMix {
633
634
 
634
635
  // Detect mimeType if not provided
635
636
  if (!mimeType) {
636
- const fileType = await fromBuffer(buffer);
637
- if (!fileType || !fileType.mime.startsWith('image/')) {
637
+ if (typeof detectFileTypeFromBuffer !== 'function') {
638
+ throw new Error('file-type module does not expose a buffer detector');
639
+ }
640
+ const detectedType = await detectFileTypeFromBuffer(buffer);
641
+ if (!detectedType || !detectedType.mime.startsWith('image/')) {
638
642
  throw new Error(`Invalid image - unable to detect valid image format`);
639
643
  }
640
- mimeType = fileType.mime;
644
+ mimeType = detectedType.mime;
641
645
  }
642
646
 
643
647
  // Update the content with processed image
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modelmix",
3
- "version": "4.4.22",
3
+ "version": "4.4.24",
4
4
  "description": "🧬 Reliable interface with automatic fallback for AI LLMs.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -82,5 +82,39 @@ describe('Image Processing and Multimodal Support Tests', () => {
82
82
  expect(response).to.include('small PNG test image');
83
83
  });
84
84
 
85
+ it('should detect image mime type from buffer when content-type header is missing', async () => {
86
+ const imageUrl = 'https://assets.example.com/test-image';
87
+ const pngBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mP8z8BQz0AEYBxVSF+FABJADveWkH6oAAAAAElFTkSuQmCC';
88
+ const pngBuffer = Buffer.from(pngBase64, 'base64');
89
+
90
+ model.sonnet46()
91
+ .addText('Describe this image')
92
+ .addImageFromUrl(imageUrl);
93
+
94
+ // No content-type header on purpose: this forces buffer-based detection.
95
+ nock('https://assets.example.com')
96
+ .get('/test-image')
97
+ .reply(200, pngBuffer);
98
+
99
+ nock('https://api.anthropic.com')
100
+ .post('/v1/messages')
101
+ .reply(function (uri, body) {
102
+ const userMsg = body.messages.find(m => m.role === 'user');
103
+ expect(userMsg).to.exist;
104
+ const imageContent = userMsg.content.find(c => c.type === 'image');
105
+ expect(imageContent).to.exist;
106
+ expect(imageContent.source.type).to.equal('base64');
107
+ expect(imageContent.source.media_type).to.equal('image/png');
108
+ expect(imageContent.source.data).to.equal(pngBase64);
109
+ return [200, {
110
+ content: [{ type: "text", text: "Image received." }],
111
+ role: "assistant"
112
+ }];
113
+ });
114
+
115
+ const response = await model.message();
116
+ expect(response).to.include('Image received.');
117
+ });
118
+
85
119
  });
86
120
  });