Skip to content

Commit 2c5934d

Browse files
committed
Accept null score in hf-inference image-segmentation response
The image-segmentation output schema declares score as optional (packages/tasks/src/tasks/image-segmentation/inference.ts: score?: number), but the runtime validator in HFInferenceImageSegmentationTask only accepted undefined or a number, rejecting null with: API Implementation Error: TypeError: Invalid output: output must be of type Array<{label:string; score:number; mask: string}> Several HF-Inference models (e.g. jonathandinu/face-parsing) return null for score on per-segment masks, which is consistent with the optional schema field but tripped the strict type guard. Allow null alongside undefined and number. Refs #1430
1 parent 3f590d2 commit 2c5934d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

packages/inference/src/providers/hf-inference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export class HFInferenceImageSegmentationTask extends HFInferenceTask implements
393393
(x) =>
394394
typeof x.label === "string" &&
395395
typeof x.mask === "string" &&
396-
(x.score === undefined || typeof x.score === "number"),
396+
(x.score === undefined || x.score === null || typeof x.score === "number"),
397397
)
398398
) {
399399
return response;

0 commit comments

Comments
 (0)