Skip to content

Commit

Permalink
Make // @ts-ignore obsolete for _call overrides by respecting LSP (#278)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kungfooman authored Sep 4, 2023
1 parent 57f2b5c commit 1488079
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ export class Pipeline extends Callable {
/**
* Executes the task associated with the pipeline.
* @param {any} texts The input texts to be processed.
* @param {...any} unused Only used to fix Liskov Substitution Principle errors.
* @returns {Promise<any>} A promise that resolves to an array containing the inputs and outputs of the task.
*/
async _call(texts) {
async _call(texts, ...unused) {
// Run tokenization
let model_inputs = this.tokenizer(texts, {
padding: true,
Expand Down Expand Up @@ -301,6 +302,16 @@ export class TokenClassificationPipeline extends Pipeline {
}
}

/**
* @typedef {object} QuestionAnsweringResult
* @property {string} answer - The answer.
* @property {number} score - The score.
*/

/**
* @typedef {Promise<QuestionAnsweringResult|QuestionAnsweringResult[]>} QuestionAnsweringReturnType
*/

/**
* Question Answering pipeline using any `ModelForQuestionAnswering`.
*
Expand All @@ -324,9 +335,9 @@ export class QuestionAnsweringPipeline extends Pipeline {
* @param {string|string[]} context The context(s) where the answer(s) can be found.
* @param {Object} options An optional object containing the following properties:
* @param {number} [options.topk=1] The number of top answer predictions to be returned.
* @returns {Promise<any>} A promise that resolves to an array or object containing the predicted answers and scores.
* @returns {QuestionAnsweringReturnType} A promise that resolves to an array or object
* containing the predicted answers and scores.
*/
// @ts-ignore
async _call(question, context, {
topk = 1
} = {}) {
Expand Down Expand Up @@ -760,7 +771,6 @@ export class ZeroShotClassificationPipeline extends Pipeline {
* candidate by doing a softmax of the entailment score vs. the contradiction score.
* @return {Promise<Object|Object[]>} The prediction(s), as a map (or list of maps) from label to score.
*/
// @ts-ignore
async _call(texts, candidate_labels, {
hypothesis_template = "This example is {}.",
multi_label = false,
Expand Down Expand Up @@ -1602,7 +1612,6 @@ export class ZeroShotImageClassificationPipeline extends Pipeline {
* @param {string} [options.hypothesis_template] The hypothesis template to use for zero-shot classification. Default: "This is a photo of {}".
* @returns {Promise<any>} An array of classifications for each input image or a single classification object if only one input image is provided.
*/
// @ts-ignore
async _call(images, candidate_labels, {
hypothesis_template = "This is a photo of {}"
} = {}) {
Expand Down

0 comments on commit 1488079

Please sign in to comment.