@promptbook/deepseek 0.86.10 → 0.86.22
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/README.md +35 -42
- package/esm/index.es.js +339 -437
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/conversion/utils/extractVariablesFromScript.d.ts +5 -5
- package/esm/typings/src/execution/AbstractTaskResult.d.ts +3 -3
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +1 -1
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +11 -1
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +9 -1
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +1 -1
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +339 -437
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -8,138 +8,19 @@ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
|
8
8
|
* @generated
|
|
9
9
|
* @see https://github.com/webgptorg/book
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
12
12
|
/**
|
|
13
13
|
* The version of the Promptbook engine
|
|
14
14
|
*
|
|
15
15
|
* @generated
|
|
16
16
|
* @see https://github.com/webgptorg/promptbook
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
|
|
19
19
|
/**
|
|
20
20
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
21
21
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
/*! *****************************************************************************
|
|
25
|
-
Copyright (c) Microsoft Corporation.
|
|
26
|
-
|
|
27
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
28
|
-
purpose with or without fee is hereby granted.
|
|
29
|
-
|
|
30
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
31
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
32
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
33
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
34
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
35
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
36
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
37
|
-
***************************************************************************** */
|
|
38
|
-
/* global Reflect, Promise */
|
|
39
|
-
|
|
40
|
-
var extendStatics = function(d, b) {
|
|
41
|
-
extendStatics = Object.setPrototypeOf ||
|
|
42
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
43
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
44
|
-
return extendStatics(d, b);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
function __extends(d, b) {
|
|
48
|
-
if (typeof b !== "function" && b !== null)
|
|
49
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
50
|
-
extendStatics(d, b);
|
|
51
|
-
function __() { this.constructor = d; }
|
|
52
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var __assign = function() {
|
|
56
|
-
__assign = Object.assign || function __assign(t) {
|
|
57
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
58
|
-
s = arguments[i];
|
|
59
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
60
|
-
}
|
|
61
|
-
return t;
|
|
62
|
-
};
|
|
63
|
-
return __assign.apply(this, arguments);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
67
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
68
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
69
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
70
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
71
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
72
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function __generator(thisArg, body) {
|
|
77
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
78
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
79
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
80
|
-
function step(op) {
|
|
81
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
82
|
-
while (_) try {
|
|
83
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
84
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
85
|
-
switch (op[0]) {
|
|
86
|
-
case 0: case 1: t = op; break;
|
|
87
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
88
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
89
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
90
|
-
default:
|
|
91
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
92
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
93
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
94
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
95
|
-
if (t[2]) _.ops.pop();
|
|
96
|
-
_.trys.pop(); continue;
|
|
97
|
-
}
|
|
98
|
-
op = body.call(thisArg, _);
|
|
99
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
100
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function __values(o) {
|
|
105
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
106
|
-
if (m) return m.call(o);
|
|
107
|
-
if (o && typeof o.length === "number") return {
|
|
108
|
-
next: function () {
|
|
109
|
-
if (o && i >= o.length) o = void 0;
|
|
110
|
-
return { value: o && o[i++], done: !o };
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function __read(o, n) {
|
|
117
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
118
|
-
if (!m) return o;
|
|
119
|
-
var i = m.call(o), r, ar = [], e;
|
|
120
|
-
try {
|
|
121
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
122
|
-
}
|
|
123
|
-
catch (error) { e = { error: error }; }
|
|
124
|
-
finally {
|
|
125
|
-
try {
|
|
126
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
127
|
-
}
|
|
128
|
-
finally { if (e) throw e.error; }
|
|
129
|
-
}
|
|
130
|
-
return ar;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function __spreadArray(to, from, pack) {
|
|
134
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
135
|
-
if (ar || !(i in from)) {
|
|
136
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
137
|
-
ar[i] = from[i];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
24
|
/**
|
|
144
25
|
* Detects if the code is running in jest environment
|
|
145
26
|
*
|
|
@@ -147,7 +28,13 @@ function __spreadArray(to, from, pack) {
|
|
|
147
28
|
*
|
|
148
29
|
* @public exported from `@promptbook/utils`
|
|
149
30
|
*/
|
|
150
|
-
|
|
31
|
+
const $isRunningInJest = new Function(`
|
|
32
|
+
try {
|
|
33
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
`);
|
|
151
38
|
/**
|
|
152
39
|
* TODO: [🎺]
|
|
153
40
|
*/
|
|
@@ -157,16 +44,13 @@ var $isRunningInJest = new Function("\n try {\n return process.env.JES
|
|
|
157
44
|
*
|
|
158
45
|
* @public exported from `@promptbook/core`
|
|
159
46
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
166
|
-
return _this;
|
|
47
|
+
class PipelineExecutionError extends Error {
|
|
48
|
+
constructor(message) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = 'PipelineExecutionError';
|
|
51
|
+
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
167
52
|
}
|
|
168
|
-
|
|
169
|
-
}(Error));
|
|
53
|
+
}
|
|
170
54
|
|
|
171
55
|
/**
|
|
172
56
|
* Freezes the given object and all its nested objects recursively
|
|
@@ -178,26 +62,15 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
178
62
|
* @public exported from `@promptbook/utils`
|
|
179
63
|
*/
|
|
180
64
|
function $deepFreeze(objectValue) {
|
|
181
|
-
var e_1, _a;
|
|
182
65
|
if (Array.isArray(objectValue)) {
|
|
183
|
-
return Object.freeze(objectValue.map(
|
|
66
|
+
return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
|
|
184
67
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (value && typeof value === 'object') {
|
|
191
|
-
$deepFreeze(value);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
196
|
-
finally {
|
|
197
|
-
try {
|
|
198
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
68
|
+
const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
69
|
+
for (const propertyName of propertyNames) {
|
|
70
|
+
const value = objectValue[propertyName];
|
|
71
|
+
if (value && typeof value === 'object') {
|
|
72
|
+
$deepFreeze(value);
|
|
199
73
|
}
|
|
200
|
-
finally { if (e_1) throw e_1.error; }
|
|
201
74
|
}
|
|
202
75
|
Object.freeze(objectValue);
|
|
203
76
|
return objectValue;
|
|
@@ -237,7 +110,7 @@ $deepFreeze({
|
|
|
237
110
|
*
|
|
238
111
|
* @public exported from `@promptbook/core`
|
|
239
112
|
*/
|
|
240
|
-
|
|
113
|
+
const UNCERTAIN_USAGE = $deepFreeze({
|
|
241
114
|
price: { value: 0, isUncertain: true },
|
|
242
115
|
input: {
|
|
243
116
|
tokensCount: { value: 0, isUncertain: true },
|
|
@@ -281,32 +154,32 @@ function $getCurrentDate() {
|
|
|
281
154
|
*
|
|
282
155
|
* @public exported from `@promptbook/core`
|
|
283
156
|
*/
|
|
284
|
-
|
|
157
|
+
const NAME = `Promptbook`;
|
|
285
158
|
/**
|
|
286
159
|
* Email of the responsible person
|
|
287
160
|
*
|
|
288
161
|
* @public exported from `@promptbook/core`
|
|
289
162
|
*/
|
|
290
|
-
|
|
163
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
291
164
|
/**
|
|
292
165
|
* Name of the responsible person for the Promptbook on GitHub
|
|
293
166
|
*
|
|
294
167
|
* @public exported from `@promptbook/core`
|
|
295
168
|
*/
|
|
296
|
-
|
|
169
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
297
170
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
298
171
|
/**
|
|
299
172
|
* The maximum number of iterations for a loops
|
|
300
173
|
*
|
|
301
174
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
302
175
|
*/
|
|
303
|
-
|
|
176
|
+
const LOOP_LIMIT = 1000;
|
|
304
177
|
/**
|
|
305
178
|
* Strings to represent various values in the context of parameter values
|
|
306
179
|
*
|
|
307
180
|
* @public exported from `@promptbook/utils`
|
|
308
181
|
*/
|
|
309
|
-
|
|
182
|
+
const VALUE_STRINGS = {
|
|
310
183
|
empty: '(nothing; empty string)',
|
|
311
184
|
null: '(no value; null)',
|
|
312
185
|
undefined: '(unknown value; undefined)',
|
|
@@ -320,7 +193,7 @@ var VALUE_STRINGS = {
|
|
|
320
193
|
*
|
|
321
194
|
* @public exported from `@promptbook/utils`
|
|
322
195
|
*/
|
|
323
|
-
|
|
196
|
+
const SMALL_NUMBER = 0.001;
|
|
324
197
|
// <- TODO: [🧜♂️]
|
|
325
198
|
/**
|
|
326
199
|
* @@@
|
|
@@ -345,8 +218,11 @@ Object.freeze({
|
|
|
345
218
|
* @public exported from `@promptbook/utils`
|
|
346
219
|
*/
|
|
347
220
|
function orderJson(options) {
|
|
348
|
-
|
|
349
|
-
|
|
221
|
+
const { value, order } = options;
|
|
222
|
+
const orderedValue = {
|
|
223
|
+
...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
|
|
224
|
+
...value,
|
|
225
|
+
};
|
|
350
226
|
return orderedValue;
|
|
351
227
|
}
|
|
352
228
|
|
|
@@ -356,11 +232,37 @@ function orderJson(options) {
|
|
|
356
232
|
* @private private within the repository
|
|
357
233
|
*/
|
|
358
234
|
function getErrorReportUrl(error) {
|
|
359
|
-
|
|
360
|
-
title:
|
|
361
|
-
body: spaceTrim(
|
|
235
|
+
const report = {
|
|
236
|
+
title: `🐜 Error report from ${NAME}`,
|
|
237
|
+
body: spaceTrim((block) => `
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
241
|
+
|
|
242
|
+
\`\`\`
|
|
243
|
+
${block(error.message || '(no error message)')}
|
|
244
|
+
\`\`\`
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
## More info:
|
|
248
|
+
|
|
249
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
250
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
251
|
+
- **Time:** ${new Date().toISOString()}
|
|
252
|
+
|
|
253
|
+
<details>
|
|
254
|
+
<summary>Stack trace:</summary>
|
|
255
|
+
|
|
256
|
+
## Stack trace:
|
|
257
|
+
|
|
258
|
+
\`\`\`stacktrace
|
|
259
|
+
${block(error.stack || '(empty)')}
|
|
260
|
+
\`\`\`
|
|
261
|
+
</details>
|
|
262
|
+
|
|
263
|
+
`),
|
|
362
264
|
};
|
|
363
|
-
|
|
265
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
364
266
|
reportUrl.searchParams.set('labels', 'bug');
|
|
365
267
|
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
366
268
|
reportUrl.searchParams.set('title', report.title);
|
|
@@ -373,16 +275,24 @@ function getErrorReportUrl(error) {
|
|
|
373
275
|
*
|
|
374
276
|
* @public exported from `@promptbook/core`
|
|
375
277
|
*/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
278
|
+
class UnexpectedError extends Error {
|
|
279
|
+
constructor(message) {
|
|
280
|
+
super(spaceTrim$1((block) => `
|
|
281
|
+
${block(message)}
|
|
282
|
+
|
|
283
|
+
Note: This error should not happen.
|
|
284
|
+
It's probbably a bug in the pipeline collection
|
|
285
|
+
|
|
286
|
+
Please report issue:
|
|
287
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
288
|
+
|
|
289
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
290
|
+
|
|
291
|
+
`));
|
|
292
|
+
this.name = 'UnexpectedError';
|
|
293
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
383
294
|
}
|
|
384
|
-
|
|
385
|
-
}(Error));
|
|
295
|
+
}
|
|
386
296
|
|
|
387
297
|
/**
|
|
388
298
|
* Checks if the value is [🚉] serializable as JSON
|
|
@@ -405,10 +315,9 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
405
315
|
* @public exported from `@promptbook/utils`
|
|
406
316
|
*/
|
|
407
317
|
function checkSerializableAsJson(options) {
|
|
408
|
-
|
|
409
|
-
var value = options.value, name = options.name, message = options.message;
|
|
318
|
+
const { value, name, message } = options;
|
|
410
319
|
if (value === undefined) {
|
|
411
|
-
throw new UnexpectedError(
|
|
320
|
+
throw new UnexpectedError(`${name} is undefined`);
|
|
412
321
|
}
|
|
413
322
|
else if (value === null) {
|
|
414
323
|
return;
|
|
@@ -423,49 +332,54 @@ function checkSerializableAsJson(options) {
|
|
|
423
332
|
return;
|
|
424
333
|
}
|
|
425
334
|
else if (typeof value === 'symbol') {
|
|
426
|
-
throw new UnexpectedError(
|
|
335
|
+
throw new UnexpectedError(`${name} is symbol`);
|
|
427
336
|
}
|
|
428
337
|
else if (typeof value === 'function') {
|
|
429
|
-
throw new UnexpectedError(
|
|
338
|
+
throw new UnexpectedError(`${name} is function`);
|
|
430
339
|
}
|
|
431
340
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
432
|
-
for (
|
|
433
|
-
checkSerializableAsJson({ name:
|
|
341
|
+
for (let i = 0; i < value.length; i++) {
|
|
342
|
+
checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
|
|
434
343
|
}
|
|
435
344
|
}
|
|
436
345
|
else if (typeof value === 'object') {
|
|
437
346
|
if (value instanceof Date) {
|
|
438
|
-
throw new UnexpectedError(spaceTrim(
|
|
347
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
348
|
+
\`${name}\` is Date
|
|
349
|
+
|
|
350
|
+
Use \`string_date_iso8601\` instead
|
|
351
|
+
|
|
352
|
+
Additional message for \`${name}\`:
|
|
353
|
+
${block(message || '(nothing)')}
|
|
354
|
+
`));
|
|
439
355
|
}
|
|
440
356
|
else if (value instanceof Map) {
|
|
441
|
-
throw new UnexpectedError(
|
|
357
|
+
throw new UnexpectedError(`${name} is Map`);
|
|
442
358
|
}
|
|
443
359
|
else if (value instanceof Set) {
|
|
444
|
-
throw new UnexpectedError(
|
|
360
|
+
throw new UnexpectedError(`${name} is Set`);
|
|
445
361
|
}
|
|
446
362
|
else if (value instanceof RegExp) {
|
|
447
|
-
throw new UnexpectedError(
|
|
363
|
+
throw new UnexpectedError(`${name} is RegExp`);
|
|
448
364
|
}
|
|
449
365
|
else if (value instanceof Error) {
|
|
450
|
-
throw new UnexpectedError(spaceTrim(
|
|
366
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
367
|
+
\`${name}\` is unserialized Error
|
|
368
|
+
|
|
369
|
+
Use function \`serializeError\`
|
|
370
|
+
|
|
371
|
+
Additional message for \`${name}\`:
|
|
372
|
+
${block(message || '(nothing)')}
|
|
373
|
+
|
|
374
|
+
`));
|
|
451
375
|
}
|
|
452
376
|
else {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
// Note: undefined in object is serializable - it is just omited
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
464
|
-
finally {
|
|
465
|
-
try {
|
|
466
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
377
|
+
for (const [subName, subValue] of Object.entries(value)) {
|
|
378
|
+
if (subValue === undefined) {
|
|
379
|
+
// Note: undefined in object is serializable - it is just omited
|
|
380
|
+
continue;
|
|
467
381
|
}
|
|
468
|
-
|
|
382
|
+
checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
|
|
469
383
|
}
|
|
470
384
|
try {
|
|
471
385
|
JSON.stringify(value); // <- TODO: [0]
|
|
@@ -474,7 +388,14 @@ function checkSerializableAsJson(options) {
|
|
|
474
388
|
if (!(error instanceof Error)) {
|
|
475
389
|
throw error;
|
|
476
390
|
}
|
|
477
|
-
throw new UnexpectedError(spaceTrim(
|
|
391
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
392
|
+
\`${name}\` is not serializable
|
|
393
|
+
|
|
394
|
+
${block(error.stack || error.message)}
|
|
395
|
+
|
|
396
|
+
Additional message for \`${name}\`:
|
|
397
|
+
${block(message || '(nothing)')}
|
|
398
|
+
`));
|
|
478
399
|
}
|
|
479
400
|
/*
|
|
480
401
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -499,7 +420,12 @@ function checkSerializableAsJson(options) {
|
|
|
499
420
|
}
|
|
500
421
|
}
|
|
501
422
|
else {
|
|
502
|
-
throw new UnexpectedError(spaceTrim(
|
|
423
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
424
|
+
\`${name}\` is unknown type
|
|
425
|
+
|
|
426
|
+
Additional message for \`${name}\`:
|
|
427
|
+
${block(message || '(nothing)')}
|
|
428
|
+
`));
|
|
503
429
|
}
|
|
504
430
|
}
|
|
505
431
|
/**
|
|
@@ -545,9 +471,9 @@ function deepClone(objectValue) {
|
|
|
545
471
|
* @public exported from `@promptbook/utils`
|
|
546
472
|
*/
|
|
547
473
|
function exportJson(options) {
|
|
548
|
-
|
|
549
|
-
checkSerializableAsJson({ name
|
|
550
|
-
|
|
474
|
+
const { name, value, order, message } = options;
|
|
475
|
+
checkSerializableAsJson({ name, value, message });
|
|
476
|
+
const orderedValue =
|
|
551
477
|
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
552
478
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
553
479
|
// @ts-ignore
|
|
@@ -570,19 +496,19 @@ function exportJson(options) {
|
|
|
570
496
|
*
|
|
571
497
|
* @private within the repository
|
|
572
498
|
*/
|
|
573
|
-
|
|
499
|
+
const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
574
500
|
/**
|
|
575
501
|
* @@@
|
|
576
502
|
*
|
|
577
503
|
* @private within the repository
|
|
578
504
|
*/
|
|
579
|
-
|
|
505
|
+
const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
580
506
|
/**
|
|
581
507
|
* @@@
|
|
582
508
|
*
|
|
583
509
|
* @private within the repository
|
|
584
510
|
*/
|
|
585
|
-
|
|
511
|
+
const RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
586
512
|
/**
|
|
587
513
|
* The names of the parameters that are reserved for special purposes
|
|
588
514
|
*
|
|
@@ -590,7 +516,7 @@ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
|
590
516
|
*/
|
|
591
517
|
exportJson({
|
|
592
518
|
name: 'RESERVED_PARAMETER_NAMES',
|
|
593
|
-
message:
|
|
519
|
+
message: `The names of the parameters that are reserved for special purposes`,
|
|
594
520
|
value: [
|
|
595
521
|
'content',
|
|
596
522
|
'context',
|
|
@@ -612,16 +538,13 @@ exportJson({
|
|
|
612
538
|
*
|
|
613
539
|
* @public exported from `@promptbook/core`
|
|
614
540
|
*/
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
621
|
-
return _this;
|
|
541
|
+
class LimitReachedError extends Error {
|
|
542
|
+
constructor(message) {
|
|
543
|
+
super(message);
|
|
544
|
+
this.name = 'LimitReachedError';
|
|
545
|
+
Object.setPrototypeOf(this, LimitReachedError.prototype);
|
|
622
546
|
}
|
|
623
|
-
|
|
624
|
-
}(Error));
|
|
547
|
+
}
|
|
625
548
|
|
|
626
549
|
/**
|
|
627
550
|
* Format either small or big number
|
|
@@ -641,9 +564,9 @@ function numberToString(value) {
|
|
|
641
564
|
else if (value === -Infinity) {
|
|
642
565
|
return VALUE_STRINGS.negativeInfinity;
|
|
643
566
|
}
|
|
644
|
-
for (
|
|
645
|
-
|
|
646
|
-
|
|
567
|
+
for (let exponent = 0; exponent < 15; exponent++) {
|
|
568
|
+
const factor = 10 ** exponent;
|
|
569
|
+
const valueRounded = Math.round(value * factor) / factor;
|
|
647
570
|
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
648
571
|
return valueRounded.toFixed(exponent);
|
|
649
572
|
}
|
|
@@ -711,47 +634,38 @@ function valueToString(value) {
|
|
|
711
634
|
* @public exported from `@promptbook/utils`
|
|
712
635
|
*/
|
|
713
636
|
function templateParameters(template, parameters) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
718
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
719
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
720
|
-
}
|
|
721
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
722
|
-
// TODO: [🍵]
|
|
723
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
724
|
-
}
|
|
637
|
+
for (const [parameterName, parameterValue] of Object.entries(parameters)) {
|
|
638
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
639
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
|
|
725
640
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
try {
|
|
730
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
641
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
642
|
+
// TODO: [🍵]
|
|
643
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
|
|
731
644
|
}
|
|
732
|
-
finally { if (e_1) throw e_1.error; }
|
|
733
645
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
646
|
+
let replacedTemplates = template;
|
|
647
|
+
let match;
|
|
648
|
+
let loopLimit = LOOP_LIMIT;
|
|
649
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
650
|
+
.exec(replacedTemplates))) {
|
|
738
651
|
if (loopLimit-- < 0) {
|
|
739
652
|
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
740
653
|
}
|
|
741
|
-
|
|
742
|
-
|
|
654
|
+
const precol = match.groups.precol;
|
|
655
|
+
const parameterName = match.groups.parameterName;
|
|
743
656
|
if (parameterName === '') {
|
|
744
|
-
|
|
657
|
+
// Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
|
|
658
|
+
continue;
|
|
745
659
|
}
|
|
746
660
|
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
747
661
|
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
748
662
|
}
|
|
749
663
|
if (parameters[parameterName] === undefined) {
|
|
750
|
-
throw new PipelineExecutionError(
|
|
664
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
751
665
|
}
|
|
752
|
-
|
|
666
|
+
let parameterValue = parameters[parameterName];
|
|
753
667
|
if (parameterValue === undefined) {
|
|
754
|
-
throw new PipelineExecutionError(
|
|
668
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
755
669
|
}
|
|
756
670
|
parameterValue = valueToString(parameterValue);
|
|
757
671
|
// Escape curly braces in parameter values to prevent prompt-injection
|
|
@@ -759,17 +673,13 @@ function templateParameters(template, parameters) {
|
|
|
759
673
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
760
674
|
parameterValue = parameterValue
|
|
761
675
|
.split('\n')
|
|
762
|
-
.map(
|
|
676
|
+
.map((line, index) => (index === 0 ? line : `${precol}${line}`))
|
|
763
677
|
.join('\n');
|
|
764
678
|
}
|
|
765
679
|
replacedTemplates =
|
|
766
680
|
replacedTemplates.substring(0, match.index + precol.length) +
|
|
767
681
|
parameterValue +
|
|
768
682
|
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
769
|
-
};
|
|
770
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
771
|
-
.exec(replacedTemplates))) {
|
|
772
|
-
_loop_1();
|
|
773
683
|
}
|
|
774
684
|
// [💫] Check if there are parameters that are not closed properly
|
|
775
685
|
if (/{\w+$/.test(replacedTemplates)) {
|
|
@@ -803,8 +713,8 @@ function asSerializable(value) {
|
|
|
803
713
|
return value.map(asSerializable);
|
|
804
714
|
}
|
|
805
715
|
else if (value !== null && typeof value === 'object') {
|
|
806
|
-
|
|
807
|
-
for (
|
|
716
|
+
const result = {};
|
|
717
|
+
for (const key in value) {
|
|
808
718
|
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
809
719
|
result[key] = asSerializable(value[key]);
|
|
810
720
|
}
|
|
@@ -822,131 +732,119 @@ function asSerializable(value) {
|
|
|
822
732
|
* @public exported from `@promptbook/vercel`
|
|
823
733
|
*/
|
|
824
734
|
function createExecutionToolsFromVercelProvider(options) {
|
|
825
|
-
|
|
826
|
-
|
|
735
|
+
let { title, description } = options;
|
|
736
|
+
const { vercelProvider, availableModels, userId, additionalChatSettings = {} } = options;
|
|
827
737
|
if (!/Vercel/i.test(title)) {
|
|
828
|
-
title =
|
|
738
|
+
title = `${title} (through Vercel)`;
|
|
829
739
|
} /* not else */
|
|
830
740
|
if (description === undefined) {
|
|
831
|
-
description =
|
|
741
|
+
description = `Implementation of ${title} through Vercel`;
|
|
832
742
|
} /* not else */
|
|
833
743
|
if (!/Vercel/i.test(description)) {
|
|
834
|
-
description =
|
|
744
|
+
description = `${description} (through Vercel)`;
|
|
835
745
|
} /* not else */
|
|
836
746
|
return {
|
|
837
|
-
title
|
|
838
|
-
description
|
|
839
|
-
checkConfiguration
|
|
747
|
+
title,
|
|
748
|
+
description,
|
|
749
|
+
checkConfiguration() {
|
|
840
750
|
// Note: There is no way how to check configuration of Vercel provider
|
|
841
751
|
return Promise.resolve();
|
|
842
752
|
},
|
|
843
|
-
listModels
|
|
844
|
-
return
|
|
845
|
-
return __generator(this, function (_a) {
|
|
846
|
-
return [2 /*return*/, availableModels];
|
|
847
|
-
});
|
|
848
|
-
});
|
|
753
|
+
async listModels() {
|
|
754
|
+
return availableModels;
|
|
849
755
|
},
|
|
850
|
-
callChatModel
|
|
756
|
+
async callChatModel(prompt) {
|
|
851
757
|
var _a;
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
rawPromptContent: rawPromptContent,
|
|
943
|
-
rawRequest: rawRequest,
|
|
944
|
-
rawResponse: asSerializable(rawResponse),
|
|
945
|
-
// <- [🗯]
|
|
946
|
-
},
|
|
947
|
-
})];
|
|
948
|
-
}
|
|
949
|
-
});
|
|
758
|
+
const { content, parameters, modelRequirements } = prompt;
|
|
759
|
+
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
760
|
+
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
761
|
+
}
|
|
762
|
+
const modelName = modelRequirements.modelName ||
|
|
763
|
+
((_a = availableModels.find(({ modelVariant }) => modelVariant === 'CHAT')) === null || _a === void 0 ? void 0 : _a.modelName);
|
|
764
|
+
if (!modelName) {
|
|
765
|
+
throw new PipelineExecutionError(spaceTrim(`
|
|
766
|
+
Can not determine which model to use.
|
|
767
|
+
|
|
768
|
+
You need to provide at least one of:
|
|
769
|
+
1) In \`createExecutionToolsFromVercelProvider\` options, provide \`availableModels\` with at least one model
|
|
770
|
+
2) In \`prompt.modelRequirements\`, provide \`modelName\` with the name of the model to use
|
|
771
|
+
|
|
772
|
+
`));
|
|
773
|
+
}
|
|
774
|
+
const model = await vercelProvider.chat(modelName, {
|
|
775
|
+
user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined,
|
|
776
|
+
...additionalChatSettings,
|
|
777
|
+
});
|
|
778
|
+
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
779
|
+
const rawRequest = {
|
|
780
|
+
// <- TODO: [☂]
|
|
781
|
+
inputFormat: 'messages',
|
|
782
|
+
mode: {
|
|
783
|
+
type: 'regular',
|
|
784
|
+
tools: [
|
|
785
|
+
/* <- TODO: Pass the tools */
|
|
786
|
+
],
|
|
787
|
+
},
|
|
788
|
+
prompt: [
|
|
789
|
+
...(modelRequirements.systemMessage === undefined
|
|
790
|
+
? []
|
|
791
|
+
: [
|
|
792
|
+
{
|
|
793
|
+
role: 'system',
|
|
794
|
+
content: modelRequirements.systemMessage,
|
|
795
|
+
},
|
|
796
|
+
]),
|
|
797
|
+
{
|
|
798
|
+
role: 'user',
|
|
799
|
+
content: [
|
|
800
|
+
{
|
|
801
|
+
type: 'text',
|
|
802
|
+
text: rawPromptContent,
|
|
803
|
+
},
|
|
804
|
+
],
|
|
805
|
+
},
|
|
806
|
+
],
|
|
807
|
+
};
|
|
808
|
+
const start = $getCurrentDate();
|
|
809
|
+
if (options.isVerbose) {
|
|
810
|
+
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
811
|
+
}
|
|
812
|
+
const rawResponse = await (async () => await model.doGenerate(rawRequest))().catch((error) => {
|
|
813
|
+
// <- Note: This weird structure is here to catch errors in both sync and async `doGenerate`
|
|
814
|
+
if (options.isVerbose) {
|
|
815
|
+
console.info(colors.bgRed('error'), error);
|
|
816
|
+
}
|
|
817
|
+
throw error;
|
|
818
|
+
});
|
|
819
|
+
await model.doGenerate(rawRequest);
|
|
820
|
+
if (options.isVerbose) {
|
|
821
|
+
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
822
|
+
}
|
|
823
|
+
if (rawResponse.text === undefined) {
|
|
824
|
+
throw new PipelineExecutionError('No response message');
|
|
825
|
+
}
|
|
826
|
+
const complete = $getCurrentDate();
|
|
827
|
+
/*
|
|
828
|
+
TODO: [🕘] Usage count
|
|
829
|
+
const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
830
|
+
*/
|
|
831
|
+
const usage = UNCERTAIN_USAGE;
|
|
832
|
+
return exportJson({
|
|
833
|
+
name: 'promptResult',
|
|
834
|
+
message: `Result of \`createExecutionToolsFromVercelProvider.callChatModel\``,
|
|
835
|
+
value: {
|
|
836
|
+
content: rawResponse.text,
|
|
837
|
+
modelName,
|
|
838
|
+
timing: {
|
|
839
|
+
start,
|
|
840
|
+
complete,
|
|
841
|
+
},
|
|
842
|
+
usage,
|
|
843
|
+
rawPromptContent,
|
|
844
|
+
rawRequest,
|
|
845
|
+
rawResponse: asSerializable(rawResponse),
|
|
846
|
+
// <- [🗯]
|
|
847
|
+
},
|
|
950
848
|
});
|
|
951
849
|
},
|
|
952
850
|
};
|
|
@@ -957,21 +855,30 @@ function createExecutionToolsFromVercelProvider(options) {
|
|
|
957
855
|
*
|
|
958
856
|
* @public exported from `@promptbook/deepseek`
|
|
959
857
|
*/
|
|
960
|
-
|
|
858
|
+
const createDeepseekExecutionTools = Object.assign((options) => {
|
|
961
859
|
if ($isRunningInJest()) {
|
|
962
860
|
// Note: [🔘]
|
|
963
861
|
throw new Error('DeepseekExecutionTools are not supported in Jest environment');
|
|
964
862
|
}
|
|
965
863
|
// Note: [🔘] Maybe there is same compatibility problem as in '@ai-sdk/deepseek'
|
|
966
864
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
865
|
+
const { createDeepSeek } = require('@ai-sdk/deepseek');
|
|
866
|
+
const deepseekVercelProvider = createDeepSeek({
|
|
867
|
+
...options,
|
|
868
|
+
// apiKey: process.env.DEEPSEEK_GENERATIVE_AI_API_KEY,
|
|
869
|
+
});
|
|
870
|
+
return createExecutionToolsFromVercelProvider({
|
|
871
|
+
title: 'Deepseek',
|
|
872
|
+
description: 'Implementation of Deepseek models',
|
|
873
|
+
vercelProvider: deepseekVercelProvider,
|
|
874
|
+
availableModels: [
|
|
970
875
|
// TODO: [🕘] Maybe list models in same way as in other providers - in separate file with metadata
|
|
971
876
|
'deepseek-chat',
|
|
972
877
|
'deepseek-reasoner',
|
|
973
878
|
// <- TODO: How picking of the default model looks like in `createExecutionToolsFromVercelProvider`
|
|
974
|
-
].map(
|
|
879
|
+
].map((modelName) => ({ modelName, modelVariant: 'CHAT' })),
|
|
880
|
+
...options,
|
|
881
|
+
});
|
|
975
882
|
}, {
|
|
976
883
|
packageName: '@promptbook/deepseek',
|
|
977
884
|
className: 'DeepseekExecutionTools',
|
|
@@ -985,16 +892,23 @@ var createDeepseekExecutionTools = Object.assign(function (options) {
|
|
|
985
892
|
*
|
|
986
893
|
* @public exported from `@promptbook/core`
|
|
987
894
|
*/
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
895
|
+
class NotYetImplementedError extends Error {
|
|
896
|
+
constructor(message) {
|
|
897
|
+
super(spaceTrim$1((block) => `
|
|
898
|
+
${block(message)}
|
|
899
|
+
|
|
900
|
+
Note: This feature is not implemented yet but it will be soon.
|
|
901
|
+
|
|
902
|
+
If you want speed up the implementation or just read more, look here:
|
|
903
|
+
https://github.com/webgptorg/promptbook
|
|
904
|
+
|
|
905
|
+
Or contact us on pavol@ptbk.io
|
|
906
|
+
|
|
907
|
+
`));
|
|
908
|
+
this.name = 'NotYetImplementedError';
|
|
909
|
+
Object.setPrototypeOf(this, NotYetImplementedError.prototype);
|
|
995
910
|
}
|
|
996
|
-
|
|
997
|
-
}(Error));
|
|
911
|
+
}
|
|
998
912
|
|
|
999
913
|
/**
|
|
1000
914
|
* @@@
|
|
@@ -1017,46 +931,35 @@ function $getGlobalScope() {
|
|
|
1017
931
|
* @public exported from `@promptbook/utils`
|
|
1018
932
|
*/
|
|
1019
933
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
if (/^[a-z]$/.test(char)) {
|
|
1029
|
-
charType = 'LOWERCASE';
|
|
1030
|
-
normalizedChar = char.toUpperCase();
|
|
1031
|
-
}
|
|
1032
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1033
|
-
charType = 'UPPERCASE';
|
|
1034
|
-
normalizedChar = char;
|
|
1035
|
-
}
|
|
1036
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1037
|
-
charType = 'NUMBER';
|
|
1038
|
-
normalizedChar = char;
|
|
1039
|
-
}
|
|
1040
|
-
else {
|
|
1041
|
-
charType = 'OTHER';
|
|
1042
|
-
normalizedChar = '_';
|
|
1043
|
-
}
|
|
1044
|
-
if (charType !== lastCharType &&
|
|
1045
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1046
|
-
!(lastCharType === 'NUMBER') &&
|
|
1047
|
-
!(charType === 'NUMBER')) {
|
|
1048
|
-
normalizedName += '_';
|
|
1049
|
-
}
|
|
1050
|
-
normalizedName += normalizedChar;
|
|
1051
|
-
lastCharType = charType;
|
|
934
|
+
let charType;
|
|
935
|
+
let lastCharType = 'OTHER';
|
|
936
|
+
let normalizedName = '';
|
|
937
|
+
for (const char of text) {
|
|
938
|
+
let normalizedChar;
|
|
939
|
+
if (/^[a-z]$/.test(char)) {
|
|
940
|
+
charType = 'LOWERCASE';
|
|
941
|
+
normalizedChar = char.toUpperCase();
|
|
1052
942
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
943
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
944
|
+
charType = 'UPPERCASE';
|
|
945
|
+
normalizedChar = char;
|
|
946
|
+
}
|
|
947
|
+
else if (/^[0-9]$/.test(char)) {
|
|
948
|
+
charType = 'NUMBER';
|
|
949
|
+
normalizedChar = char;
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
charType = 'OTHER';
|
|
953
|
+
normalizedChar = '_';
|
|
954
|
+
}
|
|
955
|
+
if (charType !== lastCharType &&
|
|
956
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
957
|
+
!(lastCharType === 'NUMBER') &&
|
|
958
|
+
!(charType === 'NUMBER')) {
|
|
959
|
+
normalizedName += '_';
|
|
1058
960
|
}
|
|
1059
|
-
|
|
961
|
+
normalizedName += normalizedChar;
|
|
962
|
+
lastCharType = charType;
|
|
1060
963
|
}
|
|
1061
964
|
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
1062
965
|
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
@@ -1093,27 +996,27 @@ function normalizeTo_snake_case(text) {
|
|
|
1093
996
|
*
|
|
1094
997
|
* @private internal utility, exported are only signleton instances of this class
|
|
1095
998
|
*/
|
|
1096
|
-
|
|
1097
|
-
|
|
999
|
+
class $Register {
|
|
1000
|
+
constructor(registerName) {
|
|
1098
1001
|
this.registerName = registerName;
|
|
1099
|
-
|
|
1100
|
-
|
|
1002
|
+
const storageName = `_promptbook_${normalizeTo_snake_case(registerName)}`;
|
|
1003
|
+
const globalScope = $getGlobalScope();
|
|
1101
1004
|
if (globalScope[storageName] === undefined) {
|
|
1102
1005
|
globalScope[storageName] = [];
|
|
1103
1006
|
}
|
|
1104
1007
|
else if (!Array.isArray(globalScope[storageName])) {
|
|
1105
|
-
throw new UnexpectedError(
|
|
1008
|
+
throw new UnexpectedError(`Expected (global) ${storageName} to be an array, but got ${typeof globalScope[storageName]}`);
|
|
1106
1009
|
}
|
|
1107
1010
|
this.storage = globalScope[storageName];
|
|
1108
1011
|
}
|
|
1109
|
-
|
|
1012
|
+
list() {
|
|
1110
1013
|
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
1111
1014
|
return this.storage;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1015
|
+
}
|
|
1016
|
+
register(registered) {
|
|
1017
|
+
const { packageName, className } = registered;
|
|
1018
|
+
const existingRegistrationIndex = this.storage.findIndex((item) => item.packageName === packageName && item.className === className);
|
|
1019
|
+
const existingRegistration = this.storage[existingRegistrationIndex];
|
|
1117
1020
|
if (!existingRegistration) {
|
|
1118
1021
|
this.storage.push(registered);
|
|
1119
1022
|
}
|
|
@@ -1122,18 +1025,17 @@ var $Register = /** @class */ (function () {
|
|
|
1122
1025
|
}
|
|
1123
1026
|
return {
|
|
1124
1027
|
registerName: this.registerName,
|
|
1125
|
-
packageName
|
|
1126
|
-
className
|
|
1028
|
+
packageName,
|
|
1029
|
+
className,
|
|
1127
1030
|
get isDestroyed() {
|
|
1128
1031
|
return false;
|
|
1129
1032
|
},
|
|
1130
|
-
destroy
|
|
1131
|
-
throw new NotYetImplementedError(
|
|
1033
|
+
destroy() {
|
|
1034
|
+
throw new NotYetImplementedError(`Registration to ${this.registerName} is permanent in this version of Promptbook`);
|
|
1132
1035
|
},
|
|
1133
1036
|
};
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
}());
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1137
1039
|
|
|
1138
1040
|
/**
|
|
1139
1041
|
* @@@
|
|
@@ -1142,7 +1044,7 @@ var $Register = /** @class */ (function () {
|
|
|
1142
1044
|
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
1143
1045
|
* @public exported from `@promptbook/core`
|
|
1144
1046
|
*/
|
|
1145
|
-
|
|
1047
|
+
const $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
1146
1048
|
/**
|
|
1147
1049
|
* TODO: [®] DRY Register logic
|
|
1148
1050
|
*/
|
|
@@ -1156,7 +1058,7 @@ var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
|
1156
1058
|
* @public exported from `@promptbook/wizzard`
|
|
1157
1059
|
* @public exported from `@promptbook/cli`
|
|
1158
1060
|
*/
|
|
1159
|
-
|
|
1061
|
+
const _DeepseekRegistration = $llmToolsRegister.register(createDeepseekExecutionTools);
|
|
1160
1062
|
/**
|
|
1161
1063
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
1162
1064
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|