@promptbook/fake-llm 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 +760 -1116
- 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 +760 -1116
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -12,128 +12,19 @@ import { forTime } from 'waitasecond';
|
|
|
12
12
|
* @generated
|
|
13
13
|
* @see https://github.com/webgptorg/book
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook engine
|
|
18
18
|
*
|
|
19
19
|
* @generated
|
|
20
20
|
* @see https://github.com/webgptorg/promptbook
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
|
|
23
23
|
/**
|
|
24
24
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
25
25
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
/*! *****************************************************************************
|
|
29
|
-
Copyright (c) Microsoft Corporation.
|
|
30
|
-
|
|
31
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
32
|
-
purpose with or without fee is hereby granted.
|
|
33
|
-
|
|
34
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
35
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
36
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
37
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
38
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
39
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
40
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
41
|
-
***************************************************************************** */
|
|
42
|
-
/* global Reflect, Promise */
|
|
43
|
-
|
|
44
|
-
var extendStatics = function(d, b) {
|
|
45
|
-
extendStatics = Object.setPrototypeOf ||
|
|
46
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
47
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
48
|
-
return extendStatics(d, b);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
function __extends(d, b) {
|
|
52
|
-
if (typeof b !== "function" && b !== null)
|
|
53
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
54
|
-
extendStatics(d, b);
|
|
55
|
-
function __() { this.constructor = d; }
|
|
56
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
var __assign = function() {
|
|
60
|
-
__assign = Object.assign || function __assign(t) {
|
|
61
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
62
|
-
s = arguments[i];
|
|
63
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
64
|
-
}
|
|
65
|
-
return t;
|
|
66
|
-
};
|
|
67
|
-
return __assign.apply(this, arguments);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
71
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
72
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
73
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
74
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
75
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
76
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function __generator(thisArg, body) {
|
|
81
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
82
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
83
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
84
|
-
function step(op) {
|
|
85
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
86
|
-
while (_) try {
|
|
87
|
-
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;
|
|
88
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
89
|
-
switch (op[0]) {
|
|
90
|
-
case 0: case 1: t = op; break;
|
|
91
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
92
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
93
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
94
|
-
default:
|
|
95
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
96
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
97
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
98
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
99
|
-
if (t[2]) _.ops.pop();
|
|
100
|
-
_.trys.pop(); continue;
|
|
101
|
-
}
|
|
102
|
-
op = body.call(thisArg, _);
|
|
103
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
104
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function __values(o) {
|
|
109
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
110
|
-
if (m) return m.call(o);
|
|
111
|
-
if (o && typeof o.length === "number") return {
|
|
112
|
-
next: function () {
|
|
113
|
-
if (o && i >= o.length) o = void 0;
|
|
114
|
-
return { value: o && o[i++], done: !o };
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function __read(o, n) {
|
|
121
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
122
|
-
if (!m) return o;
|
|
123
|
-
var i = m.call(o), r, ar = [], e;
|
|
124
|
-
try {
|
|
125
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
126
|
-
}
|
|
127
|
-
catch (error) { e = { error: error }; }
|
|
128
|
-
finally {
|
|
129
|
-
try {
|
|
130
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
131
|
-
}
|
|
132
|
-
finally { if (e) throw e.error; }
|
|
133
|
-
}
|
|
134
|
-
return ar;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
28
|
/**
|
|
138
29
|
* Freezes the given object and all its nested objects recursively
|
|
139
30
|
*
|
|
@@ -144,26 +35,15 @@ function __read(o, n) {
|
|
|
144
35
|
* @public exported from `@promptbook/utils`
|
|
145
36
|
*/
|
|
146
37
|
function $deepFreeze(objectValue) {
|
|
147
|
-
var e_1, _a;
|
|
148
38
|
if (Array.isArray(objectValue)) {
|
|
149
|
-
return Object.freeze(objectValue.map(
|
|
150
|
-
}
|
|
151
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
152
|
-
try {
|
|
153
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
154
|
-
var propertyName = propertyNames_1_1.value;
|
|
155
|
-
var value = objectValue[propertyName];
|
|
156
|
-
if (value && typeof value === 'object') {
|
|
157
|
-
$deepFreeze(value);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
39
|
+
return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
|
|
160
40
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
41
|
+
const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
42
|
+
for (const propertyName of propertyNames) {
|
|
43
|
+
const value = objectValue[propertyName];
|
|
44
|
+
if (value && typeof value === 'object') {
|
|
45
|
+
$deepFreeze(value);
|
|
165
46
|
}
|
|
166
|
-
finally { if (e_1) throw e_1.error; }
|
|
167
47
|
}
|
|
168
48
|
Object.freeze(objectValue);
|
|
169
49
|
return objectValue;
|
|
@@ -177,7 +57,7 @@ function $deepFreeze(objectValue) {
|
|
|
177
57
|
*
|
|
178
58
|
* @public exported from `@promptbook/core`
|
|
179
59
|
*/
|
|
180
|
-
|
|
60
|
+
const ZERO_USAGE = $deepFreeze({
|
|
181
61
|
price: { value: 0 },
|
|
182
62
|
input: {
|
|
183
63
|
tokensCount: { value: 0 },
|
|
@@ -247,38 +127,38 @@ function $getCurrentDate() {
|
|
|
247
127
|
*
|
|
248
128
|
* @public exported from `@promptbook/core`
|
|
249
129
|
*/
|
|
250
|
-
|
|
130
|
+
const NAME = `Promptbook`;
|
|
251
131
|
/**
|
|
252
132
|
* Email of the responsible person
|
|
253
133
|
*
|
|
254
134
|
* @public exported from `@promptbook/core`
|
|
255
135
|
*/
|
|
256
|
-
|
|
136
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
257
137
|
/**
|
|
258
138
|
* Name of the responsible person for the Promptbook on GitHub
|
|
259
139
|
*
|
|
260
140
|
* @public exported from `@promptbook/core`
|
|
261
141
|
*/
|
|
262
|
-
|
|
142
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
263
143
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
264
144
|
/**
|
|
265
145
|
* The maximum number of iterations for a loops
|
|
266
146
|
*
|
|
267
147
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
268
148
|
*/
|
|
269
|
-
|
|
149
|
+
const LOOP_LIMIT = 1000;
|
|
270
150
|
/**
|
|
271
151
|
* The maximum number of iterations for a loops which adds characters one by one
|
|
272
152
|
*
|
|
273
153
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
274
154
|
*/
|
|
275
|
-
|
|
155
|
+
const CHARACTER_LOOP_LIMIT = 100000;
|
|
276
156
|
/**
|
|
277
157
|
* Strings to represent various values in the context of parameter values
|
|
278
158
|
*
|
|
279
159
|
* @public exported from `@promptbook/utils`
|
|
280
160
|
*/
|
|
281
|
-
|
|
161
|
+
const VALUE_STRINGS = {
|
|
282
162
|
empty: '(nothing; empty string)',
|
|
283
163
|
null: '(no value; null)',
|
|
284
164
|
undefined: '(unknown value; undefined)',
|
|
@@ -292,7 +172,7 @@ var VALUE_STRINGS = {
|
|
|
292
172
|
*
|
|
293
173
|
* @public exported from `@promptbook/utils`
|
|
294
174
|
*/
|
|
295
|
-
|
|
175
|
+
const SMALL_NUMBER = 0.001;
|
|
296
176
|
// <- TODO: [🧜♂️]
|
|
297
177
|
/**
|
|
298
178
|
* @@@
|
|
@@ -317,8 +197,11 @@ Object.freeze({
|
|
|
317
197
|
* @public exported from `@promptbook/utils`
|
|
318
198
|
*/
|
|
319
199
|
function orderJson(options) {
|
|
320
|
-
|
|
321
|
-
|
|
200
|
+
const { value, order } = options;
|
|
201
|
+
const orderedValue = {
|
|
202
|
+
...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
|
|
203
|
+
...value,
|
|
204
|
+
};
|
|
322
205
|
return orderedValue;
|
|
323
206
|
}
|
|
324
207
|
|
|
@@ -328,11 +211,37 @@ function orderJson(options) {
|
|
|
328
211
|
* @private private within the repository
|
|
329
212
|
*/
|
|
330
213
|
function getErrorReportUrl(error) {
|
|
331
|
-
|
|
332
|
-
title:
|
|
333
|
-
body: spaceTrim(
|
|
214
|
+
const report = {
|
|
215
|
+
title: `🐜 Error report from ${NAME}`,
|
|
216
|
+
body: spaceTrim((block) => `
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
220
|
+
|
|
221
|
+
\`\`\`
|
|
222
|
+
${block(error.message || '(no error message)')}
|
|
223
|
+
\`\`\`
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
## More info:
|
|
227
|
+
|
|
228
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
229
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
230
|
+
- **Time:** ${new Date().toISOString()}
|
|
231
|
+
|
|
232
|
+
<details>
|
|
233
|
+
<summary>Stack trace:</summary>
|
|
234
|
+
|
|
235
|
+
## Stack trace:
|
|
236
|
+
|
|
237
|
+
\`\`\`stacktrace
|
|
238
|
+
${block(error.stack || '(empty)')}
|
|
239
|
+
\`\`\`
|
|
240
|
+
</details>
|
|
241
|
+
|
|
242
|
+
`),
|
|
334
243
|
};
|
|
335
|
-
|
|
244
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
336
245
|
reportUrl.searchParams.set('labels', 'bug');
|
|
337
246
|
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
338
247
|
reportUrl.searchParams.set('title', report.title);
|
|
@@ -345,16 +254,24 @@ function getErrorReportUrl(error) {
|
|
|
345
254
|
*
|
|
346
255
|
* @public exported from `@promptbook/core`
|
|
347
256
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
257
|
+
class UnexpectedError extends Error {
|
|
258
|
+
constructor(message) {
|
|
259
|
+
super(spaceTrim$1((block) => `
|
|
260
|
+
${block(message)}
|
|
261
|
+
|
|
262
|
+
Note: This error should not happen.
|
|
263
|
+
It's probbably a bug in the pipeline collection
|
|
264
|
+
|
|
265
|
+
Please report issue:
|
|
266
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
267
|
+
|
|
268
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
269
|
+
|
|
270
|
+
`));
|
|
271
|
+
this.name = 'UnexpectedError';
|
|
272
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
355
273
|
}
|
|
356
|
-
|
|
357
|
-
}(Error));
|
|
274
|
+
}
|
|
358
275
|
|
|
359
276
|
/**
|
|
360
277
|
* Checks if the value is [🚉] serializable as JSON
|
|
@@ -377,10 +294,9 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
377
294
|
* @public exported from `@promptbook/utils`
|
|
378
295
|
*/
|
|
379
296
|
function checkSerializableAsJson(options) {
|
|
380
|
-
|
|
381
|
-
var value = options.value, name = options.name, message = options.message;
|
|
297
|
+
const { value, name, message } = options;
|
|
382
298
|
if (value === undefined) {
|
|
383
|
-
throw new UnexpectedError(
|
|
299
|
+
throw new UnexpectedError(`${name} is undefined`);
|
|
384
300
|
}
|
|
385
301
|
else if (value === null) {
|
|
386
302
|
return;
|
|
@@ -395,49 +311,54 @@ function checkSerializableAsJson(options) {
|
|
|
395
311
|
return;
|
|
396
312
|
}
|
|
397
313
|
else if (typeof value === 'symbol') {
|
|
398
|
-
throw new UnexpectedError(
|
|
314
|
+
throw new UnexpectedError(`${name} is symbol`);
|
|
399
315
|
}
|
|
400
316
|
else if (typeof value === 'function') {
|
|
401
|
-
throw new UnexpectedError(
|
|
317
|
+
throw new UnexpectedError(`${name} is function`);
|
|
402
318
|
}
|
|
403
319
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
404
|
-
for (
|
|
405
|
-
checkSerializableAsJson({ name:
|
|
320
|
+
for (let i = 0; i < value.length; i++) {
|
|
321
|
+
checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
|
|
406
322
|
}
|
|
407
323
|
}
|
|
408
324
|
else if (typeof value === 'object') {
|
|
409
325
|
if (value instanceof Date) {
|
|
410
|
-
throw new UnexpectedError(spaceTrim(
|
|
326
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
327
|
+
\`${name}\` is Date
|
|
328
|
+
|
|
329
|
+
Use \`string_date_iso8601\` instead
|
|
330
|
+
|
|
331
|
+
Additional message for \`${name}\`:
|
|
332
|
+
${block(message || '(nothing)')}
|
|
333
|
+
`));
|
|
411
334
|
}
|
|
412
335
|
else if (value instanceof Map) {
|
|
413
|
-
throw new UnexpectedError(
|
|
336
|
+
throw new UnexpectedError(`${name} is Map`);
|
|
414
337
|
}
|
|
415
338
|
else if (value instanceof Set) {
|
|
416
|
-
throw new UnexpectedError(
|
|
339
|
+
throw new UnexpectedError(`${name} is Set`);
|
|
417
340
|
}
|
|
418
341
|
else if (value instanceof RegExp) {
|
|
419
|
-
throw new UnexpectedError(
|
|
342
|
+
throw new UnexpectedError(`${name} is RegExp`);
|
|
420
343
|
}
|
|
421
344
|
else if (value instanceof Error) {
|
|
422
|
-
throw new UnexpectedError(spaceTrim(
|
|
345
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
346
|
+
\`${name}\` is unserialized Error
|
|
347
|
+
|
|
348
|
+
Use function \`serializeError\`
|
|
349
|
+
|
|
350
|
+
Additional message for \`${name}\`:
|
|
351
|
+
${block(message || '(nothing)')}
|
|
352
|
+
|
|
353
|
+
`));
|
|
423
354
|
}
|
|
424
355
|
else {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// Note: undefined in object is serializable - it is just omited
|
|
430
|
-
continue;
|
|
431
|
-
}
|
|
432
|
-
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
436
|
-
finally {
|
|
437
|
-
try {
|
|
438
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
356
|
+
for (const [subName, subValue] of Object.entries(value)) {
|
|
357
|
+
if (subValue === undefined) {
|
|
358
|
+
// Note: undefined in object is serializable - it is just omited
|
|
359
|
+
continue;
|
|
439
360
|
}
|
|
440
|
-
|
|
361
|
+
checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
|
|
441
362
|
}
|
|
442
363
|
try {
|
|
443
364
|
JSON.stringify(value); // <- TODO: [0]
|
|
@@ -446,7 +367,14 @@ function checkSerializableAsJson(options) {
|
|
|
446
367
|
if (!(error instanceof Error)) {
|
|
447
368
|
throw error;
|
|
448
369
|
}
|
|
449
|
-
throw new UnexpectedError(spaceTrim(
|
|
370
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
371
|
+
\`${name}\` is not serializable
|
|
372
|
+
|
|
373
|
+
${block(error.stack || error.message)}
|
|
374
|
+
|
|
375
|
+
Additional message for \`${name}\`:
|
|
376
|
+
${block(message || '(nothing)')}
|
|
377
|
+
`));
|
|
450
378
|
}
|
|
451
379
|
/*
|
|
452
380
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -471,7 +399,12 @@ function checkSerializableAsJson(options) {
|
|
|
471
399
|
}
|
|
472
400
|
}
|
|
473
401
|
else {
|
|
474
|
-
throw new UnexpectedError(spaceTrim(
|
|
402
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
403
|
+
\`${name}\` is unknown type
|
|
404
|
+
|
|
405
|
+
Additional message for \`${name}\`:
|
|
406
|
+
${block(message || '(nothing)')}
|
|
407
|
+
`));
|
|
475
408
|
}
|
|
476
409
|
}
|
|
477
410
|
/**
|
|
@@ -517,9 +450,9 @@ function deepClone(objectValue) {
|
|
|
517
450
|
* @public exported from `@promptbook/utils`
|
|
518
451
|
*/
|
|
519
452
|
function exportJson(options) {
|
|
520
|
-
|
|
521
|
-
checkSerializableAsJson({ name
|
|
522
|
-
|
|
453
|
+
const { name, value, order, message } = options;
|
|
454
|
+
checkSerializableAsJson({ name, value, message });
|
|
455
|
+
const orderedValue =
|
|
523
456
|
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
524
457
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
525
458
|
// @ts-ignore
|
|
@@ -542,19 +475,19 @@ function exportJson(options) {
|
|
|
542
475
|
*
|
|
543
476
|
* @private within the repository
|
|
544
477
|
*/
|
|
545
|
-
|
|
478
|
+
const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
546
479
|
/**
|
|
547
480
|
* @@@
|
|
548
481
|
*
|
|
549
482
|
* @private within the repository
|
|
550
483
|
*/
|
|
551
|
-
|
|
484
|
+
const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
552
485
|
/**
|
|
553
486
|
* @@@
|
|
554
487
|
*
|
|
555
488
|
* @private within the repository
|
|
556
489
|
*/
|
|
557
|
-
|
|
490
|
+
const RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
558
491
|
/**
|
|
559
492
|
* The names of the parameters that are reserved for special purposes
|
|
560
493
|
*
|
|
@@ -562,7 +495,7 @@ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
|
562
495
|
*/
|
|
563
496
|
exportJson({
|
|
564
497
|
name: 'RESERVED_PARAMETER_NAMES',
|
|
565
|
-
message:
|
|
498
|
+
message: `The names of the parameters that are reserved for special purposes`,
|
|
566
499
|
value: [
|
|
567
500
|
'content',
|
|
568
501
|
'context',
|
|
@@ -584,32 +517,26 @@ exportJson({
|
|
|
584
517
|
*
|
|
585
518
|
* @public exported from `@promptbook/core`
|
|
586
519
|
*/
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
593
|
-
return _this;
|
|
520
|
+
class LimitReachedError extends Error {
|
|
521
|
+
constructor(message) {
|
|
522
|
+
super(message);
|
|
523
|
+
this.name = 'LimitReachedError';
|
|
524
|
+
Object.setPrototypeOf(this, LimitReachedError.prototype);
|
|
594
525
|
}
|
|
595
|
-
|
|
596
|
-
}(Error));
|
|
526
|
+
}
|
|
597
527
|
|
|
598
528
|
/**
|
|
599
529
|
* This error indicates errors during the execution of the pipeline
|
|
600
530
|
*
|
|
601
531
|
* @public exported from `@promptbook/core`
|
|
602
532
|
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
609
|
-
return _this;
|
|
533
|
+
class PipelineExecutionError extends Error {
|
|
534
|
+
constructor(message) {
|
|
535
|
+
super(message);
|
|
536
|
+
this.name = 'PipelineExecutionError';
|
|
537
|
+
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
610
538
|
}
|
|
611
|
-
|
|
612
|
-
}(Error));
|
|
539
|
+
}
|
|
613
540
|
|
|
614
541
|
/**
|
|
615
542
|
* Format either small or big number
|
|
@@ -629,9 +556,9 @@ function numberToString(value) {
|
|
|
629
556
|
else if (value === -Infinity) {
|
|
630
557
|
return VALUE_STRINGS.negativeInfinity;
|
|
631
558
|
}
|
|
632
|
-
for (
|
|
633
|
-
|
|
634
|
-
|
|
559
|
+
for (let exponent = 0; exponent < 15; exponent++) {
|
|
560
|
+
const factor = 10 ** exponent;
|
|
561
|
+
const valueRounded = Math.round(value * factor) / factor;
|
|
635
562
|
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
636
563
|
return valueRounded.toFixed(exponent);
|
|
637
564
|
}
|
|
@@ -699,47 +626,38 @@ function valueToString(value) {
|
|
|
699
626
|
* @public exported from `@promptbook/utils`
|
|
700
627
|
*/
|
|
701
628
|
function templateParameters(template, parameters) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
706
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
707
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
708
|
-
}
|
|
709
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
710
|
-
// TODO: [🍵]
|
|
711
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
712
|
-
}
|
|
629
|
+
for (const [parameterName, parameterValue] of Object.entries(parameters)) {
|
|
630
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
631
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
|
|
713
632
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
try {
|
|
718
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
633
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
634
|
+
// TODO: [🍵]
|
|
635
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
|
|
719
636
|
}
|
|
720
|
-
finally { if (e_1) throw e_1.error; }
|
|
721
637
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
638
|
+
let replacedTemplates = template;
|
|
639
|
+
let match;
|
|
640
|
+
let loopLimit = LOOP_LIMIT;
|
|
641
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
642
|
+
.exec(replacedTemplates))) {
|
|
726
643
|
if (loopLimit-- < 0) {
|
|
727
644
|
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
728
645
|
}
|
|
729
|
-
|
|
730
|
-
|
|
646
|
+
const precol = match.groups.precol;
|
|
647
|
+
const parameterName = match.groups.parameterName;
|
|
731
648
|
if (parameterName === '') {
|
|
732
|
-
|
|
649
|
+
// Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
|
|
650
|
+
continue;
|
|
733
651
|
}
|
|
734
652
|
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
735
653
|
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
736
654
|
}
|
|
737
655
|
if (parameters[parameterName] === undefined) {
|
|
738
|
-
throw new PipelineExecutionError(
|
|
656
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
739
657
|
}
|
|
740
|
-
|
|
658
|
+
let parameterValue = parameters[parameterName];
|
|
741
659
|
if (parameterValue === undefined) {
|
|
742
|
-
throw new PipelineExecutionError(
|
|
660
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
743
661
|
}
|
|
744
662
|
parameterValue = valueToString(parameterValue);
|
|
745
663
|
// Escape curly braces in parameter values to prevent prompt-injection
|
|
@@ -747,17 +665,13 @@ function templateParameters(template, parameters) {
|
|
|
747
665
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
748
666
|
parameterValue = parameterValue
|
|
749
667
|
.split('\n')
|
|
750
|
-
.map(
|
|
668
|
+
.map((line, index) => (index === 0 ? line : `${precol}${line}`))
|
|
751
669
|
.join('\n');
|
|
752
670
|
}
|
|
753
671
|
replacedTemplates =
|
|
754
672
|
replacedTemplates.substring(0, match.index + precol.length) +
|
|
755
673
|
parameterValue +
|
|
756
674
|
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
757
|
-
};
|
|
758
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
759
|
-
.exec(replacedTemplates))) {
|
|
760
|
-
_loop_1();
|
|
761
675
|
}
|
|
762
676
|
// [💫] Check if there are parameters that are not closed properly
|
|
763
677
|
if (/{\w+$/.test(replacedTemplates)) {
|
|
@@ -775,33 +689,24 @@ function templateParameters(template, parameters) {
|
|
|
775
689
|
*
|
|
776
690
|
* @public exported from `@promptbook/fake-llm`
|
|
777
691
|
*/
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
if (options === void 0) { options = {}; }
|
|
692
|
+
class MockedEchoLlmExecutionTools {
|
|
693
|
+
constructor(options = {}) {
|
|
781
694
|
this.options = options;
|
|
782
695
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
});
|
|
790
|
-
Object.defineProperty(MockedEchoLlmExecutionTools.prototype, "description", {
|
|
791
|
-
get: function () {
|
|
792
|
-
return 'What you say is whay you get - just for testing';
|
|
793
|
-
},
|
|
794
|
-
enumerable: false,
|
|
795
|
-
configurable: true
|
|
796
|
-
});
|
|
696
|
+
get title() {
|
|
697
|
+
return 'Mocked echo';
|
|
698
|
+
}
|
|
699
|
+
get description() {
|
|
700
|
+
return 'What you say is whay you get - just for testing';
|
|
701
|
+
}
|
|
797
702
|
/**
|
|
798
703
|
* Does nothing, just to implement the interface
|
|
799
704
|
*/
|
|
800
|
-
|
|
705
|
+
checkConfiguration() { }
|
|
801
706
|
/**
|
|
802
707
|
* List all available mocked-models that can be used
|
|
803
708
|
*/
|
|
804
|
-
|
|
709
|
+
listModels() {
|
|
805
710
|
return [
|
|
806
711
|
{
|
|
807
712
|
modelTitle: 'Echo chat',
|
|
@@ -815,83 +720,78 @@ var MockedEchoLlmExecutionTools = /** @class */ (function () {
|
|
|
815
720
|
},
|
|
816
721
|
// <- Note: [🤖]
|
|
817
722
|
];
|
|
818
|
-
}
|
|
723
|
+
}
|
|
819
724
|
/**
|
|
820
725
|
* Mocks chat model
|
|
821
726
|
*/
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
})];
|
|
853
|
-
});
|
|
727
|
+
async callChatModel(prompt) {
|
|
728
|
+
if (this.options.isVerbose) {
|
|
729
|
+
console.info('💬 Mocked callChatModel call');
|
|
730
|
+
}
|
|
731
|
+
const modelName = 'mocked-echo';
|
|
732
|
+
const rawPromptContent = templateParameters(prompt.content, { ...prompt.parameters, modelName });
|
|
733
|
+
const usage = ZERO_USAGE;
|
|
734
|
+
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
735
|
+
return exportJson({
|
|
736
|
+
name: 'promptResult',
|
|
737
|
+
message: `Result of \`MockedEchoLlmExecutionTools.callChatModel\``,
|
|
738
|
+
order: [],
|
|
739
|
+
value: {
|
|
740
|
+
content: spaceTrim$1((block) => `
|
|
741
|
+
You said:
|
|
742
|
+
${block(rawPromptContent)}
|
|
743
|
+
`),
|
|
744
|
+
modelName,
|
|
745
|
+
timing: {
|
|
746
|
+
start: $getCurrentDate(),
|
|
747
|
+
complete: $getCurrentDate(),
|
|
748
|
+
},
|
|
749
|
+
usage,
|
|
750
|
+
rawPromptContent,
|
|
751
|
+
rawRequest: null,
|
|
752
|
+
rawResponse: {
|
|
753
|
+
note: 'This is mocked echo',
|
|
754
|
+
},
|
|
755
|
+
// <- [🗯]
|
|
756
|
+
},
|
|
854
757
|
});
|
|
855
|
-
}
|
|
758
|
+
}
|
|
856
759
|
/**
|
|
857
760
|
* Mocks completion model
|
|
858
761
|
*/
|
|
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
|
-
});
|
|
762
|
+
async callCompletionModel(prompt) {
|
|
763
|
+
if (this.options.isVerbose) {
|
|
764
|
+
console.info('🖋 Mocked callCompletionModel call');
|
|
765
|
+
}
|
|
766
|
+
const modelName = 'mocked-echo';
|
|
767
|
+
const rawPromptContent = templateParameters(prompt.content, { ...prompt.parameters, modelName });
|
|
768
|
+
const usage = ZERO_USAGE;
|
|
769
|
+
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
770
|
+
return exportJson({
|
|
771
|
+
name: 'promptResult',
|
|
772
|
+
message: `Result of \`MockedEchoLlmExecutionTools.callCompletionModel\``,
|
|
773
|
+
order: [],
|
|
774
|
+
value: {
|
|
775
|
+
content: spaceTrim$1((block) => `
|
|
776
|
+
${block(rawPromptContent)}
|
|
777
|
+
And so on...
|
|
778
|
+
`),
|
|
779
|
+
modelName,
|
|
780
|
+
timing: {
|
|
781
|
+
start: $getCurrentDate(),
|
|
782
|
+
complete: $getCurrentDate(),
|
|
783
|
+
},
|
|
784
|
+
usage,
|
|
785
|
+
rawPromptContent,
|
|
786
|
+
rawRequest: null,
|
|
787
|
+
rawResponse: {
|
|
788
|
+
note: 'This is mocked echo',
|
|
789
|
+
},
|
|
790
|
+
// <- [🗯]
|
|
791
|
+
},
|
|
891
792
|
});
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
}());
|
|
793
|
+
}
|
|
794
|
+
}
|
|
895
795
|
/**
|
|
896
796
|
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
897
797
|
* TODO: Allow in spaceTrim: nesting with > ${block(prompt.request)}, same as replace params
|
|
@@ -905,16 +805,13 @@ var MockedEchoLlmExecutionTools = /** @class */ (function () {
|
|
|
905
805
|
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
906
806
|
* Note: This is a kindof subtype of PipelineExecutionError
|
|
907
807
|
*/
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
914
|
-
return _this;
|
|
808
|
+
class ExpectError extends Error {
|
|
809
|
+
constructor(message) {
|
|
810
|
+
super(message);
|
|
811
|
+
this.name = 'ExpectError';
|
|
812
|
+
Object.setPrototypeOf(this, ExpectError.prototype);
|
|
915
813
|
}
|
|
916
|
-
|
|
917
|
-
}(Error));
|
|
814
|
+
}
|
|
918
815
|
|
|
919
816
|
/**
|
|
920
817
|
* Counts number of characters in the text
|
|
@@ -936,13 +833,13 @@ function countCharacters(text) {
|
|
|
936
833
|
*
|
|
937
834
|
* @public exported from `@promptbook/utils`
|
|
938
835
|
*/
|
|
939
|
-
|
|
836
|
+
const CHARACTERS_PER_STANDARD_LINE = 63;
|
|
940
837
|
/**
|
|
941
838
|
* Number of lines per standard A4 page with 11pt Arial font size and standard margins and spacing.
|
|
942
839
|
*
|
|
943
840
|
* @public exported from `@promptbook/utils`
|
|
944
841
|
*/
|
|
945
|
-
|
|
842
|
+
const LINES_PER_STANDARD_PAGE = 44;
|
|
946
843
|
/**
|
|
947
844
|
* TODO: [🧠] Should be this `constants.ts` or `config.ts`?
|
|
948
845
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -958,8 +855,8 @@ var LINES_PER_STANDARD_PAGE = 44;
|
|
|
958
855
|
function countLines(text) {
|
|
959
856
|
text = text.replace('\r\n', '\n');
|
|
960
857
|
text = text.replace('\r', '\n');
|
|
961
|
-
|
|
962
|
-
return lines.reduce(
|
|
858
|
+
const lines = text.split('\n');
|
|
859
|
+
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
963
860
|
}
|
|
964
861
|
|
|
965
862
|
/**
|
|
@@ -979,7 +876,7 @@ function countPages(text) {
|
|
|
979
876
|
* @public exported from `@promptbook/utils`
|
|
980
877
|
*/
|
|
981
878
|
function countParagraphs(text) {
|
|
982
|
-
return text.split(/\n\s*\n/).filter(
|
|
879
|
+
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
983
880
|
}
|
|
984
881
|
|
|
985
882
|
/**
|
|
@@ -988,7 +885,7 @@ function countParagraphs(text) {
|
|
|
988
885
|
* @public exported from `@promptbook/utils`
|
|
989
886
|
*/
|
|
990
887
|
function splitIntoSentences(text) {
|
|
991
|
-
return text.split(/[.!?]+/).filter(
|
|
888
|
+
return text.split(/[.!?]+/).filter((sentence) => sentence.trim() !== '');
|
|
992
889
|
}
|
|
993
890
|
/**
|
|
994
891
|
* Counts number of sentences in the text
|
|
@@ -999,7 +896,7 @@ function countSentences(text) {
|
|
|
999
896
|
return splitIntoSentences(text).length;
|
|
1000
897
|
}
|
|
1001
898
|
|
|
1002
|
-
|
|
899
|
+
const defaultDiacriticsRemovalMap = [
|
|
1003
900
|
{
|
|
1004
901
|
base: 'A',
|
|
1005
902
|
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
@@ -1218,12 +1115,12 @@ var defaultDiacriticsRemovalMap = [
|
|
|
1218
1115
|
*
|
|
1219
1116
|
* @public exported from `@promptbook/utils`
|
|
1220
1117
|
*/
|
|
1221
|
-
|
|
1118
|
+
const DIACRITIC_VARIANTS_LETTERS = {};
|
|
1222
1119
|
// tslint:disable-next-line: prefer-for-of
|
|
1223
|
-
for (
|
|
1224
|
-
|
|
1120
|
+
for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
1121
|
+
const letters = defaultDiacriticsRemovalMap[i].letters;
|
|
1225
1122
|
// tslint:disable-next-line: prefer-for-of
|
|
1226
|
-
for (
|
|
1123
|
+
for (let j = 0; j < letters.length; j++) {
|
|
1227
1124
|
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
1228
1125
|
}
|
|
1229
1126
|
}
|
|
@@ -1252,7 +1149,7 @@ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
|
1252
1149
|
*/
|
|
1253
1150
|
function removeDiacritics(input) {
|
|
1254
1151
|
/*eslint no-control-regex: "off"*/
|
|
1255
|
-
return input.replace(/[^\u0000-\u007E]/g,
|
|
1152
|
+
return input.replace(/[^\u0000-\u007E]/g, (a) => {
|
|
1256
1153
|
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1257
1154
|
});
|
|
1258
1155
|
}
|
|
@@ -1268,7 +1165,9 @@ function removeDiacritics(input) {
|
|
|
1268
1165
|
function countWords(text) {
|
|
1269
1166
|
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
1270
1167
|
text = removeDiacritics(text);
|
|
1271
|
-
|
|
1168
|
+
// Add spaces before uppercase letters preceded by lowercase letters (for camelCase)
|
|
1169
|
+
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
1170
|
+
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
1272
1171
|
}
|
|
1273
1172
|
|
|
1274
1173
|
/**
|
|
@@ -1276,7 +1175,7 @@ function countWords(text) {
|
|
|
1276
1175
|
*
|
|
1277
1176
|
* @public exported from `@promptbook/utils`
|
|
1278
1177
|
*/
|
|
1279
|
-
|
|
1178
|
+
const CountUtils = {
|
|
1280
1179
|
CHARACTERS: countCharacters,
|
|
1281
1180
|
WORDS: countWords,
|
|
1282
1181
|
SENTENCES: countSentences,
|
|
@@ -1301,26 +1200,15 @@ var CountUtils = {
|
|
|
1301
1200
|
* @private internal function of `createPipelineExecutor`
|
|
1302
1201
|
*/
|
|
1303
1202
|
function checkExpectations(expectations, value) {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
} /* not else */
|
|
1312
|
-
if (max && amount > max) {
|
|
1313
|
-
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
1314
|
-
}
|
|
1203
|
+
for (const [unit, { max, min }] of Object.entries(expectations)) {
|
|
1204
|
+
const amount = CountUtils[unit.toUpperCase()](value);
|
|
1205
|
+
if (min && amount < min) {
|
|
1206
|
+
throw new ExpectError(`Expected at least ${min} ${unit} but got ${amount}`);
|
|
1207
|
+
} /* not else */
|
|
1208
|
+
if (max && amount > max) {
|
|
1209
|
+
throw new ExpectError(`Expected at most ${max} ${unit} but got ${amount}`);
|
|
1315
1210
|
}
|
|
1316
1211
|
}
|
|
1317
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1318
|
-
finally {
|
|
1319
|
-
try {
|
|
1320
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1321
|
-
}
|
|
1322
|
-
finally { if (e_1) throw e_1.error; }
|
|
1323
|
-
}
|
|
1324
1212
|
}
|
|
1325
1213
|
/**
|
|
1326
1214
|
* Function checkExpectations will check if the expectations on given value are met
|
|
@@ -1360,53 +1248,41 @@ function isPassingExpectations(expectations, value) {
|
|
|
1360
1248
|
* @example 'iLovePromptbook'
|
|
1361
1249
|
* @public exported from `@promptbook/utils`
|
|
1362
1250
|
*/
|
|
1363
|
-
function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
normalizedChar =
|
|
1388
|
-
}
|
|
1389
|
-
if (!lastCharType) {
|
|
1390
|
-
if (_isFirstLetterCapital) {
|
|
1391
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
else if (charType !== lastCharType &&
|
|
1395
|
-
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
1396
|
-
!(lastCharType === 'NUMBER') &&
|
|
1397
|
-
!(charType === 'NUMBER')) {
|
|
1398
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
1251
|
+
function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
|
|
1252
|
+
let charType;
|
|
1253
|
+
let lastCharType = null;
|
|
1254
|
+
let normalizedName = '';
|
|
1255
|
+
for (const char of text) {
|
|
1256
|
+
let normalizedChar;
|
|
1257
|
+
if (/^[a-z]$/.test(char)) {
|
|
1258
|
+
charType = 'LOWERCASE';
|
|
1259
|
+
normalizedChar = char;
|
|
1260
|
+
}
|
|
1261
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
1262
|
+
charType = 'UPPERCASE';
|
|
1263
|
+
normalizedChar = char.toLowerCase();
|
|
1264
|
+
}
|
|
1265
|
+
else if (/^[0-9]$/.test(char)) {
|
|
1266
|
+
charType = 'NUMBER';
|
|
1267
|
+
normalizedChar = char;
|
|
1268
|
+
}
|
|
1269
|
+
else {
|
|
1270
|
+
charType = 'OTHER';
|
|
1271
|
+
normalizedChar = '';
|
|
1272
|
+
}
|
|
1273
|
+
if (!lastCharType) {
|
|
1274
|
+
if (_isFirstLetterCapital) {
|
|
1275
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
1399
1276
|
}
|
|
1400
|
-
normalizedName += normalizedChar;
|
|
1401
|
-
lastCharType = charType;
|
|
1402
1277
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1278
|
+
else if (charType !== lastCharType &&
|
|
1279
|
+
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
1280
|
+
!(lastCharType === 'NUMBER') &&
|
|
1281
|
+
!(charType === 'NUMBER')) {
|
|
1282
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
1408
1283
|
}
|
|
1409
|
-
|
|
1284
|
+
normalizedName += normalizedChar;
|
|
1285
|
+
lastCharType = charType;
|
|
1410
1286
|
}
|
|
1411
1287
|
return normalizedName;
|
|
1412
1288
|
}
|
|
@@ -1440,47 +1316,36 @@ function removeEmojis(text) {
|
|
|
1440
1316
|
* @public exported from `@promptbook/utils`
|
|
1441
1317
|
*/
|
|
1442
1318
|
function normalizeToKebabCase(text) {
|
|
1443
|
-
var e_1, _a;
|
|
1444
1319
|
text = removeDiacritics(text);
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
charType = 'LOWERCASE';
|
|
1454
|
-
normalizedChar = char;
|
|
1455
|
-
}
|
|
1456
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1457
|
-
charType = 'UPPERCASE';
|
|
1458
|
-
normalizedChar = char.toLowerCase();
|
|
1459
|
-
}
|
|
1460
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1461
|
-
charType = 'NUMBER';
|
|
1462
|
-
normalizedChar = char;
|
|
1463
|
-
}
|
|
1464
|
-
else {
|
|
1465
|
-
charType = 'OTHER';
|
|
1466
|
-
normalizedChar = '-';
|
|
1467
|
-
}
|
|
1468
|
-
if (charType !== lastCharType &&
|
|
1469
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1470
|
-
!(lastCharType === 'NUMBER') &&
|
|
1471
|
-
!(charType === 'NUMBER')) {
|
|
1472
|
-
normalizedName += '-';
|
|
1473
|
-
}
|
|
1474
|
-
normalizedName += normalizedChar;
|
|
1475
|
-
lastCharType = charType;
|
|
1320
|
+
let charType;
|
|
1321
|
+
let lastCharType = 'OTHER';
|
|
1322
|
+
let normalizedName = '';
|
|
1323
|
+
for (const char of text) {
|
|
1324
|
+
let normalizedChar;
|
|
1325
|
+
if (/^[a-z]$/.test(char)) {
|
|
1326
|
+
charType = 'LOWERCASE';
|
|
1327
|
+
normalizedChar = char;
|
|
1476
1328
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
try {
|
|
1481
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
1329
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
1330
|
+
charType = 'UPPERCASE';
|
|
1331
|
+
normalizedChar = char.toLowerCase();
|
|
1482
1332
|
}
|
|
1483
|
-
|
|
1333
|
+
else if (/^[0-9]$/.test(char)) {
|
|
1334
|
+
charType = 'NUMBER';
|
|
1335
|
+
normalizedChar = char;
|
|
1336
|
+
}
|
|
1337
|
+
else {
|
|
1338
|
+
charType = 'OTHER';
|
|
1339
|
+
normalizedChar = '-';
|
|
1340
|
+
}
|
|
1341
|
+
if (charType !== lastCharType &&
|
|
1342
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1343
|
+
!(lastCharType === 'NUMBER') &&
|
|
1344
|
+
!(charType === 'NUMBER')) {
|
|
1345
|
+
normalizedName += '-';
|
|
1346
|
+
}
|
|
1347
|
+
normalizedName += normalizedChar;
|
|
1348
|
+
lastCharType = charType;
|
|
1484
1349
|
}
|
|
1485
1350
|
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
1486
1351
|
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
@@ -1497,221 +1362,31 @@ function normalizeToKebabCase(text) {
|
|
|
1497
1362
|
*
|
|
1498
1363
|
* @public exported from `@promptbook/core`
|
|
1499
1364
|
*/
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
1506
|
-
return _this;
|
|
1365
|
+
class ParseError extends Error {
|
|
1366
|
+
constructor(message) {
|
|
1367
|
+
super(message);
|
|
1368
|
+
this.name = 'ParseError';
|
|
1369
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
1507
1370
|
}
|
|
1508
|
-
|
|
1509
|
-
}(Error));
|
|
1371
|
+
}
|
|
1510
1372
|
/**
|
|
1511
1373
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1512
1374
|
*/
|
|
1513
1375
|
|
|
1514
|
-
/**
|
|
1515
|
-
* This error indicates problems parsing the format value
|
|
1516
|
-
*
|
|
1517
|
-
* For example, when the format value is not a valid JSON or CSV
|
|
1518
|
-
* This is not thrown directly but in extended classes
|
|
1519
|
-
*
|
|
1520
|
-
* @public exported from `@promptbook/core`
|
|
1521
|
-
*/
|
|
1522
|
-
var AbstractFormatError = /** @class */ (function (_super) {
|
|
1523
|
-
__extends(AbstractFormatError, _super);
|
|
1524
|
-
// Note: To allow instanceof do not put here error `name`
|
|
1525
|
-
// public readonly name = 'AbstractFormatError';
|
|
1526
|
-
function AbstractFormatError(message) {
|
|
1527
|
-
var _this = _super.call(this, message) || this;
|
|
1528
|
-
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
1529
|
-
return _this;
|
|
1530
|
-
}
|
|
1531
|
-
return AbstractFormatError;
|
|
1532
|
-
}(Error));
|
|
1533
|
-
|
|
1534
|
-
/**
|
|
1535
|
-
* This error indicates problem with parsing of CSV
|
|
1536
|
-
*
|
|
1537
|
-
* @public exported from `@promptbook/core`
|
|
1538
|
-
*/
|
|
1539
|
-
var CsvFormatError = /** @class */ (function (_super) {
|
|
1540
|
-
__extends(CsvFormatError, _super);
|
|
1541
|
-
function CsvFormatError(message) {
|
|
1542
|
-
var _this = _super.call(this, message) || this;
|
|
1543
|
-
_this.name = 'CsvFormatError';
|
|
1544
|
-
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
1545
|
-
return _this;
|
|
1546
|
-
}
|
|
1547
|
-
return CsvFormatError;
|
|
1548
|
-
}(AbstractFormatError));
|
|
1549
|
-
|
|
1550
|
-
/**
|
|
1551
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1552
|
-
*
|
|
1553
|
-
* @public exported from `@promptbook/core`
|
|
1554
|
-
*/
|
|
1555
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
1556
|
-
__extends(CollectionError, _super);
|
|
1557
|
-
function CollectionError(message) {
|
|
1558
|
-
var _this = _super.call(this, message) || this;
|
|
1559
|
-
_this.name = 'CollectionError';
|
|
1560
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
1561
|
-
return _this;
|
|
1562
|
-
}
|
|
1563
|
-
return CollectionError;
|
|
1564
|
-
}(Error));
|
|
1565
|
-
|
|
1566
|
-
/**
|
|
1567
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
1568
|
-
*
|
|
1569
|
-
* @public exported from `@promptbook/core`
|
|
1570
|
-
*/
|
|
1571
|
-
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
1572
|
-
__extends(EnvironmentMismatchError, _super);
|
|
1573
|
-
function EnvironmentMismatchError(message) {
|
|
1574
|
-
var _this = _super.call(this, message) || this;
|
|
1575
|
-
_this.name = 'EnvironmentMismatchError';
|
|
1576
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
1577
|
-
return _this;
|
|
1578
|
-
}
|
|
1579
|
-
return EnvironmentMismatchError;
|
|
1580
|
-
}(Error));
|
|
1581
|
-
|
|
1582
|
-
/**
|
|
1583
|
-
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
1584
|
-
*
|
|
1585
|
-
* @public exported from `@promptbook/core`
|
|
1586
|
-
*/
|
|
1587
|
-
var KnowledgeScrapeError = /** @class */ (function (_super) {
|
|
1588
|
-
__extends(KnowledgeScrapeError, _super);
|
|
1589
|
-
function KnowledgeScrapeError(message) {
|
|
1590
|
-
var _this = _super.call(this, message) || this;
|
|
1591
|
-
_this.name = 'KnowledgeScrapeError';
|
|
1592
|
-
Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
|
|
1593
|
-
return _this;
|
|
1594
|
-
}
|
|
1595
|
-
return KnowledgeScrapeError;
|
|
1596
|
-
}(Error));
|
|
1597
|
-
|
|
1598
|
-
/**
|
|
1599
|
-
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
1600
|
-
*
|
|
1601
|
-
* @public exported from `@promptbook/core`
|
|
1602
|
-
*/
|
|
1603
|
-
var MissingToolsError = /** @class */ (function (_super) {
|
|
1604
|
-
__extends(MissingToolsError, _super);
|
|
1605
|
-
function MissingToolsError(message) {
|
|
1606
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
|
|
1607
|
-
_this.name = 'MissingToolsError';
|
|
1608
|
-
Object.setPrototypeOf(_this, MissingToolsError.prototype);
|
|
1609
|
-
return _this;
|
|
1610
|
-
}
|
|
1611
|
-
return MissingToolsError;
|
|
1612
|
-
}(Error));
|
|
1613
|
-
|
|
1614
|
-
/**
|
|
1615
|
-
* This error indicates that promptbook not found in the collection
|
|
1616
|
-
*
|
|
1617
|
-
* @public exported from `@promptbook/core`
|
|
1618
|
-
*/
|
|
1619
|
-
var NotFoundError = /** @class */ (function (_super) {
|
|
1620
|
-
__extends(NotFoundError, _super);
|
|
1621
|
-
function NotFoundError(message) {
|
|
1622
|
-
var _this = _super.call(this, message) || this;
|
|
1623
|
-
_this.name = 'NotFoundError';
|
|
1624
|
-
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1625
|
-
return _this;
|
|
1626
|
-
}
|
|
1627
|
-
return NotFoundError;
|
|
1628
|
-
}(Error));
|
|
1629
|
-
|
|
1630
|
-
/**
|
|
1631
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
1632
|
-
*
|
|
1633
|
-
* @public exported from `@promptbook/core`
|
|
1634
|
-
*/
|
|
1635
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1636
|
-
__extends(NotYetImplementedError, _super);
|
|
1637
|
-
function NotYetImplementedError(message) {
|
|
1638
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on pavol@ptbk.io\n\n "); })) || this;
|
|
1639
|
-
_this.name = 'NotYetImplementedError';
|
|
1640
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1641
|
-
return _this;
|
|
1642
|
-
}
|
|
1643
|
-
return NotYetImplementedError;
|
|
1644
|
-
}(Error));
|
|
1645
|
-
|
|
1646
|
-
/**
|
|
1647
|
-
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
1648
|
-
*
|
|
1649
|
-
* @public exported from `@promptbook/core`
|
|
1650
|
-
*/
|
|
1651
|
-
var PipelineLogicError = /** @class */ (function (_super) {
|
|
1652
|
-
__extends(PipelineLogicError, _super);
|
|
1653
|
-
function PipelineLogicError(message) {
|
|
1654
|
-
var _this = _super.call(this, message) || this;
|
|
1655
|
-
_this.name = 'PipelineLogicError';
|
|
1656
|
-
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
1657
|
-
return _this;
|
|
1658
|
-
}
|
|
1659
|
-
return PipelineLogicError;
|
|
1660
|
-
}(Error));
|
|
1661
|
-
|
|
1662
|
-
/**
|
|
1663
|
-
* This error indicates errors in referencing promptbooks between each other
|
|
1664
|
-
*
|
|
1665
|
-
* @public exported from `@promptbook/core`
|
|
1666
|
-
*/
|
|
1667
|
-
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1668
|
-
__extends(PipelineUrlError, _super);
|
|
1669
|
-
function PipelineUrlError(message) {
|
|
1670
|
-
var _this = _super.call(this, message) || this;
|
|
1671
|
-
_this.name = 'PipelineUrlError';
|
|
1672
|
-
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1673
|
-
return _this;
|
|
1674
|
-
}
|
|
1675
|
-
return PipelineUrlError;
|
|
1676
|
-
}(Error));
|
|
1677
|
-
|
|
1678
|
-
/**
|
|
1679
|
-
* Index of all custom errors
|
|
1680
|
-
*
|
|
1681
|
-
* @public exported from `@promptbook/core`
|
|
1682
|
-
*/
|
|
1683
|
-
var PROMPTBOOK_ERRORS = {
|
|
1684
|
-
AbstractFormatError: AbstractFormatError,
|
|
1685
|
-
CsvFormatError: CsvFormatError,
|
|
1686
|
-
CollectionError: CollectionError,
|
|
1687
|
-
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
1688
|
-
ExpectError: ExpectError,
|
|
1689
|
-
KnowledgeScrapeError: KnowledgeScrapeError,
|
|
1690
|
-
LimitReachedError: LimitReachedError,
|
|
1691
|
-
MissingToolsError: MissingToolsError,
|
|
1692
|
-
NotFoundError: NotFoundError,
|
|
1693
|
-
NotYetImplementedError: NotYetImplementedError,
|
|
1694
|
-
ParseError: ParseError,
|
|
1695
|
-
PipelineExecutionError: PipelineExecutionError,
|
|
1696
|
-
PipelineLogicError: PipelineLogicError,
|
|
1697
|
-
PipelineUrlError: PipelineUrlError,
|
|
1698
|
-
UnexpectedError: UnexpectedError,
|
|
1699
|
-
// TODO: [🪑]> VersionMismatchError,
|
|
1700
|
-
};
|
|
1701
1376
|
/**
|
|
1702
1377
|
* Index of all javascript errors
|
|
1703
1378
|
*
|
|
1704
1379
|
* @private for internal usage
|
|
1705
1380
|
*/
|
|
1706
|
-
|
|
1707
|
-
Error
|
|
1708
|
-
EvalError
|
|
1709
|
-
RangeError
|
|
1710
|
-
ReferenceError
|
|
1711
|
-
SyntaxError
|
|
1712
|
-
TypeError
|
|
1713
|
-
URIError
|
|
1714
|
-
AggregateError
|
|
1381
|
+
({
|
|
1382
|
+
Error,
|
|
1383
|
+
EvalError,
|
|
1384
|
+
RangeError,
|
|
1385
|
+
ReferenceError,
|
|
1386
|
+
SyntaxError,
|
|
1387
|
+
TypeError,
|
|
1388
|
+
URIError,
|
|
1389
|
+
AggregateError,
|
|
1715
1390
|
/*
|
|
1716
1391
|
Note: Not widely supported
|
|
1717
1392
|
> InternalError,
|
|
@@ -1720,13 +1395,7 @@ var COMMON_JAVASCRIPT_ERRORS = {
|
|
|
1720
1395
|
> WebAssemblyCompileError,
|
|
1721
1396
|
> WebAssemblyRuntimeError,
|
|
1722
1397
|
*/
|
|
1723
|
-
};
|
|
1724
|
-
/**
|
|
1725
|
-
* Index of all errors
|
|
1726
|
-
*
|
|
1727
|
-
* @private for internal usage
|
|
1728
|
-
*/
|
|
1729
|
-
__assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
1398
|
+
});
|
|
1730
1399
|
/**
|
|
1731
1400
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1732
1401
|
*/
|
|
@@ -1738,7 +1407,13 @@ __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
|
1738
1407
|
*
|
|
1739
1408
|
* @public exported from `@promptbook/utils`
|
|
1740
1409
|
*/
|
|
1741
|
-
new Function(
|
|
1410
|
+
new Function(`
|
|
1411
|
+
try {
|
|
1412
|
+
return this === window;
|
|
1413
|
+
} catch (e) {
|
|
1414
|
+
return false;
|
|
1415
|
+
}
|
|
1416
|
+
`);
|
|
1742
1417
|
/**
|
|
1743
1418
|
* TODO: [🎺]
|
|
1744
1419
|
*/
|
|
@@ -1750,7 +1425,13 @@ new Function("\n try {\n return this === window;\n } catch (e) {\n
|
|
|
1750
1425
|
*
|
|
1751
1426
|
* @public exported from `@promptbook/utils`
|
|
1752
1427
|
*/
|
|
1753
|
-
new Function(
|
|
1428
|
+
new Function(`
|
|
1429
|
+
try {
|
|
1430
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
1431
|
+
} catch (e) {
|
|
1432
|
+
return false;
|
|
1433
|
+
}
|
|
1434
|
+
`);
|
|
1754
1435
|
/**
|
|
1755
1436
|
* TODO: [🎺]
|
|
1756
1437
|
*/
|
|
@@ -1762,7 +1443,13 @@ new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefin
|
|
|
1762
1443
|
*
|
|
1763
1444
|
* @public exported from `@promptbook/utils`
|
|
1764
1445
|
*/
|
|
1765
|
-
new Function(
|
|
1446
|
+
new Function(`
|
|
1447
|
+
try {
|
|
1448
|
+
return this === global;
|
|
1449
|
+
} catch (e) {
|
|
1450
|
+
return false;
|
|
1451
|
+
}
|
|
1452
|
+
`);
|
|
1766
1453
|
/**
|
|
1767
1454
|
* TODO: [🎺]
|
|
1768
1455
|
*/
|
|
@@ -1774,7 +1461,17 @@ new Function("\n try {\n return this === global;\n } catch (e) {\n
|
|
|
1774
1461
|
*
|
|
1775
1462
|
* @public exported from `@promptbook/utils`
|
|
1776
1463
|
*/
|
|
1777
|
-
new Function(
|
|
1464
|
+
new Function(`
|
|
1465
|
+
try {
|
|
1466
|
+
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
|
|
1467
|
+
return true;
|
|
1468
|
+
} else {
|
|
1469
|
+
return false;
|
|
1470
|
+
}
|
|
1471
|
+
} catch (e) {
|
|
1472
|
+
return false;
|
|
1473
|
+
}
|
|
1474
|
+
`);
|
|
1778
1475
|
/**
|
|
1779
1476
|
* TODO: [🎺]
|
|
1780
1477
|
*/
|
|
@@ -1807,46 +1504,35 @@ function decapitalize(word) {
|
|
|
1807
1504
|
* @public exported from `@promptbook/utils`
|
|
1808
1505
|
*/
|
|
1809
1506
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
if (/^[a-z]$/.test(char)) {
|
|
1819
|
-
charType = 'LOWERCASE';
|
|
1820
|
-
normalizedChar = char.toUpperCase();
|
|
1821
|
-
}
|
|
1822
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1823
|
-
charType = 'UPPERCASE';
|
|
1824
|
-
normalizedChar = char;
|
|
1825
|
-
}
|
|
1826
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1827
|
-
charType = 'NUMBER';
|
|
1828
|
-
normalizedChar = char;
|
|
1829
|
-
}
|
|
1830
|
-
else {
|
|
1831
|
-
charType = 'OTHER';
|
|
1832
|
-
normalizedChar = '_';
|
|
1833
|
-
}
|
|
1834
|
-
if (charType !== lastCharType &&
|
|
1835
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1836
|
-
!(lastCharType === 'NUMBER') &&
|
|
1837
|
-
!(charType === 'NUMBER')) {
|
|
1838
|
-
normalizedName += '_';
|
|
1839
|
-
}
|
|
1840
|
-
normalizedName += normalizedChar;
|
|
1841
|
-
lastCharType = charType;
|
|
1507
|
+
let charType;
|
|
1508
|
+
let lastCharType = 'OTHER';
|
|
1509
|
+
let normalizedName = '';
|
|
1510
|
+
for (const char of text) {
|
|
1511
|
+
let normalizedChar;
|
|
1512
|
+
if (/^[a-z]$/.test(char)) {
|
|
1513
|
+
charType = 'LOWERCASE';
|
|
1514
|
+
normalizedChar = char.toUpperCase();
|
|
1842
1515
|
}
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
try {
|
|
1847
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
1516
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
1517
|
+
charType = 'UPPERCASE';
|
|
1518
|
+
normalizedChar = char;
|
|
1848
1519
|
}
|
|
1849
|
-
|
|
1520
|
+
else if (/^[0-9]$/.test(char)) {
|
|
1521
|
+
charType = 'NUMBER';
|
|
1522
|
+
normalizedChar = char;
|
|
1523
|
+
}
|
|
1524
|
+
else {
|
|
1525
|
+
charType = 'OTHER';
|
|
1526
|
+
normalizedChar = '_';
|
|
1527
|
+
}
|
|
1528
|
+
if (charType !== lastCharType &&
|
|
1529
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1530
|
+
!(lastCharType === 'NUMBER') &&
|
|
1531
|
+
!(charType === 'NUMBER')) {
|
|
1532
|
+
normalizedName += '_';
|
|
1533
|
+
}
|
|
1534
|
+
normalizedName += normalizedChar;
|
|
1535
|
+
lastCharType = charType;
|
|
1850
1536
|
}
|
|
1851
1537
|
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
1852
1538
|
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
@@ -1871,10 +1557,10 @@ function normalizeTo_SCREAMING_CASE(text) {
|
|
|
1871
1557
|
* @public exported from `@promptbook/utils`
|
|
1872
1558
|
*/
|
|
1873
1559
|
function parseKeywordsFromString(input) {
|
|
1874
|
-
|
|
1560
|
+
const keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
|
|
1875
1561
|
.toLowerCase()
|
|
1876
1562
|
.split(/[^a-z0-9]+/gs)
|
|
1877
|
-
.filter(
|
|
1563
|
+
.filter((value) => value);
|
|
1878
1564
|
return new Set(keywords);
|
|
1879
1565
|
}
|
|
1880
1566
|
|
|
@@ -1887,7 +1573,7 @@ function parseKeywordsFromString(input) {
|
|
|
1887
1573
|
* @public exported from `@promptbook/utils`
|
|
1888
1574
|
*/
|
|
1889
1575
|
function nameToUriPart(name) {
|
|
1890
|
-
|
|
1576
|
+
let uriPart = name;
|
|
1891
1577
|
uriPart = uriPart.toLowerCase();
|
|
1892
1578
|
uriPart = removeDiacritics(uriPart);
|
|
1893
1579
|
uriPart = uriPart.replace(/[^a-zA-Z0-9]+/g, '-');
|
|
@@ -1907,7 +1593,7 @@ function nameToUriPart(name) {
|
|
|
1907
1593
|
function nameToUriParts(name) {
|
|
1908
1594
|
return nameToUriPart(name)
|
|
1909
1595
|
.split('-')
|
|
1910
|
-
.filter(
|
|
1596
|
+
.filter((value) => value !== '');
|
|
1911
1597
|
}
|
|
1912
1598
|
|
|
1913
1599
|
/**
|
|
@@ -2015,15 +1701,15 @@ function trimEndOfCodeBlock(value) {
|
|
|
2015
1701
|
* @public exported from `@promptbook/utils`
|
|
2016
1702
|
*/
|
|
2017
1703
|
function unwrapResult(text, options) {
|
|
2018
|
-
|
|
2019
|
-
|
|
1704
|
+
const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
|
|
1705
|
+
let trimmedText = text;
|
|
2020
1706
|
// Remove leading and trailing spaces and newlines
|
|
2021
1707
|
if (isTrimmed) {
|
|
2022
1708
|
trimmedText = spaceTrim$1(trimmedText);
|
|
2023
1709
|
}
|
|
2024
|
-
|
|
1710
|
+
let processedText = trimmedText;
|
|
2025
1711
|
if (isIntroduceSentenceRemoved) {
|
|
2026
|
-
|
|
1712
|
+
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
|
2027
1713
|
if (introduceSentenceRegex.test(text)) {
|
|
2028
1714
|
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
2029
1715
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
@@ -2037,7 +1723,7 @@ function unwrapResult(text, options) {
|
|
|
2037
1723
|
return trimmedText;
|
|
2038
1724
|
}
|
|
2039
1725
|
// Remove the quotes by extracting the substring without the first and last characters
|
|
2040
|
-
|
|
1726
|
+
const unquotedText = processedText.slice(1, -1);
|
|
2041
1727
|
// Check if the text starts and ends with quotes
|
|
2042
1728
|
if ([
|
|
2043
1729
|
['"', '"'],
|
|
@@ -2047,8 +1733,7 @@ function unwrapResult(text, options) {
|
|
|
2047
1733
|
['_', '_'],
|
|
2048
1734
|
['„', '“'],
|
|
2049
1735
|
['«', '»'] /* <- QUOTES to config */,
|
|
2050
|
-
].some(
|
|
2051
|
-
var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1];
|
|
1736
|
+
].some(([startQuote, endQuote]) => {
|
|
2052
1737
|
if (!processedText.startsWith(startQuote)) {
|
|
2053
1738
|
return false;
|
|
2054
1739
|
}
|
|
@@ -2088,61 +1773,50 @@ function unwrapResult(text, options) {
|
|
|
2088
1773
|
* @public exported from `@promptbook/markdown-utils`
|
|
2089
1774
|
*/
|
|
2090
1775
|
function extractAllBlocksFromMarkdown(markdown) {
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
var lines = markdown.split('\n');
|
|
1776
|
+
const codeBlocks = [];
|
|
1777
|
+
const lines = markdown.split('\n');
|
|
2094
1778
|
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2095
1779
|
lines.push('');
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
if (currentCodeBlock.content !== '') {
|
|
2106
|
-
currentCodeBlock.content += '\n';
|
|
2107
|
-
}
|
|
2108
|
-
currentCodeBlock.content += line.slice(2);
|
|
1780
|
+
let currentCodeBlock = null;
|
|
1781
|
+
for (const line of lines) {
|
|
1782
|
+
if (line.startsWith('> ') || line === '>') {
|
|
1783
|
+
if (currentCodeBlock === null) {
|
|
1784
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
1785
|
+
} /* not else */
|
|
1786
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
1787
|
+
if (currentCodeBlock.content !== '') {
|
|
1788
|
+
currentCodeBlock.content += '\n';
|
|
2109
1789
|
}
|
|
1790
|
+
currentCodeBlock.content += line.slice(2);
|
|
2110
1791
|
}
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
}
|
|
2121
|
-
else {
|
|
2122
|
-
if (language !== null) {
|
|
2123
|
-
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2124
|
-
}
|
|
2125
|
-
codeBlocks.push(currentCodeBlock);
|
|
2126
|
-
currentCodeBlock = null;
|
|
2127
|
-
}
|
|
1792
|
+
}
|
|
1793
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
1794
|
+
codeBlocks.push(currentCodeBlock);
|
|
1795
|
+
currentCodeBlock = null;
|
|
1796
|
+
}
|
|
1797
|
+
/* not else */
|
|
1798
|
+
if (line.startsWith('```')) {
|
|
1799
|
+
const language = line.slice(3).trim() || null;
|
|
1800
|
+
if (currentCodeBlock === null) {
|
|
1801
|
+
currentCodeBlock = { blockNotation: '```', language, content: '' };
|
|
2128
1802
|
}
|
|
2129
|
-
else
|
|
2130
|
-
if (
|
|
2131
|
-
currentCodeBlock.
|
|
1803
|
+
else {
|
|
1804
|
+
if (language !== null) {
|
|
1805
|
+
throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed and already opening new ${language} code block`);
|
|
2132
1806
|
}
|
|
2133
|
-
|
|
1807
|
+
codeBlocks.push(currentCodeBlock);
|
|
1808
|
+
currentCodeBlock = null;
|
|
2134
1809
|
}
|
|
2135
1810
|
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
1811
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
1812
|
+
if (currentCodeBlock.content !== '') {
|
|
1813
|
+
currentCodeBlock.content += '\n';
|
|
1814
|
+
}
|
|
1815
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2141
1816
|
}
|
|
2142
|
-
finally { if (e_1) throw e_1.error; }
|
|
2143
1817
|
}
|
|
2144
1818
|
if (currentCodeBlock !== null) {
|
|
2145
|
-
throw new ParseError(
|
|
1819
|
+
throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed at the end of the markdown`);
|
|
2146
1820
|
}
|
|
2147
1821
|
return codeBlocks;
|
|
2148
1822
|
}
|
|
@@ -2167,9 +1841,13 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
2167
1841
|
* @throws {ParseError} if there is not exactly one code block in the markdown
|
|
2168
1842
|
*/
|
|
2169
1843
|
function extractOneBlockFromMarkdown(markdown) {
|
|
2170
|
-
|
|
1844
|
+
const codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2171
1845
|
if (codeBlocks.length !== 1) {
|
|
2172
|
-
throw new ParseError(spaceTrim(
|
|
1846
|
+
throw new ParseError(spaceTrim((block) => `
|
|
1847
|
+
There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
|
|
1848
|
+
|
|
1849
|
+
${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
|
|
1850
|
+
`));
|
|
2173
1851
|
}
|
|
2174
1852
|
return codeBlocks[0];
|
|
2175
1853
|
}
|
|
@@ -2192,7 +1870,7 @@ function extractOneBlockFromMarkdown(markdown) {
|
|
|
2192
1870
|
* @throws {ParseError} if there is not exactly one code block in the markdown
|
|
2193
1871
|
*/
|
|
2194
1872
|
function extractBlock(markdown) {
|
|
2195
|
-
|
|
1873
|
+
const { content } = extractOneBlockFromMarkdown(markdown);
|
|
2196
1874
|
return content;
|
|
2197
1875
|
}
|
|
2198
1876
|
|
|
@@ -2223,7 +1901,7 @@ function prettifyMarkdown(content) {
|
|
|
2223
1901
|
catch (error) {
|
|
2224
1902
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2225
1903
|
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
2226
|
-
error
|
|
1904
|
+
error,
|
|
2227
1905
|
html: content,
|
|
2228
1906
|
});
|
|
2229
1907
|
return content;
|
|
@@ -2240,34 +1918,24 @@ function prettifyMarkdown(content) {
|
|
|
2240
1918
|
*/
|
|
2241
1919
|
function preserve(func) {
|
|
2242
1920
|
// Note: NOT calling the function
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
case 2:
|
|
2255
|
-
_a.trys.push([2, , 4, 5]);
|
|
2256
|
-
return [4 /*yield*/, func()];
|
|
2257
|
-
case 3:
|
|
2258
|
-
_a.sent();
|
|
2259
|
-
return [3 /*break*/, 5];
|
|
2260
|
-
case 4: return [7 /*endfinally*/];
|
|
2261
|
-
case 5: return [2 /*return*/];
|
|
2262
|
-
}
|
|
2263
|
-
});
|
|
2264
|
-
}); })();
|
|
1921
|
+
(async () => {
|
|
1922
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
1923
|
+
await forTime(100000000);
|
|
1924
|
+
// [1]
|
|
1925
|
+
try {
|
|
1926
|
+
await func();
|
|
1927
|
+
}
|
|
1928
|
+
finally {
|
|
1929
|
+
// do nothing
|
|
1930
|
+
}
|
|
1931
|
+
})();
|
|
2265
1932
|
}
|
|
2266
1933
|
/**
|
|
2267
1934
|
* TODO: Probbably remove in favour of `keepImported`
|
|
2268
1935
|
* TODO: [1] This maybe does memory leak
|
|
2269
1936
|
*/
|
|
2270
1937
|
|
|
1938
|
+
// Note: [💎]
|
|
2271
1939
|
/**
|
|
2272
1940
|
* ScriptExecutionTools for JavaScript implemented via eval
|
|
2273
1941
|
*
|
|
@@ -2276,163 +1944,191 @@ function preserve(func) {
|
|
|
2276
1944
|
*
|
|
2277
1945
|
* @public exported from `@promptbook/execute-javascript`
|
|
2278
1946
|
*/
|
|
2279
|
-
|
|
2280
|
-
|
|
1947
|
+
class JavascriptEvalExecutionTools {
|
|
1948
|
+
constructor(options) {
|
|
2281
1949
|
this.options = options || {};
|
|
2282
1950
|
}
|
|
2283
1951
|
/**
|
|
2284
1952
|
* Executes a JavaScript
|
|
2285
1953
|
*/
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
1954
|
+
async execute(options) {
|
|
1955
|
+
const { scriptLanguage, parameters } = options;
|
|
1956
|
+
let { script } = options;
|
|
1957
|
+
if (scriptLanguage !== 'javascript') {
|
|
1958
|
+
throw new PipelineExecutionError(`Script language ${scriptLanguage} not supported to be executed by JavascriptEvalExecutionTools`);
|
|
1959
|
+
}
|
|
1960
|
+
// Note: [💎]
|
|
1961
|
+
// Note: Using direct eval, following variables are in same scope as eval call so they are accessible from inside the evaluated script:
|
|
1962
|
+
const spaceTrim$1 = (_) => spaceTrim(_);
|
|
1963
|
+
preserve(spaceTrim$1);
|
|
1964
|
+
const removeQuotes$1 = removeQuotes;
|
|
1965
|
+
preserve(removeQuotes$1);
|
|
1966
|
+
const unwrapResult$1 = unwrapResult;
|
|
1967
|
+
preserve(unwrapResult$1);
|
|
1968
|
+
const trimEndOfCodeBlock$1 = trimEndOfCodeBlock;
|
|
1969
|
+
preserve(trimEndOfCodeBlock$1);
|
|
1970
|
+
const trimCodeBlock$1 = trimCodeBlock;
|
|
1971
|
+
preserve(trimCodeBlock$1);
|
|
1972
|
+
// TODO: DRY [🍯]
|
|
1973
|
+
const trim = (str) => str.trim();
|
|
1974
|
+
preserve(trim);
|
|
1975
|
+
// TODO: DRY [🍯]
|
|
1976
|
+
const reverse = (str) => str.split('').reverse().join('');
|
|
1977
|
+
preserve(reverse);
|
|
1978
|
+
const removeEmojis$1 = removeEmojis;
|
|
1979
|
+
preserve(removeEmojis$1);
|
|
1980
|
+
const prettifyMarkdown$1 = prettifyMarkdown;
|
|
1981
|
+
preserve(prettifyMarkdown$1);
|
|
1982
|
+
//-------[n12:]---
|
|
1983
|
+
const capitalize$1 = capitalize;
|
|
1984
|
+
const decapitalize$1 = decapitalize;
|
|
1985
|
+
const nameToUriPart$1 = nameToUriPart;
|
|
1986
|
+
const nameToUriParts$1 = nameToUriParts;
|
|
1987
|
+
const removeDiacritics$1 = removeDiacritics;
|
|
1988
|
+
const normalizeWhitespaces$1 = normalizeWhitespaces;
|
|
1989
|
+
const normalizeToKebabCase$1 = normalizeToKebabCase;
|
|
1990
|
+
const normalizeTo_camelCase$1 = normalizeTo_camelCase;
|
|
1991
|
+
const normalizeTo_snake_case$1 = normalizeTo_snake_case;
|
|
1992
|
+
const normalizeTo_PascalCase$1 = normalizeTo_PascalCase;
|
|
1993
|
+
const parseKeywords = (input) =>
|
|
1994
|
+
// TODO: DRY [🍯]
|
|
1995
|
+
Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
|
|
1996
|
+
const normalizeTo_SCREAMING_CASE$1 = normalizeTo_SCREAMING_CASE;
|
|
1997
|
+
preserve(capitalize$1);
|
|
1998
|
+
preserve(decapitalize$1);
|
|
1999
|
+
preserve(nameToUriPart$1);
|
|
2000
|
+
preserve(nameToUriParts$1);
|
|
2001
|
+
preserve(removeDiacritics$1);
|
|
2002
|
+
preserve(normalizeWhitespaces$1);
|
|
2003
|
+
preserve(normalizeToKebabCase$1);
|
|
2004
|
+
preserve(normalizeTo_camelCase$1);
|
|
2005
|
+
preserve(normalizeTo_snake_case$1);
|
|
2006
|
+
preserve(normalizeTo_PascalCase$1);
|
|
2007
|
+
preserve(parseKeywords);
|
|
2008
|
+
preserve(normalizeTo_SCREAMING_CASE$1);
|
|
2009
|
+
//-------[/n12]---
|
|
2010
|
+
if (!script.includes('return')) {
|
|
2011
|
+
script = `return ${script}`;
|
|
2012
|
+
}
|
|
2013
|
+
// TODO: DRY [🍯]
|
|
2014
|
+
const buildinFunctions = {
|
|
2015
|
+
// TODO: [🍯] DRY all these functions across the file
|
|
2016
|
+
spaceTrim: spaceTrim$1,
|
|
2017
|
+
removeQuotes: removeQuotes$1,
|
|
2018
|
+
unwrapResult: unwrapResult$1,
|
|
2019
|
+
trimEndOfCodeBlock: trimEndOfCodeBlock$1,
|
|
2020
|
+
trimCodeBlock: trimCodeBlock$1,
|
|
2021
|
+
trim,
|
|
2022
|
+
reverse,
|
|
2023
|
+
removeEmojis: removeEmojis$1,
|
|
2024
|
+
prettifyMarkdown: prettifyMarkdown$1,
|
|
2025
|
+
capitalize: capitalize$1,
|
|
2026
|
+
decapitalize: decapitalize$1,
|
|
2027
|
+
nameToUriPart: nameToUriPart$1,
|
|
2028
|
+
nameToUriParts: nameToUriParts$1,
|
|
2029
|
+
removeDiacritics: removeDiacritics$1,
|
|
2030
|
+
normalizeWhitespaces: normalizeWhitespaces$1,
|
|
2031
|
+
normalizeToKebabCase: normalizeToKebabCase$1,
|
|
2032
|
+
normalizeTo_camelCase: normalizeTo_camelCase$1,
|
|
2033
|
+
normalizeTo_snake_case: normalizeTo_snake_case$1,
|
|
2034
|
+
normalizeTo_PascalCase: normalizeTo_PascalCase$1,
|
|
2035
|
+
parseKeywords,
|
|
2036
|
+
normalizeTo_SCREAMING_CASE: normalizeTo_SCREAMING_CASE$1,
|
|
2037
|
+
extractBlock, // <- [🍓] Remove balast in all other functions, use this one as example
|
|
2038
|
+
};
|
|
2039
|
+
const buildinFunctionsStatement = Object.keys(buildinFunctions)
|
|
2040
|
+
.map((functionName) =>
|
|
2041
|
+
// Note: Custom functions are exposed to the current scope as variables
|
|
2042
|
+
`const ${functionName} = buildinFunctions.${functionName};`)
|
|
2043
|
+
.join('\n');
|
|
2044
|
+
// TODO: DRY [🍯]
|
|
2045
|
+
const customFunctions = this.options.functions || {};
|
|
2046
|
+
const customFunctionsStatement = Object.keys(customFunctions)
|
|
2047
|
+
.map((functionName) =>
|
|
2048
|
+
// Note: Custom functions are exposed to the current scope as variables
|
|
2049
|
+
`const ${functionName} = customFunctions.${functionName};`)
|
|
2050
|
+
.join('\n');
|
|
2051
|
+
const statementToEvaluate = spaceTrim((block) => `
|
|
2052
|
+
|
|
2053
|
+
// Build-in functions:
|
|
2054
|
+
${block(buildinFunctionsStatement)}
|
|
2055
|
+
|
|
2056
|
+
// Custom functions:
|
|
2057
|
+
${block(customFunctionsStatement || '// -- No custom functions --')}
|
|
2058
|
+
|
|
2059
|
+
// The script:
|
|
2060
|
+
${block(Object.entries(parameters)
|
|
2061
|
+
.map(([key, value]) => `const ${key} = ${JSON.stringify(value)};`)
|
|
2062
|
+
.join('\n'))}
|
|
2063
|
+
(()=>{ ${script} })()
|
|
2064
|
+
`);
|
|
2065
|
+
if (this.options.isVerbose) {
|
|
2066
|
+
console.info(spaceTrim((block) => `
|
|
2067
|
+
🚀 Evaluating ${scriptLanguage} script:
|
|
2068
|
+
|
|
2069
|
+
${block(statementToEvaluate)}`));
|
|
2070
|
+
}
|
|
2071
|
+
let result;
|
|
2072
|
+
try {
|
|
2073
|
+
result = await eval(statementToEvaluate);
|
|
2074
|
+
if (typeof result !== 'string') {
|
|
2075
|
+
throw new PipelineExecutionError(`Script must return a string, but returned ${valueToString(result)}`);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
catch (error) {
|
|
2079
|
+
if (!(error instanceof Error)) {
|
|
2080
|
+
throw error;
|
|
2081
|
+
}
|
|
2082
|
+
if (error instanceof ReferenceError) {
|
|
2083
|
+
const undefinedName = error.message.split(' ')[0];
|
|
2084
|
+
/*
|
|
2085
|
+
Note: Remapping error
|
|
2086
|
+
From: [PipelineUrlError: thing is not defined],
|
|
2087
|
+
To: [PipelineExecutionError: Parameter `{thing}` is not defined],
|
|
2088
|
+
*/
|
|
2089
|
+
if (!statementToEvaluate.includes(undefinedName + '(')) {
|
|
2090
|
+
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
2091
|
+
|
|
2092
|
+
Parameter \`{${undefinedName}}\` is not defined
|
|
2093
|
+
|
|
2094
|
+
This happen during evaluation of the javascript, which has access to the following parameters as javascript variables:
|
|
2095
|
+
|
|
2096
|
+
${block(Object.keys(parameters)
|
|
2097
|
+
.map((key) => ` - ${key}\n`)
|
|
2098
|
+
.join(''))}
|
|
2099
|
+
|
|
2100
|
+
The script is:
|
|
2101
|
+
\`\`\`javascript
|
|
2102
|
+
${block(script)}
|
|
2103
|
+
\`\`\`
|
|
2104
|
+
|
|
2105
|
+
Original error message:
|
|
2106
|
+
${block(error.message)}
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
`));
|
|
2430
2110
|
}
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2111
|
+
else {
|
|
2112
|
+
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
2113
|
+
Function ${undefinedName}() is not defined
|
|
2114
|
+
|
|
2115
|
+
- Make sure that the function is one of built-in functions
|
|
2116
|
+
- Or you have to defined the function during construction of JavascriptEvalExecutionTools
|
|
2117
|
+
|
|
2118
|
+
Original error message:
|
|
2119
|
+
${block(error.message)}
|
|
2120
|
+
|
|
2121
|
+
`));
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
throw error;
|
|
2125
|
+
}
|
|
2126
|
+
if (typeof result !== 'string') {
|
|
2127
|
+
throw new PipelineExecutionError(`Script must return a string, but ${valueToString(result)}`);
|
|
2128
|
+
}
|
|
2129
|
+
return result;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2436
2132
|
/**
|
|
2437
2133
|
* TODO: Put predefined functions (like removeQuotes, spaceTrim, etc.) into annotation OR pass into constructor
|
|
2438
2134
|
* TODO: [🧠][💙] Distinct between options passed into ExecutionTools and to ExecutionTools.execute
|
|
@@ -2444,7 +2140,7 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
|
|
|
2444
2140
|
* @alias JavascriptExecutionTools
|
|
2445
2141
|
* @public exported from `@promptbook/execute-javascript`
|
|
2446
2142
|
*/
|
|
2447
|
-
|
|
2143
|
+
const JavascriptExecutionTools = JavascriptEvalExecutionTools;
|
|
2448
2144
|
|
|
2449
2145
|
/**
|
|
2450
2146
|
* Gets the expectations and creates a fake text that meets the expectations
|
|
@@ -2455,76 +2151,50 @@ var JavascriptExecutionTools = JavascriptEvalExecutionTools;
|
|
|
2455
2151
|
*
|
|
2456
2152
|
* @private internal utility for MockedFackedLlmExecutionTools
|
|
2457
2153
|
*/
|
|
2458
|
-
function $fakeTextToExpectations(expectations, postprocessingFunctionNames) {
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
return __generator(this, function (_d) {
|
|
2463
|
-
switch (_d.label) {
|
|
2464
|
-
case 0:
|
|
2465
|
-
lorem = new LoremIpsum({
|
|
2466
|
-
wordsPerSentence: { min: 5, max: 15 },
|
|
2467
|
-
sentencesPerParagraph: { min: 5, max: 15 },
|
|
2468
|
-
});
|
|
2469
|
-
loremText = '';
|
|
2470
|
-
text = '';
|
|
2471
|
-
loopLimit = CHARACTER_LOOP_LIMIT;
|
|
2472
|
-
_d.label = 1;
|
|
2473
|
-
case 1:
|
|
2474
|
-
if (!(loopLimit-- > 0)) return [3 /*break*/, 11];
|
|
2475
|
-
textToCheck = text;
|
|
2476
|
-
scriptTools = null;
|
|
2477
|
-
_d.label = 2;
|
|
2478
|
-
case 2:
|
|
2479
|
-
_d.trys.push([2, 7, 8, 9]);
|
|
2480
|
-
_a = (e_1 = void 0, __values(postprocessingFunctionNames || [])), _b = _a.next();
|
|
2481
|
-
_d.label = 3;
|
|
2482
|
-
case 3:
|
|
2483
|
-
if (!!_b.done) return [3 /*break*/, 6];
|
|
2484
|
-
postprocessingFunctionName = _b.value;
|
|
2485
|
-
if (scriptTools === null) {
|
|
2486
|
-
scriptTools = new JavascriptExecutionTools();
|
|
2487
|
-
}
|
|
2488
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
2489
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2490
|
-
script: "".concat(postprocessingFunctionName, "(result)"),
|
|
2491
|
-
parameters: {
|
|
2492
|
-
result: textToCheck || '',
|
|
2493
|
-
// Note: No ...parametersForTask, because working with result only
|
|
2494
|
-
},
|
|
2495
|
-
})];
|
|
2496
|
-
case 4:
|
|
2497
|
-
textToCheck = _d.sent();
|
|
2498
|
-
_d.label = 5;
|
|
2499
|
-
case 5:
|
|
2500
|
-
_b = _a.next();
|
|
2501
|
-
return [3 /*break*/, 3];
|
|
2502
|
-
case 6: return [3 /*break*/, 9];
|
|
2503
|
-
case 7:
|
|
2504
|
-
e_1_1 = _d.sent();
|
|
2505
|
-
e_1 = { error: e_1_1 };
|
|
2506
|
-
return [3 /*break*/, 9];
|
|
2507
|
-
case 8:
|
|
2508
|
-
try {
|
|
2509
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2510
|
-
}
|
|
2511
|
-
finally { if (e_1) throw e_1.error; }
|
|
2512
|
-
return [7 /*endfinally*/];
|
|
2513
|
-
case 9:
|
|
2514
|
-
if (isPassingExpectations(expectations, textToCheck)) {
|
|
2515
|
-
return [2 /*return*/, text]; // <- Note: Returning the text because the postprocessing
|
|
2516
|
-
}
|
|
2517
|
-
if (loremText === '') {
|
|
2518
|
-
loremText = lorem.generateParagraphs(1) + '\n\n';
|
|
2519
|
-
}
|
|
2520
|
-
text += loremText.substring(0, 1);
|
|
2521
|
-
loremText = loremText.substring(1);
|
|
2522
|
-
_d.label = 10;
|
|
2523
|
-
case 10: return [3 /*break*/, 1];
|
|
2524
|
-
case 11: throw new LimitReachedError(spaceTrim$1(function (block) { return "\n Can not generate fake text to met the expectations\n\n Loop limit reached\n The expectations:\n ".concat(block(JSON.stringify(expectations, null, 4)), "\n\n The draft text:\n ").concat(block(text), "\n\n "); }));
|
|
2525
|
-
}
|
|
2526
|
-
});
|
|
2154
|
+
async function $fakeTextToExpectations(expectations, postprocessingFunctionNames) {
|
|
2155
|
+
const lorem = new LoremIpsum({
|
|
2156
|
+
wordsPerSentence: { min: 5, max: 15 },
|
|
2157
|
+
sentencesPerParagraph: { min: 5, max: 15 },
|
|
2527
2158
|
});
|
|
2159
|
+
let loremText = '';
|
|
2160
|
+
let text = '';
|
|
2161
|
+
for (let loopLimit = CHARACTER_LOOP_LIMIT; loopLimit-- > 0;) {
|
|
2162
|
+
let textToCheck = text;
|
|
2163
|
+
// TODO: DRY [☯]
|
|
2164
|
+
let scriptTools = null;
|
|
2165
|
+
for (const postprocessingFunctionName of postprocessingFunctionNames || []) {
|
|
2166
|
+
if (scriptTools === null) {
|
|
2167
|
+
scriptTools = new JavascriptExecutionTools();
|
|
2168
|
+
}
|
|
2169
|
+
textToCheck = await scriptTools.execute({
|
|
2170
|
+
scriptLanguage: `javascript` /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2171
|
+
script: `${postprocessingFunctionName}(result)`,
|
|
2172
|
+
parameters: {
|
|
2173
|
+
result: textToCheck || '',
|
|
2174
|
+
// Note: No ...parametersForTask, because working with result only
|
|
2175
|
+
},
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
if (isPassingExpectations(expectations, textToCheck)) {
|
|
2179
|
+
return text; // <- Note: Returning the text because the postprocessing
|
|
2180
|
+
}
|
|
2181
|
+
if (loremText === '') {
|
|
2182
|
+
loremText = lorem.generateParagraphs(1) + '\n\n';
|
|
2183
|
+
}
|
|
2184
|
+
text += loremText.substring(0, 1);
|
|
2185
|
+
loremText = loremText.substring(1);
|
|
2186
|
+
}
|
|
2187
|
+
throw new LimitReachedError(spaceTrim$1((block) => `
|
|
2188
|
+
Can not generate fake text to met the expectations
|
|
2189
|
+
|
|
2190
|
+
Loop limit reached
|
|
2191
|
+
The expectations:
|
|
2192
|
+
${block(JSON.stringify(expectations, null, 4))}
|
|
2193
|
+
|
|
2194
|
+
The draft text:
|
|
2195
|
+
${block(text)}
|
|
2196
|
+
|
|
2197
|
+
`));
|
|
2528
2198
|
}
|
|
2529
2199
|
/**
|
|
2530
2200
|
* TODO: [💝] Unite object for expecting amount and format - use here also a format
|
|
@@ -2535,33 +2205,24 @@ function $fakeTextToExpectations(expectations, postprocessingFunctionNames) {
|
|
|
2535
2205
|
*
|
|
2536
2206
|
* @public exported from `@promptbook/fake-llm`
|
|
2537
2207
|
*/
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
if (options === void 0) { options = {}; }
|
|
2208
|
+
class MockedFackedLlmExecutionTools {
|
|
2209
|
+
constructor(options = {}) {
|
|
2541
2210
|
this.options = options;
|
|
2542
2211
|
}
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
});
|
|
2550
|
-
Object.defineProperty(MockedFackedLlmExecutionTools.prototype, "description", {
|
|
2551
|
-
get: function () {
|
|
2552
|
-
return 'Use faked lorem ipsum data - just for testing';
|
|
2553
|
-
},
|
|
2554
|
-
enumerable: false,
|
|
2555
|
-
configurable: true
|
|
2556
|
-
});
|
|
2212
|
+
get title() {
|
|
2213
|
+
return 'Mocked facked';
|
|
2214
|
+
}
|
|
2215
|
+
get description() {
|
|
2216
|
+
return 'Use faked lorem ipsum data - just for testing';
|
|
2217
|
+
}
|
|
2557
2218
|
/**
|
|
2558
2219
|
* Does nothing, just to implement the interface
|
|
2559
2220
|
*/
|
|
2560
|
-
|
|
2221
|
+
checkConfiguration() { }
|
|
2561
2222
|
/**
|
|
2562
2223
|
* List all available fake-models that can be used
|
|
2563
2224
|
*/
|
|
2564
|
-
|
|
2225
|
+
listModels() {
|
|
2565
2226
|
return [
|
|
2566
2227
|
{
|
|
2567
2228
|
modelTitle: 'Fake chat',
|
|
@@ -2575,107 +2236,90 @@ var MockedFackedLlmExecutionTools = /** @class */ (function () {
|
|
|
2575
2236
|
},
|
|
2576
2237
|
// <- Note: [🤖]
|
|
2577
2238
|
];
|
|
2578
|
-
}
|
|
2239
|
+
}
|
|
2579
2240
|
/**
|
|
2580
2241
|
* Fakes chat model
|
|
2581
2242
|
*/
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
}
|
|
2617
|
-
return [2 /*return*/, exportJson({
|
|
2618
|
-
name: 'promptResult',
|
|
2619
|
-
message: "Result of `MockedFackedLlmExecutionTools.callChatModel`",
|
|
2620
|
-
order: [],
|
|
2621
|
-
value: result,
|
|
2622
|
-
})];
|
|
2623
|
-
}
|
|
2624
|
-
});
|
|
2243
|
+
async callChatModel(prompt) {
|
|
2244
|
+
if (this.options.isVerbose) {
|
|
2245
|
+
console.info('💬 Mocked faked prompt', prompt);
|
|
2246
|
+
}
|
|
2247
|
+
const modelName = 'mocked-facked';
|
|
2248
|
+
const rawPromptContent = templateParameters(prompt.content, { ...prompt.parameters, modelName });
|
|
2249
|
+
const usage = ZERO_USAGE;
|
|
2250
|
+
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
2251
|
+
const content = await $fakeTextToExpectations(prompt.expectations || {
|
|
2252
|
+
sentences: { min: 1, max: 1 },
|
|
2253
|
+
}, prompt.postprocessingFunctionNames);
|
|
2254
|
+
const result = {
|
|
2255
|
+
content,
|
|
2256
|
+
modelName,
|
|
2257
|
+
timing: {
|
|
2258
|
+
start: $getCurrentDate(),
|
|
2259
|
+
complete: $getCurrentDate(),
|
|
2260
|
+
},
|
|
2261
|
+
usage,
|
|
2262
|
+
rawPromptContent,
|
|
2263
|
+
rawRequest: null,
|
|
2264
|
+
rawResponse: {
|
|
2265
|
+
note: 'This is mocked echo',
|
|
2266
|
+
},
|
|
2267
|
+
// <- [🗯]
|
|
2268
|
+
};
|
|
2269
|
+
if (this.options.isVerbose) {
|
|
2270
|
+
console.info('💬 Mocked faked result', result);
|
|
2271
|
+
}
|
|
2272
|
+
return exportJson({
|
|
2273
|
+
name: 'promptResult',
|
|
2274
|
+
message: `Result of \`MockedFackedLlmExecutionTools.callChatModel\``,
|
|
2275
|
+
order: [],
|
|
2276
|
+
value: result,
|
|
2625
2277
|
});
|
|
2626
|
-
}
|
|
2278
|
+
}
|
|
2627
2279
|
/**
|
|
2628
2280
|
* Fakes completion model
|
|
2629
2281
|
*/
|
|
2630
|
-
|
|
2631
|
-
return
|
|
2632
|
-
|
|
2633
|
-
return [2 /*return*/, this.callChatModel(prompt)];
|
|
2634
|
-
});
|
|
2635
|
-
});
|
|
2636
|
-
};
|
|
2282
|
+
async callCompletionModel(prompt) {
|
|
2283
|
+
return this.callChatModel(prompt);
|
|
2284
|
+
}
|
|
2637
2285
|
/**
|
|
2638
2286
|
* Fakes embedding model
|
|
2639
2287
|
*/
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
value: result,
|
|
2673
|
-
})];
|
|
2674
|
-
});
|
|
2288
|
+
async callEmbeddingModel(prompt) {
|
|
2289
|
+
const modelName = 'mocked-facked';
|
|
2290
|
+
const rawPromptContent = templateParameters(prompt.content, { ...prompt.parameters, modelName });
|
|
2291
|
+
const content = new Array(1024)
|
|
2292
|
+
.fill(0)
|
|
2293
|
+
.map(() => Math.random() * 2 - 1); /* <- Note: [🤛] */
|
|
2294
|
+
const usage = ZERO_USAGE;
|
|
2295
|
+
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
2296
|
+
// TODO: Make content vector exactly length of 1
|
|
2297
|
+
const result = {
|
|
2298
|
+
content,
|
|
2299
|
+
modelName,
|
|
2300
|
+
timing: {
|
|
2301
|
+
start: $getCurrentDate(),
|
|
2302
|
+
complete: $getCurrentDate(),
|
|
2303
|
+
},
|
|
2304
|
+
usage,
|
|
2305
|
+
rawPromptContent,
|
|
2306
|
+
rawRequest: null,
|
|
2307
|
+
rawResponse: {
|
|
2308
|
+
note: 'This is mocked embedding',
|
|
2309
|
+
},
|
|
2310
|
+
// <- [🗯]
|
|
2311
|
+
};
|
|
2312
|
+
if (this.options.isVerbose) {
|
|
2313
|
+
console.info('💬 Mocked faked result', result);
|
|
2314
|
+
}
|
|
2315
|
+
return exportJson({
|
|
2316
|
+
name: 'promptResult',
|
|
2317
|
+
message: `Result of \`MockedFackedLlmExecutionTools.callEmbeddingModel\``,
|
|
2318
|
+
order: [],
|
|
2319
|
+
value: result,
|
|
2675
2320
|
});
|
|
2676
|
-
}
|
|
2677
|
-
|
|
2678
|
-
}());
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2679
2323
|
/**
|
|
2680
2324
|
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
2681
2325
|
*/
|