wingbot 3.65.10 → 3.65.12
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/plugins/index.js +7 -7
- package/src/AiMatching.js +30 -3
- package/src/graphApi/GraphApi.js +16 -3
package/package.json
CHANGED
package/plugins/index.js
CHANGED
|
@@ -8,14 +8,14 @@ const pluginsJson = require('./plugins.json');
|
|
|
8
8
|
const plugins = new Map();
|
|
9
9
|
|
|
10
10
|
for (const plugin of pluginsJson.plugins) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
plugins.set(plugin.id, {
|
|
12
|
+
pluginFactory: (...args) => {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const fn = module.require(`./${plugin.id}/plugin`);
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
plugins.set(plugin.id, fn);
|
|
18
|
-
}
|
|
16
|
+
return plugin.isFactory ? fn(...args) : fn;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
module.exports = plugins;
|
package/src/AiMatching.js
CHANGED
|
@@ -160,6 +160,13 @@ class AiMatching {
|
|
|
160
160
|
*/
|
|
161
161
|
this.redundantEntityHandicap = 0.02;
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Upper threshold for redundant entity handicaps
|
|
165
|
+
*
|
|
166
|
+
* @type {number}
|
|
167
|
+
*/
|
|
168
|
+
this.redundantEntityClamp = 0.1;
|
|
169
|
+
|
|
163
170
|
/**
|
|
164
171
|
* When there is additional intent, the final score will be lowered by this value
|
|
165
172
|
* (0.02 by default)
|
|
@@ -808,11 +815,31 @@ class AiMatching {
|
|
|
808
815
|
? 1
|
|
809
816
|
: 0;
|
|
810
817
|
|
|
811
|
-
|
|
812
|
-
|
|
818
|
+
const matchingSame = requestEntities.reduce((cnt, e) => {
|
|
819
|
+
const inMatching = matched.some((me) => e.entity === me.entity);
|
|
820
|
+
return cnt + (inMatching ? 1 : 0);
|
|
821
|
+
}, 0);
|
|
822
|
+
|
|
823
|
+
// all of them can be in state
|
|
824
|
+
const distinctEntities = new Set(matched.map((m) => m.entity)).size;
|
|
825
|
+
const matchSameOver = matchingSame - matched.length;
|
|
826
|
+
const nonMatching = requestEntities.length - matchingSame;
|
|
827
|
+
|
|
828
|
+
const redundantCount = nonMatching
|
|
829
|
+
+ (matchSameOver > distinctEntities ? matchSameOver * 0.5 : matchSameOver);
|
|
830
|
+
|
|
831
|
+
// eslint-disable-next-line max-len
|
|
832
|
+
// console.log({ distinctEntities, redundantCount, nonMatching, matchSameOver, mat: matched.length, req: requestEntities.length });
|
|
833
|
+
|
|
834
|
+
const redundantHandicap = Math.min(
|
|
835
|
+
this.redundantEntityHandicap * (redundantCount + fromState + coveringHandicap),
|
|
836
|
+
this.redundantEntityClamp
|
|
837
|
+
);
|
|
838
|
+
|
|
839
|
+
handicap += redundantHandicap;
|
|
813
840
|
|
|
814
841
|
// eslint-disable-next-line max-len
|
|
815
|
-
// console.log({ requestEntities, matched, handicap, coveringHandicap, otherEntitiesTextLen });
|
|
842
|
+
// console.log({ redundantHandicap, requestEntities, matched, handicap, coveringHandicap, otherEntitiesTextLen });
|
|
816
843
|
|
|
817
844
|
}
|
|
818
845
|
const score = matched.length === 0 ? 0 : sum / matched.length;
|
package/src/graphApi/GraphApi.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
6
|
const assert = require('assert');
|
|
7
|
-
const { graphql, buildSchema } = require('graphql');
|
|
8
7
|
const WingbotApiConnector = require('./WingbotApiConnector');
|
|
9
8
|
// @ts-ignore
|
|
10
9
|
const packageJson = require('../../package.json');
|
|
@@ -21,6 +20,7 @@ const DEFAULT_CACHE = 86400000; // 24 hours
|
|
|
21
20
|
*/
|
|
22
21
|
|
|
23
22
|
/** @typedef {import('../CallbackAuditLog')} AuditLog */
|
|
23
|
+
/** @typedef {import('graphql')} GqlLib */
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Experimental chatbot API
|
|
@@ -81,6 +81,19 @@ class GraphApi {
|
|
|
81
81
|
cacheKeys: opts.cacheKeys,
|
|
82
82
|
useBundledGql: opts.useBundledGql
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
this._lib = null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @returns {GqlLib}
|
|
90
|
+
*/
|
|
91
|
+
get _gql () {
|
|
92
|
+
if (this._lib === null) {
|
|
93
|
+
// eslint-disable-next-line global-require
|
|
94
|
+
this._lib = require('graphql');
|
|
95
|
+
}
|
|
96
|
+
return this._lib;
|
|
84
97
|
}
|
|
85
98
|
|
|
86
99
|
/**
|
|
@@ -139,7 +152,7 @@ class GraphApi {
|
|
|
139
152
|
audit
|
|
140
153
|
};
|
|
141
154
|
|
|
142
|
-
const response = await graphql({
|
|
155
|
+
const response = await this._gql.graphql({
|
|
143
156
|
schema,
|
|
144
157
|
source: body.query,
|
|
145
158
|
rootValue: this._root,
|
|
@@ -159,7 +172,7 @@ class GraphApi {
|
|
|
159
172
|
|
|
160
173
|
if (!schemaIsSame) {
|
|
161
174
|
this._originalSchema = loadedSchema;
|
|
162
|
-
this._cachedSchema = buildSchema(loadedSchema);
|
|
175
|
+
this._cachedSchema = this._gql.buildSchema(loadedSchema);
|
|
163
176
|
}
|
|
164
177
|
return this._cachedSchema;
|
|
165
178
|
}
|