wingbot 3.76.4-alpha.3 → 3.76.4-alpha.4
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/src/LLMDispatcher.js +1 -0
- package/src/LLMRouter.js +25 -14
package/package.json
CHANGED
package/src/LLMDispatcher.js
CHANGED
package/src/LLMRouter.js
CHANGED
|
@@ -66,7 +66,8 @@ const LLMType = require('./LLMType');
|
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
* @typedef {Pick<LLMRoutingCache,
|
|
69
|
+
* @typedef {Pick<LLMRoutingCache,
|
|
70
|
+
* 'actionList'|'actionListString'|'byAction'|'structuredOutput'>} LLMRoutingInput
|
|
70
71
|
*/
|
|
71
72
|
|
|
72
73
|
/**
|
|
@@ -74,6 +75,7 @@ const LLMType = require('./LLMType');
|
|
|
74
75
|
* @prop {boolean} [keepUserInInteractionsWithBounceAllowed]
|
|
75
76
|
* @prop {string} actionListString
|
|
76
77
|
* @prop {LLMAction[]} actionList
|
|
78
|
+
* @prop {object} structuredOutput - JSON schema for the routing response
|
|
77
79
|
* @prop {ILLMRouter|null} router
|
|
78
80
|
* @prop {Map<string, GlobalIntentResolved>} byAction
|
|
79
81
|
* @prop {GlobalIntentResolved[]} routes
|
|
@@ -142,24 +144,31 @@ class LLMRouter {
|
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
/**
|
|
145
|
-
*
|
|
147
|
+
* Sentinel action returned when the user did not change the conversation
|
|
148
|
+
* context (or when the model can't decide). Not present in `byAction`.
|
|
149
|
+
*
|
|
150
|
+
* @type {string}
|
|
146
151
|
*/
|
|
147
|
-
static
|
|
152
|
+
static NOT_CHANGED = '-not-changed-';
|
|
148
153
|
|
|
149
154
|
/**
|
|
155
|
+
* Builds the JSON schema for the routing response. The `action` field is
|
|
156
|
+
* constrained to an enum of the routable actions plus the `-not-changed-`
|
|
157
|
+
* sentinel, so the model can only return a valid routing target.
|
|
158
|
+
*
|
|
159
|
+
* Called once per router config from `_prepareRoutingInput`; the result is
|
|
160
|
+
* stored on the routing cache, so it is not rebuilt per request.
|
|
150
161
|
*
|
|
162
|
+
* @param {string[]} [actions] - routable action values (e.g. `/btm/dodavatel`)
|
|
151
163
|
* @returns {object}
|
|
152
164
|
*/
|
|
153
|
-
static structuredOutput () {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
.toJSON();
|
|
161
|
-
}
|
|
162
|
-
return LLMRouter._cachedStructuredOutput;
|
|
165
|
+
static structuredOutput (actions = []) {
|
|
166
|
+
return LLMType
|
|
167
|
+
.object({
|
|
168
|
+
action: LLMType.enum([LLMRouter.NOT_CHANGED, ...actions])
|
|
169
|
+
.description('recommended action')
|
|
170
|
+
}, 'conversation_routing_information')
|
|
171
|
+
.toJSON();
|
|
163
172
|
}
|
|
164
173
|
|
|
165
174
|
/**
|
|
@@ -183,7 +192,7 @@ class LLMRouter {
|
|
|
183
192
|
|
|
184
193
|
let res;
|
|
185
194
|
try {
|
|
186
|
-
res = await session.generateStructured(
|
|
195
|
+
res = await session.generateStructured(routing.structuredOutput);
|
|
187
196
|
} catch (e) {
|
|
188
197
|
// Fail closed: any error in routing classification is treated
|
|
189
198
|
// as "no context change" so the user's current flow continues.
|
|
@@ -315,6 +324,7 @@ class LLMRouter {
|
|
|
315
324
|
: {}),
|
|
316
325
|
actionListString,
|
|
317
326
|
actionList,
|
|
327
|
+
structuredOutput: LLMRouter.structuredOutput(actionList.map((a) => a.action)),
|
|
318
328
|
byAction,
|
|
319
329
|
router,
|
|
320
330
|
routes: resolvedLlm
|
|
@@ -367,6 +377,7 @@ class LLMRouter {
|
|
|
367
377
|
: {
|
|
368
378
|
actionListString: '',
|
|
369
379
|
actionList: [],
|
|
380
|
+
structuredOutput: LLMRouter.structuredOutput(),
|
|
370
381
|
byAction: new Map(),
|
|
371
382
|
router: null,
|
|
372
383
|
routes: []
|