UNPKG

n8n-nodes-langsmith-prompt

Version:

n8n node to use LangSmith prompt templates with variable substitution

104 lines 4.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LangSmithPrompt = void 0; const n8n_workflow_1 = require("n8n-workflow"); const LangSmithHelper_1 = require("./LangSmithHelper"); class LangSmithPrompt { constructor() { this.description = { displayName: 'LangSmith Prompt', name: 'langSmithPrompt', icon: 'file:langsmith.svg', group: ['input'], version: 1, subtitle: '={{$parameter["promptName"] || "LangSmith Prompt"}}', description: 'Fill in a prompt template stored in LangSmith', defaults: { name: 'LangSmith Prompt', }, inputs: ["main"], outputs: ["main"], properties: [ { displayName: 'Prompt Name', name: 'promptName', type: 'string', default: '', required: true, description: 'The name of the prompt template in your LangSmith account', }, { displayName: 'Input Parameters', name: 'inputParameters', type: 'fixedCollection', typeOptions: { multipleValues: true, }, default: { parameters: [], }, description: 'Parameters to substitute in the prompt template', options: [ { name: 'parameters', displayName: 'Parameters', values: [ { displayName: 'Name', name: 'name', type: 'string', default: '', description: 'Parameter name that appears in the template like {name}', required: true, }, { displayName: 'Value', name: 'value', type: 'string', default: '', description: 'Value to substitute in the template', required: true, }, ], }, ], }, ], credentials: [ { name: 'langSmithApi', required: true, }, ], }; } async execute() { const returnData = []; try { const credentials = await this.getCredentials('langSmithApi'); const promptName = this.getNodeParameter('promptName', 0); const inputParametersData = this.getNodeParameter('inputParameters.parameters', 0, []); const promptParameters = {}; for (const param of inputParametersData) { promptParameters[param.name] = param.value; } const langSmithApiKey = credentials.langSmithApiKey; const promptTemplate = await (0, LangSmithHelper_1.fetchPromptTemplateByName)(promptName, langSmithApiKey); if (!promptTemplate) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Prompt with name "${promptName}" not found`); } const finalPrompt = (0, LangSmithHelper_1.invokePromptRaw)(promptTemplate, promptParameters); returnData.push({ json: { [promptName]: finalPrompt }, }); return [returnData]; } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), error); } } } exports.LangSmithPrompt = LangSmithPrompt; //# sourceMappingURL=LangSmithPrompt.node.js.map