UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

109 lines 4.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SENTIMENT_ASSIST = void 0; /* Custom Modules */ const createNodeDescriptor_1 = require("../../createNodeDescriptor"); /* Templates */ const sentimentAnalysisTemplate_1 = require("./htmlTemplates/sentimentAnalysisTemplate"); const prompt_1 = require("../nlu/generativeSlotFiller/prompt"); const constants_1 = require("./constants/constants"); const sentiment_helper_1 = require("./helpers/sentiment.helper"); const getFontSizeFieldOptions_1 = require("./helpers/getFontSizeFieldOptions"); /** * Node name: "sentimentAssist" * * Purpose: * Set a Sentiment Assist Tile for the Agent Assist Workspace */ exports.SENTIMENT_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "sentimentAssist", defaultLabel: "Copilot: Sentiment Tile", summary: "UI__NODE_EDITOR__SENTIMENT_ASSIST__SUMMARY", appearance: { showIcon: false, }, tags: ["agentAssist"], fields: [ { key: "tileId", label: "UI__NODE_EDITOR__SENTIMENT_ASSIST__FIELDS__TILE_ID__LABEL", description: "UI__NODE_EDITOR__SENTIMENT_ASSIST__FIELDS__TILE_ID__DESCRIPTION", type: "cognigyText", defaultValue: "sentiment", }, { key: "sentimentAnalysisInput", label: "UI__NODE_EDITOR__SENTIMENT_ASSIST__FIELDS__SENTIMENT_ANALYSIS_INPUT__LABEL", type: "select", defaultValue: "lastInput", params: { options: [ { label: "UI__NODE_EDITOR__SENTIMENT_ASSIST__FIELDS__SENTIMENT_ANALYSIS_INPUT__OPTIONS__LAST_INPUT__LABEL", value: "lastInput", }, { label: "UI__NODE_EDITOR__SENTIMENT_ASSIST__FIELDS__SENTIMENT_ANALYSIS_INPUT__OPTIONS__LAST_TEN_INPUTS__LABEL", value: "lastTenInputs", }, ], }, }, { key: "fontSize", type: "select", label: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE", description: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE__INFO", defaultValue: "text-sm", params: { options: getFontSizeFieldOptions_1.getFontSizeFieldOptions, }, }, ], sections: [ { key: "uiPreferences", label: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__TITLE", defaultCollapsed: true, fields: ["fontSize"], }, ], form: [ { type: "field", key: "tileId" }, { type: "field", key: "sentimentAnalysisInput" }, { type: "section", key: "uiPreferences" }, ].filter((element) => !!element), function: async (params) => { const { cognigy, config } = params; const { api, input } = cognigy; const sentimentSelection = config.sentimentAnalysisInput; try { let prompt = ""; if (sentimentSelection === "lastInput") { const curInput = cognigy.input.text; prompt = `${constants_1.LAST_INPUT_PROMPT} ${curInput}`; } else if (sentimentSelection === "lastTenInputs") { const conversation = (0, prompt_1.createLastUserInputString)(cognigy.lastConversationEntries) + "\n"; prompt = `A User had the following conversation with a bot: ${conversation}. Return the average sentiment of the conversation with one word. Use positive, neutral or negative only`; } const sentiment = await (0, sentiment_helper_1.sentimentAnalysis)(api, prompt); const data = { html: (0, sentimentAnalysisTemplate_1.default)({ sentiment, fontSize: config.fontSize, input, }), }; cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, params), { tile: { id: config.tileId, type: "html", data, } })); } catch (err) { api.logDebugError(err, "Sentiment Assist Error"); } }, }); //# sourceMappingURL=sentimentAssist.js.map