New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@huggingface/inference

Package Overview
Dependencies
Maintainers
3
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huggingface/inference - npm Package Compare versions

Comparing version 1.6.2 to 1.6.3

139

dist/index.js

@@ -46,3 +46,12 @@ var __defProp = Object.defineProperty;

async fillMask(args, options) {
return this.request(args, options);
const res = await this.request(args, options);
const isValidOutput = Array.isArray(res) && res.every(
(x) => typeof x.score === "number" && typeof x.sequence === "string" && typeof x.token === "number" && typeof x.token_str === "string"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<score: number, sequence:string, token:number, token_str:string>"
);
}
return res;
}

@@ -53,3 +62,8 @@ /**

async summarization(args, options) {
return (await this.request(args, options))?.[0];
const res = await this.request(args, options);
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.summary_text === "string");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<summary_text: string>");
}
return res?.[0];
}

@@ -60,3 +74,10 @@ /**

async questionAnswer(args, options) {
return await this.request(args, options);
const res = await this.request(args, options);
const isValidOutput = typeof res.answer === "string" && typeof res.end === "number" && typeof res.score === "number" && typeof res.start === "number";
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type <answer: string, end: number, score: number, start: number>"
);
}
return res;
}

@@ -67,3 +88,10 @@ /**

async tableQuestionAnswer(args, options) {
return await this.request(args, options);
const res = await this.request(args, options);
const isValidOutput = typeof res.aggregator === "string" && typeof res.answer === "string" && Array.isArray(res.cells) && res.cells.every((x) => typeof x === "string") && Array.isArray(res.coordinates) && res.coordinates.every((coord) => Array.isArray(coord) && coord.every((x) => typeof x === "number"));
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type <aggregator: string, answer: string, cells: string[], coordinates: number[][]>"
);
}
return res;
}

@@ -74,3 +102,8 @@ /**

async textClassification(args, options) {
return (await this.request(args, options))?.[0];
const res = (await this.request(args, options))?.[0];
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<label: string, score: number>");
}
return res;
}

@@ -81,3 +114,8 @@ /**

async textGeneration(args, options) {
return (await this.request(args, options))?.[0];
const res = await this.request(args, options);
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.generated_text === "string");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<generated_text: string>");
}
return res?.[0];
}

@@ -88,3 +126,12 @@ /**

async tokenClassification(args, options) {
return toArray(await this.request(args, options));
const res = toArray(await this.request(args, options));
const isValidOutput = Array.isArray(res) && res.every(
(x) => typeof x.end === "number" && typeof x.entity_group === "string" && typeof x.score === "number" && typeof x.start === "number" && typeof x.word === "string"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<end: number, entity_group: string, score: number, start: number, word: string>"
);
}
return res;
}

@@ -95,3 +142,8 @@ /**

async translation(args, options) {
return (await this.request(args, options))?.[0];
const res = await this.request(args, options);
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.translation_text === "string");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<translation_text: string>");
}
return res?.[0];
}

@@ -102,5 +154,14 @@ /**

async zeroShotClassification(args, options) {
return toArray(
const res = toArray(
await this.request(args, options)
);
const isValidOutput = Array.isArray(res) && res.every(
(x) => Array.isArray(x.labels) && x.labels.every((_label) => typeof _label === "string") && Array.isArray(x.scores) && x.scores.every((_score) => typeof _score === "number") && typeof x.sequence === "string"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<labels: string[], scores: number[], sequence: string>"
);
}
return res;
}

@@ -112,3 +173,10 @@ /**

async conversational(args, options) {
return await this.request(args, options);
const res = await this.request(args, options);
const isValidOutput = Array.isArray(res.conversation.generated_responses) && res.conversation.generated_responses.every((x) => typeof x === "string") && Array.isArray(res.conversation.past_user_inputs) && res.conversation.past_user_inputs.every((x) => typeof x === "string") && typeof res.generated_text === "string" && Array.isArray(res.warnings) && res.warnings.every((x) => typeof x === "string");
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type <conversation: {generated_responses: string[], past_user_inputs: string[]}, generated_text: string, warnings: string[]>"
);
}
return res;
}

@@ -119,3 +187,4 @@ /**

async featureExtraction(args, options) {
return await this.request(args, options);
const res = await this.request(args, options);
return res;
}

@@ -127,6 +196,11 @@ /**

async automaticSpeechRecognition(args, options) {
return await this.request(args, {
const res = await this.request(args, {
...options,
binary: true
});
const isValidOutput = typeof res.text === "string";
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type <text: string>");
}
return res;
}

@@ -138,6 +212,11 @@ /**

async audioClassification(args, options) {
return await this.request(args, {
const res = await this.request(args, {
...options,
binary: true
});
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<label: string, score: number>");
}
return res;
}

@@ -149,6 +228,11 @@ /**

async imageClassification(args, options) {
return await this.request(args, {
const res = await this.request(args, {
...options,
binary: true
});
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<label: string, score: number>");
}
return res;
}

@@ -160,6 +244,15 @@ /**

async objectDetection(args, options) {
return await this.request(args, {
const res = await this.request(args, {
...options,
binary: true
});
const isValidOutput = Array.isArray(res) && res.every(
(x) => typeof x.label === "string" && typeof x.score === "number" && typeof x.box.xmin === "number" && typeof x.box.ymin === "number" && typeof x.box.xmax === "number" && typeof x.box.ymax === "number"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<{label:string; score:number; box:{xmin:number; ymin:number; xmax:number; ymax:number}}>"
);
}
return res;
}

@@ -171,6 +264,13 @@ /**

async imageSegmentation(args, options) {
return await this.request(args, {
const res = await this.request(args, {
...options,
binary: true
});
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.mask === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<label: string, mask: string, score: number>"
);
}
return res;
}

@@ -182,6 +282,11 @@ /**

async textToImage(args, options) {
return await this.request(args, {
const res = await this.request(args, {
...options,
blob: true
});
const isValidOutput = res && res instanceof Blob;
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type object & of instance Blob");
}
return res;
}

@@ -188,0 +293,0 @@ async request(args, options) {

2

package.json
{
"name": "@huggingface/inference",
"version": "1.6.2",
"version": "1.6.3",
"license": "MIT",

@@ -5,0 +5,0 @@ "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",

@@ -522,3 +522,18 @@ import { toArray } from "./utils/to-array";

public async fillMask(args: FillMaskArgs, options?: Options): Promise<FillMaskReturn> {
return this.request(args, options);
const res = await this.request<FillMaskReturn>(args, options);
const isValidOutput =
Array.isArray(res) &&
res.every(
(x) =>
typeof x.score === "number" &&
typeof x.sequence === "string" &&
typeof x.token === "number" &&
typeof x.token_str === "string"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<score: number, sequence:string, token:number, token_str:string>"
);
}
return res;
}

@@ -530,3 +545,8 @@

public async summarization(args: SummarizationArgs, options?: Options): Promise<SummarizationReturn> {
return (await this.request<SummarizationReturn[]>(args, options))?.[0];
const res = await this.request<SummarizationReturn[]>(args, options);
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.summary_text === "string");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<summary_text: string>");
}
return res?.[0];
}

@@ -538,3 +558,14 @@

public async questionAnswer(args: QuestionAnswerArgs, options?: Options): Promise<QuestionAnswerReturn> {
return await this.request(args, options);
const res = await this.request<QuestionAnswerReturn>(args, options);
const isValidOutput =
typeof res.answer === "string" &&
typeof res.end === "number" &&
typeof res.score === "number" &&
typeof res.start === "number";
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type <answer: string, end: number, score: number, start: number>"
);
}
return res;
}

@@ -549,3 +580,16 @@

): Promise<TableQuestionAnswerReturn> {
return await this.request(args, options);
const res = await this.request<TableQuestionAnswerReturn>(args, options);
const isValidOutput =
typeof res.aggregator === "string" &&
typeof res.answer === "string" &&
Array.isArray(res.cells) &&
res.cells.every((x) => typeof x === "string") &&
Array.isArray(res.coordinates) &&
res.coordinates.every((coord) => Array.isArray(coord) && coord.every((x) => typeof x === "number"));
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type <aggregator: string, answer: string, cells: string[], coordinates: number[][]>"
);
}
return res;
}

@@ -557,3 +601,9 @@

public async textClassification(args: TextClassificationArgs, options?: Options): Promise<TextClassificationReturn> {
return (await this.request<TextClassificationReturn[]>(args, options))?.[0];
const res = (await this.request<TextClassificationReturn[]>(args, options))?.[0];
const isValidOutput =
Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<label: string, score: number>");
}
return res;
}

@@ -565,3 +615,8 @@

public async textGeneration(args: TextGenerationArgs, options?: Options): Promise<TextGenerationReturn> {
return (await this.request<TextGenerationReturn[]>(args, options))?.[0];
const res = await this.request<TextGenerationReturn[]>(args, options);
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.generated_text === "string");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<generated_text: string>");
}
return res?.[0];
}

@@ -576,3 +631,19 @@

): Promise<TokenClassificationReturn> {
return toArray(await this.request(args, options));
const res = toArray(await this.request<TokenClassificationReturnValue | TokenClassificationReturn>(args, options));
const isValidOutput =
Array.isArray(res) &&
res.every(
(x) =>
typeof x.end === "number" &&
typeof x.entity_group === "string" &&
typeof x.score === "number" &&
typeof x.start === "number" &&
typeof x.word === "string"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<end: number, entity_group: string, score: number, start: number, word: string>"
);
}
return res;
}

@@ -584,3 +655,8 @@

public async translation(args: TranslationArgs, options?: Options): Promise<TranslationReturn> {
return (await this.request<TranslationReturn[]>(args, options))?.[0];
const res = await this.request<TranslationReturn[]>(args, options);
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.translation_text === "string");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<translation_text: string>");
}
return res?.[0];
}

@@ -595,5 +671,21 @@

): Promise<ZeroShotClassificationReturn> {
return toArray(
await this.request<ZeroShotClassificationReturnValue | ZeroShotClassificationReturnValue[]>(args, options)
const res = toArray(
await this.request<ZeroShotClassificationReturnValue | ZeroShotClassificationReturn>(args, options)
);
const isValidOutput =
Array.isArray(res) &&
res.every(
(x) =>
Array.isArray(x.labels) &&
x.labels.every((_label) => typeof _label === "string") &&
Array.isArray(x.scores) &&
x.scores.every((_score) => typeof _score === "number") &&
typeof x.sequence === "string"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<labels: string[], scores: number[], sequence: string>"
);
}
return res;
}

@@ -606,3 +698,17 @@

public async conversational(args: ConversationalArgs, options?: Options): Promise<ConversationalReturn> {
return await this.request(args, options);
const res = await this.request<ConversationalReturn>(args, options);
const isValidOutput =
Array.isArray(res.conversation.generated_responses) &&
res.conversation.generated_responses.every((x) => typeof x === "string") &&
Array.isArray(res.conversation.past_user_inputs) &&
res.conversation.past_user_inputs.every((x) => typeof x === "string") &&
typeof res.generated_text === "string" &&
Array.isArray(res.warnings) &&
res.warnings.every((x) => typeof x === "string");
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type <conversation: {generated_responses: string[], past_user_inputs: string[]}, generated_text: string, warnings: string[]>"
);
}
return res;
}

@@ -614,3 +720,4 @@

public async featureExtraction(args: FeatureExtractionArgs, options?: Options): Promise<FeatureExtractionReturn> {
return await this.request(args, options);
const res = await this.request<FeatureExtractionReturn>(args, options);
return res;
}

@@ -626,6 +733,11 @@

): Promise<AutomaticSpeechRecognitionReturn> {
return await this.request(args, {
const res = await this.request<AutomaticSpeechRecognitionReturn>(args, {
...options,
binary: true,
});
const isValidOutput = typeof res.text === "string";
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type <text: string>");
}
return res;
}

@@ -641,6 +753,12 @@

): Promise<AudioClassificationReturn> {
return await this.request(args, {
const res = await this.request<AudioClassificationReturn>(args, {
...options,
binary: true,
});
const isValidOutput =
Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<label: string, score: number>");
}
return res;
}

@@ -656,6 +774,12 @@

): Promise<ImageClassificationReturn> {
return await this.request(args, {
const res = await this.request<ImageClassificationReturn>(args, {
...options,
binary: true,
});
const isValidOutput =
Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type Array<label: string, score: number>");
}
return res;
}

@@ -668,6 +792,23 @@

public async objectDetection(args: ObjectDetectionArgs, options?: Options): Promise<ObjectDetectionReturn> {
return await this.request(args, {
const res = await this.request<ObjectDetectionReturn>(args, {
...options,
binary: true,
});
const isValidOutput =
Array.isArray(res) &&
res.every(
(x) =>
typeof x.label === "string" &&
typeof x.score === "number" &&
typeof x.box.xmin === "number" &&
typeof x.box.ymin === "number" &&
typeof x.box.xmax === "number" &&
typeof x.box.ymax === "number"
);
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<{label:string; score:number; box:{xmin:number; ymin:number; xmax:number; ymax:number}}>"
);
}
return res;
}

@@ -680,6 +821,15 @@

public async imageSegmentation(args: ImageSegmentationArgs, options?: Options): Promise<ImageSegmentationReturn> {
return await this.request(args, {
const res = await this.request<ImageSegmentationReturn>(args, {
...options,
binary: true,
});
const isValidOutput =
Array.isArray(res) &&
res.every((x) => typeof x.label === "string" && typeof x.mask === "string" && typeof x.score === "number");
if (!isValidOutput) {
throw new TypeError(
"Invalid inference output: output must be of type Array<label: string, mask: string, score: number>"
);
}
return res;
}

@@ -692,6 +842,11 @@

public async textToImage(args: TextToImageArgs, options?: Options): Promise<TextToImageReturn> {
return await this.request(args, {
const res = await this.request<TextToImageReturn>(args, {
...options,
blob: true,
});
const isValidOutput = res && res instanceof Blob;
if (!isValidOutput) {
throw new TypeError("Invalid inference output: output must be of type object & of instance Blob");
}
return res;
}

@@ -698,0 +853,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc