in src/nodes/server/summarization.ts [29:81]
async runWithInputs(inputs: Inputs) {
const { text, apikey, modelid } = inputs;
const _modelid = modelid?.trim();
if (this.hf && apikey) {
this.hf = new HfInference(apikey);
}
if (!text) {
this.dispatchEvent(
new CustomEvent("outputs", { detail: { results: null } })
);
return;
}
if (this.cachedOutput && compareObjects(this.cachedInputs, inputs)) {
this.dispatchEvent(
new CustomEvent("outputs", { detail: this.cachedOutput })
);
return;
}
try {
const summResul = await this.hf?.summarization({
model: _modelid,
inputs: text,
});
if (!summResul?.summary_text) {
throw new Error("Invalid response");
}
this.cachedOutput = {
results: summResul.summary_text,
text: text,
};
this.cachedInputs = inputs;
this.dispatchEvent(
new CustomEvent("outputs", { detail: this.cachedOutput })
);
} catch (error: any) {
this.dispatchEvent(
new CustomEvent("outputs", {
detail: {
error: {
title: "Error",
message: error.message,
},
},
})
);
}
}