@n8n/n8n-nodes-langchain
Version:

95 lines • 3.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = void 0;
exports.execute = execute;
const n8n_workflow_1 = require("n8n-workflow");
const transport_1 = require("../../../transport");
const descriptions_1 = require("../descriptions");
const responses_1 = require("../text/helpers/responses");
const properties = [
{
displayName: 'Messages',
name: 'messages',
type: 'fixedCollection',
typeOptions: {
sortable: true,
multipleValues: true,
},
placeholder: 'Add Message',
default: { values: [{ type: 'text' }] },
options: [
{
displayName: 'Message',
name: 'values',
values: [
{
displayName: 'Role',
name: 'role',
type: 'options',
description: "Role in shaping the model's response, it tells the model how it should behave and interact with the user",
options: [
{
name: 'User',
value: 'user',
description: 'Send a message as a user and get a response from the model',
},
{
name: 'Assistant',
value: 'assistant',
description: 'Tell the model to adopt a specific tone or personality',
},
{
name: 'System',
value: 'system',
description: "Usually used to set the model's behavior or context for the next user message",
},
],
default: 'user',
},
{
...descriptions_1.textMessageProperties[0],
displayOptions: {},
},
],
},
],
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
options: [descriptions_1.metadataProperty],
},
];
const displayOptions = {
show: {
operation: ['create'],
resource: ['conversation'],
},
};
exports.description = (0, n8n_workflow_1.updateDisplayOptions)(displayOptions, properties);
async function execute(i) {
const options = this.getNodeParameter('options', i, {});
const messages = this.getNodeParameter('messages.values', i, []);
const body = {
items: await responses_1.formatInputMessages.call(this, i, messages),
};
if (options.metadata) {
const metadata = (0, n8n_workflow_1.jsonParse)(options.metadata, {
errorMessage: 'Invalid JSON in metadata field',
});
if (!(0, n8n_workflow_1.isObjectEmpty)(metadata)) {
body.metadata = metadata;
}
}
const response = await transport_1.apiRequest.call(this, 'POST', '/conversations', { body });
return [
{
json: response,
pairedItem: { item: i },
},
];
}
//# sourceMappingURL=create.operation.js.map