Skip to content

Commit 1488079

Browse files
authored
Make // @ts-ignore obsolete for _call overrides by respecting LSP (#278)
* Make // @ts-ignore obsolete for _call overrides by respecting LSP * oops can't be undefined, back to how it was * Use `...unused` instead to fix LSP errors
1 parent 57f2b5c commit 1488079

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/pipelines.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ export class Pipeline extends Callable {
109109
/**
110110
* Executes the task associated with the pipeline.
111111
* @param {any} texts The input texts to be processed.
112+
* @param {...any} unused Only used to fix Liskov Substitution Principle errors.
112113
* @returns {Promise<any>} A promise that resolves to an array containing the inputs and outputs of the task.
113114
*/
114-
async _call(texts) {
115+
async _call(texts, ...unused) {
115116
// Run tokenization
116117
let model_inputs = this.tokenizer(texts, {
117118
padding: true,
@@ -301,6 +302,16 @@ export class TokenClassificationPipeline extends Pipeline {
301302
}
302303
}
303304

305+
/**
306+
* @typedef {object} QuestionAnsweringResult
307+
* @property {string} answer - The answer.
308+
* @property {number} score - The score.
309+
*/
310+
311+
/**
312+
* @typedef {Promise<QuestionAnsweringResult|QuestionAnsweringResult[]>} QuestionAnsweringReturnType
313+
*/
314+
304315
/**
305316
* Question Answering pipeline using any `ModelForQuestionAnswering`.
306317
*
@@ -324,9 +335,9 @@ export class QuestionAnsweringPipeline extends Pipeline {
324335
* @param {string|string[]} context The context(s) where the answer(s) can be found.
325336
* @param {Object} options An optional object containing the following properties:
326337
* @param {number} [options.topk=1] The number of top answer predictions to be returned.
327-
* @returns {Promise<any>} A promise that resolves to an array or object containing the predicted answers and scores.
338+
* @returns {QuestionAnsweringReturnType} A promise that resolves to an array or object
339+
* containing the predicted answers and scores.
328340
*/
329-
// @ts-ignore
330341
async _call(question, context, {
331342
topk = 1
332343
} = {}) {
@@ -760,7 +771,6 @@ export class ZeroShotClassificationPipeline extends Pipeline {
760771
* candidate by doing a softmax of the entailment score vs. the contradiction score.
761772
* @return {Promise<Object|Object[]>} The prediction(s), as a map (or list of maps) from label to score.
762773
*/
763-
// @ts-ignore
764774
async _call(texts, candidate_labels, {
765775
hypothesis_template = "This example is {}.",
766776
multi_label = false,
@@ -1602,7 +1612,6 @@ export class ZeroShotImageClassificationPipeline extends Pipeline {
16021612
* @param {string} [options.hypothesis_template] The hypothesis template to use for zero-shot classification. Default: "This is a photo of {}".
16031613
* @returns {Promise<any>} An array of classifications for each input image or a single classification object if only one input image is provided.
16041614
*/
1605-
// @ts-ignore
16061615
async _call(images, candidate_labels, {
16071616
hypothesis_template = "This is a photo of {}"
16081617
} = {}) {

0 commit comments

Comments
 (0)