Forked from vadimfedenko/analyze-images
Forked from vadimfedenko/analyze-images
scripts / webp-route-probe.cjs
scripts / webp-route-probe.cjs
// Explicit live diagnostic only: use the already-loaded model; never change plugin settings.
const sharp = require('sharp');
const fs = require('node:fs/promises');
const crypto = require('node:crypto');
const { LMStudioClient } = require('@lmstudio/sdk');
const { inlineImage } = require('../dist/inlineImage');
(async () => {
if (!process.argv.includes('--live')) throw Error('Use --live to probe the loaded local Gemma model.');
const timer = setTimeout(() => { console.error('Diagnostic timeout'); process.exit(1); }, 180_000);
try {
const bytes = await sharp({create: {width: 64, height: 48, channels: 3, background: '#e02020'}}).webp().toBuffer();
console.log('Source:', {format: (await sharp(bytes).metadata()).format, bytes: bytes.length, sha256: crypto.createHash('sha256').update(bytes).digest('hex')});
const client = new LMStudioClient({baseUrl: 'ws://127.0.0.1:1234'});
const model = await client.llm.model('google/gemma-4-31b-qat');
const uploaded = await client.files.prepareImageBase64('same-source.webp', bytes.toString('base64'));
const stored = await fs.readFile(await uploaded.getFilePath());
console.log('SDK upload:', {format: (await sharp(stored).metadata()).format, bytes: stored.length, identical: stored.equals(bytes)});
const cases = [
['SDK normal upload', uploaded],
['SDK inline raw WebP', inlineImage(client, 'same-source.webp', bytes)],
['SDK inline PNG', inlineImage(client, 'same-source.png', await sharp(bytes).png().toBuffer())],
];
for (const [label, image] of cases) {
try {
await model.respond([{role: 'user', content: 'Name the main color.', images: [image]}], {maxTokens: 8});
console.log(label + ': prediction accepted');
} catch (error) { console.log(label + ': ' + String(error.message).replace(/\s+/g, ' ').slice(0, 500)); }
}
console.log('GUI manual attachment is not exercised by this diagnostic.');
} finally {clearTimeout(timer);}
})().then(() => process.exit(0)).catch(error => {console.error(error.message); process.exit(1);});
// Explicit live diagnostic only: use the already-loaded model; never change plugin settings.
const sharp = require('sharp');
const fs = require('node:fs/promises');
const crypto = require('node:crypto');
const { LMStudioClient } = require('@lmstudio/sdk');
const { inlineImage } = require('../dist/inlineImage');
(async () => {
if (!process.argv.includes('--live')) throw Error('Use --live to probe the loaded local Gemma model.');
const timer = setTimeout(() => { console.error('Diagnostic timeout'); process.exit(1); }, 180_000);
try {
const bytes = await sharp({create: {width: 64, height: 48, channels: 3, background: '#e02020'}}).webp().toBuffer();
console.log('Source:', {format: (await sharp(bytes).metadata()).format, bytes: bytes.length, sha256: crypto.createHash('sha256').update(bytes).digest('hex')});
const client = new LMStudioClient({baseUrl: 'ws://127.0.0.1:1234'});
const model = await client.llm.model('google/gemma-4-31b-qat');
const uploaded = await client.files.prepareImageBase64('same-source.webp', bytes.toString('base64'));
const stored = await fs.readFile(await uploaded.getFilePath());
console.log('SDK upload:', {format: (await sharp(stored).metadata()).format, bytes: stored.length, identical: stored.equals(bytes)});
const cases = [
['SDK normal upload', uploaded],
['SDK inline raw WebP', inlineImage(client, 'same-source.webp', bytes)],
['SDK inline PNG', inlineImage(client, 'same-source.png', await sharp(bytes).png().toBuffer())],
];
for (const [label, image] of cases) {
try {
await model.respond([{role: 'user', content: 'Name the main color.', images: [image]}], {maxTokens: 8});
console.log(label + ': prediction accepted');
} catch (error) { console.log(label + ': ' + String(error.message).replace(/\s+/g, ' ').slice(0, 500)); }
}
console.log('GUI manual attachment is not exercised by this diagnostic.');
} finally {clearTimeout(timer);}
})().then(() => process.exit(0)).catch(error => {console.error(error.message); process.exit(1);});