@promptbook/fake-llm 0.77.1 → 0.78.2
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/esm/index.es.js +209 -187
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -8
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
- package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +208 -186
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
- /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('lorem-ipsum'), require('prettier'), require('prettier/parser-html'), require('waitasecond')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'lorem-ipsum', 'prettier', 'prettier/parser-html', 'waitasecond'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-fake-llm"] = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-fake-llm"] = {}, global.spaceTrim, global.loremIpsum, global.prettier, global.parserHtml, global.waitasecond));
|
|
5
|
+
})(this, (function (exports, spaceTrim, loremIpsum, prettier, parserHtml, waitasecond) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
10
10
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
11
11
|
|
|
12
12
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @see https://github.com/webgptorg/promptbook
|
|
23
23
|
*/
|
|
24
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
24
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
25
25
|
/**
|
|
26
26
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
27
27
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -239,164 +239,25 @@
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
/**
|
|
242
|
-
*
|
|
242
|
+
* Name for the Promptbook
|
|
243
|
+
*
|
|
244
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
243
245
|
*
|
|
244
246
|
* @public exported from `@promptbook/core`
|
|
245
247
|
*/
|
|
246
|
-
var
|
|
247
|
-
__extends(UnexpectedError, _super);
|
|
248
|
-
function UnexpectedError(message) {
|
|
249
|
-
var _this = _super.call(this, _spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
250
|
-
_this.name = 'UnexpectedError';
|
|
251
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
252
|
-
return _this;
|
|
253
|
-
}
|
|
254
|
-
return UnexpectedError;
|
|
255
|
-
}(Error));
|
|
256
|
-
|
|
248
|
+
var NAME = "Promptbook";
|
|
257
249
|
/**
|
|
258
|
-
*
|
|
259
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
260
|
-
*
|
|
261
|
-
* - Almost all primitives are serializable BUT:
|
|
262
|
-
* - `undefined` is not serializable
|
|
263
|
-
* - `NaN` is not serializable
|
|
264
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
265
|
-
* - Functions are not serializable
|
|
266
|
-
* - Circular references are not serializable
|
|
267
|
-
* - `Date` objects are not serializable
|
|
268
|
-
* - `Map` and `Set` objects are not serializable
|
|
269
|
-
* - `RegExp` objects are not serializable
|
|
270
|
-
* - `Error` objects are not serializable
|
|
271
|
-
* - `Symbol` objects are not serializable
|
|
272
|
-
* - And much more...
|
|
250
|
+
* Email of the responsible person
|
|
273
251
|
*
|
|
274
|
-
* @
|
|
275
|
-
* @public exported from `@promptbook/utils`
|
|
276
|
-
*/
|
|
277
|
-
function checkSerializableAsJson(name, value) {
|
|
278
|
-
var e_1, _a;
|
|
279
|
-
if (value === undefined) {
|
|
280
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
281
|
-
}
|
|
282
|
-
else if (value === null) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
else if (typeof value === 'boolean') {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
else if (typeof value === 'string') {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
else if (typeof value === 'symbol') {
|
|
295
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
296
|
-
}
|
|
297
|
-
else if (typeof value === 'function') {
|
|
298
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
299
|
-
}
|
|
300
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
301
|
-
for (var i = 0; i < value.length; i++) {
|
|
302
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
else if (typeof value === 'object') {
|
|
306
|
-
if (value instanceof Date) {
|
|
307
|
-
throw new UnexpectedError(_spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
308
|
-
}
|
|
309
|
-
else if (value instanceof Map) {
|
|
310
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
311
|
-
}
|
|
312
|
-
else if (value instanceof Set) {
|
|
313
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
314
|
-
}
|
|
315
|
-
else if (value instanceof RegExp) {
|
|
316
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
317
|
-
}
|
|
318
|
-
else if (value instanceof Error) {
|
|
319
|
-
throw new UnexpectedError(_spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
try {
|
|
323
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
324
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
325
|
-
if (subValue === undefined) {
|
|
326
|
-
// Note: undefined in object is serializable - it is just omited
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
333
|
-
finally {
|
|
334
|
-
try {
|
|
335
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
336
|
-
}
|
|
337
|
-
finally { if (e_1) throw e_1.error; }
|
|
338
|
-
}
|
|
339
|
-
try {
|
|
340
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
341
|
-
}
|
|
342
|
-
catch (error) {
|
|
343
|
-
if (!(error instanceof Error)) {
|
|
344
|
-
throw error;
|
|
345
|
-
}
|
|
346
|
-
throw new UnexpectedError(_spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
347
|
-
}
|
|
348
|
-
/*
|
|
349
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
350
|
-
const seen = new Set();
|
|
351
|
-
const stack = [{ value }];
|
|
352
|
-
while (stack.length > 0) {
|
|
353
|
-
const { value } = stack.pop()!;
|
|
354
|
-
if (typeof value === 'object' && value !== null) {
|
|
355
|
-
if (seen.has(value)) {
|
|
356
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
357
|
-
}
|
|
358
|
-
seen.add(value);
|
|
359
|
-
if (Array.isArray(value)) {
|
|
360
|
-
stack.push(...value.map((value) => ({ value })));
|
|
361
|
-
} else {
|
|
362
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
*/
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
376
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
377
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
252
|
+
* @public exported from `@promptbook/core`
|
|
378
253
|
*/
|
|
379
|
-
|
|
254
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
380
255
|
/**
|
|
381
|
-
*
|
|
382
|
-
* @@@
|
|
383
|
-
*
|
|
384
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
256
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
385
257
|
*
|
|
386
|
-
* @
|
|
387
|
-
* @param objectValue - Object to be deeply frozen
|
|
388
|
-
* @returns The same object as the input, but deeply frozen
|
|
389
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
390
|
-
*/
|
|
391
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
392
|
-
checkSerializableAsJson(name, objectValue);
|
|
393
|
-
return $deepFreeze(objectValue);
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
397
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
258
|
+
* @public exported from `@promptbook/core`
|
|
398
259
|
*/
|
|
399
|
-
|
|
260
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
400
261
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
401
262
|
/**
|
|
402
263
|
* The maximum number of iterations for a loops
|
|
@@ -416,22 +277,6 @@
|
|
|
416
277
|
* @private within the repository
|
|
417
278
|
*/
|
|
418
279
|
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
419
|
-
/**
|
|
420
|
-
* The names of the parameters that are reserved for special purposes
|
|
421
|
-
*
|
|
422
|
-
* @public exported from `@promptbook/core`
|
|
423
|
-
*/
|
|
424
|
-
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
425
|
-
'content',
|
|
426
|
-
'context',
|
|
427
|
-
'knowledge',
|
|
428
|
-
'examples',
|
|
429
|
-
'modelName',
|
|
430
|
-
'currentDate',
|
|
431
|
-
// <- TODO: list here all command names
|
|
432
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
433
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
434
|
-
]);
|
|
435
280
|
/**
|
|
436
281
|
* @@@
|
|
437
282
|
*
|
|
@@ -494,6 +339,40 @@
|
|
|
494
339
|
return PipelineExecutionError;
|
|
495
340
|
}(Error));
|
|
496
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Make error report URL for the given error
|
|
344
|
+
*
|
|
345
|
+
* @private !!!!!!
|
|
346
|
+
*/
|
|
347
|
+
function getErrorReportUrl(error) {
|
|
348
|
+
var report = {
|
|
349
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
350
|
+
body: spaceTrim__default["default"](function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
351
|
+
};
|
|
352
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
353
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
354
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
355
|
+
reportUrl.searchParams.set('title', report.title);
|
|
356
|
+
reportUrl.searchParams.set('body', report.body);
|
|
357
|
+
return reportUrl;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
362
|
+
*
|
|
363
|
+
* @public exported from `@promptbook/core`
|
|
364
|
+
*/
|
|
365
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
366
|
+
__extends(UnexpectedError, _super);
|
|
367
|
+
function UnexpectedError(message) {
|
|
368
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
369
|
+
_this.name = 'UnexpectedError';
|
|
370
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
371
|
+
return _this;
|
|
372
|
+
}
|
|
373
|
+
return UnexpectedError;
|
|
374
|
+
}(Error));
|
|
375
|
+
|
|
497
376
|
/**
|
|
498
377
|
* Replaces parameters in template with values from parameters object
|
|
499
378
|
*
|
|
@@ -573,6 +452,149 @@
|
|
|
573
452
|
return replacedTemplates;
|
|
574
453
|
}
|
|
575
454
|
|
|
455
|
+
/**
|
|
456
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
457
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
458
|
+
*
|
|
459
|
+
* - Almost all primitives are serializable BUT:
|
|
460
|
+
* - `undefined` is not serializable
|
|
461
|
+
* - `NaN` is not serializable
|
|
462
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
463
|
+
* - Functions are not serializable
|
|
464
|
+
* - Circular references are not serializable
|
|
465
|
+
* - `Date` objects are not serializable
|
|
466
|
+
* - `Map` and `Set` objects are not serializable
|
|
467
|
+
* - `RegExp` objects are not serializable
|
|
468
|
+
* - `Error` objects are not serializable
|
|
469
|
+
* - `Symbol` objects are not serializable
|
|
470
|
+
* - And much more...
|
|
471
|
+
*
|
|
472
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
473
|
+
* @public exported from `@promptbook/utils`
|
|
474
|
+
*/
|
|
475
|
+
function checkSerializableAsJson(name, value) {
|
|
476
|
+
var e_1, _a;
|
|
477
|
+
if (value === undefined) {
|
|
478
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
479
|
+
}
|
|
480
|
+
else if (value === null) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
else if (typeof value === 'boolean') {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
else if (typeof value === 'string') {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
else if (typeof value === 'symbol') {
|
|
493
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
494
|
+
}
|
|
495
|
+
else if (typeof value === 'function') {
|
|
496
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
497
|
+
}
|
|
498
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
499
|
+
for (var i = 0; i < value.length; i++) {
|
|
500
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
else if (typeof value === 'object') {
|
|
504
|
+
if (value instanceof Date) {
|
|
505
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
506
|
+
}
|
|
507
|
+
else if (value instanceof Map) {
|
|
508
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
509
|
+
}
|
|
510
|
+
else if (value instanceof Set) {
|
|
511
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
512
|
+
}
|
|
513
|
+
else if (value instanceof RegExp) {
|
|
514
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
515
|
+
}
|
|
516
|
+
else if (value instanceof Error) {
|
|
517
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
try {
|
|
521
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
522
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
523
|
+
if (subValue === undefined) {
|
|
524
|
+
// Note: undefined in object is serializable - it is just omited
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
531
|
+
finally {
|
|
532
|
+
try {
|
|
533
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
534
|
+
}
|
|
535
|
+
finally { if (e_1) throw e_1.error; }
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
if (!(error instanceof Error)) {
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
545
|
+
}
|
|
546
|
+
/*
|
|
547
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
548
|
+
const seen = new Set();
|
|
549
|
+
const stack = [{ value }];
|
|
550
|
+
while (stack.length > 0) {
|
|
551
|
+
const { value } = stack.pop()!;
|
|
552
|
+
if (typeof value === 'object' && value !== null) {
|
|
553
|
+
if (seen.has(value)) {
|
|
554
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
555
|
+
}
|
|
556
|
+
seen.add(value);
|
|
557
|
+
if (Array.isArray(value)) {
|
|
558
|
+
stack.push(...value.map((value) => ({ value })));
|
|
559
|
+
} else {
|
|
560
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
*/
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
574
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
575
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
576
|
+
*/
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @@@
|
|
580
|
+
* @@@
|
|
581
|
+
*
|
|
582
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
583
|
+
*
|
|
584
|
+
* @param name - Name of the object for debugging purposes
|
|
585
|
+
* @param objectValue - Object to be deeply frozen
|
|
586
|
+
* @returns The same object as the input, but deeply frozen
|
|
587
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
588
|
+
*/
|
|
589
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
590
|
+
checkSerializableAsJson(name, objectValue);
|
|
591
|
+
return $deepFreeze(objectValue);
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
595
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
596
|
+
*/
|
|
597
|
+
|
|
576
598
|
/**
|
|
577
599
|
* Mocked execution Tools for just echoing the requests for testing purposes.
|
|
578
600
|
*
|
|
@@ -634,7 +656,7 @@
|
|
|
634
656
|
usage = ZERO_USAGE;
|
|
635
657
|
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
636
658
|
return [2 /*return*/, $asDeeplyFrozenSerializableJson('MockedEchoLlmExecutionTools ChatPromptResult', {
|
|
637
|
-
content:
|
|
659
|
+
content: spaceTrim.spaceTrim(function (block) { return "\n You said:\n ".concat(block(rawPromptContent), "\n "); }),
|
|
638
660
|
modelName: modelName,
|
|
639
661
|
timing: {
|
|
640
662
|
start: $getCurrentDate(),
|
|
@@ -666,7 +688,7 @@
|
|
|
666
688
|
usage = ZERO_USAGE;
|
|
667
689
|
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
668
690
|
return [2 /*return*/, $asDeeplyFrozenSerializableJson('MockedEchoLlmExecutionTools CompletionPromptResult', {
|
|
669
|
-
content:
|
|
691
|
+
content: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(rawPromptContent), "\n And so on...\n "); }),
|
|
670
692
|
modelName: modelName,
|
|
671
693
|
timing: {
|
|
672
694
|
start: $getCurrentDate(),
|
|
@@ -1267,7 +1289,7 @@
|
|
|
1267
1289
|
function extractOneBlockFromMarkdown(markdown) {
|
|
1268
1290
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
1269
1291
|
if (codeBlocks.length !== 1) {
|
|
1270
|
-
throw new ParseError(
|
|
1292
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n There should be exactly 1 code block in task section, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
1271
1293
|
}
|
|
1272
1294
|
return codeBlocks[0];
|
|
1273
1295
|
}
|
|
@@ -1658,13 +1680,13 @@
|
|
|
1658
1680
|
* @public exported from `@promptbook/utils`
|
|
1659
1681
|
*/
|
|
1660
1682
|
function trimCodeBlock(value) {
|
|
1661
|
-
value =
|
|
1683
|
+
value = spaceTrim.spaceTrim(value);
|
|
1662
1684
|
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
|
1663
1685
|
return value;
|
|
1664
1686
|
}
|
|
1665
1687
|
value = value.replace(/^```[a-z]*/i, '');
|
|
1666
1688
|
value = value.replace(/```$/i, '');
|
|
1667
|
-
value =
|
|
1689
|
+
value = spaceTrim.spaceTrim(value);
|
|
1668
1690
|
return value;
|
|
1669
1691
|
}
|
|
1670
1692
|
|
|
@@ -1677,9 +1699,9 @@
|
|
|
1677
1699
|
* @public exported from `@promptbook/utils`
|
|
1678
1700
|
*/
|
|
1679
1701
|
function trimEndOfCodeBlock(value) {
|
|
1680
|
-
value =
|
|
1702
|
+
value = spaceTrim.spaceTrim(value);
|
|
1681
1703
|
value = value.replace(/```$/g, '');
|
|
1682
|
-
value =
|
|
1704
|
+
value = spaceTrim.spaceTrim(value);
|
|
1683
1705
|
return value;
|
|
1684
1706
|
}
|
|
1685
1707
|
|
|
@@ -1701,7 +1723,7 @@
|
|
|
1701
1723
|
var trimmedText = text;
|
|
1702
1724
|
// Remove leading and trailing spaces and newlines
|
|
1703
1725
|
if (isTrimmed) {
|
|
1704
|
-
trimmedText =
|
|
1726
|
+
trimmedText = spaceTrim.spaceTrim(trimmedText);
|
|
1705
1727
|
}
|
|
1706
1728
|
var processedText = trimmedText;
|
|
1707
1729
|
if (isIntroduceSentenceRemoved) {
|
|
@@ -1710,7 +1732,7 @@
|
|
|
1710
1732
|
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
1711
1733
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
1712
1734
|
}
|
|
1713
|
-
processedText =
|
|
1735
|
+
processedText = spaceTrim.spaceTrim(processedText);
|
|
1714
1736
|
}
|
|
1715
1737
|
if (processedText.length < 3) {
|
|
1716
1738
|
return trimmedText;
|
|
@@ -1770,10 +1792,10 @@
|
|
|
1770
1792
|
return __generator(this, function (_a) {
|
|
1771
1793
|
switch (_a.label) {
|
|
1772
1794
|
case 0:
|
|
1773
|
-
// TODO: Change to `await forEver` or something better
|
|
1795
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
1774
1796
|
return [4 /*yield*/, waitasecond.forTime(100000000)];
|
|
1775
1797
|
case 1:
|
|
1776
|
-
// TODO: Change to `await forEver` or something better
|
|
1798
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
1777
1799
|
_a.sent();
|
|
1778
1800
|
_a.label = 2;
|
|
1779
1801
|
case 2:
|
|
@@ -1846,7 +1868,7 @@
|
|
|
1846
1868
|
if (scriptLanguage !== 'javascript') {
|
|
1847
1869
|
throw new PipelineExecutionError("Script language ".concat(scriptLanguage, " not supported to be executed by JavascriptEvalExecutionTools"));
|
|
1848
1870
|
}
|
|
1849
|
-
spaceTrim = function (_) { return
|
|
1871
|
+
spaceTrim = function (_) { return spaceTrim__default["default"](_); };
|
|
1850
1872
|
preserve(spaceTrim);
|
|
1851
1873
|
removeQuotes$1 = removeQuotes;
|
|
1852
1874
|
preserve(removeQuotes$1);
|
|
@@ -1933,14 +1955,14 @@
|
|
|
1933
1955
|
return "const ".concat(functionName, " = customFunctions.").concat(functionName, ";");
|
|
1934
1956
|
})
|
|
1935
1957
|
.join('\n');
|
|
1936
|
-
statementToEvaluate =
|
|
1958
|
+
statementToEvaluate = spaceTrim__default["default"](function (block) { return "\n\n // Build-in functions:\n ".concat(block(buildinFunctionsStatement), "\n\n // Custom functions:\n ").concat(block(customFunctionsStatement || '// -- No custom functions --'), "\n\n // The script:\n ").concat(block(Object.entries(parameters)
|
|
1937
1959
|
.map(function (_a) {
|
|
1938
1960
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
1939
1961
|
return "const ".concat(key, " = ").concat(JSON.stringify(value), ";");
|
|
1940
1962
|
})
|
|
1941
1963
|
.join('\n')), "\n (()=>{ ").concat(script, " })()\n "); });
|
|
1942
1964
|
if (this.options.isVerbose) {
|
|
1943
|
-
console.info(
|
|
1965
|
+
console.info(spaceTrim__default["default"](function (block) { return "\n \uD83D\uDE80 Evaluating ".concat(scriptLanguage, " script:\n\n ").concat(block(statementToEvaluate)); }));
|
|
1944
1966
|
}
|
|
1945
1967
|
_a.label = 1;
|
|
1946
1968
|
case 1:
|
|
@@ -1965,12 +1987,12 @@
|
|
|
1965
1987
|
To: [PipelineExecutionError: Parameter `{thing}` is not defined],
|
|
1966
1988
|
*/
|
|
1967
1989
|
if (!statementToEvaluate.includes(undefinedName_1 + '(')) {
|
|
1968
|
-
throw new PipelineExecutionError(
|
|
1990
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n\n Parameter `{".concat(undefinedName_1, "}` is not defined\n\n This happen during evaluation of the javascript, which has access to the following parameters as javascript variables:\n\n ").concat(block(Object.keys(parameters)
|
|
1969
1991
|
.map(function (key) { return " - ".concat(key, "\n"); })
|
|
1970
1992
|
.join('')), "\n\n The script is:\n ```javascript\n ").concat(block(script), "\n ```\n\n Original error message:\n ").concat(block(error_1.message), "\n\n\n "); }));
|
|
1971
1993
|
}
|
|
1972
1994
|
else {
|
|
1973
|
-
throw new PipelineExecutionError(
|
|
1995
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n Function ".concat(undefinedName_1, "() is not defined\n\n - Make sure that the function is one of built-in functions\n - Or you have to defined the function during construction of JavascriptEvalExecutionTools\n\n Original error message:\n ").concat(block(error_1.message), "\n\n "); }));
|
|
1974
1996
|
}
|
|
1975
1997
|
}
|
|
1976
1998
|
throw error_1;
|
|
@@ -2073,7 +2095,7 @@
|
|
|
2073
2095
|
loremText = loremText.substring(1);
|
|
2074
2096
|
_d.label = 10;
|
|
2075
2097
|
case 10: return [3 /*break*/, 1];
|
|
2076
|
-
case 11: throw new LimitReachedError(
|
|
2098
|
+
case 11: throw new LimitReachedError(spaceTrim.spaceTrim(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 "); }));
|
|
2077
2099
|
}
|
|
2078
2100
|
});
|
|
2079
2101
|
});
|