Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/inference/src/providers/hf-inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,15 @@ export class HFInferenceImageSegmentationTask extends HFInferenceTask implements
(x) =>
typeof x.label === "string" &&
typeof x.mask === "string" &&
(x.score === undefined || typeof x.score === "number"),
(x.score === undefined || x.score === null || typeof x.score === "number"),
Comment thread
cursor[bot] marked this conversation as resolved.
)
) {
return response;
// Coerce `null` scores (returned by some HF models, e.g. face-parsing)
// to `undefined` so the result matches the declared
// `ImageSegmentationOutputElement` type (`score?: number`). Without
// this, downstream consumers using `if (segment.score !== undefined)`
// would treat `null` as a valid number and crash on numeric ops.
return response.map((x) => (x.score === null ? { ...x, score: undefined } : x));
}
throw new InferenceClientProviderOutputError(
"Received malformed response from HF-Inference image-segmentation API: expected Array<{label: string, mask: string, score: number}>",
Expand Down