@n8n/n8n-nodes-langchain
Version:

73 lines • 2.59 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Guardrails_node_exports = {};
__export(Guardrails_node_exports, {
Guardrails: () => Guardrails
});
module.exports = __toCommonJS(Guardrails_node_exports);
var import_process = require("./actions/process");
var import_description = require("./description");
var import_model = require("./helpers/model");
class Guardrails {
constructor() {
this.description = import_description.versionDescription;
}
async execute() {
const items = this.getInputData();
const operation = this.getNodeParameter("operation", 0);
const model = operation === "classify" ? await import_model.getChatModel.call(this) : null;
const failedItems = [];
const passedItems = [];
for (let i = 0; i < items.length; i++) {
try {
const responseData = await import_process.process.call(this, i, model);
if (responseData.passed) {
passedItems.push({
json: { guardrailsInput: responseData.guardrailsInput, ...responseData.passed },
pairedItem: { item: i }
});
}
if (responseData.failed) {
failedItems.push({
json: { guardrailsInput: responseData.guardrailsInput, ...responseData.failed },
pairedItem: { item: i }
});
}
} catch (error) {
if (this.continueOnFail()) {
failedItems.push({
json: { error: error.message, guardrailsInput: "" },
pairedItem: { item: i }
});
} else {
throw error;
}
}
}
if (operation === "classify") {
return [passedItems, failedItems];
}
return [passedItems];
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Guardrails
});
//# sourceMappingURL=Guardrails.node.js.map