@promptbook/google 0.79.0 → 0.80.0-1
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 +222 -143
- 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 +8 -6
- package/esm/typings/src/_packages/types.index.d.ts +6 -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/getParserForCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -1
- 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/{pipelineStringToJson.d.ts → compilePipeline.d.ts} +3 -3
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/{pipelineStringToJsonSync.d.ts → precompilePipeline.d.ts} +4 -3
- 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/prepare/unpreparePipeline.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 +222 -143
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
- /package/esm/typings/src/conversion/{pipelineStringToJson.test.d.ts → compilePipeline.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/{pipelineStringToJsonSync.test.d.ts → precompilePipeline.test.d.ts} +0 -0
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/google`
|
|
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
|
@@ -13,7 +13,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
13
13
|
*
|
|
14
14
|
* @see https://github.com/webgptorg/promptbook
|
|
15
15
|
*/
|
|
16
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
16
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.80.0-0';
|
|
17
17
|
/**
|
|
18
18
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
19
19
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -164,7 +164,7 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
164
164
|
}(Error));
|
|
165
165
|
|
|
166
166
|
/**
|
|
167
|
-
*
|
|
167
|
+
* Freezes the given object and all its nested objects recursively
|
|
168
168
|
*
|
|
169
169
|
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
170
170
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
@@ -194,7 +194,8 @@ function $deepFreeze(objectValue) {
|
|
|
194
194
|
}
|
|
195
195
|
finally { if (e_1) throw e_1.error; }
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
Object.freeze(objectValue);
|
|
198
|
+
return objectValue;
|
|
198
199
|
}
|
|
199
200
|
/**
|
|
200
201
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -295,24 +296,6 @@ var ADMIN_GITHUB_NAME = 'hejny';
|
|
|
295
296
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
296
297
|
*/
|
|
297
298
|
var LOOP_LIMIT = 1000;
|
|
298
|
-
/**
|
|
299
|
-
* Nonce which is used for replacing things in strings
|
|
300
|
-
*
|
|
301
|
-
* @private within the repository
|
|
302
|
-
*/
|
|
303
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
304
|
-
/**
|
|
305
|
-
* @@@
|
|
306
|
-
*
|
|
307
|
-
* @private within the repository
|
|
308
|
-
*/
|
|
309
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
310
|
-
/**
|
|
311
|
-
* @@@
|
|
312
|
-
*
|
|
313
|
-
* @private within the repository
|
|
314
|
-
*/
|
|
315
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
316
299
|
// <- TODO: [🧜♂️]
|
|
317
300
|
/**
|
|
318
301
|
* @@@
|
|
@@ -326,26 +309,21 @@ Object.freeze({
|
|
|
326
309
|
skipEmptyLines: true,
|
|
327
310
|
});
|
|
328
311
|
/**
|
|
329
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
330
312
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
331
313
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
332
314
|
*/
|
|
333
315
|
|
|
334
316
|
/**
|
|
335
|
-
*
|
|
317
|
+
* Orders JSON object by keys
|
|
336
318
|
*
|
|
337
|
-
* @
|
|
319
|
+
* @returns The same type of object as the input re-ordered
|
|
320
|
+
* @public exported from `@promptbook/utils`
|
|
338
321
|
*/
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
345
|
-
return _this;
|
|
346
|
-
}
|
|
347
|
-
return LimitReachedError;
|
|
348
|
-
}(Error));
|
|
322
|
+
function orderJson(options) {
|
|
323
|
+
var value = options.value, order = options.order;
|
|
324
|
+
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
|
|
325
|
+
return orderedValue;
|
|
326
|
+
}
|
|
349
327
|
|
|
350
328
|
/**
|
|
351
329
|
* Make error report URL for the given error
|
|
@@ -381,85 +359,6 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
381
359
|
return UnexpectedError;
|
|
382
360
|
}(Error));
|
|
383
361
|
|
|
384
|
-
/**
|
|
385
|
-
* Replaces parameters in template with values from parameters object
|
|
386
|
-
*
|
|
387
|
-
* @param template the template with parameters in {curly} braces
|
|
388
|
-
* @param parameters the object with parameters
|
|
389
|
-
* @returns the template with replaced parameters
|
|
390
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
391
|
-
* @public exported from `@promptbook/utils`
|
|
392
|
-
*/
|
|
393
|
-
function replaceParameters(template, parameters) {
|
|
394
|
-
var e_1, _a;
|
|
395
|
-
try {
|
|
396
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
397
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
398
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
399
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
400
|
-
}
|
|
401
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
402
|
-
// TODO: [🍵]
|
|
403
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
408
|
-
finally {
|
|
409
|
-
try {
|
|
410
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
411
|
-
}
|
|
412
|
-
finally { if (e_1) throw e_1.error; }
|
|
413
|
-
}
|
|
414
|
-
var replacedTemplates = template;
|
|
415
|
-
var match;
|
|
416
|
-
var loopLimit = LOOP_LIMIT;
|
|
417
|
-
var _loop_1 = function () {
|
|
418
|
-
if (loopLimit-- < 0) {
|
|
419
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
420
|
-
}
|
|
421
|
-
var precol = match.groups.precol;
|
|
422
|
-
var parameterName = match.groups.parameterName;
|
|
423
|
-
if (parameterName === '') {
|
|
424
|
-
return "continue";
|
|
425
|
-
}
|
|
426
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
427
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
428
|
-
}
|
|
429
|
-
if (parameters[parameterName] === undefined) {
|
|
430
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
431
|
-
}
|
|
432
|
-
var parameterValue = parameters[parameterName];
|
|
433
|
-
if (parameterValue === undefined) {
|
|
434
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
435
|
-
}
|
|
436
|
-
parameterValue = parameterValue.toString();
|
|
437
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
438
|
-
parameterValue = parameterValue
|
|
439
|
-
.split('\n')
|
|
440
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
441
|
-
.join('\n');
|
|
442
|
-
}
|
|
443
|
-
replacedTemplates =
|
|
444
|
-
replacedTemplates.substring(0, match.index + precol.length) +
|
|
445
|
-
parameterValue +
|
|
446
|
-
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
447
|
-
};
|
|
448
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
449
|
-
.exec(replacedTemplates))) {
|
|
450
|
-
_loop_1();
|
|
451
|
-
}
|
|
452
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
453
|
-
if (/{\w+$/.test(replacedTemplates)) {
|
|
454
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
455
|
-
}
|
|
456
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
457
|
-
if (/^\w+}/.test(replacedTemplates)) {
|
|
458
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
459
|
-
}
|
|
460
|
-
return replacedTemplates;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
362
|
/**
|
|
464
363
|
* Checks if the value is [🚉] serializable as JSON
|
|
465
364
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -480,8 +379,9 @@ function replaceParameters(template, parameters) {
|
|
|
480
379
|
* @throws UnexpectedError if the value is not serializable as JSON
|
|
481
380
|
* @public exported from `@promptbook/utils`
|
|
482
381
|
*/
|
|
483
|
-
function checkSerializableAsJson(
|
|
382
|
+
function checkSerializableAsJson(options) {
|
|
484
383
|
var e_1, _a;
|
|
384
|
+
var value = options.value, name = options.name, message = options.message;
|
|
485
385
|
if (value === undefined) {
|
|
486
386
|
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
487
387
|
}
|
|
@@ -505,12 +405,12 @@ function checkSerializableAsJson(name, value) {
|
|
|
505
405
|
}
|
|
506
406
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
507
407
|
for (var i = 0; i < value.length; i++) {
|
|
508
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
408
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
509
409
|
}
|
|
510
410
|
}
|
|
511
411
|
else if (typeof value === 'object') {
|
|
512
412
|
if (value instanceof Date) {
|
|
513
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
413
|
+
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 "); }));
|
|
514
414
|
}
|
|
515
415
|
else if (value instanceof Map) {
|
|
516
416
|
throw new UnexpectedError("".concat(name, " is Map"));
|
|
@@ -522,7 +422,7 @@ function checkSerializableAsJson(name, value) {
|
|
|
522
422
|
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
523
423
|
}
|
|
524
424
|
else if (value instanceof Error) {
|
|
525
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
425
|
+
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 "); }));
|
|
526
426
|
}
|
|
527
427
|
else {
|
|
528
428
|
try {
|
|
@@ -532,7 +432,7 @@ function checkSerializableAsJson(name, value) {
|
|
|
532
432
|
// Note: undefined in object is serializable - it is just omited
|
|
533
433
|
continue;
|
|
534
434
|
}
|
|
535
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
435
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
536
436
|
}
|
|
537
437
|
}
|
|
538
438
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -549,7 +449,7 @@ function checkSerializableAsJson(name, value) {
|
|
|
549
449
|
if (!(error instanceof Error)) {
|
|
550
450
|
throw error;
|
|
551
451
|
}
|
|
552
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
452
|
+
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 "); }));
|
|
553
453
|
}
|
|
554
454
|
/*
|
|
555
455
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -574,35 +474,210 @@ function checkSerializableAsJson(name, value) {
|
|
|
574
474
|
}
|
|
575
475
|
}
|
|
576
476
|
else {
|
|
577
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
477
|
+
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 "); }));
|
|
578
478
|
}
|
|
579
479
|
}
|
|
580
480
|
/**
|
|
581
|
-
* TODO:
|
|
481
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
582
482
|
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
583
483
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
584
484
|
*/
|
|
585
485
|
|
|
586
486
|
/**
|
|
587
|
-
* @@@
|
|
588
487
|
* @@@
|
|
589
488
|
*
|
|
590
|
-
*
|
|
489
|
+
* @public exported from `@promptbook/utils`
|
|
490
|
+
*/
|
|
491
|
+
function deepClone(objectValue) {
|
|
492
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
493
|
+
/*
|
|
494
|
+
!!!!!!!!
|
|
495
|
+
TODO: [🧠] Is there a better implementation?
|
|
496
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
497
|
+
> for (const propertyName of propertyNames) {
|
|
498
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
499
|
+
> if (value && typeof value === 'object') {
|
|
500
|
+
> deepClone(value);
|
|
501
|
+
> }
|
|
502
|
+
> }
|
|
503
|
+
> return Object.assign({}, objectValue);
|
|
504
|
+
*/
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
508
|
+
*/
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Utility to export a JSON object from a function
|
|
591
512
|
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
513
|
+
* 1) Checks if the value is serializable as JSON
|
|
514
|
+
* 2) Makes a deep clone of the object
|
|
515
|
+
* 2) Orders the object properties
|
|
516
|
+
* 2) Deeply freezes the cloned object
|
|
517
|
+
*
|
|
518
|
+
* Note: This function does not mutates the given object
|
|
519
|
+
*
|
|
520
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
521
|
+
* @public exported from `@promptbook/utils`
|
|
596
522
|
*/
|
|
597
|
-
function
|
|
598
|
-
|
|
599
|
-
|
|
523
|
+
function exportJson(options) {
|
|
524
|
+
var name = options.name, value = options.value, order = options.order, message = options.message;
|
|
525
|
+
checkSerializableAsJson({ name: name, value: value, message: message });
|
|
526
|
+
var orderedValue =
|
|
527
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
528
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
529
|
+
// @ts-ignore
|
|
530
|
+
order === undefined
|
|
531
|
+
? deepClone(value)
|
|
532
|
+
: orderJson({
|
|
533
|
+
value: value,
|
|
534
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
535
|
+
order: order,
|
|
536
|
+
});
|
|
537
|
+
$deepFreeze(orderedValue);
|
|
538
|
+
return orderedValue;
|
|
600
539
|
}
|
|
601
540
|
/**
|
|
602
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
603
541
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
604
542
|
*/
|
|
605
543
|
|
|
544
|
+
/**
|
|
545
|
+
* Nonce which is used for replacing things in strings
|
|
546
|
+
*
|
|
547
|
+
* @private within the repository
|
|
548
|
+
*/
|
|
549
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
550
|
+
/**
|
|
551
|
+
* @@@
|
|
552
|
+
*
|
|
553
|
+
* @private within the repository
|
|
554
|
+
*/
|
|
555
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
556
|
+
/**
|
|
557
|
+
* @@@
|
|
558
|
+
*
|
|
559
|
+
* @private within the repository
|
|
560
|
+
*/
|
|
561
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
562
|
+
/**
|
|
563
|
+
* The names of the parameters that are reserved for special purposes
|
|
564
|
+
*
|
|
565
|
+
* @public exported from `@promptbook/core`
|
|
566
|
+
*/
|
|
567
|
+
exportJson({
|
|
568
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
569
|
+
message: "The names of the parameters that are reserved for special purposes",
|
|
570
|
+
value: [
|
|
571
|
+
'content',
|
|
572
|
+
'context',
|
|
573
|
+
'knowledge',
|
|
574
|
+
'examples',
|
|
575
|
+
'modelName',
|
|
576
|
+
'currentDate',
|
|
577
|
+
// <- TODO: list here all command names
|
|
578
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
579
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
580
|
+
],
|
|
581
|
+
});
|
|
582
|
+
/**
|
|
583
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
584
|
+
*/
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* This error type indicates that some limit was reached
|
|
588
|
+
*
|
|
589
|
+
* @public exported from `@promptbook/core`
|
|
590
|
+
*/
|
|
591
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
592
|
+
__extends(LimitReachedError, _super);
|
|
593
|
+
function LimitReachedError(message) {
|
|
594
|
+
var _this = _super.call(this, message) || this;
|
|
595
|
+
_this.name = 'LimitReachedError';
|
|
596
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
597
|
+
return _this;
|
|
598
|
+
}
|
|
599
|
+
return LimitReachedError;
|
|
600
|
+
}(Error));
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Replaces parameters in template with values from parameters object
|
|
604
|
+
*
|
|
605
|
+
* @param template the template with parameters in {curly} braces
|
|
606
|
+
* @param parameters the object with parameters
|
|
607
|
+
* @returns the template with replaced parameters
|
|
608
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
609
|
+
* @public exported from `@promptbook/utils`
|
|
610
|
+
*/
|
|
611
|
+
function replaceParameters(template, parameters) {
|
|
612
|
+
var e_1, _a;
|
|
613
|
+
try {
|
|
614
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
615
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
616
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
617
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
618
|
+
}
|
|
619
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
620
|
+
// TODO: [🍵]
|
|
621
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
626
|
+
finally {
|
|
627
|
+
try {
|
|
628
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
629
|
+
}
|
|
630
|
+
finally { if (e_1) throw e_1.error; }
|
|
631
|
+
}
|
|
632
|
+
var replacedTemplates = template;
|
|
633
|
+
var match;
|
|
634
|
+
var loopLimit = LOOP_LIMIT;
|
|
635
|
+
var _loop_1 = function () {
|
|
636
|
+
if (loopLimit-- < 0) {
|
|
637
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
638
|
+
}
|
|
639
|
+
var precol = match.groups.precol;
|
|
640
|
+
var parameterName = match.groups.parameterName;
|
|
641
|
+
if (parameterName === '') {
|
|
642
|
+
return "continue";
|
|
643
|
+
}
|
|
644
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
645
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
646
|
+
}
|
|
647
|
+
if (parameters[parameterName] === undefined) {
|
|
648
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
649
|
+
}
|
|
650
|
+
var parameterValue = parameters[parameterName];
|
|
651
|
+
if (parameterValue === undefined) {
|
|
652
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
653
|
+
}
|
|
654
|
+
parameterValue = parameterValue.toString();
|
|
655
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
656
|
+
parameterValue = parameterValue
|
|
657
|
+
.split('\n')
|
|
658
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
659
|
+
.join('\n');
|
|
660
|
+
}
|
|
661
|
+
replacedTemplates =
|
|
662
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
663
|
+
parameterValue +
|
|
664
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
665
|
+
};
|
|
666
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
667
|
+
.exec(replacedTemplates))) {
|
|
668
|
+
_loop_1();
|
|
669
|
+
}
|
|
670
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
671
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
672
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
673
|
+
}
|
|
674
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
675
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
676
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
677
|
+
}
|
|
678
|
+
return replacedTemplates;
|
|
679
|
+
}
|
|
680
|
+
|
|
606
681
|
/**
|
|
607
682
|
* Function `asSerializable` will convert values which are not serializable to serializable values
|
|
608
683
|
* It walks deeply through the object and converts all values
|
|
@@ -682,7 +757,7 @@ function createExecutionToolsFromVercelProvider(options) {
|
|
|
682
757
|
return modelVariant === 'CHAT';
|
|
683
758
|
})) === null || _a === void 0 ? void 0 : _a.modelName);
|
|
684
759
|
if (!modelName) {
|
|
685
|
-
throw new PipelineExecutionError(spaceTrim("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n
|
|
760
|
+
throw new PipelineExecutionError(spaceTrim("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n\n "));
|
|
686
761
|
}
|
|
687
762
|
return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
|
|
688
763
|
case 1:
|
|
@@ -745,18 +820,22 @@ function createExecutionToolsFromVercelProvider(options) {
|
|
|
745
820
|
}
|
|
746
821
|
complete = $getCurrentDate();
|
|
747
822
|
usage = UNCERTAIN_USAGE;
|
|
748
|
-
return [2 /*return*/,
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
823
|
+
return [2 /*return*/, exportJson({
|
|
824
|
+
name: 'promptResult',
|
|
825
|
+
message: "Result of `createExecutionToolsFromVercelProvider.callChatModel`",
|
|
826
|
+
value: {
|
|
827
|
+
content: rawResponse.text,
|
|
828
|
+
modelName: modelName,
|
|
829
|
+
timing: {
|
|
830
|
+
start: start,
|
|
831
|
+
complete: complete,
|
|
832
|
+
},
|
|
833
|
+
usage: usage,
|
|
834
|
+
rawPromptContent: rawPromptContent,
|
|
835
|
+
rawRequest: rawRequest,
|
|
836
|
+
rawResponse: asSerializable(rawResponse),
|
|
837
|
+
// <- [🗯]
|
|
754
838
|
},
|
|
755
|
-
usage: usage,
|
|
756
|
-
rawPromptContent: rawPromptContent,
|
|
757
|
-
rawRequest: rawRequest,
|
|
758
|
-
rawResponse: asSerializable(rawResponse),
|
|
759
|
-
// <- [🗯]
|
|
760
839
|
})];
|
|
761
840
|
}
|
|
762
841
|
});
|