UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

35 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sentimentAnalysis = void 0; const sentimentList = ["Positive", "Neutral", "Negative"]; /** * This method is used to analyze the sentiment based on the given prompt string. * It returns either the detected sentiment or 'Neutral' if the sentiment could not be detected or was not clear. * * @param api * @param prompt The prompt to be analyzed */ const sentimentAnalysis = async (api, prompt) => { var _a; const payload = { prompt, useCase: "sentimentAnalysis", }; const llmResponse = await ((_a = api.runGenerativeAIPrompt) === null || _a === void 0 ? void 0 : _a.call(api, payload, "sentimentAnalysis")); if (llmResponse) { return getSentiment(llmResponse); } return ""; }; exports.sentimentAnalysis = sentimentAnalysis; /** * This function is used to extract the sentiment from the LLM response. * If no sentiment is detected, the function returns "Neutral". * * @param text The text to be analyzed */ function getSentiment(text) { var _a; return (_a = sentimentList.find((sentiment) => text.toLowerCase().includes(sentiment.toLowerCase()))) !== null && _a !== void 0 ? _a : "Neutral"; } //# sourceMappingURL=sentiment.helper.js.map