@cognigy/rest-api-client 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/build/GenericTusFn.js +64 -0
- package/build/RestAPIClient.js +3 -0
- package/build/apigroups/AdministrationAPIGroup_2_0.js +7 -2
- package/build/apigroups/ResourcesAPIGroup_2_0.js +28 -23
- package/build/{shared/interfaces/agentAssist/ISendTileUpdateReferenceParams.js → apigroups/TTusAPIOperation.js} +1 -1
- package/build/apigroups/index.js +2 -0
- package/build/connector/AxiosAdapter.js +5 -4
- package/build/shared/charts/descriptors/agentAssist/constants/constants.js +7 -0
- package/build/shared/charts/descriptors/agentAssist/helpers/sentiment.helper.js +41 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/identityAssistTemplate.js +54 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/knowledgeAssistTemplate.js +187 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/nextActionWidgetTemplate.js +93 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stage0.js +81 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stage1.js +84 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stage2.js +97 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stageError.js +85 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/sentimentAnalysisTemplate.js +41 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/stylesPartial.js +15 -0
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/transcriptAssistTemplate.js +53 -0
- package/build/shared/charts/descriptors/agentAssist/identityAssist.js +135 -0
- package/build/shared/charts/descriptors/agentAssist/index.js +15 -1
- package/build/shared/charts/descriptors/agentAssist/knowledgeAssist.js +625 -0
- package/build/shared/charts/descriptors/agentAssist/nextActionAssist.js +77 -0
- package/build/shared/charts/descriptors/agentAssist/sentimentAssist.js +86 -0
- package/build/shared/charts/descriptors/agentAssist/setAdaptiveCardTile.js +2 -2
- package/build/shared/charts/descriptors/agentAssist/setAgentAssistGrid.js +105 -0
- package/build/shared/charts/descriptors/agentAssist/setHtmlTile.js +2 -2
- package/build/shared/charts/descriptors/agentAssist/setIframeTile.js +2 -2
- package/build/shared/charts/descriptors/agentAssist/setSecureFormsTile.js +171 -0
- package/build/shared/charts/descriptors/agentAssist/transcriptAssist.js +72 -0
- package/build/shared/charts/descriptors/allFields.js +6 -0
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/TGenerativeAIConnectionFields.js +3 -0
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/alephAlphaProviderConnection.js +11 -0
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/anthropicProviderConnection.js +1 -1
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/azureOpenAIProviderConnectionV2.js +1 -1
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/index.js +6 -2
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/openAIProviderConnection.js +1 -1
- package/build/shared/charts/descriptors/connectionNodes/internalStorageProviders/amazonStorageProviderConnection.js +4 -4
- package/build/shared/charts/descriptors/connectionNodes/internalStorageProviders/azureBlobStorageProviderConnection.js +3 -3
- package/build/shared/charts/descriptors/connectionNodes/internalStorageProviders/googleCloudStorageProviderConnection.js +3 -3
- package/build/shared/charts/descriptors/connectionNodes/mongoDB/mongoDBConnection.js +1 -1
- package/build/shared/charts/descriptors/connectionNodes/smtp/oAuth2Connection.js +8 -8
- package/build/shared/charts/descriptors/connectionNodes/smtp/serviceConnection.js +2 -2
- package/build/shared/charts/descriptors/connectionNodes/smtp/smtpConnection.js +5 -5
- package/build/shared/charts/descriptors/connectionNodes/speechProviders/awsSpeechProviderConnection.js +4 -4
- package/build/shared/charts/descriptors/connectionNodes/speechProviders/microsoftSpeechProviderConnection.js +2 -2
- package/build/shared/charts/descriptors/connectionNodes/sql/sqlConnection.js +5 -5
- package/build/shared/charts/descriptors/connectionNodes/translationProviders/deeplTranslationProviderConnection.js +15 -0
- package/build/shared/charts/descriptors/connectionNodes/translationProviders/googleTranslationProviderConnection.js +15 -0
- package/build/shared/charts/descriptors/connectionNodes/translationProviders/index.js +23 -0
- package/build/shared/charts/descriptors/connectionNodes/translationProviders/microsoftTranslationProviderConnection.js +21 -0
- package/build/shared/charts/descriptors/index.js +13 -2
- package/build/shared/charts/descriptors/knowledgeSearch/constants/constants.js +6 -0
- package/build/shared/charts/descriptors/knowledgeSearch/index.js +5 -1
- package/build/shared/charts/descriptors/knowledgeSearch/knowledgeSearch.js +7 -2
- package/build/shared/charts/descriptors/knowledgeSearch/knowledgeSearchV2.js +151 -0
- package/build/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +985 -0
- package/build/shared/charts/descriptors/logic/goTo.js +3 -1
- package/build/shared/charts/descriptors/message/question/optionalQuestion.js +2 -2
- package/build/shared/charts/descriptors/message/question/question.js +215 -8
- package/build/shared/charts/descriptors/nlu/cleanText.js +1 -0
- package/build/shared/charts/descriptors/nlu/generativeSlotFiller/prompt.js +103 -5
- package/build/shared/charts/descriptors/service/GPTConversation.js +125 -23
- package/build/shared/charts/descriptors/service/GPTPrompt.js +148 -12
- package/build/shared/charts/descriptors/service/checkAgentAvailability.js +15 -1
- package/build/shared/charts/descriptors/service/handoverV2.js +45 -0
- package/build/shared/{interfaces/twilioInterface.js → charts/descriptors/voice/interface/IBandwidth.js} +1 -1
- package/build/shared/charts/descriptors/voice/mappers/base.mapper.js +14 -0
- package/build/shared/charts/descriptors/voice/mappers/hangup.mapper.js +26 -0
- package/build/shared/charts/descriptors/voice/mappers/muteSpeechInput.mapper.js +17 -2
- package/build/shared/charts/descriptors/voice/mappers/play.mapper.js +54 -0
- package/build/shared/charts/descriptors/voice/mappers/record.mapper.js +7 -0
- package/build/shared/charts/descriptors/voice/mappers/sendMetadata.mapper.js +15 -0
- package/build/shared/charts/descriptors/voice/mappers/setSessionConfig.mapper.js +38 -8
- package/build/shared/charts/descriptors/voice/mappers/transfer.mapper.js +31 -9
- package/build/shared/charts/descriptors/voice/nodes/muteSpeechInput.js +1 -1
- package/build/shared/charts/descriptors/voice/nodes/play.js +1 -1
- package/build/shared/charts/descriptors/voice/nodes/sessionSpeechParameters.js +118 -4
- package/build/shared/charts/descriptors/voice/nodes/transfer.js +11 -3
- package/build/shared/charts/descriptors/voice/utils/vgConstants.js +14 -0
- package/build/shared/charts/descriptors/voicegateway/index.js +14 -11
- package/build/shared/charts/descriptors/voicegateway/utils/paramUtils.js +1 -5
- package/build/shared/charts/descriptors/voicegateway2/nodes/muteSpeechInput.js +12 -1
- package/build/shared/charts/descriptors/voicegateway2/nodes/play.js +6 -0
- package/build/shared/charts/descriptors/voicegateway2/nodes/setSessionConfig.js +158 -10
- package/build/shared/charts/descriptors/voicegateway2/nodes/transfer.js +296 -43
- package/build/shared/charts/descriptors/voicegateway2/utils/helper.js +30 -4
- package/build/shared/charts/helpers/generativeAI/rephraseSentenceWithAi.js +1 -1
- package/build/shared/constants.js +5 -1
- package/build/shared/handoverClients/interfaces/THandoverEventType.js +3 -1
- package/build/shared/helper/BaseContext.js +2 -15
- package/build/shared/helper/nlu/textCleaner.js +25 -3
- package/build/shared/interfaces/IEndpointTranslationSettings.js +9 -0
- package/build/shared/interfaces/IOrganisation.js +2 -1
- package/build/shared/interfaces/agentAssist/ISendConfigUpdateParams.js +3 -0
- package/build/shared/interfaces/agentAssist/ISendUpdateReferenceParams.js +3 -0
- package/build/shared/interfaces/amqpInterface.js +18 -22
- package/build/shared/interfaces/channels/genesysBotConnector.js +21 -0
- package/build/shared/interfaces/channels/niceCXOne.js +8 -0
- package/build/shared/interfaces/generativeAI/IGenerativeAIModels.js +15 -7
- package/build/shared/interfaces/handover.js +57 -3
- package/build/shared/interfaces/journeys/IJourney.js +6 -0
- package/build/shared/interfaces/journeys/IJourneyTrackEvent.js +2 -0
- package/build/shared/interfaces/messageAPI/endpoints.js +91 -8
- package/build/shared/interfaces/resources/IAuditEvent.js +1 -0
- package/build/shared/interfaces/resources/IConnectionSchema.js +3 -0
- package/build/shared/interfaces/resources/IEndpoint.js +1 -0
- package/build/shared/interfaces/resources/IExtension.js +3 -0
- package/build/shared/interfaces/resources/ILargeLanguageModel.js +24 -5
- package/build/shared/interfaces/resources/INodeDescriptorSet.js +23 -1
- package/build/shared/interfaces/resources/TNLUConnectorType.js +0 -1
- package/build/shared/interfaces/resources/TRestChannelType.js +16 -11
- package/build/shared/interfaces/resources/TWebhookChannelType.js +6 -1
- package/build/shared/interfaces/resources/knowledgeStore/IKnowledgeChunk.js +21 -3
- package/build/shared/interfaces/resources/knowledgeStore/IKnowledgeSource.js +13 -2
- package/build/shared/interfaces/resources/knowledgeStore/IKnowledgeStore.js +1 -1
- package/build/shared/interfaces/resources/settings/IAgentSettings.js +3 -23
- package/build/shared/interfaces/resources/settings/IGenerativeAISettings.js +4 -0
- package/build/shared/interfaces/resources/settings/ITranslationSettings.js +63 -0
- package/build/shared/interfaces/resources/settings/index.js +4 -1
- package/build/shared/interfaces/restAPI/administration/voiceGateway/v2.0/IReadVoiceGatewayAccountRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/administration/voiceGateway/v2.0/ISetupVoiceGatewayAccountRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/administration/voiceGateway/v2.0/index.js +3 -0
- package/build/shared/interfaces/restAPI/metrics/knowledgeQueryCounter/v2.0/IGetKnowledgeQueryCounterOrganisationRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/metrics/knowledgeQueryCounter/v2.0/IGetKnowledgeQueryCounterRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/metrics/knowledgeQueryCounter/v2.0/IKnowlegeQueryCounterAggregatedValue_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/metrics/knowledgeQueryCounter/v2.0/index.js +3 -0
- package/build/shared/interfaces/restAPI/resources/nluconnector/v2.0/TNLUConnectorType_2_0.js +0 -2
- package/build/shared/interfaces/restAPI/resources/uploadResumable/v2.0/IUploadResumableRest_2_0.js +17 -0
- package/build/shared/interfaces/restAPI/resources/uploadResumable/v2.0/index.js +3 -0
- package/build/shared/interfaces/security/IKnowledgeQueryCounterAggregatedValue.js +3 -0
- package/build/shared/interfaces/security/IPermission.js +2 -0
- package/build/shared/interfaces/security/IRole.js +3 -1
- package/build/test.js +27 -0
- package/package.json +19 -17
- package/types/index.d.ts +581 -129
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SET_ADAPTIVE_CARD_TILE = exports.SET_HTML_TILE = exports.SET_IFRAME_TILE = void 0;
|
|
3
|
+
exports.KNOWLEDGE_ASSIST = exports.IDENTITY_ASSIST = exports.TRANSCRIPT_ASSIST = exports.SENTIMENT_ASSIST = exports.NEXT_ACTION_ASSIST = exports.SET_SECURE_FORMS_TILE = exports.SET_AGENT_ASSIST_GRID = exports.SET_ADAPTIVE_CARD_TILE = exports.SET_HTML_TILE = exports.SET_IFRAME_TILE = void 0;
|
|
4
4
|
var setIframeTile_1 = require("./setIframeTile");
|
|
5
5
|
Object.defineProperty(exports, "SET_IFRAME_TILE", { enumerable: true, get: function () { return setIframeTile_1.SET_IFRAME_TILE; } });
|
|
6
6
|
var setHtmlTile_1 = require("./setHtmlTile");
|
|
7
7
|
Object.defineProperty(exports, "SET_HTML_TILE", { enumerable: true, get: function () { return setHtmlTile_1.SET_HTML_TILE; } });
|
|
8
8
|
var setAdaptiveCardTile_1 = require("./setAdaptiveCardTile");
|
|
9
9
|
Object.defineProperty(exports, "SET_ADAPTIVE_CARD_TILE", { enumerable: true, get: function () { return setAdaptiveCardTile_1.SET_ADAPTIVE_CARD_TILE; } });
|
|
10
|
+
var setAgentAssistGrid_1 = require("./setAgentAssistGrid");
|
|
11
|
+
Object.defineProperty(exports, "SET_AGENT_ASSIST_GRID", { enumerable: true, get: function () { return setAgentAssistGrid_1.SET_AGENT_ASSIST_GRID; } });
|
|
12
|
+
var setSecureFormsTile_1 = require("./setSecureFormsTile");
|
|
13
|
+
Object.defineProperty(exports, "SET_SECURE_FORMS_TILE", { enumerable: true, get: function () { return setSecureFormsTile_1.SET_SECURE_FORMS_TILE; } });
|
|
14
|
+
var nextActionAssist_1 = require("./nextActionAssist");
|
|
15
|
+
Object.defineProperty(exports, "NEXT_ACTION_ASSIST", { enumerable: true, get: function () { return nextActionAssist_1.NEXT_ACTION_ASSIST; } });
|
|
16
|
+
var sentimentAssist_1 = require("./sentimentAssist");
|
|
17
|
+
Object.defineProperty(exports, "SENTIMENT_ASSIST", { enumerable: true, get: function () { return sentimentAssist_1.SENTIMENT_ASSIST; } });
|
|
18
|
+
var transcriptAssist_1 = require("./transcriptAssist");
|
|
19
|
+
Object.defineProperty(exports, "TRANSCRIPT_ASSIST", { enumerable: true, get: function () { return transcriptAssist_1.TRANSCRIPT_ASSIST; } });
|
|
20
|
+
var identityAssist_1 = require("./identityAssist");
|
|
21
|
+
Object.defineProperty(exports, "IDENTITY_ASSIST", { enumerable: true, get: function () { return identityAssist_1.IDENTITY_ASSIST; } });
|
|
22
|
+
var knowledgeAssist_1 = require("./knowledgeAssist");
|
|
23
|
+
Object.defineProperty(exports, "KNOWLEDGE_ASSIST", { enumerable: true, get: function () { return knowledgeAssist_1.KNOWLEDGE_ASSIST; } });
|
|
10
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KNOWLEDGE_ASSIST = void 0;
|
|
4
|
+
/* Custom modules */
|
|
5
|
+
const createNodeDescriptor_1 = require("../../createNodeDescriptor");
|
|
6
|
+
const logic_1 = require("../logic");
|
|
7
|
+
const errors_1 = require("../../../errors");
|
|
8
|
+
/*Template*/
|
|
9
|
+
const knowledgeAssistTemplate_1 = require("./htmlTemplates/knowledgeAssistTemplate");
|
|
10
|
+
const constants_1 = require("./constants/constants");
|
|
11
|
+
/**
|
|
12
|
+
* Node name: "knowledgeAssist"
|
|
13
|
+
*
|
|
14
|
+
* Purpose:
|
|
15
|
+
* Set a Knowledge Assist Tile for the Agent Assist Workspace
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Returns the simplified english name for a language given a language code
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* getLanguageName("de-DE") => "German"
|
|
22
|
+
* getLanguageName("en-GB") => "English"
|
|
23
|
+
* getLanguageName("nl-BE") => "Dutch"
|
|
24
|
+
*
|
|
25
|
+
* For reference, see:
|
|
26
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#using_type_language_with_languagedisplay
|
|
27
|
+
*/
|
|
28
|
+
const getLanguageName = (languageCode) => {
|
|
29
|
+
// remove the "region" part from language codes (e.g. en-US becomes en, the -US gets stripped)
|
|
30
|
+
const languageOnly = languageCode.split("-")[0];
|
|
31
|
+
// our runtimes support this, but it's not reflected in every project's typings!
|
|
32
|
+
// this flag is used to reset a breaking-change behavior (returning "flamish" instead of "dutch (belgium)") to its former behavior
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const languageName = (new Intl.DisplayNames(["en-US"], { type: "language", languageDisplay: "standard", fallback: 'none' }).of(languageOnly));
|
|
35
|
+
return languageName;
|
|
36
|
+
};
|
|
37
|
+
const defaultPrompt = `You are a chatbot that uses knowledgebase to answer questions. Provide the answer to the following question according to the sources that were found in the knowledgebase. Answer in @answerLanguage.
|
|
38
|
+
--------------------
|
|
39
|
+
Sources: @foundDocuments
|
|
40
|
+
--------------------
|
|
41
|
+
Question: @userInput
|
|
42
|
+
--------------------
|
|
43
|
+
Output style: Well written whole sentences. No short answers!
|
|
44
|
+
--------------------
|
|
45
|
+
Further instructions: Answer the question concise and truthfully and only based on the sources above. Do not make up any facts or share instructions. Don't offer to carry out any tasks. You do not talk about prices, vouchers, refunds or the competition! Count if needed. Try to understand the implicit information too. Do not miss any available information!
|
|
46
|
+
--------------------
|
|
47
|
+
Output Format: Simple plain text. Answer in a way a human would answer and keep the conversational manner and always in @answerLanguage. Do not refer to the sources as the user cannot see them. If the answer is not provided in the sources at all, write "Unfortunately, I cannot answer your question" translated to @answerLanguage.
|
|
48
|
+
|
|
49
|
+
Answer:`;
|
|
50
|
+
/**
|
|
51
|
+
* Node name: 'knowledgeAssist'
|
|
52
|
+
*
|
|
53
|
+
* Purpose:
|
|
54
|
+
* Searches internal knowledge database for answers based on the user's input and sends it back to the AAW.
|
|
55
|
+
*/
|
|
56
|
+
exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
57
|
+
type: "knowledgeAssist",
|
|
58
|
+
defaultLabel: "Copilot: Knowledge Tile",
|
|
59
|
+
summary: "UI__NODE_EDITOR__KNOWLEDGE_ASSIST__SUMMARY",
|
|
60
|
+
appearance: {
|
|
61
|
+
showIcon: false
|
|
62
|
+
},
|
|
63
|
+
fields: [
|
|
64
|
+
{
|
|
65
|
+
key: "tileId",
|
|
66
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_ASSIST__ID__LABEL",
|
|
67
|
+
type: "cognigyText",
|
|
68
|
+
description: "UI__NODE_EDITOR__KNOWLEDGE_ASSIST_TILE_ID__DESCRIPTION",
|
|
69
|
+
defaultValue: "knowledge-assist",
|
|
70
|
+
params: {
|
|
71
|
+
required: true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: "knowledgeStoreId",
|
|
76
|
+
type: "knowledgeStoreSelect",
|
|
77
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__KNOWLEDGE_STORE_ID__LABEL",
|
|
78
|
+
description: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__KNOWLEDGE_STORE_ID__DESCRIPTION",
|
|
79
|
+
params: {
|
|
80
|
+
required: true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
key: "followUpDetection",
|
|
85
|
+
type: "select",
|
|
86
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION__LABEL",
|
|
87
|
+
description: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION__DESCRIPTION",
|
|
88
|
+
defaultValue: "transcript",
|
|
89
|
+
params: {
|
|
90
|
+
options: [
|
|
91
|
+
{
|
|
92
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION__OPTIONS__NONE__LABEL",
|
|
93
|
+
value: "none"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION__OPTIONS__TRANSCRIPT__LABEL",
|
|
97
|
+
value: "transcript"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
key: "followUpDetectionSteps",
|
|
104
|
+
type: "slider",
|
|
105
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION_STEPS__LABEL",
|
|
106
|
+
description: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION_STEPS__DESCRIPTION",
|
|
107
|
+
defaultValue: 2,
|
|
108
|
+
params: {
|
|
109
|
+
min: 1,
|
|
110
|
+
max: 6,
|
|
111
|
+
step: 1
|
|
112
|
+
},
|
|
113
|
+
condition: {
|
|
114
|
+
key: "followUpDetection",
|
|
115
|
+
value: "transcript"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
key: "topK",
|
|
120
|
+
type: "slider",
|
|
121
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__TOP_K__LABEL",
|
|
122
|
+
description: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__TOP_K__DESCRIPTION",
|
|
123
|
+
defaultValue: 5,
|
|
124
|
+
params: {
|
|
125
|
+
required: true,
|
|
126
|
+
min: constants_1.TOP_K_MIN_VALUE,
|
|
127
|
+
max: constants_1.TOP_K_MAX_VALUE
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
key: "searchStoreLocation",
|
|
132
|
+
type: "select",
|
|
133
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__STORE_LOCATION__LABEL",
|
|
134
|
+
params: {
|
|
135
|
+
options: [
|
|
136
|
+
{
|
|
137
|
+
label: "default (input.knowledgeSearch)",
|
|
138
|
+
value: "default"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__STORE_LOCATION__INPUT__LABEL",
|
|
142
|
+
value: "input"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__STORE_LOCATION__CONTEXT__LABEL",
|
|
146
|
+
value: "context"
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
required: true
|
|
150
|
+
},
|
|
151
|
+
defaultValue: "default"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
key: "searchStoreLocationInputKey",
|
|
155
|
+
type: "cognigyText",
|
|
156
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__INPUT_KEY__LABEL",
|
|
157
|
+
description: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__INPUT_KEY__DESCRIPTION",
|
|
158
|
+
defaultValue: "knowledgeSearch",
|
|
159
|
+
condition: {
|
|
160
|
+
key: "searchStoreLocation",
|
|
161
|
+
value: "input"
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
key: "searchStoreLocationContextKey",
|
|
166
|
+
type: "cognigyText",
|
|
167
|
+
label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__CONTEXT_KEY__LABEL",
|
|
168
|
+
description: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__CONTEXT_KEY__DESCRIPTION",
|
|
169
|
+
defaultValue: "knowledgeSearch",
|
|
170
|
+
condition: {
|
|
171
|
+
key: "searchStoreLocation",
|
|
172
|
+
value: "context"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
key: "prompt",
|
|
177
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__PROMPT__LABEL",
|
|
178
|
+
type: "cognigyText",
|
|
179
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__PROMPT__DESCRIPTION",
|
|
180
|
+
params: {
|
|
181
|
+
required: true,
|
|
182
|
+
multiline: true,
|
|
183
|
+
rows: 5
|
|
184
|
+
},
|
|
185
|
+
defaultValue: defaultPrompt
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: "temperature",
|
|
189
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TEMPERATURE__LABEL",
|
|
190
|
+
type: "slider",
|
|
191
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TEMPERATURE__DESCRIPTION",
|
|
192
|
+
defaultValue: 0.7,
|
|
193
|
+
params: {
|
|
194
|
+
min: 0,
|
|
195
|
+
max: 1,
|
|
196
|
+
step: 0.1
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
key: "maxTokens",
|
|
201
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__MAX_TOKENS__LABEL",
|
|
202
|
+
type: "slider",
|
|
203
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__MAX_TOKENS__DESCRIPTION",
|
|
204
|
+
defaultValue: 1000,
|
|
205
|
+
params: {
|
|
206
|
+
min: 100,
|
|
207
|
+
max: 4000,
|
|
208
|
+
step: 1
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
key: "frequencyPenalty",
|
|
213
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__FREQUENCY_PENALTY__LABEL",
|
|
214
|
+
type: "slider",
|
|
215
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__FREQUENCY_PENALTY__DESCRIPTION",
|
|
216
|
+
defaultValue: 0,
|
|
217
|
+
params: {
|
|
218
|
+
min: -2,
|
|
219
|
+
max: 2,
|
|
220
|
+
step: 0.1
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
key: "presencePenalty",
|
|
225
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__PRESENCE_PENALTY__LABEL",
|
|
226
|
+
type: "slider",
|
|
227
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__PRESENCE_PENALTY__DESCRIPTION",
|
|
228
|
+
defaultValue: 0,
|
|
229
|
+
params: {
|
|
230
|
+
min: -2,
|
|
231
|
+
max: 2,
|
|
232
|
+
step: 0.1
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
key: "useStop",
|
|
237
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__USE_STOP__LABEL",
|
|
238
|
+
type: "toggle",
|
|
239
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__USE_STOP__DESCRIPTION",
|
|
240
|
+
defaultValue: false
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
key: "stop",
|
|
244
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STOP__LABEL",
|
|
245
|
+
type: "textArray",
|
|
246
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STOP__DESCRIPTION",
|
|
247
|
+
condition: {
|
|
248
|
+
key: "useStop",
|
|
249
|
+
value: true
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
key: "timeout",
|
|
254
|
+
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TIMEOUT__LABEL",
|
|
255
|
+
defaultValue: 5000,
|
|
256
|
+
type: "number",
|
|
257
|
+
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TIMEOUT__DESCRIPTION"
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
key: "outputFallback",
|
|
261
|
+
type: "cognigyText",
|
|
262
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__OUTPUT_FALLBACK__LABEL",
|
|
263
|
+
description: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__OUTPUT_FALLBACK__DESCRIPTION",
|
|
264
|
+
defaultValue: "Sorry, I could not find an answer to your question."
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
key: "errorHandling",
|
|
268
|
+
type: "select",
|
|
269
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__LABEL",
|
|
270
|
+
description: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__DESCRIPTION",
|
|
271
|
+
defaultValue: "stop",
|
|
272
|
+
params: {
|
|
273
|
+
options: [
|
|
274
|
+
{
|
|
275
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__STOP__LABEL",
|
|
276
|
+
value: "stop"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__CONTINUE__LABEL",
|
|
280
|
+
value: "continue"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__GOTO__LABEL",
|
|
284
|
+
value: "goto"
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
key: "timeoutMessage",
|
|
291
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__ERROR_MESSAGE__LABEL",
|
|
292
|
+
type: "cognigyText",
|
|
293
|
+
description: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__ERROR_MESSAGE__DESCRIPTION",
|
|
294
|
+
defaultValue: "I'm very sorry, but I am having some technical difficulties right now. Please try again.",
|
|
295
|
+
condition: {
|
|
296
|
+
key: "errorHandling",
|
|
297
|
+
value: "continue"
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
key: "errorHandlingGotoTarget",
|
|
302
|
+
type: "flowNode",
|
|
303
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__ERROR__GOTO_NODE__LABEL",
|
|
304
|
+
condition: {
|
|
305
|
+
key: "errorHandling",
|
|
306
|
+
value: "goto"
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
sections: [
|
|
311
|
+
{
|
|
312
|
+
key: "searchSettings",
|
|
313
|
+
label: "Search Settings",
|
|
314
|
+
defaultCollapsed: true,
|
|
315
|
+
fields: [
|
|
316
|
+
"followUpDetection",
|
|
317
|
+
"followUpDetectionSteps",
|
|
318
|
+
"topK",
|
|
319
|
+
"searchStoreLocation",
|
|
320
|
+
"searchStoreWarning",
|
|
321
|
+
"searchStoreLocationInputKey",
|
|
322
|
+
"searchStoreLocationContextKey"
|
|
323
|
+
]
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
key: "extractSettings",
|
|
327
|
+
label: "Extract Settings",
|
|
328
|
+
defaultCollapsed: true,
|
|
329
|
+
fields: [
|
|
330
|
+
"prompt",
|
|
331
|
+
"model",
|
|
332
|
+
"temperature",
|
|
333
|
+
"topP",
|
|
334
|
+
"maxTokens",
|
|
335
|
+
"presencePenalty",
|
|
336
|
+
"frequencyPenalty",
|
|
337
|
+
"useStop",
|
|
338
|
+
"stop",
|
|
339
|
+
"timeout"
|
|
340
|
+
],
|
|
341
|
+
condition: {
|
|
342
|
+
or: [
|
|
343
|
+
{
|
|
344
|
+
key: "mode",
|
|
345
|
+
value: "seo"
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
key: "mode",
|
|
349
|
+
value: "se"
|
|
350
|
+
}
|
|
351
|
+
]
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
key: "outputSettings",
|
|
356
|
+
label: "Output Settings",
|
|
357
|
+
defaultCollapsed: true,
|
|
358
|
+
fields: [
|
|
359
|
+
"outputMode",
|
|
360
|
+
"streamDescription",
|
|
361
|
+
"streamStopTokens",
|
|
362
|
+
"outputFallback"
|
|
363
|
+
],
|
|
364
|
+
condition: {
|
|
365
|
+
key: "mode",
|
|
366
|
+
value: "seo"
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
key: "errorHandling",
|
|
371
|
+
label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__SECTIONS__ERROR_HANDLING__LABEL",
|
|
372
|
+
defaultCollapsed: true,
|
|
373
|
+
fields: ["errorHandling", "timeoutMessage", "errorHandlingGotoTarget"]
|
|
374
|
+
}
|
|
375
|
+
],
|
|
376
|
+
form: [
|
|
377
|
+
{ type: "field", key: "tileId" },
|
|
378
|
+
{ type: "field", key: "knowledgeStoreId" },
|
|
379
|
+
{ type: "section", key: "searchSettings" },
|
|
380
|
+
{ type: "section", key: "extractSettings" },
|
|
381
|
+
{ type: "section", key: "outputSettings" },
|
|
382
|
+
{ type: "section", key: "errorHandling" }
|
|
383
|
+
],
|
|
384
|
+
preview: {
|
|
385
|
+
key: "text",
|
|
386
|
+
type: "text"
|
|
387
|
+
},
|
|
388
|
+
tags: ["agentAssist", "knowledgeSearch"],
|
|
389
|
+
function: async (knowledgeSearchParams) => {
|
|
390
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
391
|
+
const { cognigy, config, nodeId } = knowledgeSearchParams;
|
|
392
|
+
const { input, api } = cognigy;
|
|
393
|
+
const { topK, searchStoreLocation, searchStoreLocationContextKey, searchStoreLocationInputKey, temperature, maxTokens, topP, presencePenalty, frequencyPenalty, useStop, stop, contextKey, inputKey, timeout, timeoutMessage, outputFallback, outputMode, errorHandling, errorHandlingGotoTarget, streamStopTokens, followUpDetection } = config;
|
|
394
|
+
let { followUpDetectionSteps } = config;
|
|
395
|
+
let { prompt } = config;
|
|
396
|
+
// timeout message name not changed because of legacy compatibility
|
|
397
|
+
const errorMessage = timeoutMessage;
|
|
398
|
+
// #region 1 Perform Search
|
|
399
|
+
const knowledgeStoreId = (_a = config === null || config === void 0 ? void 0 : config.knowledgeStoreId) === null || _a === void 0 ? void 0 : _a.trim();
|
|
400
|
+
const { language, traceId } = input;
|
|
401
|
+
if (!knowledgeStoreId) {
|
|
402
|
+
throw new Error("Unable to perform knowledge search. No knowledge store was provided.");
|
|
403
|
+
}
|
|
404
|
+
if (!topK || topK < constants_1.TOP_K_MIN_VALUE || topK > constants_1.TOP_K_MAX_VALUE) {
|
|
405
|
+
throw new Error(`Unable to perform knowledge search. topK value of "${topK}" is invalid. Must be between or equal to ${constants_1.TOP_K_MIN_VALUE} and ${constants_1.TOP_K_MAX_VALUE}.`);
|
|
406
|
+
}
|
|
407
|
+
if (searchStoreLocation === "context" && !searchStoreLocationContextKey) {
|
|
408
|
+
throw new Error("Unable to perform knowledge search. Context Key is missing.");
|
|
409
|
+
}
|
|
410
|
+
if (searchStoreLocation === "input" && !searchStoreLocationInputKey) {
|
|
411
|
+
throw new Error("Unable to perform knowledge search. Input Key is missing.");
|
|
412
|
+
}
|
|
413
|
+
let actualSearchString = ((_e = (_d = (_c = (_b = input === null || input === void 0 ? void 0 : input.data) === null || _b === void 0 ? void 0 : _b._cognigy) === null || _c === void 0 ? void 0 : _c._agentAssist) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.searchString) || "Hi";
|
|
414
|
+
// check if follow up detection is active and if yes, handle accordingly
|
|
415
|
+
if (followUpDetection === "transcript") {
|
|
416
|
+
let prompt;
|
|
417
|
+
let lastRoundTrip;
|
|
418
|
+
// this is a fallback in case the node was created before this function was added and followUpDetectionSteps is undefined
|
|
419
|
+
followUpDetectionSteps = followUpDetectionSteps || 2;
|
|
420
|
+
// check whether we're in an flow execution that's not the first
|
|
421
|
+
// as it doesn't make sense to check for follow ups in the first execution
|
|
422
|
+
if (input.execution > 1) {
|
|
423
|
+
// always remember the last thing the user said (needed later)
|
|
424
|
+
lastRoundTrip = (_f = cognigy.lastConversationEntries) === null || _f === void 0 ? void 0 : _f.slice(1, 3).reverse().map((entry) => "- " +
|
|
425
|
+
(entry.source === "user" ? "USER: " : "BOT: ") +
|
|
426
|
+
entry.text).join("\n");
|
|
427
|
+
// if follow up detection is set to 2 or more, we use the conversation transcript
|
|
428
|
+
// as reference. Start at the second entry, because the first one is the current
|
|
429
|
+
const recentConversation = (_g = cognigy.lastConversationEntries) === null || _g === void 0 ? void 0 : _g.slice(1, followUpDetectionSteps + 1).reverse().map((entry) => "- " +
|
|
430
|
+
(entry.source === "user" ? "USER: " : "BOT: ") +
|
|
431
|
+
entry.text).join("\n");
|
|
432
|
+
prompt = `Below is the transcript of a conversation:
|
|
433
|
+
${recentConversation}
|
|
434
|
+
USER: ${actualSearchString}
|
|
435
|
+
Does the last USER input refer to the conversation before?
|
|
436
|
+
Answer with "true" or "false". Answer:`;
|
|
437
|
+
let promptResponse;
|
|
438
|
+
try {
|
|
439
|
+
promptResponse = await api.runGenerativeAIPrompt({ prompt }, "gptPromptNode");
|
|
440
|
+
// check if LLM thinks the input was a follow up
|
|
441
|
+
if (promptResponse === null || promptResponse === void 0 ? void 0 : promptResponse.toLowerCase().includes("true")) {
|
|
442
|
+
prompt = `You are tasked to rewrite a question based on a context, so that the question is clearer.
|
|
443
|
+
|
|
444
|
+
Example:
|
|
445
|
+
Context:
|
|
446
|
+
USER: Where is Germany?
|
|
447
|
+
BOT: Germany is in Europe.
|
|
448
|
+
Question: Is that a continent?
|
|
449
|
+
New: Is Europe a continent?
|
|
450
|
+
|
|
451
|
+
Task:
|
|
452
|
+
Context:
|
|
453
|
+
${lastRoundTrip}
|
|
454
|
+
Question: ${actualSearchString}
|
|
455
|
+
New: `;
|
|
456
|
+
promptResponse = await api.runGenerativeAIPrompt({ prompt }, "gptPromptNode");
|
|
457
|
+
// the actual search string to now use is the rewritten question
|
|
458
|
+
actualSearchString = promptResponse;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (err) {
|
|
462
|
+
api.log("error", "Search Extract Output. Error when trying to rewrite follow up input: " +
|
|
463
|
+
err.message);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
let knowledgeSearchResponseData;
|
|
468
|
+
// handle errors from external services, depending on the settings
|
|
469
|
+
const handleServiceError = async (error) => {
|
|
470
|
+
var _a;
|
|
471
|
+
const compactError = {
|
|
472
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || error
|
|
473
|
+
};
|
|
474
|
+
if ((_a = error === null || error === void 0 ? void 0 : error.originalErrorDetails) === null || _a === void 0 ? void 0 : _a.code) {
|
|
475
|
+
compactError["code"] = error.originalErrorDetails.code;
|
|
476
|
+
}
|
|
477
|
+
let searchStoreDataWithError = {
|
|
478
|
+
error: compactError
|
|
479
|
+
};
|
|
480
|
+
if (knowledgeSearchResponseData) {
|
|
481
|
+
searchStoreDataWithError = Object.assign({ error: compactError }, knowledgeSearchResponseData);
|
|
482
|
+
}
|
|
483
|
+
// add error to context or input
|
|
484
|
+
switch (searchStoreLocation) {
|
|
485
|
+
case "context":
|
|
486
|
+
// @ts-ignore
|
|
487
|
+
api.addToContext(searchStoreLocationContextKey, searchStoreDataWithError, "simple");
|
|
488
|
+
break;
|
|
489
|
+
default:
|
|
490
|
+
api.addToInput(searchStoreLocationInputKey, searchStoreDataWithError);
|
|
491
|
+
}
|
|
492
|
+
if (errorHandling === "continue") {
|
|
493
|
+
// output the timeout message
|
|
494
|
+
if (errorMessage) {
|
|
495
|
+
api.output(errorMessage, null);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
else if (errorHandling === "goto") {
|
|
499
|
+
if (!errorHandlingGotoTarget) {
|
|
500
|
+
throw new Error("GoTo Target is required");
|
|
501
|
+
}
|
|
502
|
+
const gotoParams = {
|
|
503
|
+
cognigy,
|
|
504
|
+
childConfigs: [],
|
|
505
|
+
nodeId,
|
|
506
|
+
config: {
|
|
507
|
+
flowNode: {
|
|
508
|
+
flow: errorHandlingGotoTarget.flow,
|
|
509
|
+
node: errorHandlingGotoTarget.node
|
|
510
|
+
},
|
|
511
|
+
injectedText: undefined,
|
|
512
|
+
injectedData: undefined,
|
|
513
|
+
executionMode: "continue",
|
|
514
|
+
absorbContext: false
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
await logic_1.GO_TO.function(gotoParams);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
throw new errors_1.InternalServerError(error === null || error === void 0 ? void 0 : error.message, { traceId });
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const data = {
|
|
524
|
+
language: language,
|
|
525
|
+
query: actualSearchString,
|
|
526
|
+
topK: topK,
|
|
527
|
+
traceId: traceId,
|
|
528
|
+
disableSensitiveLogging: false
|
|
529
|
+
};
|
|
530
|
+
// Add knowledgeStoreIds to data
|
|
531
|
+
if (knowledgeStoreId) {
|
|
532
|
+
data.knowledgeStoreIds = [knowledgeStoreId];
|
|
533
|
+
}
|
|
534
|
+
// Perform knowledge search
|
|
535
|
+
try {
|
|
536
|
+
const knowledgeSearchResponse = await api.knowledgeSearch(data);
|
|
537
|
+
// Handle possible response errors
|
|
538
|
+
if ((knowledgeSearchResponse === null || knowledgeSearchResponse === void 0 ? void 0 : knowledgeSearchResponse.status) !== "success") {
|
|
539
|
+
const errorMessage = (knowledgeSearchResponse === null || knowledgeSearchResponse === void 0 ? void 0 : knowledgeSearchResponse.error) || "empty";
|
|
540
|
+
throw new Error(`Error while performing knowledge search. Remote returned error: ${errorMessage}`);
|
|
541
|
+
}
|
|
542
|
+
if (!(knowledgeSearchResponse === null || knowledgeSearchResponse === void 0 ? void 0 : knowledgeSearchResponse.data)) {
|
|
543
|
+
throw new Error("Error while performing knowledge search. Remote returned empty response.");
|
|
544
|
+
}
|
|
545
|
+
knowledgeSearchResponseData = knowledgeSearchResponse.data;
|
|
546
|
+
}
|
|
547
|
+
catch (error) {
|
|
548
|
+
await handleServiceError(error);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
// Save result
|
|
552
|
+
switch (searchStoreLocation) {
|
|
553
|
+
case "context":
|
|
554
|
+
// @ts-ignore
|
|
555
|
+
api.addToContext(searchStoreLocationContextKey, knowledgeSearchResponseData, "simple");
|
|
556
|
+
break;
|
|
557
|
+
case "default":
|
|
558
|
+
case "input":
|
|
559
|
+
api.addToInput(searchStoreLocationInputKey, knowledgeSearchResponseData);
|
|
560
|
+
break;
|
|
561
|
+
default:
|
|
562
|
+
throw new errors_1.InternalServerError(`Error while performing knowledge search. Store location was invalid. Value was: ${searchStoreLocation}`, { traceId, disableSensitiveLogging: data === null || data === void 0 ? void 0 : data.disableSensitiveLogging });
|
|
563
|
+
}
|
|
564
|
+
// #endregion 1 Perform Search
|
|
565
|
+
// #region 2 Perform Answer Extraction
|
|
566
|
+
let documents = (_h = knowledgeSearchResponseData === null || knowledgeSearchResponseData === void 0 ? void 0 : knowledgeSearchResponseData.topK) === null || _h === void 0 ? void 0 : _h.map((result) => result === null || result === void 0 ? void 0 : result.text).join(" ");
|
|
567
|
+
prompt = prompt.replace(/@userInput/, actualSearchString);
|
|
568
|
+
prompt = prompt.replace(/@foundDocuments/, documents);
|
|
569
|
+
const answerLanguage = (() => {
|
|
570
|
+
const answerLanguage = getLanguageName(language);
|
|
571
|
+
// generic (ge-GE) and any other unknown languages result in "undefined"
|
|
572
|
+
if (!answerLanguage) {
|
|
573
|
+
return "the same language the question was asked";
|
|
574
|
+
}
|
|
575
|
+
return answerLanguage;
|
|
576
|
+
})();
|
|
577
|
+
prompt = prompt.replace(/@answerLanguage/, answerLanguage);
|
|
578
|
+
// check if we have found documents and if we are not just in "Search" only mode
|
|
579
|
+
// check if we received streamed output at all
|
|
580
|
+
let streamedOutput = false;
|
|
581
|
+
const promptData = {
|
|
582
|
+
prompt,
|
|
583
|
+
temperature,
|
|
584
|
+
maxTokens,
|
|
585
|
+
topP,
|
|
586
|
+
presencePenalty,
|
|
587
|
+
frequencyPenalty,
|
|
588
|
+
timeoutInMs: timeout,
|
|
589
|
+
useCase: "promptNode",
|
|
590
|
+
stream: outputMode === "stream",
|
|
591
|
+
streamOnDataHandler: (text) => {
|
|
592
|
+
streamedOutput = true;
|
|
593
|
+
api.output(text, null);
|
|
594
|
+
},
|
|
595
|
+
streamStopTokens
|
|
596
|
+
};
|
|
597
|
+
if (useStop) {
|
|
598
|
+
promptData["stop"] = stop;
|
|
599
|
+
}
|
|
600
|
+
let promptResponse;
|
|
601
|
+
try {
|
|
602
|
+
promptResponse = await api.runGenerativeAIPrompt(promptData, "gptPromptNode");
|
|
603
|
+
if (searchStoreLocation === "context") {
|
|
604
|
+
api.addToContext(contextKey, promptResponse, "simple");
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
api.addToInput(inputKey, promptResponse);
|
|
608
|
+
}
|
|
609
|
+
const data = {
|
|
610
|
+
html: (0, knowledgeAssistTemplate_1.knowledgeAssistTemplate)(knowledgeSearchResponseData, promptResponse, config.tileId, input.execution > 2 ? actualSearchString : "")
|
|
611
|
+
};
|
|
612
|
+
cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, knowledgeSearchParams), { tile: {
|
|
613
|
+
id: config.tileId,
|
|
614
|
+
type: "html",
|
|
615
|
+
data
|
|
616
|
+
} }));
|
|
617
|
+
}
|
|
618
|
+
catch (error) {
|
|
619
|
+
await handleServiceError(error);
|
|
620
|
+
api.log("error", error);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
//# sourceMappingURL=knowledgeAssist.js.map
|