UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

107 lines 4.26 kB
import { __awaiter } from "tslib"; /* Custom Modules */ import { createNodeDescriptor } from "../../createNodeDescriptor"; /* Templates */ import sentimentAnalysisTemplate from "./htmlTemplates/sentimentAnalysisTemplate"; import { createLastUserInputString } from "../nlu/generativeSlotFiller/prompt"; import { LAST_INPUT_PROMPT } from "./constants/constants"; import { sentimentAnalysis } from "./helpers/sentiment.helper"; import { getFontSizeFieldOptions } from "./helpers/getFontSizeFieldOptions"; /** * Node name: "sentimentAssist" * * Purpose: * Set a Sentiment Assist Tile for the Agent Assist Workspace */ export const SENTIMENT_ASSIST = 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, }, }, ], 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: (params) => __awaiter(void 0, void 0, void 0, function* () { const { cognigy, config } = params; const { api, input } = cognigy; const sentimentSelection = config.sentimentAnalysisInput; try { let prompt = ""; if (sentimentSelection === "lastInput") { const curInput = cognigy.input.text; prompt = `${LAST_INPUT_PROMPT} ${curInput}`; } else if (sentimentSelection === "lastTenInputs") { const conversation = 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 = yield sentimentAnalysis(api, prompt); const data = { html: sentimentAnalysisTemplate({ 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