test: accept synchronous vip98k image results
This commit is contained in:
parent
42359fbf0f
commit
2fb53b4279
@ -134,6 +134,17 @@ function extractTaskId(payload: unknown) {
|
|||||||
return String(data.taskId || data.task_id || data.id || root.id || "");
|
return String(data.taskId || data.task_id || data.id || root.id || "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractImmediateOutputUrl(payload: unknown) {
|
||||||
|
const root = asRecord(payload);
|
||||||
|
const data = Array.isArray(root.data) ? root.data : [];
|
||||||
|
for (const item of data) {
|
||||||
|
const record = asRecord(item);
|
||||||
|
const url = String(record.url || record.image_url || "").trim();
|
||||||
|
if (url.startsWith("http")) return url;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchCatalog(apiKey: string) {
|
async function fetchCatalog(apiKey: string) {
|
||||||
const [catalogPayload, authorizedPayload] = await Promise.all([
|
const [catalogPayload, authorizedPayload] = await Promise.all([
|
||||||
readJson(
|
readJson(
|
||||||
@ -265,6 +276,7 @@ async function analyzeImage(url: string, modelId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function testModel(apiKey: string, model: JsonRecord) {
|
async function testModel(apiKey: string, model: JsonRecord) {
|
||||||
|
const startedAt = Date.now();
|
||||||
const modelId = String(model.id || "");
|
const modelId = String(model.id || "");
|
||||||
const invocations = (Array.isArray(model.invocations)
|
const invocations = (Array.isArray(model.invocations)
|
||||||
? model.invocations
|
? model.invocations
|
||||||
@ -307,14 +319,24 @@ async function testModel(apiKey: string, model: JsonRecord) {
|
|||||||
signal: AbortSignal.timeout(120_000),
|
signal: AbortSignal.timeout(120_000),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
const immediateOutputUrl = extractImmediateOutputUrl(submitted);
|
||||||
const taskId = extractTaskId(submitted);
|
const taskId = extractTaskId(submitted);
|
||||||
if (!taskId) throw new Error(`${modelId} returned no task ID`);
|
let completed: { durationMs: number; outputUrl: string };
|
||||||
const resultPath = String(invocation.result_path || "").replace(
|
if (immediateOutputUrl) {
|
||||||
"{task_id}",
|
completed = {
|
||||||
encodeURIComponent(taskId),
|
durationMs: Date.now() - startedAt,
|
||||||
);
|
outputUrl: immediateOutputUrl,
|
||||||
if (!resultPath) throw new Error(`${modelId} publishes no result path`);
|
};
|
||||||
const completed = await pollTask(apiKey, taskId, resultPath);
|
} else {
|
||||||
|
if (!taskId) throw new Error(`${modelId} returned neither a task ID nor an image URL`);
|
||||||
|
const resultPath = String(invocation.result_path || "").replace(
|
||||||
|
"{task_id}",
|
||||||
|
encodeURIComponent(taskId),
|
||||||
|
);
|
||||||
|
if (!resultPath) throw new Error(`${modelId} publishes no result path`);
|
||||||
|
completed = await pollTask(apiKey, taskId, resultPath);
|
||||||
|
completed.durationMs = Date.now() - startedAt;
|
||||||
|
}
|
||||||
const image = await analyzeImage(completed.outputUrl, modelId);
|
const image = await analyzeImage(completed.outputUrl, modelId);
|
||||||
const passed = USES_CUSTOM_REFERENCES || image.bothReferencesDetected;
|
const passed = USES_CUSTOM_REFERENCES || image.bothReferencesDetected;
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user