@promptbook/core 0.23.2 → 0.24.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/esm/index.es.js +292 -35
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/types.index.d.ts +2 -2
- package/esm/typings/_packages/utils.index.d.ts +11 -1
- package/esm/typings/conversion/parseCommand.d.ts +2 -2
- package/esm/typings/execution/PromptResult.d.ts +1 -1
- package/esm/typings/types/Command.d.ts +17 -4
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
- package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +19 -0
- package/esm/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
- package/esm/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
- package/esm/typings/types/typeAliases.d.ts +3 -1
- package/esm/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countLines.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countPages.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countSentences.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countWords.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/index.d.ts +5 -0
- package/esm/typings/utils/parseNumber.d.ts +10 -0
- package/esm/typings/utils/parseNumber.test.d.ts +1 -0
- package/esm/typings/utils/trimCodeBlock.d.ts +8 -0
- package/esm/typings/utils/trimCodeBlock.test.d.ts +1 -0
- package/esm/typings/utils/trimEndOfCodeBlock.d.ts +2 -1
- package/package.json +1 -1
- package/umd/index.umd.js +291 -34
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/types.index.d.ts +2 -2
- package/umd/typings/_packages/utils.index.d.ts +11 -1
- package/umd/typings/conversion/parseCommand.d.ts +2 -2
- package/umd/typings/execution/PromptResult.d.ts +1 -1
- package/umd/typings/types/Command.d.ts +17 -4
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
- package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +19 -0
- package/umd/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
- package/umd/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
- package/umd/typings/types/typeAliases.d.ts +3 -1
- package/umd/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countLines.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countPages.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countSentences.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countWords.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/index.d.ts +5 -0
- package/umd/typings/utils/parseNumber.d.ts +10 -0
- package/umd/typings/utils/parseNumber.test.d.ts +1 -0
- package/umd/typings/utils/trimCodeBlock.d.ts +8 -0
- package/umd/typings/utils/trimCodeBlock.test.d.ts +1 -0
- package/umd/typings/utils/trimEndOfCodeBlock.d.ts +2 -1
package/umd/index.umd.js
CHANGED
|
@@ -349,6 +349,14 @@
|
|
|
349
349
|
*/
|
|
350
350
|
var ExecutionTypes = ['PROMPT_TEMPLATE', 'SIMPLE_TEMPLATE', 'SCRIPT', 'PROMPT_DIALOG'];
|
|
351
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Units of text measurement
|
|
354
|
+
*/
|
|
355
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'PARAGRAPHS', 'LINES', 'PAGES'];
|
|
356
|
+
/**
|
|
357
|
+
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
358
|
+
*/
|
|
359
|
+
|
|
352
360
|
/**
|
|
353
361
|
* Removes Markdown formatting tags from a string.
|
|
354
362
|
*
|
|
@@ -365,10 +373,73 @@
|
|
|
365
373
|
return str;
|
|
366
374
|
}
|
|
367
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Function parseNumber will parse number from string
|
|
378
|
+
*
|
|
379
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
380
|
+
* Note: it also works only with decimal numbers
|
|
381
|
+
*/
|
|
382
|
+
function parseNumber(value) {
|
|
383
|
+
var originalValue = value;
|
|
384
|
+
if (typeof value === 'number') {
|
|
385
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
386
|
+
}
|
|
387
|
+
if (typeof value !== 'string') {
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
value = value.trim();
|
|
391
|
+
if (value.startsWith('+')) {
|
|
392
|
+
return parseNumber(value.substring(1));
|
|
393
|
+
}
|
|
394
|
+
if (value.startsWith('-')) {
|
|
395
|
+
var number = parseNumber(value.substring(1));
|
|
396
|
+
if (number === 0) {
|
|
397
|
+
return 0; // <- Note: To prevent -0
|
|
398
|
+
}
|
|
399
|
+
return -number;
|
|
400
|
+
}
|
|
401
|
+
value = value.replace(/,/g, '.');
|
|
402
|
+
value = value.toUpperCase();
|
|
403
|
+
if (value === '') {
|
|
404
|
+
return 0;
|
|
405
|
+
}
|
|
406
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
407
|
+
return Infinity;
|
|
408
|
+
}
|
|
409
|
+
if (value.includes('/')) {
|
|
410
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
411
|
+
var numerator = parseNumber(numerator_);
|
|
412
|
+
var denominator = parseNumber(denominator_);
|
|
413
|
+
if (denominator === 0) {
|
|
414
|
+
throw new Error("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
415
|
+
}
|
|
416
|
+
return numerator / denominator;
|
|
417
|
+
}
|
|
418
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
419
|
+
return 0;
|
|
420
|
+
}
|
|
421
|
+
if (value.includes('E')) {
|
|
422
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
423
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
424
|
+
}
|
|
425
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
426
|
+
throw new Error("Unable to parse number from \"".concat(originalValue, "\""));
|
|
427
|
+
}
|
|
428
|
+
var num = parseFloat(value);
|
|
429
|
+
if (isNaN(num)) {
|
|
430
|
+
throw new Error("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
431
|
+
}
|
|
432
|
+
return num;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
436
|
+
*/
|
|
437
|
+
|
|
368
438
|
/**
|
|
369
439
|
* Parses one line of ul/ol to command
|
|
370
440
|
*/
|
|
371
441
|
function parseCommand(listItem) {
|
|
442
|
+
var e_1, _a;
|
|
372
443
|
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
373
444
|
throw new Error('Command can not contain new line characters:');
|
|
374
445
|
}
|
|
@@ -475,7 +546,7 @@
|
|
|
475
546
|
throw new Error(spaceTrim__default["default"]("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
476
547
|
}
|
|
477
548
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
478
|
-
var
|
|
549
|
+
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
479
550
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
480
551
|
throw new Error(spaceTrim__default["default"]("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
481
552
|
}
|
|
@@ -497,6 +568,74 @@
|
|
|
497
568
|
functionName: functionName,
|
|
498
569
|
};
|
|
499
570
|
}
|
|
571
|
+
else if (type.startsWith('EXPECT')) {
|
|
572
|
+
try {
|
|
573
|
+
listItemParts.shift();
|
|
574
|
+
var sign = void 0;
|
|
575
|
+
var signRaw = listItemParts.shift();
|
|
576
|
+
if (/^exact/i.test(signRaw)) {
|
|
577
|
+
sign = 'EXACTLY';
|
|
578
|
+
}
|
|
579
|
+
else if (/^min/i.test(signRaw)) {
|
|
580
|
+
sign = 'MINIMUM';
|
|
581
|
+
}
|
|
582
|
+
else if (/^max/i.test(signRaw)) {
|
|
583
|
+
sign = 'MAXIMUM';
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
throw new Error("Invalid sign \"".concat(signRaw, "\""));
|
|
587
|
+
}
|
|
588
|
+
var amountRaw = listItemParts.shift();
|
|
589
|
+
var amount = parseNumber(amountRaw);
|
|
590
|
+
if (amount < 0) {
|
|
591
|
+
throw new Error('Amount must be positive number or zero');
|
|
592
|
+
}
|
|
593
|
+
if (amount !== Math.floor(amount)) {
|
|
594
|
+
throw new Error('Amount must be whole number');
|
|
595
|
+
}
|
|
596
|
+
var unitRaw = listItemParts.shift();
|
|
597
|
+
var unit = undefined;
|
|
598
|
+
try {
|
|
599
|
+
for (var EXPECTATION_UNITS_1 = __values(EXPECTATION_UNITS), EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next(); !EXPECTATION_UNITS_1_1.done; EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next()) {
|
|
600
|
+
var existingUnit = EXPECTATION_UNITS_1_1.value;
|
|
601
|
+
var existingUnitText = existingUnit;
|
|
602
|
+
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
603
|
+
if (existingUnitText === 'CHARACTER') {
|
|
604
|
+
existingUnitText = 'CHAR';
|
|
605
|
+
}
|
|
606
|
+
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
607
|
+
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
608
|
+
if (unit !== undefined) {
|
|
609
|
+
throw new Error("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
610
|
+
}
|
|
611
|
+
unit = existingUnit;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
616
|
+
finally {
|
|
617
|
+
try {
|
|
618
|
+
if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
|
|
619
|
+
}
|
|
620
|
+
finally { if (e_1) throw e_1.error; }
|
|
621
|
+
}
|
|
622
|
+
if (unit === undefined) {
|
|
623
|
+
throw new Error("Invalid unit \"".concat(unitRaw, "\""));
|
|
624
|
+
}
|
|
625
|
+
return {
|
|
626
|
+
type: 'EXPECT',
|
|
627
|
+
sign: sign,
|
|
628
|
+
unit: unit,
|
|
629
|
+
amount: amount,
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
catch (error) {
|
|
633
|
+
if (!(error instanceof Error)) {
|
|
634
|
+
throw error;
|
|
635
|
+
}
|
|
636
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
637
|
+
}
|
|
638
|
+
}
|
|
500
639
|
else {
|
|
501
640
|
throw new Error(spaceTrim__default["default"]("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Model\n - Parameter\n - Input parameter\n - Output parameter\n - PTBK Version\n ")));
|
|
502
641
|
}
|
|
@@ -605,6 +744,7 @@
|
|
|
605
744
|
var postprocessingCommands = [];
|
|
606
745
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
607
746
|
var executionType = 'PROMPT_TEMPLATE';
|
|
747
|
+
var expectations = {};
|
|
608
748
|
var isExecutionTypeChanged = false;
|
|
609
749
|
try {
|
|
610
750
|
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
@@ -628,6 +768,23 @@
|
|
|
628
768
|
case 'POSTPROCESS':
|
|
629
769
|
postprocessingCommands.push(command);
|
|
630
770
|
break;
|
|
771
|
+
case 'EXPECT':
|
|
772
|
+
// eslint-disable-next-line no-case-declarations
|
|
773
|
+
var unit = command.unit.toLowerCase();
|
|
774
|
+
expectations[unit] = expectations[unit] || {};
|
|
775
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
776
|
+
if (expectations[unit].min !== undefined) {
|
|
777
|
+
throw new Error("Already defined minumum ".concat(expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
778
|
+
}
|
|
779
|
+
expectations[unit].min = command.amount;
|
|
780
|
+
} /* not else */
|
|
781
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
782
|
+
if (expectations[unit].max !== undefined) {
|
|
783
|
+
throw new Error("Already defined maximum ".concat(expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
784
|
+
}
|
|
785
|
+
expectations[unit].max = command.amount;
|
|
786
|
+
}
|
|
787
|
+
break;
|
|
631
788
|
default:
|
|
632
789
|
throw new Error("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the prompt template pipeline"));
|
|
633
790
|
}
|
|
@@ -691,6 +848,7 @@
|
|
|
691
848
|
title: section.title,
|
|
692
849
|
description: description_1,
|
|
693
850
|
executionType: executionType,
|
|
851
|
+
expectations: expectations,
|
|
694
852
|
modelRequirements: templateModelRequirements,
|
|
695
853
|
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
696
854
|
content: content,
|
|
@@ -927,6 +1085,74 @@
|
|
|
927
1085
|
* TODO: [🧠] Each PromptTemplatePipeline should have its unique hash to be able to compare them and execute on server ONLY the desired ones
|
|
928
1086
|
*/
|
|
929
1087
|
|
|
1088
|
+
/**
|
|
1089
|
+
* Counts number of characters in the text
|
|
1090
|
+
*/
|
|
1091
|
+
function countCharacters(text) {
|
|
1092
|
+
// Remove null characters
|
|
1093
|
+
text = text.replace(/\0/g, '');
|
|
1094
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
1095
|
+
text = text.replace(/(\p{Emoji})\p{Modifier_Symbol}/gu, '$1');
|
|
1096
|
+
text = text.replace(/(\p{Emoji})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
1097
|
+
text = text.replace(/\p{Emoji}(\u{200D}\p{Emoji})*/gu, '-');
|
|
1098
|
+
return text.length;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* Counts number of lines in the text
|
|
1103
|
+
*/
|
|
1104
|
+
function countLines(text) {
|
|
1105
|
+
if (text === '') {
|
|
1106
|
+
return 0;
|
|
1107
|
+
}
|
|
1108
|
+
return text.split('\n').length;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Counts number of pages in the text
|
|
1113
|
+
*/
|
|
1114
|
+
function countPages(text) {
|
|
1115
|
+
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
1116
|
+
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
1117
|
+
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
1118
|
+
return pageCount;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Counts number of paragraphs in the text
|
|
1123
|
+
*/
|
|
1124
|
+
function countParagraphs(text) {
|
|
1125
|
+
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Counts number of sentences in the text
|
|
1130
|
+
*/
|
|
1131
|
+
function countSentences(text) {
|
|
1132
|
+
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; }).length;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Counts number of words in the text
|
|
1137
|
+
*/
|
|
1138
|
+
function countWords(text) {
|
|
1139
|
+
text = text.replace(/[\p{Emoji}]/gu, 'a');
|
|
1140
|
+
text = n12.removeDiacritics(text);
|
|
1141
|
+
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Index of all counter functions
|
|
1146
|
+
*/
|
|
1147
|
+
var CountUtils = {
|
|
1148
|
+
CHARACTERS: countCharacters,
|
|
1149
|
+
WORDS: countWords,
|
|
1150
|
+
SENTENCES: countSentences,
|
|
1151
|
+
PARAGRAPHS: countParagraphs,
|
|
1152
|
+
LINES: countLines,
|
|
1153
|
+
PAGES: countPages,
|
|
1154
|
+
};
|
|
1155
|
+
|
|
930
1156
|
/**
|
|
931
1157
|
* All possible emoji chars like "🍆", "🍡", "🍤"...
|
|
932
1158
|
* Note: this will be needed to update annually - now updated at 2022-01-19
|
|
@@ -1052,17 +1278,18 @@
|
|
|
1052
1278
|
var _this = this;
|
|
1053
1279
|
var ptp = options.ptp, tools = options.tools;
|
|
1054
1280
|
var ptpExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1055
|
-
var parametersToPass, currentTemplate, _loop_1;
|
|
1281
|
+
var parametersToPass, currentTemplate, executionReport, _loop_1;
|
|
1056
1282
|
return __generator(this, function (_a) {
|
|
1057
1283
|
switch (_a.label) {
|
|
1058
1284
|
case 0:
|
|
1059
1285
|
parametersToPass = inputParameters;
|
|
1060
1286
|
currentTemplate = ptp.entryPromptTemplate;
|
|
1287
|
+
executionReport = [];
|
|
1061
1288
|
_loop_1 = function () {
|
|
1062
|
-
var resultingParameter, name_1, title, prompt_1, chatThread, completionResult,
|
|
1063
|
-
var e_1,
|
|
1064
|
-
return __generator(this, function (
|
|
1065
|
-
switch (
|
|
1289
|
+
var resultingParameter, name_1, title, prompt_1, chatThread, completionResult, result, resultString, scriptExecutionErrors, isScriptExecutionSuccessful, _b, _c, _d, _e, _f, unit, _g, max, min, amount, _h, _j, scriptTools, error_1, e_1_1;
|
|
1290
|
+
var e_2, _k, e_1, _l, _m;
|
|
1291
|
+
return __generator(this, function (_o) {
|
|
1292
|
+
switch (_o.label) {
|
|
1066
1293
|
case 0:
|
|
1067
1294
|
resultingParameter = ptp.getResultingParameter(currentTemplate.name);
|
|
1068
1295
|
name_1 = "ptp-executor-frame-".concat(currentTemplate.name);
|
|
@@ -1078,13 +1305,14 @@
|
|
|
1078
1305
|
parameterValue: null,
|
|
1079
1306
|
})];
|
|
1080
1307
|
case 1:
|
|
1081
|
-
|
|
1082
|
-
|
|
1308
|
+
_o.sent();
|
|
1309
|
+
_o.label = 2;
|
|
1083
1310
|
case 2:
|
|
1084
1311
|
prompt_1 = void 0;
|
|
1085
1312
|
chatThread = void 0;
|
|
1086
1313
|
completionResult = void 0;
|
|
1087
|
-
|
|
1314
|
+
result = void 0;
|
|
1315
|
+
resultString = null;
|
|
1088
1316
|
isScriptExecutionSuccessful = void 0;
|
|
1089
1317
|
_b = currentTemplate.executionType;
|
|
1090
1318
|
switch (_b) {
|
|
@@ -1095,7 +1323,7 @@
|
|
|
1095
1323
|
}
|
|
1096
1324
|
return [3 /*break*/, 24];
|
|
1097
1325
|
case 3:
|
|
1098
|
-
|
|
1326
|
+
resultString = replaceParameters(currentTemplate.content, parametersToPass);
|
|
1099
1327
|
return [3 /*break*/, 25];
|
|
1100
1328
|
case 4:
|
|
1101
1329
|
prompt_1 = {
|
|
@@ -1114,19 +1342,48 @@
|
|
|
1114
1342
|
return [3 /*break*/, 9];
|
|
1115
1343
|
case 5: return [4 /*yield*/, tools.natural.gptChat(prompt_1)];
|
|
1116
1344
|
case 6:
|
|
1117
|
-
chatThread =
|
|
1118
|
-
// TODO: Use all information from chatThread like "model"
|
|
1345
|
+
chatThread = _o.sent();
|
|
1119
1346
|
// TODO: [🍬] Destroy chatThread
|
|
1120
|
-
|
|
1347
|
+
result = chatThread;
|
|
1348
|
+
resultString = chatThread.content;
|
|
1121
1349
|
return [3 /*break*/, 10];
|
|
1122
1350
|
case 7: return [4 /*yield*/, tools.natural.gptComplete(prompt_1)];
|
|
1123
1351
|
case 8:
|
|
1124
|
-
completionResult =
|
|
1125
|
-
|
|
1126
|
-
|
|
1352
|
+
completionResult = _o.sent();
|
|
1353
|
+
result = completionResult;
|
|
1354
|
+
resultString = completionResult.content;
|
|
1127
1355
|
return [3 /*break*/, 10];
|
|
1128
1356
|
case 9: throw new Error("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
1129
|
-
case 10:
|
|
1357
|
+
case 10:
|
|
1358
|
+
try {
|
|
1359
|
+
for (_d = (e_2 = void 0, __values(Object.entries(currentTemplate.expectations))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1360
|
+
_f = __read(_e.value, 2), unit = _f[0], _g = _f[1], max = _g.max, min = _g.min;
|
|
1361
|
+
amount = CountUtils[unit](resultString);
|
|
1362
|
+
// TODO: !!!!! Do not crash BUT retry some amount of times
|
|
1363
|
+
if (min && amount < min) {
|
|
1364
|
+
throw new Error("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
1365
|
+
} /* not else */
|
|
1366
|
+
if (max && amount > max) {
|
|
1367
|
+
throw new Error("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1372
|
+
finally {
|
|
1373
|
+
try {
|
|
1374
|
+
if (_e && !_e.done && (_k = _d.return)) _k.call(_d);
|
|
1375
|
+
}
|
|
1376
|
+
finally { if (e_2) throw e_2.error; }
|
|
1377
|
+
}
|
|
1378
|
+
executionReport.push({
|
|
1379
|
+
prompt: {
|
|
1380
|
+
content: prompt_1.content,
|
|
1381
|
+
modelRequirements: prompt_1.modelRequirements,
|
|
1382
|
+
// <- Note: Do want to pass ONLY wanted information to the report
|
|
1383
|
+
},
|
|
1384
|
+
result: result,
|
|
1385
|
+
});
|
|
1386
|
+
return [3 /*break*/, 25];
|
|
1130
1387
|
case 11:
|
|
1131
1388
|
if (tools.script.length === 0) {
|
|
1132
1389
|
throw new Error('No script execution tools are available');
|
|
@@ -1136,44 +1393,44 @@
|
|
|
1136
1393
|
}
|
|
1137
1394
|
scriptExecutionErrors = [];
|
|
1138
1395
|
isScriptExecutionSuccessful = false;
|
|
1139
|
-
|
|
1396
|
+
_o.label = 12;
|
|
1140
1397
|
case 12:
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1398
|
+
_o.trys.push([12, 19, 20, 21]);
|
|
1399
|
+
_h = (e_1 = void 0, __values(tools.script)), _j = _h.next();
|
|
1400
|
+
_o.label = 13;
|
|
1144
1401
|
case 13:
|
|
1145
|
-
if (!!
|
|
1146
|
-
scriptTools =
|
|
1147
|
-
|
|
1402
|
+
if (!!_j.done) return [3 /*break*/, 18];
|
|
1403
|
+
scriptTools = _j.value;
|
|
1404
|
+
_o.label = 14;
|
|
1148
1405
|
case 14:
|
|
1149
|
-
|
|
1406
|
+
_o.trys.push([14, 16, , 17]);
|
|
1150
1407
|
return [4 /*yield*/, scriptTools.execute({
|
|
1151
1408
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
1152
1409
|
script: currentTemplate.content,
|
|
1153
1410
|
parameters: parametersToPass,
|
|
1154
1411
|
})];
|
|
1155
1412
|
case 15:
|
|
1156
|
-
|
|
1413
|
+
resultString = _o.sent();
|
|
1157
1414
|
isScriptExecutionSuccessful = true;
|
|
1158
1415
|
return [3 /*break*/, 18];
|
|
1159
1416
|
case 16:
|
|
1160
|
-
error_1 =
|
|
1417
|
+
error_1 = _o.sent();
|
|
1161
1418
|
if (!(error_1 instanceof Error)) {
|
|
1162
1419
|
throw error_1;
|
|
1163
1420
|
}
|
|
1164
1421
|
scriptExecutionErrors.push(error_1);
|
|
1165
1422
|
return [3 /*break*/, 17];
|
|
1166
1423
|
case 17:
|
|
1167
|
-
|
|
1424
|
+
_j = _h.next();
|
|
1168
1425
|
return [3 /*break*/, 13];
|
|
1169
1426
|
case 18: return [3 /*break*/, 21];
|
|
1170
1427
|
case 19:
|
|
1171
|
-
e_1_1 =
|
|
1428
|
+
e_1_1 = _o.sent();
|
|
1172
1429
|
e_1 = { error: e_1_1 };
|
|
1173
1430
|
return [3 /*break*/, 21];
|
|
1174
1431
|
case 20:
|
|
1175
1432
|
try {
|
|
1176
|
-
if (
|
|
1433
|
+
if (_j && !_j.done && (_l = _h.return)) _l.call(_h);
|
|
1177
1434
|
}
|
|
1178
1435
|
finally { if (e_1) throw e_1.error; }
|
|
1179
1436
|
return [7 /*endfinally*/];
|
|
@@ -1194,13 +1451,13 @@
|
|
|
1194
1451
|
placeholder: undefined,
|
|
1195
1452
|
})];
|
|
1196
1453
|
case 23:
|
|
1197
|
-
|
|
1454
|
+
resultString = _o.sent();
|
|
1198
1455
|
return [3 /*break*/, 25];
|
|
1199
1456
|
case 24:
|
|
1200
1457
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1201
1458
|
throw new Error("Unknown execution type \"".concat(currentTemplate.executionType, "\""));
|
|
1202
1459
|
case 25:
|
|
1203
|
-
if (
|
|
1460
|
+
if (resultString === null) {
|
|
1204
1461
|
// <- TODO: [🥨] Make some NeverShouldHappenError
|
|
1205
1462
|
throw new Error('Something went wrong and prompt result is null');
|
|
1206
1463
|
}
|
|
@@ -1212,10 +1469,10 @@
|
|
|
1212
1469
|
isDone: true,
|
|
1213
1470
|
executionType: currentTemplate.executionType,
|
|
1214
1471
|
parameterName: resultingParameter.name,
|
|
1215
|
-
parameterValue:
|
|
1472
|
+
parameterValue: resultString,
|
|
1216
1473
|
});
|
|
1217
1474
|
}
|
|
1218
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (
|
|
1475
|
+
parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[resultingParameter.name] = resultString /* <- Note: Not need to detect parameter collision here because PromptTemplatePipeline checks logic consistency during construction */, _m));
|
|
1219
1476
|
currentTemplate = ptp.getFollowingPromptTemplate(currentTemplate.name);
|
|
1220
1477
|
return [2 /*return*/];
|
|
1221
1478
|
}
|