@docbrasil/api-systemmanager 1.1.30 → 1.1.31
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/api/ai.js +97 -0
- package/dist/bundle.cjs +93 -0
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +42 -0
- package/docs/Admin.html +1 -1
- package/docs/AdminDocuments.html +1 -1
- package/docs/AdminForm.html +1 -1
- package/docs/AdminLists.html +1 -1
- package/docs/AdminMessage.html +1 -1
- package/docs/AdminNotification.html +1 -1
- package/docs/AdminPlugin.html +1 -1
- package/docs/AdminPolicy.html +1 -1
- package/docs/AdminProcesses.html +1 -1
- package/docs/AdminTask.html +1 -1
- package/docs/AdminUser.html +1 -1
- package/docs/Application.html +1 -1
- package/docs/Chart.html +1 -1
- package/docs/Dashboard.html +1 -1
- package/docs/Datasource.html +1 -1
- package/docs/Dispatch.html +3 -3
- package/docs/Documents.html +1 -1
- package/docs/External.html +1 -1
- package/docs/GeoLocation.html +1 -1
- package/docs/Help.html +1 -1
- package/docs/Login.html +1 -1
- package/docs/MyTasks.html +1 -1
- package/docs/MyndAI.html +650 -0
- package/docs/Notification.html +1 -1
- package/docs/Organization.html +1 -1
- package/docs/Page.html +1 -1
- package/docs/Process.html +1 -1
- package/docs/Register.html +1 -1
- package/docs/Session.html +1 -1
- package/docs/Settings.html +1 -1
- package/docs/Task.html +1 -1
- package/docs/TaskAvailable.html +1 -1
- package/docs/Updates.html +1 -1
- package/docs/User.html +1 -1
- package/docs/Users.html +1 -1
- package/docs/admin_doctypes.js.html +1 -1
- package/docs/admin_document.js.html +1 -1
- package/docs/admin_form.js.html +1 -1
- package/docs/admin_index.js.html +1 -1
- package/docs/admin_list.js.html +1 -1
- package/docs/admin_message.js.html +1 -1
- package/docs/admin_notification.js.html +1 -1
- package/docs/admin_organization.js.html +1 -1
- package/docs/admin_plugin.js.html +1 -1
- package/docs/admin_policy.js.html +1 -1
- package/docs/admin_processes.js.html +1 -1
- package/docs/admin_task.js.html +1 -1
- package/docs/admin_user.js.html +1 -1
- package/docs/ai.js.html +214 -0
- package/docs/dispatch.js.html +7 -2
- package/docs/external.js.html +1 -1
- package/docs/general_geoLocation.js.html +1 -1
- package/docs/general_index.js.html +1 -1
- package/docs/index.html +1 -1
- package/docs/login.js.html +1 -1
- package/docs/session.js.html +1 -1
- package/docs/user_application.js.html +1 -1
- package/docs/user_dashboard.js.html +1 -1
- package/docs/user_datasource.js.html +1 -1
- package/docs/user_document.js.html +1 -1
- package/docs/user_help.js.html +1 -1
- package/docs/user_index.js.html +1 -1
- package/docs/user_my_tasks.js.html +1 -1
- package/docs/user_notification.js.html +1 -1
- package/docs/user_organization.js.html +1 -1
- package/docs/user_page.js.html +1 -1
- package/docs/user_process.js.html +1 -1
- package/docs/user_register.js.html +1 -1
- package/docs/user_settings.js.html +1 -1
- package/docs/user_task.js.html +1 -1
- package/docs/user_task_available.js.html +1 -1
- package/docs/user_updates.js.html +1 -1
- package/docs/user_user.js.html +1 -1
- package/docs/utils_promises.js.html +1 -1
- package/index.js +2 -0
- package/package.json +1 -1
package/api/ai.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class using AI
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class MyndAI {
|
|
10
|
+
|
|
11
|
+
constructor(options) {
|
|
12
|
+
Joi.assert(options, Joi.object().required());
|
|
13
|
+
Joi.assert(options.parent, Joi.object().required());
|
|
14
|
+
|
|
15
|
+
const self = this;
|
|
16
|
+
self.parent = options.parent;
|
|
17
|
+
self._client = self.parent.dispatch.getClient();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
22
|
+
* @description Get the return data and check for errors
|
|
23
|
+
* @param {object} retData Response HTTP
|
|
24
|
+
* @return {*}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
_returnData(retData, def = {}) {
|
|
28
|
+
if (retData.status !== 200) {
|
|
29
|
+
throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
30
|
+
} else {
|
|
31
|
+
return _.get(retData, 'data', def);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
37
|
+
* @description Set header with new session
|
|
38
|
+
* @param {string} session Session, token JWT
|
|
39
|
+
* @return {object} header with new session
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
_setHeader(authorization) {
|
|
43
|
+
return {
|
|
44
|
+
headers: {
|
|
45
|
+
authorization,
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
52
|
+
* @description Create new document
|
|
53
|
+
* @param {object} params Object for add new document
|
|
54
|
+
* @param {string} params.model The model to use for the explain
|
|
55
|
+
* @param {object} params.context The context to apply to a prompt
|
|
56
|
+
* @param {string} params.text The text to add to the prompt
|
|
57
|
+
* @param {array<base64>} params.medias Medias to add to the case in base64 (PDF, Image, Video, Audio)
|
|
58
|
+
* @param {string} params.propmpt The actual prompt with context and text to apply to
|
|
59
|
+
* @return {Promise<object>} data
|
|
60
|
+
* @return {boolean} data.success true|false for success
|
|
61
|
+
* @return {object} data.result the result of the AI call
|
|
62
|
+
* @return {string} data.result.response The actual text response according the prompt
|
|
63
|
+
* @return {number} data.result.tokens The quantity of token used in this request
|
|
64
|
+
* @public
|
|
65
|
+
* @async
|
|
66
|
+
* @example
|
|
67
|
+
*
|
|
68
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
69
|
+
* const api = new API();
|
|
70
|
+
* const authorization = '...';
|
|
71
|
+
* const params = {
|
|
72
|
+
* model: 'model-name',
|
|
73
|
+
* context: { name: 'Some name' },
|
|
74
|
+
* text: 'Say hello to the world',
|
|
75
|
+
* medias: ['...'],
|
|
76
|
+
* prompt: 'Write a story about {{name}} with the following theme: {{text}}',
|
|
77
|
+
* };
|
|
78
|
+
* const retData = await api.ai.explain(params, authorization);
|
|
79
|
+
*/
|
|
80
|
+
async explain(params, authorization) {
|
|
81
|
+
const self = this;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
Joi.assert(params, Joi.object().required().error(new Error('params is required')));
|
|
85
|
+
Joi.assert(params.propmpt, Joi.string().required().error(new Error('Provide a prompt')));
|
|
86
|
+
|
|
87
|
+
const apiCall = self._client
|
|
88
|
+
.post('/agents/explain', params, self._setHeader(authorization));
|
|
89
|
+
|
|
90
|
+
return self._returnData(await apiCall);
|
|
91
|
+
} catch (ex) {
|
|
92
|
+
throw ex;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default MyndAI;
|
package/dist/bundle.cjs
CHANGED
|
@@ -13929,6 +13929,98 @@ class External {
|
|
|
13929
13929
|
|
|
13930
13930
|
}
|
|
13931
13931
|
|
|
13932
|
+
/**
|
|
13933
|
+
* Class using AI
|
|
13934
|
+
* @class
|
|
13935
|
+
*/
|
|
13936
|
+
class MyndAI {
|
|
13937
|
+
|
|
13938
|
+
constructor(options) {
|
|
13939
|
+
Joi__default["default"].assert(options, Joi__default["default"].object().required());
|
|
13940
|
+
Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
|
|
13941
|
+
|
|
13942
|
+
const self = this;
|
|
13943
|
+
self.parent = options.parent;
|
|
13944
|
+
self._client = self.parent.dispatch.getClient();
|
|
13945
|
+
}
|
|
13946
|
+
|
|
13947
|
+
/**
|
|
13948
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
13949
|
+
* @description Get the return data and check for errors
|
|
13950
|
+
* @param {object} retData Response HTTP
|
|
13951
|
+
* @return {*}
|
|
13952
|
+
* @private
|
|
13953
|
+
*/
|
|
13954
|
+
_returnData(retData, def = {}) {
|
|
13955
|
+
if (retData.status !== 200) {
|
|
13956
|
+
throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
|
|
13957
|
+
} else {
|
|
13958
|
+
return ___default["default"].get(retData, 'data', def);
|
|
13959
|
+
}
|
|
13960
|
+
}
|
|
13961
|
+
|
|
13962
|
+
/**
|
|
13963
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
13964
|
+
* @description Set header with new session
|
|
13965
|
+
* @param {string} session Session, token JWT
|
|
13966
|
+
* @return {object} header with new session
|
|
13967
|
+
* @private
|
|
13968
|
+
*/
|
|
13969
|
+
_setHeader(authorization) {
|
|
13970
|
+
return {
|
|
13971
|
+
headers: {
|
|
13972
|
+
authorization,
|
|
13973
|
+
}
|
|
13974
|
+
};
|
|
13975
|
+
}
|
|
13976
|
+
|
|
13977
|
+
/**
|
|
13978
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
13979
|
+
* @description Create new document
|
|
13980
|
+
* @param {object} params Object for add new document
|
|
13981
|
+
* @param {string} params.model The model to use for the explain
|
|
13982
|
+
* @param {object} params.context The context to apply to a prompt
|
|
13983
|
+
* @param {string} params.text The text to add to the prompt
|
|
13984
|
+
* @param {array<base64>} params.medias Medias to add to the case in base64 (PDF, Image, Video, Audio)
|
|
13985
|
+
* @param {string} params.propmpt The actual prompt with context and text to apply to
|
|
13986
|
+
* @return {Promise<object>} data
|
|
13987
|
+
* @return {boolean} data.success true|false for success
|
|
13988
|
+
* @return {object} data.result the result of the AI call
|
|
13989
|
+
* @return {string} data.result.response The actual text response according the prompt
|
|
13990
|
+
* @return {number} data.result.tokens The quantity of token used in this request
|
|
13991
|
+
* @public
|
|
13992
|
+
* @async
|
|
13993
|
+
* @example
|
|
13994
|
+
*
|
|
13995
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
13996
|
+
* const api = new API();
|
|
13997
|
+
* const authorization = '...';
|
|
13998
|
+
* const params = {
|
|
13999
|
+
* model: 'model-name',
|
|
14000
|
+
* context: { name: 'Some name' },
|
|
14001
|
+
* text: 'Say hello to the world',
|
|
14002
|
+
* medias: ['...'],
|
|
14003
|
+
* prompt: 'Write a story about {{name}} with the following theme: {{text}}',
|
|
14004
|
+
* };
|
|
14005
|
+
* const retData = await api.ai.explain(params, authorization);
|
|
14006
|
+
*/
|
|
14007
|
+
async explain(params, authorization) {
|
|
14008
|
+
const self = this;
|
|
14009
|
+
|
|
14010
|
+
try {
|
|
14011
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
|
|
14012
|
+
Joi__default["default"].assert(params.propmpt, Joi__default["default"].string().required().error(new Error('Provide a prompt')));
|
|
14013
|
+
|
|
14014
|
+
const apiCall = self._client
|
|
14015
|
+
.post('/agents/explain', params, self._setHeader(authorization));
|
|
14016
|
+
|
|
14017
|
+
return self._returnData(await apiCall);
|
|
14018
|
+
} catch (ex) {
|
|
14019
|
+
throw ex;
|
|
14020
|
+
}
|
|
14021
|
+
}
|
|
14022
|
+
}
|
|
14023
|
+
|
|
13932
14024
|
/**
|
|
13933
14025
|
* Class API
|
|
13934
14026
|
*/
|
|
@@ -14000,6 +14092,7 @@ class API {
|
|
|
14000
14092
|
self.user = new Users({parent: self});
|
|
14001
14093
|
self.admin = new Admin({parent: self});
|
|
14002
14094
|
self.external = new External({parent: self});
|
|
14095
|
+
self.ai = new MyndAI({parent: self});
|
|
14003
14096
|
}
|
|
14004
14097
|
}
|
|
14005
14098
|
|