wingbot 3.76.4-alpha.11 → 3.76.4-alpha.13
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/.claude/settings.local.json +11 -0
- package/package.json +2 -2
- package/src/LLM.js +36 -6
- package/src/LLMSession.js +4 -2
- package/src/LLMType.js +21 -1
- package/src/graphApi/schema.gql +8 -0
- package/src/testTools/PromptAssert.js +3 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(npx mocha:*)",
|
|
5
|
+
"Bash(npx tsc *)",
|
|
6
|
+
"Bash(npm test *)",
|
|
7
|
+
"Bash(node -e \"const p = require\\('./bot/plugins/BTMLLM'\\); console.log\\('factory type:', typeof p\\); console.log\\('factory name:', p.name\\);\")",
|
|
8
|
+
"Bash(grep -n \"prompt\\\\`\\\\|tagged\\\\|render\\\\|compile\\\\|hbs\" /Users/ondrejveres/Wingbot/wingbot-llm/src/prompt.js)"
|
|
9
|
+
]
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wingbot",
|
|
3
|
-
"version": "3.76.4-alpha.
|
|
3
|
+
"version": "3.76.4-alpha.13",
|
|
4
4
|
"description": "Enterprise Messaging Bot Conversation Engine",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -76,4 +76,4 @@
|
|
|
76
76
|
"axios": "^1.6.4",
|
|
77
77
|
"handlebars": "^4.0.0"
|
|
78
78
|
}
|
|
79
|
-
}
|
|
79
|
+
}
|
package/src/LLM.js
CHANGED
|
@@ -107,6 +107,7 @@ const LLMSession = require('./LLMSession');
|
|
|
107
107
|
* @prop {'low'|'medium'|'high'|string} [verbosity]
|
|
108
108
|
* @prop {'text'|SimpleJsonSchema} [responseFormat]
|
|
109
109
|
* @prop {number} [temperature]
|
|
110
|
+
* @prop {number} [maxToolCallRounds]
|
|
110
111
|
*/
|
|
111
112
|
|
|
112
113
|
/**
|
|
@@ -157,9 +158,12 @@ const LLMSession = require('./LLMSession');
|
|
|
157
158
|
/**
|
|
158
159
|
* @typedef {object} PromptInfo
|
|
159
160
|
* @prop {LLMMessage[]} prompt
|
|
160
|
-
* @prop {LLMMessage} result
|
|
161
|
+
* @prop {LLMMessage|null} result
|
|
161
162
|
* @prop {VectorSearchResult} [vectorSearchResult]
|
|
162
163
|
* @prop {ToolFunction[]} [tools]
|
|
164
|
+
* @prop {number} [durationMs]
|
|
165
|
+
* @prop {LLMCallOptions} [options]
|
|
166
|
+
* @prop {string} [error]
|
|
163
167
|
*/
|
|
164
168
|
|
|
165
169
|
/**
|
|
@@ -425,22 +429,48 @@ class LLM {
|
|
|
425
429
|
async generate (session, preset = {}, logOptions = {}) {
|
|
426
430
|
const opts = this.llmOptions(preset);
|
|
427
431
|
const prompt = await session.toArray(true);
|
|
428
|
-
const
|
|
429
|
-
|
|
432
|
+
const startTime = Date.now();
|
|
433
|
+
let result = null;
|
|
434
|
+
let error = null;
|
|
435
|
+
try {
|
|
436
|
+
result = await this._provider.requestChat(prompt, opts, session.tools);
|
|
437
|
+
} catch (e) {
|
|
438
|
+
error = e;
|
|
439
|
+
}
|
|
440
|
+
const durationMs = Date.now() - startTime;
|
|
441
|
+
this.logPrompt(
|
|
442
|
+
prompt,
|
|
443
|
+
result,
|
|
444
|
+
logOptions.vectorSearchResult,
|
|
445
|
+
session.tools,
|
|
446
|
+
durationMs,
|
|
447
|
+
opts,
|
|
448
|
+
error
|
|
449
|
+
);
|
|
450
|
+
if (error) throw error;
|
|
430
451
|
return result;
|
|
431
452
|
}
|
|
432
453
|
|
|
433
454
|
/**
|
|
434
455
|
*
|
|
435
456
|
* @param {LLMMessage[]} prompt
|
|
436
|
-
* @param {LLMMessage} result
|
|
457
|
+
* @param {LLMMessage|null} result
|
|
437
458
|
* @param {VectorSearchResult} [vectorSearchResult]
|
|
438
459
|
* @param {ToolFunction[]} [tools]
|
|
460
|
+
* @param {number} [durationMs]
|
|
461
|
+
* @param {LLMCallOptions} [options]
|
|
462
|
+
* @param {Error} [error]
|
|
439
463
|
*/
|
|
440
|
-
logPrompt (prompt, result, vectorSearchResult, tools) {
|
|
464
|
+
logPrompt (prompt, result, vectorSearchResult, tools, durationMs, options, error) {
|
|
441
465
|
this._lastResult = result;
|
|
442
466
|
this._configuration.logger.logPrompt({
|
|
443
|
-
prompt,
|
|
467
|
+
prompt,
|
|
468
|
+
result,
|
|
469
|
+
vectorSearchResult,
|
|
470
|
+
tools,
|
|
471
|
+
durationMs,
|
|
472
|
+
...(options != null && { options }),
|
|
473
|
+
...(error != null && { error: error?.message || String(error) })
|
|
444
474
|
});
|
|
445
475
|
}
|
|
446
476
|
|
package/src/LLMSession.js
CHANGED
|
@@ -93,6 +93,7 @@ const stateData = require('./utils/stateData');
|
|
|
93
93
|
* @prop {string[]} [enum] - Allowed values for this parameter
|
|
94
94
|
* @prop {number} [minimum] - Minimum value for numeric parameters
|
|
95
95
|
* @prop {number} [maximum] - Maximum value for numeric parameters
|
|
96
|
+
* @prop {string} [format] - JSON Schema string format, e.g. 'date-time', 'email', 'uuid'
|
|
96
97
|
*/
|
|
97
98
|
|
|
98
99
|
/** @typedef {{ [key: string]: JsonSchemaProp }} SimpleJsonSchema */
|
|
@@ -972,12 +973,13 @@ class LLMSession {
|
|
|
972
973
|
* @returns {Promise<LLMMessage<any>>}
|
|
973
974
|
*/
|
|
974
975
|
async _generate (providerOptions = this._preset, logOptions = {}) {
|
|
976
|
+
const { maxToolCallRounds = MAX_TOOL_CALL_ROUNDS } = this._llm.llmOptions(providerOptions);
|
|
975
977
|
let result = await this._llm.generate(this, providerOptions, logOptions);
|
|
976
978
|
|
|
977
979
|
// the model may chain several rounds of tool calls before it produces
|
|
978
980
|
// a final text answer - keep resolving them until it stops (bounded)
|
|
979
981
|
let rounds = 0;
|
|
980
|
-
while (result.toolCalls?.length && rounds <
|
|
982
|
+
while (result.toolCalls?.length && rounds < maxToolCallRounds) {
|
|
981
983
|
rounds += 1;
|
|
982
984
|
const toolCalls = [];
|
|
983
985
|
const results = await Promise.all(
|
|
@@ -1016,7 +1018,7 @@ class LLMSession {
|
|
|
1016
1018
|
// a tool-call message (content === null) to the send pipeline
|
|
1017
1019
|
if (result.toolCalls?.length) {
|
|
1018
1020
|
this._llm.log.error(
|
|
1019
|
-
`LLMSession: reached
|
|
1021
|
+
`LLMSession: reached maxToolCallRounds (${maxToolCallRounds}), `
|
|
1020
1022
|
+ 'dropping pending tool calls and forcing a tool-less final answer',
|
|
1021
1023
|
{ toolCalls: result.toolCalls }
|
|
1022
1024
|
);
|
package/src/LLMType.js
CHANGED
|
@@ -25,6 +25,7 @@ class LLMType {
|
|
|
25
25
|
this._name = name;
|
|
26
26
|
|
|
27
27
|
this._description = null;
|
|
28
|
+
this._format = null;
|
|
28
29
|
this._min = null;
|
|
29
30
|
this._max = null;
|
|
30
31
|
|
|
@@ -155,6 +156,24 @@ class LLMType {
|
|
|
155
156
|
return this;
|
|
156
157
|
}
|
|
157
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Sets the JSON Schema `format` for a string property.
|
|
161
|
+
*
|
|
162
|
+
* Supported values: `'date-time'`, `'time'`, `'date'`, `'duration'`,
|
|
163
|
+
* `'email'`, `'hostname'`, `'ipv4'`, `'ipv6'`, `'uuid'`.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* const createdAt = LLMType.string().format('date-time').description('Creation timestamp');
|
|
167
|
+
*
|
|
168
|
+
* @param {'date-time'|'time'|'date'|'duration'|'email'|
|
|
169
|
+
* 'hostname'|'ipv4'|'ipv6'|'uuid'|string} value
|
|
170
|
+
* @returns {this}
|
|
171
|
+
*/
|
|
172
|
+
format (value) {
|
|
173
|
+
this._format = value;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
158
177
|
/**
|
|
159
178
|
* Sets minimum boundary and maps it to a type-specific JSON Schema keyword.
|
|
160
179
|
*
|
|
@@ -282,7 +301,8 @@ class LLMType {
|
|
|
282
301
|
_baseSchema () {
|
|
283
302
|
return /** @type {object} */ ({
|
|
284
303
|
...(this._description !== null && { description: this._description }),
|
|
285
|
-
...(this._name !== null && { name: this._name })
|
|
304
|
+
...(this._name !== null && { name: this._name }),
|
|
305
|
+
...(this._format !== null && { format: this._format })
|
|
286
306
|
});
|
|
287
307
|
}
|
|
288
308
|
|
package/src/graphApi/schema.gql
CHANGED
|
@@ -123,10 +123,18 @@ type VectorSearchResult {
|
|
|
123
123
|
resultDocuments: [VectorSearchDocument!]!
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
type ToolFunction {
|
|
127
|
+
name: String!
|
|
128
|
+
description: String
|
|
129
|
+
parameters: Any
|
|
130
|
+
}
|
|
131
|
+
|
|
126
132
|
type PromptInfo {
|
|
127
133
|
prompt: [LLMMessage!]!
|
|
128
134
|
result: LLMMessage!
|
|
129
135
|
vectorSearchResult: VectorSearchResult
|
|
136
|
+
tools: [ToolFunction!]
|
|
137
|
+
durationMs: Float
|
|
130
138
|
}
|
|
131
139
|
|
|
132
140
|
type UserInteraction {
|
|
@@ -88,7 +88,8 @@ class PromptAssert {
|
|
|
88
88
|
*/
|
|
89
89
|
_flatResults () {
|
|
90
90
|
return this._prompts
|
|
91
|
-
.map((prompt) => prompt.result)
|
|
91
|
+
.map((prompt) => prompt.result)
|
|
92
|
+
.filter(Boolean);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
/**
|
|
@@ -190,7 +191,7 @@ class PromptAssert {
|
|
|
190
191
|
return [
|
|
191
192
|
`${i + 1}) ${PromptAssert.promptStats(p.prompt)}`,
|
|
192
193
|
`${prompt.join('\n ')}`,
|
|
193
|
-
`# ${PromptAssert._content(p.result)}`
|
|
194
|
+
`# ${p.result ? PromptAssert._content(p.result) : `[ERROR] ${p.error || 'unknown'}`}`
|
|
194
195
|
].join('\n ');
|
|
195
196
|
});
|
|
196
197
|
}
|