in src/nodes/client/text-to-text.ts [34:78]
async runWithInputs(inputs: Inputs) {
const { text, modelid, device, quantized } = inputs;
const _modelid = modelid?.trim();
if (!text) {
// No input node
this.dispatchEvent(
new CustomEvent("outputs", { detail: { results: null } })
);
return;
}
if (this.cachedResult && compareObjects(this.cachedInput, inputs)) {
this.dispatchEvent(
new CustomEvent("outputs", {
detail: {
results: this.cachedResult.generated_text,
text: text,
},
})
);
return;
}
const translator: Text2TextGenerationPipeline = await this.getInstance(
_modelid,
quantized,
device
);
const result = await translator(text);
const resultSingle = (
Array.isArray(result) ? result[0] : result
) as Text2TextGenerationSingle;
// Output.
this.cachedInput = inputs;
this.cachedResult = resultSingle;
this.dispatchEvent(
new CustomEvent("outputs", {
detail: {
results: resultSingle.generated_text,
text: text,
},
})
);
}