@drsamonline/prober 0.12.34 → 0.12.36
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/package.json +1 -1
- package/src/index.js +25 -17
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -66,11 +66,13 @@ export const PROBE_FIXTURE_VERSION = '1.0.0';
|
|
|
66
66
|
export const FIXTURES = {
|
|
67
67
|
readiness: {
|
|
68
68
|
messages: [{ role: 'user', content: 'Reply with the single word: ready' }],
|
|
69
|
-
|
|
69
|
+
// A reasoning model thinks before it speaks. 8 tokens were spent entirely on
|
|
70
|
+
// thinking, so the reply was empty and a working provider was marked unusable.
|
|
71
|
+
max_tokens: 256,
|
|
70
72
|
},
|
|
71
73
|
jsonSchema: {
|
|
72
74
|
messages: [{ role: 'user', content: 'Return JSON with exactly one key "ok", set to true.' }],
|
|
73
|
-
max_tokens:
|
|
75
|
+
max_tokens: 256,
|
|
74
76
|
response_format: { type: 'json_object' },
|
|
75
77
|
},
|
|
76
78
|
tools: {
|
|
@@ -202,11 +204,17 @@ export async function probeTarget(entry, opts = {}) {
|
|
|
202
204
|
reasons,
|
|
203
205
|
};
|
|
204
206
|
}
|
|
207
|
+
// The model that answered readiness is the model every later check must use. The
|
|
208
|
+
// suitability probes used to ask for `modelFor(entry)` — a family name like
|
|
209
|
+
// "openai-compatible" — so Groq answered readiness and then 404'd all three,
|
|
210
|
+
// and a working provider was recorded as unsuitable.
|
|
211
|
+
const provenModel = probeModel(entry, discoveredModels);
|
|
212
|
+
|
|
205
213
|
levels.readiness = await timed(async () => {
|
|
206
214
|
const res = await fetchImpl(`${base}/chat/completions`, {
|
|
207
215
|
method: 'POST',
|
|
208
216
|
headers,
|
|
209
|
-
body: JSON.stringify({ model:
|
|
217
|
+
body: JSON.stringify({ model: provenModel, ...FIXTURES.readiness }),
|
|
210
218
|
signal: AbortSignal.timeout(timeoutMs),
|
|
211
219
|
});
|
|
212
220
|
if (!res.ok) {
|
|
@@ -214,7 +222,11 @@ export async function probeTarget(entry, opts = {}) {
|
|
|
214
222
|
return { ok: false, status: res.status, note: `HTTP ${res.status}: ${firstLine(body)}` };
|
|
215
223
|
}
|
|
216
224
|
const json = await res.json().catch(() => null);
|
|
217
|
-
|
|
225
|
+
const message = json?.choices?.[0]?.message ?? {};
|
|
226
|
+
// a reasoning model leaves `content` empty and puts the answer in `reasoning`
|
|
227
|
+
const content = typeof message.content === 'string' ? message.content : '';
|
|
228
|
+
const reasoning = typeof message.reasoning_content === 'string' ? message.reasoning_content : message.reasoning;
|
|
229
|
+
sample = content || (typeof reasoning === 'string' ? reasoning : '');
|
|
218
230
|
const ok = typeof sample === 'string' && sample.trim().length > 0;
|
|
219
231
|
return { ok, status: res.status, note: ok ? 'returned text' : 'empty completion' };
|
|
220
232
|
});
|
|
@@ -225,15 +237,15 @@ export async function probeTarget(entry, opts = {}) {
|
|
|
225
237
|
const capabilities = opts.capabilities ?? entry.capabilities ?? [];
|
|
226
238
|
if (levels.readiness.ok) {
|
|
227
239
|
if (capabilities.includes('streaming')) {
|
|
228
|
-
levels.suitability.streaming = await probeStreaming({ fetchImpl, base, headers, entry, timeoutMs });
|
|
240
|
+
levels.suitability.streaming = await probeStreaming({ fetchImpl, base, headers, entry, timeoutMs, model: provenModel });
|
|
229
241
|
if (!levels.suitability.streaming.ok) reasons.push(`streaming: ${levels.suitability.streaming.note}`);
|
|
230
242
|
}
|
|
231
243
|
if (capabilities.includes('json_schema')) {
|
|
232
|
-
levels.suitability.json_schema = await probeJson({ fetchImpl, base, headers, entry, timeoutMs });
|
|
244
|
+
levels.suitability.json_schema = await probeJson({ fetchImpl, base, headers, entry, timeoutMs, model: provenModel });
|
|
233
245
|
if (!levels.suitability.json_schema.ok) reasons.push(`json_schema: ${levels.suitability.json_schema.note}`);
|
|
234
246
|
}
|
|
235
247
|
if (capabilities.includes('tools')) {
|
|
236
|
-
levels.suitability.tools = await probeTools({ fetchImpl, base, headers, entry, timeoutMs });
|
|
248
|
+
levels.suitability.tools = await probeTools({ fetchImpl, base, headers, entry, timeoutMs, model: provenModel });
|
|
237
249
|
if (!levels.suitability.tools.ok) reasons.push(`tools: ${levels.suitability.tools.note}`);
|
|
238
250
|
}
|
|
239
251
|
}
|
|
@@ -260,12 +272,12 @@ export async function probeTarget(entry, opts = {}) {
|
|
|
260
272
|
}
|
|
261
273
|
|
|
262
274
|
/** Streaming must be a real event sequence, not one blob pretending to be SSE. */
|
|
263
|
-
async function probeStreaming({ fetchImpl, base, headers, entry, timeoutMs }) {
|
|
275
|
+
async function probeStreaming({ fetchImpl, base, headers, entry, timeoutMs, model }) {
|
|
264
276
|
return timed(async () => {
|
|
265
277
|
const res = await fetchImpl(`${base}/chat/completions`, {
|
|
266
278
|
method: 'POST',
|
|
267
279
|
headers,
|
|
268
|
-
body: JSON.stringify({ model
|
|
280
|
+
body: JSON.stringify({ model, stream: true, ...FIXTURES.readiness }),
|
|
269
281
|
signal: AbortSignal.timeout(timeoutMs),
|
|
270
282
|
});
|
|
271
283
|
if (!res.ok) return { ok: false, status: res.status, note: `HTTP ${res.status}` };
|
|
@@ -322,12 +334,12 @@ async function probeStreaming({ fetchImpl, base, headers, entry, timeoutMs }) {
|
|
|
322
334
|
}
|
|
323
335
|
|
|
324
336
|
/** A JSON request has to come back as JSON, not as a promise to be JSON. */
|
|
325
|
-
async function probeJson({ fetchImpl, base, headers, entry, timeoutMs }) {
|
|
337
|
+
async function probeJson({ fetchImpl, base, headers, entry, timeoutMs, model }) {
|
|
326
338
|
return timed(async () => {
|
|
327
339
|
const res = await fetchImpl(`${base}/chat/completions`, {
|
|
328
340
|
method: 'POST',
|
|
329
341
|
headers,
|
|
330
|
-
body: JSON.stringify({ model
|
|
342
|
+
body: JSON.stringify({ model, ...FIXTURES.jsonSchema }),
|
|
331
343
|
signal: AbortSignal.timeout(timeoutMs),
|
|
332
344
|
});
|
|
333
345
|
if (!res.ok) return { ok: false, status: res.status, note: `HTTP ${res.status}` };
|
|
@@ -349,12 +361,12 @@ async function probeJson({ fetchImpl, base, headers, entry, timeoutMs }) {
|
|
|
349
361
|
* shape — not that the model chose to call the tool. Refusing to call a tool is a
|
|
350
362
|
* legitimate answer; a 400 is not.
|
|
351
363
|
*/
|
|
352
|
-
async function probeTools({ fetchImpl, base, headers, entry, timeoutMs }) {
|
|
364
|
+
async function probeTools({ fetchImpl, base, headers, entry, timeoutMs, model }) {
|
|
353
365
|
return timed(async () => {
|
|
354
366
|
const res = await fetchImpl(`${base}/chat/completions`, {
|
|
355
367
|
method: 'POST',
|
|
356
368
|
headers,
|
|
357
|
-
body: JSON.stringify({ model
|
|
369
|
+
body: JSON.stringify({ model, ...FIXTURES.tools }),
|
|
358
370
|
signal: AbortSignal.timeout(timeoutMs),
|
|
359
371
|
});
|
|
360
372
|
if (!res.ok) return { ok: false, status: res.status, note: `HTTP ${res.status} — tools rejected` };
|
|
@@ -385,10 +397,6 @@ function probeModel(entry, discovered = []) {
|
|
|
385
397
|
return 'default';
|
|
386
398
|
}
|
|
387
399
|
|
|
388
|
-
function modelFor(entry) {
|
|
389
|
-
return entry.probe_model ?? entry.model_family ?? 'default';
|
|
390
|
-
}
|
|
391
|
-
|
|
392
400
|
async function timed(fn) {
|
|
393
401
|
const t0 = performance.now();
|
|
394
402
|
try {
|