quickblox 2.17.0-beta.1 → 2.17.0-beta.2
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/package.json +1 -1
- package/quickblox.d.ts +7 -3
- package/quickblox.js +20 -38
- package/quickblox.min.js +1 -1
- package/src/modules/qbAI.js +20 -38
package/package.json
CHANGED
package/quickblox.d.ts
CHANGED
|
@@ -420,7 +420,11 @@ export class AIRole {
|
|
|
420
420
|
|
|
421
421
|
export interface AIChatMessage {
|
|
422
422
|
role: AIRole;
|
|
423
|
-
|
|
423
|
+
message: string;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export interface AIAnswerResponse {
|
|
427
|
+
answer: string;
|
|
424
428
|
}
|
|
425
429
|
|
|
426
430
|
export declare type AIChatHistory = AIChatMessage[] | null | undefined;
|
|
@@ -430,12 +434,12 @@ interface QBAIModule{
|
|
|
430
434
|
answerAssist(smartChatAssistantId: string,
|
|
431
435
|
message: string,
|
|
432
436
|
history :AIChatHistory,
|
|
433
|
-
callback: QBCallback<
|
|
437
|
+
callback: QBCallback<AIAnswerResponse>): void
|
|
434
438
|
//QB.ai.translate
|
|
435
439
|
translate(smartChatAssistantId: string,
|
|
436
440
|
message: string,
|
|
437
441
|
languageCode: string,
|
|
438
|
-
callback: QBCallback<
|
|
442
|
+
callback: QBCallback<AIAnswerResponse>): void
|
|
439
443
|
|
|
440
444
|
}
|
|
441
445
|
|
package/quickblox.js
CHANGED
|
@@ -48795,7 +48795,6 @@ function AIProxy(service) {
|
|
|
48795
48795
|
* @namespace QB.ai
|
|
48796
48796
|
**/
|
|
48797
48797
|
AIProxy.prototype = {
|
|
48798
|
-
|
|
48799
48798
|
/**
|
|
48800
48799
|
* Provides answer assistant functionality that helps users effortlessly send various answers considering({@link https://docs.quickblox.com/docs/js-sdk-ai-features#ai-assist-answer read more}).
|
|
48801
48800
|
* @memberof QB.ai
|
|
@@ -48807,8 +48806,8 @@ AIProxy.prototype = {
|
|
|
48807
48806
|
* var history = [
|
|
48808
48807
|
* {role: "user", message: "Hello"},
|
|
48809
48808
|
* {role: "assistant", message: "Hi"}
|
|
48810
|
-
*
|
|
48811
|
-
*
|
|
48809
|
+
* ];
|
|
48810
|
+
* var messageToAssist = 'Where is my order?';
|
|
48812
48811
|
* QB.ai.answerAssist(smartChatAssistantId, messageToAssist, history, callback);
|
|
48813
48812
|
* // or third parameters can be null
|
|
48814
48813
|
* QB.ai.answerAssist(smartChatAssistantId, messageToAssist, null, callback);
|
|
@@ -48821,61 +48820,36 @@ AIProxy.prototype = {
|
|
|
48821
48820
|
* @param {String} [response.answer] - assist answer for message
|
|
48822
48821
|
* @callback answerAssistCallback
|
|
48823
48822
|
* */
|
|
48823
|
+
if (!callback || typeof callback !== 'function') {
|
|
48824
|
+
throw new Error('Callback function is required and must be a function');
|
|
48825
|
+
}
|
|
48824
48826
|
function validateHistory(history) {
|
|
48825
48827
|
var AIRole = {
|
|
48826
48828
|
user: 'user',
|
|
48827
48829
|
assistant: 'assistant'
|
|
48828
48830
|
};
|
|
48829
|
-
// throw new Error('The QB.addressbook.get accept callback function is required.');
|
|
48830
|
-
// isArray, isCallback
|
|
48831
48831
|
if (history !== null && history !== undefined) {
|
|
48832
48832
|
if (!Array.isArray(history)) {
|
|
48833
|
-
|
|
48834
|
-
code: 400,
|
|
48835
|
-
message: 'History must be an array'
|
|
48836
|
-
});
|
|
48837
|
-
return false;
|
|
48833
|
+
throw new Error('History must be an array');
|
|
48838
48834
|
}
|
|
48839
|
-
|
|
48840
48835
|
for (var i = 0; i < history.length; i++) {
|
|
48841
48836
|
var item = history[i];
|
|
48842
48837
|
if (typeof item !== 'object' || item === null || Array.isArray(item)) {
|
|
48843
|
-
|
|
48844
|
-
code: 400,
|
|
48845
|
-
message: 'Each element of history must be an object'
|
|
48846
|
-
});
|
|
48847
|
-
return false;
|
|
48838
|
+
throw new Error('Each element of history must be an object');
|
|
48848
48839
|
}
|
|
48849
|
-
|
|
48850
48840
|
if (!('role' in item) || !('message' in item)) {
|
|
48851
|
-
|
|
48852
|
-
code: 400,
|
|
48853
|
-
message: 'Each element of history must have an role and message fields'
|
|
48854
|
-
});
|
|
48855
|
-
return false;
|
|
48841
|
+
throw new Error('Each element of history must have an role and message fields');
|
|
48856
48842
|
}
|
|
48857
|
-
|
|
48858
48843
|
if (!(item.role === AIRole.user || item.role === AIRole.assistant)) {
|
|
48859
|
-
|
|
48860
|
-
code: 400,
|
|
48861
|
-
message: 'Invalid role in history item'
|
|
48862
|
-
});
|
|
48863
|
-
return false;
|
|
48844
|
+
throw new Error('Invalid role in history item');
|
|
48864
48845
|
}
|
|
48865
|
-
|
|
48866
48846
|
if (typeof item.message !== 'string') {
|
|
48867
|
-
|
|
48868
|
-
code: 400,
|
|
48869
|
-
message: 'Message of history item must be a string'
|
|
48870
|
-
});
|
|
48871
|
-
return false;
|
|
48847
|
+
throw new Error('Message of history item must be a string');
|
|
48872
48848
|
}
|
|
48873
48849
|
}
|
|
48874
48850
|
}
|
|
48875
|
-
|
|
48876
48851
|
return true;
|
|
48877
48852
|
}
|
|
48878
|
-
|
|
48879
48853
|
if (!validateHistory(history)) {
|
|
48880
48854
|
return;
|
|
48881
48855
|
}
|
|
@@ -48903,10 +48877,11 @@ AIProxy.prototype = {
|
|
|
48903
48877
|
* @memberof QB.ai
|
|
48904
48878
|
* @param {String} smartChatAssistantId - Smart Chat Assistant id.
|
|
48905
48879
|
* @param {String} text - Text to translate.
|
|
48906
|
-
* @param {String} languageCode - Translation language code.
|
|
48880
|
+
* @param {String} languageCode - Translation language code. All list see on page: {@link https://docs.quickblox.com/docs/js-sdk-ai-features#ai-translate }
|
|
48907
48881
|
* @param {translateCallback} callback - The callback function.
|
|
48882
|
+
*
|
|
48908
48883
|
* */
|
|
48909
|
-
|
|
48884
|
+
|
|
48910
48885
|
translate: function(smartChatAssistantId, text, languageCode, callback) {
|
|
48911
48886
|
/**
|
|
48912
48887
|
* Callback for QB.ai.translate().
|
|
@@ -48914,7 +48889,14 @@ AIProxy.prototype = {
|
|
|
48914
48889
|
* @param {Object} response - The server response object.
|
|
48915
48890
|
* @param {String} [response.answer] - translated message
|
|
48916
48891
|
* @callback translateCallback
|
|
48892
|
+
* @example
|
|
48893
|
+
* var textToTranslate = 'Hola!';
|
|
48894
|
+
* var languageCode = 'en';
|
|
48895
|
+
* QB.ai.translate(smartChatAssistantId, textToTranslate, languageCode, callback);
|
|
48917
48896
|
* */
|
|
48897
|
+
if (!callback || typeof callback !== 'function') {
|
|
48898
|
+
throw new Error('Callback function is required and must be a function');
|
|
48899
|
+
}
|
|
48918
48900
|
var data = {
|
|
48919
48901
|
smart_chat_assistant_id: smartChatAssistantId,
|
|
48920
48902
|
text: text,
|