@promptbook/fake-llm 0.79.0 → 0.80.0-0
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 +4 -0
- package/esm/index.es.js +270 -175
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
- package/esm/typings/src/config.d.ts +0 -25
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
- package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
- package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
- package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
- package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
- package/package.json +2 -2
- package/umd/index.umd.js +270 -175
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/fake-llm`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
package/esm/index.es.js
CHANGED
|
@@ -16,7 +16,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
16
16
|
*
|
|
17
17
|
* @see https://github.com/webgptorg/promptbook
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
19
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.79.0';
|
|
20
20
|
/**
|
|
21
21
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
22
22
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -132,7 +132,7 @@ function __read(o, n) {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* Freezes the given object and all its nested objects recursively
|
|
136
136
|
*
|
|
137
137
|
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
138
138
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
@@ -162,7 +162,8 @@ function $deepFreeze(objectValue) {
|
|
|
162
162
|
}
|
|
163
163
|
finally { if (e_1) throw e_1.error; }
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
Object.freeze(objectValue);
|
|
166
|
+
return objectValue;
|
|
166
167
|
}
|
|
167
168
|
/**
|
|
168
169
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -269,24 +270,6 @@ var LOOP_LIMIT = 1000;
|
|
|
269
270
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
270
271
|
*/
|
|
271
272
|
var CHARACTER_LOOP_LIMIT = 100000;
|
|
272
|
-
/**
|
|
273
|
-
* Nonce which is used for replacing things in strings
|
|
274
|
-
*
|
|
275
|
-
* @private within the repository
|
|
276
|
-
*/
|
|
277
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
278
|
-
/**
|
|
279
|
-
* @@@
|
|
280
|
-
*
|
|
281
|
-
* @private within the repository
|
|
282
|
-
*/
|
|
283
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
284
|
-
/**
|
|
285
|
-
* @@@
|
|
286
|
-
*
|
|
287
|
-
* @private within the repository
|
|
288
|
-
*/
|
|
289
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
290
273
|
// <- TODO: [🧜♂️]
|
|
291
274
|
/**
|
|
292
275
|
* @@@
|
|
@@ -300,42 +283,21 @@ Object.freeze({
|
|
|
300
283
|
skipEmptyLines: true,
|
|
301
284
|
});
|
|
302
285
|
/**
|
|
303
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
304
286
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
305
287
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
306
288
|
*/
|
|
307
289
|
|
|
308
290
|
/**
|
|
309
|
-
*
|
|
291
|
+
* Orders JSON object by keys
|
|
310
292
|
*
|
|
311
|
-
* @
|
|
312
|
-
|
|
313
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
314
|
-
__extends(LimitReachedError, _super);
|
|
315
|
-
function LimitReachedError(message) {
|
|
316
|
-
var _this = _super.call(this, message) || this;
|
|
317
|
-
_this.name = 'LimitReachedError';
|
|
318
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
319
|
-
return _this;
|
|
320
|
-
}
|
|
321
|
-
return LimitReachedError;
|
|
322
|
-
}(Error));
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* This error indicates errors during the execution of the pipeline
|
|
326
|
-
*
|
|
327
|
-
* @public exported from `@promptbook/core`
|
|
293
|
+
* @returns The same type of object as the input re-ordered
|
|
294
|
+
* @public exported from `@promptbook/utils`
|
|
328
295
|
*/
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
function
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
335
|
-
return _this;
|
|
336
|
-
}
|
|
337
|
-
return PipelineExecutionError;
|
|
338
|
-
}(Error));
|
|
296
|
+
function orderJson(options) {
|
|
297
|
+
var value = options.value, order = options.order;
|
|
298
|
+
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
|
|
299
|
+
return orderedValue;
|
|
300
|
+
}
|
|
339
301
|
|
|
340
302
|
/**
|
|
341
303
|
* Make error report URL for the given error
|
|
@@ -371,85 +333,6 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
371
333
|
return UnexpectedError;
|
|
372
334
|
}(Error));
|
|
373
335
|
|
|
374
|
-
/**
|
|
375
|
-
* Replaces parameters in template with values from parameters object
|
|
376
|
-
*
|
|
377
|
-
* @param template the template with parameters in {curly} braces
|
|
378
|
-
* @param parameters the object with parameters
|
|
379
|
-
* @returns the template with replaced parameters
|
|
380
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
381
|
-
* @public exported from `@promptbook/utils`
|
|
382
|
-
*/
|
|
383
|
-
function replaceParameters(template, parameters) {
|
|
384
|
-
var e_1, _a;
|
|
385
|
-
try {
|
|
386
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
387
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
388
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
389
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
390
|
-
}
|
|
391
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
392
|
-
// TODO: [🍵]
|
|
393
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
398
|
-
finally {
|
|
399
|
-
try {
|
|
400
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
401
|
-
}
|
|
402
|
-
finally { if (e_1) throw e_1.error; }
|
|
403
|
-
}
|
|
404
|
-
var replacedTemplates = template;
|
|
405
|
-
var match;
|
|
406
|
-
var loopLimit = LOOP_LIMIT;
|
|
407
|
-
var _loop_1 = function () {
|
|
408
|
-
if (loopLimit-- < 0) {
|
|
409
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
410
|
-
}
|
|
411
|
-
var precol = match.groups.precol;
|
|
412
|
-
var parameterName = match.groups.parameterName;
|
|
413
|
-
if (parameterName === '') {
|
|
414
|
-
return "continue";
|
|
415
|
-
}
|
|
416
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
417
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
418
|
-
}
|
|
419
|
-
if (parameters[parameterName] === undefined) {
|
|
420
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
421
|
-
}
|
|
422
|
-
var parameterValue = parameters[parameterName];
|
|
423
|
-
if (parameterValue === undefined) {
|
|
424
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
425
|
-
}
|
|
426
|
-
parameterValue = parameterValue.toString();
|
|
427
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
428
|
-
parameterValue = parameterValue
|
|
429
|
-
.split('\n')
|
|
430
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
431
|
-
.join('\n');
|
|
432
|
-
}
|
|
433
|
-
replacedTemplates =
|
|
434
|
-
replacedTemplates.substring(0, match.index + precol.length) +
|
|
435
|
-
parameterValue +
|
|
436
|
-
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
437
|
-
};
|
|
438
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
439
|
-
.exec(replacedTemplates))) {
|
|
440
|
-
_loop_1();
|
|
441
|
-
}
|
|
442
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
443
|
-
if (/{\w+$/.test(replacedTemplates)) {
|
|
444
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
445
|
-
}
|
|
446
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
447
|
-
if (/^\w+}/.test(replacedTemplates)) {
|
|
448
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
449
|
-
}
|
|
450
|
-
return replacedTemplates;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
336
|
/**
|
|
454
337
|
* Checks if the value is [🚉] serializable as JSON
|
|
455
338
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -470,8 +353,9 @@ function replaceParameters(template, parameters) {
|
|
|
470
353
|
* @throws UnexpectedError if the value is not serializable as JSON
|
|
471
354
|
* @public exported from `@promptbook/utils`
|
|
472
355
|
*/
|
|
473
|
-
function checkSerializableAsJson(
|
|
356
|
+
function checkSerializableAsJson(options) {
|
|
474
357
|
var e_1, _a;
|
|
358
|
+
var value = options.value, name = options.name, message = options.message;
|
|
475
359
|
if (value === undefined) {
|
|
476
360
|
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
477
361
|
}
|
|
@@ -495,12 +379,12 @@ function checkSerializableAsJson(name, value) {
|
|
|
495
379
|
}
|
|
496
380
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
497
381
|
for (var i = 0; i < value.length; i++) {
|
|
498
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
382
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
499
383
|
}
|
|
500
384
|
}
|
|
501
385
|
else if (typeof value === 'object') {
|
|
502
386
|
if (value instanceof Date) {
|
|
503
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
387
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
504
388
|
}
|
|
505
389
|
else if (value instanceof Map) {
|
|
506
390
|
throw new UnexpectedError("".concat(name, " is Map"));
|
|
@@ -512,7 +396,7 @@ function checkSerializableAsJson(name, value) {
|
|
|
512
396
|
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
513
397
|
}
|
|
514
398
|
else if (value instanceof Error) {
|
|
515
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
399
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
|
|
516
400
|
}
|
|
517
401
|
else {
|
|
518
402
|
try {
|
|
@@ -522,7 +406,7 @@ function checkSerializableAsJson(name, value) {
|
|
|
522
406
|
// Note: undefined in object is serializable - it is just omited
|
|
523
407
|
continue;
|
|
524
408
|
}
|
|
525
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
409
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
526
410
|
}
|
|
527
411
|
}
|
|
528
412
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -539,7 +423,7 @@ function checkSerializableAsJson(name, value) {
|
|
|
539
423
|
if (!(error instanceof Error)) {
|
|
540
424
|
throw error;
|
|
541
425
|
}
|
|
542
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
426
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
543
427
|
}
|
|
544
428
|
/*
|
|
545
429
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -564,35 +448,226 @@ function checkSerializableAsJson(name, value) {
|
|
|
564
448
|
}
|
|
565
449
|
}
|
|
566
450
|
else {
|
|
567
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
451
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
568
452
|
}
|
|
569
453
|
}
|
|
570
454
|
/**
|
|
571
|
-
* TODO:
|
|
455
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
572
456
|
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
573
457
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
574
458
|
*/
|
|
575
459
|
|
|
576
460
|
/**
|
|
577
|
-
* @@@
|
|
578
461
|
* @@@
|
|
579
462
|
*
|
|
580
|
-
*
|
|
463
|
+
* @public exported from `@promptbook/utils`
|
|
464
|
+
*/
|
|
465
|
+
function deepClone(objectValue) {
|
|
466
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
467
|
+
/*
|
|
468
|
+
!!!!!!!!
|
|
469
|
+
TODO: [🧠] Is there a better implementation?
|
|
470
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
471
|
+
> for (const propertyName of propertyNames) {
|
|
472
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
473
|
+
> if (value && typeof value === 'object') {
|
|
474
|
+
> deepClone(value);
|
|
475
|
+
> }
|
|
476
|
+
> }
|
|
477
|
+
> return Object.assign({}, objectValue);
|
|
478
|
+
*/
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Utility to export a JSON object from a function
|
|
581
486
|
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
487
|
+
* 1) Checks if the value is serializable as JSON
|
|
488
|
+
* 2) Makes a deep clone of the object
|
|
489
|
+
* 2) Orders the object properties
|
|
490
|
+
* 2) Deeply freezes the cloned object
|
|
491
|
+
*
|
|
492
|
+
* Note: This function does not mutates the given object
|
|
493
|
+
*
|
|
494
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
495
|
+
* @public exported from `@promptbook/utils`
|
|
586
496
|
*/
|
|
587
|
-
function
|
|
588
|
-
|
|
589
|
-
|
|
497
|
+
function exportJson(options) {
|
|
498
|
+
var name = options.name, value = options.value, order = options.order, message = options.message;
|
|
499
|
+
checkSerializableAsJson({ name: name, value: value, message: message });
|
|
500
|
+
var orderedValue =
|
|
501
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
502
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
503
|
+
// @ts-ignore
|
|
504
|
+
order === undefined
|
|
505
|
+
? deepClone(value)
|
|
506
|
+
: orderJson({
|
|
507
|
+
value: value,
|
|
508
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
509
|
+
order: order,
|
|
510
|
+
});
|
|
511
|
+
$deepFreeze(orderedValue);
|
|
512
|
+
return orderedValue;
|
|
590
513
|
}
|
|
591
514
|
/**
|
|
592
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
593
515
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
594
516
|
*/
|
|
595
517
|
|
|
518
|
+
/**
|
|
519
|
+
* Nonce which is used for replacing things in strings
|
|
520
|
+
*
|
|
521
|
+
* @private within the repository
|
|
522
|
+
*/
|
|
523
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
524
|
+
/**
|
|
525
|
+
* @@@
|
|
526
|
+
*
|
|
527
|
+
* @private within the repository
|
|
528
|
+
*/
|
|
529
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
530
|
+
/**
|
|
531
|
+
* @@@
|
|
532
|
+
*
|
|
533
|
+
* @private within the repository
|
|
534
|
+
*/
|
|
535
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
536
|
+
/**
|
|
537
|
+
* The names of the parameters that are reserved for special purposes
|
|
538
|
+
*
|
|
539
|
+
* @public exported from `@promptbook/core`
|
|
540
|
+
*/
|
|
541
|
+
exportJson({
|
|
542
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
543
|
+
message: "The names of the parameters that are reserved for special purposes",
|
|
544
|
+
value: [
|
|
545
|
+
'content',
|
|
546
|
+
'context',
|
|
547
|
+
'knowledge',
|
|
548
|
+
'examples',
|
|
549
|
+
'modelName',
|
|
550
|
+
'currentDate',
|
|
551
|
+
// <- TODO: list here all command names
|
|
552
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
553
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
554
|
+
],
|
|
555
|
+
});
|
|
556
|
+
/**
|
|
557
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
558
|
+
*/
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* This error type indicates that some limit was reached
|
|
562
|
+
*
|
|
563
|
+
* @public exported from `@promptbook/core`
|
|
564
|
+
*/
|
|
565
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
566
|
+
__extends(LimitReachedError, _super);
|
|
567
|
+
function LimitReachedError(message) {
|
|
568
|
+
var _this = _super.call(this, message) || this;
|
|
569
|
+
_this.name = 'LimitReachedError';
|
|
570
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
571
|
+
return _this;
|
|
572
|
+
}
|
|
573
|
+
return LimitReachedError;
|
|
574
|
+
}(Error));
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* This error indicates errors during the execution of the pipeline
|
|
578
|
+
*
|
|
579
|
+
* @public exported from `@promptbook/core`
|
|
580
|
+
*/
|
|
581
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
582
|
+
__extends(PipelineExecutionError, _super);
|
|
583
|
+
function PipelineExecutionError(message) {
|
|
584
|
+
var _this = _super.call(this, message) || this;
|
|
585
|
+
_this.name = 'PipelineExecutionError';
|
|
586
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
587
|
+
return _this;
|
|
588
|
+
}
|
|
589
|
+
return PipelineExecutionError;
|
|
590
|
+
}(Error));
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Replaces parameters in template with values from parameters object
|
|
594
|
+
*
|
|
595
|
+
* @param template the template with parameters in {curly} braces
|
|
596
|
+
* @param parameters the object with parameters
|
|
597
|
+
* @returns the template with replaced parameters
|
|
598
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
599
|
+
* @public exported from `@promptbook/utils`
|
|
600
|
+
*/
|
|
601
|
+
function replaceParameters(template, parameters) {
|
|
602
|
+
var e_1, _a;
|
|
603
|
+
try {
|
|
604
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
605
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
606
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
607
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
608
|
+
}
|
|
609
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
610
|
+
// TODO: [🍵]
|
|
611
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
616
|
+
finally {
|
|
617
|
+
try {
|
|
618
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
619
|
+
}
|
|
620
|
+
finally { if (e_1) throw e_1.error; }
|
|
621
|
+
}
|
|
622
|
+
var replacedTemplates = template;
|
|
623
|
+
var match;
|
|
624
|
+
var loopLimit = LOOP_LIMIT;
|
|
625
|
+
var _loop_1 = function () {
|
|
626
|
+
if (loopLimit-- < 0) {
|
|
627
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
628
|
+
}
|
|
629
|
+
var precol = match.groups.precol;
|
|
630
|
+
var parameterName = match.groups.parameterName;
|
|
631
|
+
if (parameterName === '') {
|
|
632
|
+
return "continue";
|
|
633
|
+
}
|
|
634
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
635
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
636
|
+
}
|
|
637
|
+
if (parameters[parameterName] === undefined) {
|
|
638
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
639
|
+
}
|
|
640
|
+
var parameterValue = parameters[parameterName];
|
|
641
|
+
if (parameterValue === undefined) {
|
|
642
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
643
|
+
}
|
|
644
|
+
parameterValue = parameterValue.toString();
|
|
645
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
646
|
+
parameterValue = parameterValue
|
|
647
|
+
.split('\n')
|
|
648
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
649
|
+
.join('\n');
|
|
650
|
+
}
|
|
651
|
+
replacedTemplates =
|
|
652
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
653
|
+
parameterValue +
|
|
654
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
655
|
+
};
|
|
656
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
657
|
+
.exec(replacedTemplates))) {
|
|
658
|
+
_loop_1();
|
|
659
|
+
}
|
|
660
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
661
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
662
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
663
|
+
}
|
|
664
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
665
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
666
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
667
|
+
}
|
|
668
|
+
return replacedTemplates;
|
|
669
|
+
}
|
|
670
|
+
|
|
596
671
|
/**
|
|
597
672
|
* Mocked execution Tools for just echoing the requests for testing purposes.
|
|
598
673
|
*
|
|
@@ -653,20 +728,25 @@ var MockedEchoLlmExecutionTools = /** @class */ (function () {
|
|
|
653
728
|
rawPromptContent = replaceParameters(prompt.content, __assign(__assign({}, prompt.parameters), { modelName: modelName }));
|
|
654
729
|
usage = ZERO_USAGE;
|
|
655
730
|
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
656
|
-
return [2 /*return*/,
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
731
|
+
return [2 /*return*/, exportJson({
|
|
732
|
+
name: 'promptResult',
|
|
733
|
+
message: "Result of `MockedEchoLlmExecutionTools.callChatModel`",
|
|
734
|
+
order: [],
|
|
735
|
+
value: {
|
|
736
|
+
content: spaceTrim$1(function (block) { return "\n You said:\n ".concat(block(rawPromptContent), "\n "); }),
|
|
737
|
+
modelName: modelName,
|
|
738
|
+
timing: {
|
|
739
|
+
start: $getCurrentDate(),
|
|
740
|
+
complete: $getCurrentDate(),
|
|
741
|
+
},
|
|
742
|
+
usage: usage,
|
|
743
|
+
rawPromptContent: rawPromptContent,
|
|
744
|
+
rawRequest: null,
|
|
745
|
+
rawResponse: {
|
|
746
|
+
note: 'This is mocked echo',
|
|
747
|
+
},
|
|
748
|
+
// <- [🗯]
|
|
668
749
|
},
|
|
669
|
-
// <- [🗯]
|
|
670
750
|
})];
|
|
671
751
|
});
|
|
672
752
|
});
|
|
@@ -685,20 +765,25 @@ var MockedEchoLlmExecutionTools = /** @class */ (function () {
|
|
|
685
765
|
rawPromptContent = replaceParameters(prompt.content, __assign(__assign({}, prompt.parameters), { modelName: modelName }));
|
|
686
766
|
usage = ZERO_USAGE;
|
|
687
767
|
// <- TODO: [🧠] Compute here at least words, characters,... etc
|
|
688
|
-
return [2 /*return*/,
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
768
|
+
return [2 /*return*/, exportJson({
|
|
769
|
+
name: 'promptResult',
|
|
770
|
+
message: "Result of `MockedEchoLlmExecutionTools.callCompletionModel`",
|
|
771
|
+
order: [],
|
|
772
|
+
value: {
|
|
773
|
+
content: spaceTrim$1(function (block) { return "\n ".concat(block(rawPromptContent), "\n And so on...\n "); }),
|
|
774
|
+
modelName: modelName,
|
|
775
|
+
timing: {
|
|
776
|
+
start: $getCurrentDate(),
|
|
777
|
+
complete: $getCurrentDate(),
|
|
778
|
+
},
|
|
779
|
+
usage: usage,
|
|
780
|
+
rawPromptContent: rawPromptContent,
|
|
781
|
+
rawRequest: null,
|
|
782
|
+
rawResponse: {
|
|
783
|
+
note: 'This is mocked echo',
|
|
784
|
+
},
|
|
785
|
+
// <- [🗯]
|
|
700
786
|
},
|
|
701
|
-
// <- [🗯]
|
|
702
787
|
})];
|
|
703
788
|
});
|
|
704
789
|
});
|
|
@@ -2186,7 +2271,12 @@ var MockedFackedLlmExecutionTools = /** @class */ (function () {
|
|
|
2186
2271
|
if (this.options.isVerbose) {
|
|
2187
2272
|
console.info('💬 Mocked faked result', result);
|
|
2188
2273
|
}
|
|
2189
|
-
return [2 /*return*/,
|
|
2274
|
+
return [2 /*return*/, exportJson({
|
|
2275
|
+
name: 'promptResult',
|
|
2276
|
+
message: "Result of `MockedFackedLlmExecutionTools.callChatModel`",
|
|
2277
|
+
order: [],
|
|
2278
|
+
value: result,
|
|
2279
|
+
})];
|
|
2190
2280
|
}
|
|
2191
2281
|
});
|
|
2192
2282
|
});
|
|
@@ -2232,7 +2322,12 @@ var MockedFackedLlmExecutionTools = /** @class */ (function () {
|
|
|
2232
2322
|
if (this.options.isVerbose) {
|
|
2233
2323
|
console.info('💬 Mocked faked result', result);
|
|
2234
2324
|
}
|
|
2235
|
-
return [2 /*return*/,
|
|
2325
|
+
return [2 /*return*/, exportJson({
|
|
2326
|
+
name: 'promptResult',
|
|
2327
|
+
message: "Result of `MockedFackedLlmExecutionTools.callEmbeddingModel`",
|
|
2328
|
+
order: [],
|
|
2329
|
+
value: result,
|
|
2330
|
+
})];
|
|
2236
2331
|
});
|
|
2237
2332
|
});
|
|
2238
2333
|
};
|