UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

148 lines 5.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GPT_CONVERSATION_SUMMARY = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../createNodeDescriptor"); const prompt_1 = require("../nlu/generativeSlotFiller/prompt"); exports.GPT_CONVERSATION_SUMMARY = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "conversationSummary", defaultLabel: "Generative Conversation Summary", summary: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__SUMMARY__DEFAULT", fields: [ { key: "temperature", label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__TEMPERATURE__DEFAULT", type: "slider", description: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__TEMPERATURE__DESCRIPTION__DEFAULT", defaultValue: 0.7, params: { min: 0, max: 1, step: 0.1 }, condition: { key: "samplingMethod", value: "temperature", } }, { key: "timeout", label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__TIMEOUT__DEFAULT", defaultValue: 5000, type: "number", description: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__TIMEOUT__DESCRIPTION", }, { key: "storeLocation", type: "select", label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__STORE_LOCATION__DEFAULT", defaultValue: "input", params: { options: [ { label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__STORE_LOCATION__PARAMS__INPUT__LABEL", value: "input" }, { label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__STORE_LOCATION__PARAMS__CONTEXT__LABEL", value: "context" } ], required: true }, }, { key: "inputKey", type: "cognigyText", label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__INPUT_KEY__DEFAULT", defaultValue: "conversationSummary", condition: { key: "storeLocation", value: "input", } }, { key: "contextKey", type: "cognigyText", label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__FIELDS__CONTEXT_KEY__DEFAULT", defaultValue: "conversationSummary", condition: { key: "storeLocation", value: "context", } }, ], sections: [ { key: "advanced", label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__SECTIONS__ADVANCED__DEFAULT", defaultCollapsed: true, fields: [ "temperature", "timeout", ] }, { key: "storage", label: "UI__NODE_EDITOR__SERVICE__CONVERSATION_SUMMARY__SECTIONS__STORAGE__DEFAULT", defaultCollapsed: true, fields: [ "storeLocation", "inputKey", "contextKey", ] } ], form: [ { type: "section", key: "advanced" }, { type: "section", key: "storage" }, ], appearance: {}, tags: ["service"], function: async ({ cognigy, config }) => { var _a; const { api } = cognigy; const { temperature, storeLocation, contextKey, inputKey, timeout, } = config; const prompt = createConversationSummaryPrompt(cognigy.lastConversationEntries); try { const data = { prompt, temperature, timeoutInMs: timeout, useCase: "conversationSummary" }; // TODO: Create a new useCase for this feature and use it here instead const response = await api.runGenerativeAIPrompt(data, "gptConversation"); if (storeLocation === "context") { api.addToContext(contextKey, response, "simple"); } else { // @ts-ignore api.addToInput(inputKey, response); } } catch (error) { const errorDetails = { name: error.name, code: error.code, message: error.message || ((_a = error.originalErrorDetails) === null || _a === void 0 ? void 0 : _a.message), }; if (storeLocation === "context") { api.addToContext(contextKey, { error: errorDetails }, "simple"); } else { // @ts-ignore api.addToInput(inputKey, { error: errorDetails }); } throw error; } } }); const createConversationSummaryPrompt = (lastConversationEntries) => { const conversation = (0, prompt_1.createLastConverationString)(lastConversationEntries); const prompt = `A bot had a conversation with a user. This is the conversation so far: ${conversation} Write a concise summary of the conversation in short sentences: `; return prompt; }; //# sourceMappingURL=conversationSummary.js.map