@promptbook/core 0.48.1-0 → 0.49.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 +1 -5
- package/esm/index.es.js +12 -7
- package/esm/index.es.js.map +1 -1
- package/esm/typings/conversion/promptbookJsonToString.d.ts +6 -3
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
- package/package.json +1 -1
- package/umd/index.umd.js +53 -47
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/conversion/promptbookJsonToString.d.ts +6 -3
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
package/umd/index.umd.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('moment')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
+
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
9
10
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
10
11
|
|
|
11
12
|
/*! *****************************************************************************
|
|
@@ -212,7 +213,7 @@
|
|
|
212
213
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
213
214
|
__extends(UnexpectedError, _super);
|
|
214
215
|
function UnexpectedError(message) {
|
|
215
|
-
var _this = _super.call(this,
|
|
216
|
+
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 promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
216
217
|
_this.name = 'UnexpectedError';
|
|
217
218
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
218
219
|
return _this;
|
|
@@ -265,7 +266,7 @@
|
|
|
265
266
|
}
|
|
266
267
|
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
267
268
|
// [🌻]
|
|
268
|
-
throw new Error(
|
|
269
|
+
throw new Error(spaceTrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
269
270
|
}
|
|
270
271
|
parent_1 = parent_1.parent;
|
|
271
272
|
}
|
|
@@ -299,7 +300,7 @@
|
|
|
299
300
|
return {
|
|
300
301
|
level: level,
|
|
301
302
|
title: title,
|
|
302
|
-
content:
|
|
303
|
+
content: spaceTrim.spaceTrim(contentLines.join('\n')),
|
|
303
304
|
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
304
305
|
};
|
|
305
306
|
}
|
|
@@ -439,13 +440,13 @@
|
|
|
439
440
|
* @returns {string} The input string with all comments removed.
|
|
440
441
|
*/
|
|
441
442
|
function removeContentComments(content) {
|
|
442
|
-
return
|
|
443
|
+
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
443
444
|
}
|
|
444
445
|
|
|
445
446
|
/**
|
|
446
447
|
* The version of the Promptbook library
|
|
447
448
|
*/
|
|
448
|
-
var PROMPTBOOK_VERSION = '0.48.0';
|
|
449
|
+
var PROMPTBOOK_VERSION = '0.48.1-0';
|
|
449
450
|
|
|
450
451
|
/**
|
|
451
452
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -490,7 +491,7 @@
|
|
|
490
491
|
if (!(error instanceof Error)) {
|
|
491
492
|
throw error;
|
|
492
493
|
}
|
|
493
|
-
throw new PromptbookSyntaxError(
|
|
494
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
494
495
|
}
|
|
495
496
|
return variables;
|
|
496
497
|
}
|
|
@@ -1316,15 +1317,15 @@
|
|
|
1316
1317
|
type.startsWith('PROMPTBOOKURL') ||
|
|
1317
1318
|
type.startsWith('HTTPS')) {
|
|
1318
1319
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
1319
|
-
throw new PromptbookSyntaxError(
|
|
1320
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
1320
1321
|
}
|
|
1321
1322
|
var promptbookUrlString = listItemParts.pop();
|
|
1322
1323
|
var promptbookUrl = new URL(promptbookUrlString);
|
|
1323
1324
|
if (promptbookUrl.protocol !== 'https:') {
|
|
1324
|
-
throw new PromptbookSyntaxError(
|
|
1325
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
1325
1326
|
}
|
|
1326
1327
|
if (promptbookUrl.hash !== '') {
|
|
1327
|
-
throw new PromptbookSyntaxError(
|
|
1328
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
1328
1329
|
}
|
|
1329
1330
|
return {
|
|
1330
1331
|
type: 'PROMPTBOOK_URL',
|
|
@@ -1333,7 +1334,7 @@
|
|
|
1333
1334
|
}
|
|
1334
1335
|
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
1335
1336
|
if (listItemParts.length !== 2) {
|
|
1336
|
-
throw new PromptbookSyntaxError(
|
|
1337
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
1337
1338
|
}
|
|
1338
1339
|
var promptbookVersion = listItemParts.pop();
|
|
1339
1340
|
// TODO: Validate version
|
|
@@ -1348,7 +1349,7 @@
|
|
|
1348
1349
|
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
1349
1350
|
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
1350
1351
|
if (executionTypes.length !== 1) {
|
|
1351
|
-
throw new PromptbookSyntaxError(
|
|
1352
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
|
|
1352
1353
|
}
|
|
1353
1354
|
return {
|
|
1354
1355
|
type: 'EXECUTE',
|
|
@@ -1373,7 +1374,7 @@
|
|
|
1373
1374
|
};
|
|
1374
1375
|
}
|
|
1375
1376
|
else {
|
|
1376
|
-
throw new PromptbookSyntaxError(
|
|
1377
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
|
|
1377
1378
|
}
|
|
1378
1379
|
}
|
|
1379
1380
|
if (type.startsWith('MODEL_NAME')) {
|
|
@@ -1384,7 +1385,7 @@
|
|
|
1384
1385
|
};
|
|
1385
1386
|
}
|
|
1386
1387
|
else {
|
|
1387
|
-
throw new PromptbookSyntaxError(
|
|
1388
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
1388
1389
|
}
|
|
1389
1390
|
}
|
|
1390
1391
|
else if (type.startsWith('PARAM') ||
|
|
@@ -1394,12 +1395,12 @@
|
|
|
1394
1395
|
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
1395
1396
|
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
1396
1397
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
1397
|
-
throw new PromptbookSyntaxError(
|
|
1398
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
1398
1399
|
}
|
|
1399
1400
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1400
1401
|
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
1401
1402
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
1402
|
-
throw new PromptbookSyntaxError(
|
|
1403
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
1403
1404
|
}
|
|
1404
1405
|
var isInput = type.startsWith('INPUT');
|
|
1405
1406
|
var isOutput = type.startsWith('OUTPUT');
|
|
@@ -1417,11 +1418,11 @@
|
|
|
1417
1418
|
}
|
|
1418
1419
|
else if (type.startsWith('JOKER')) {
|
|
1419
1420
|
if (listItemParts.length !== 2) {
|
|
1420
|
-
throw new PromptbookSyntaxError(
|
|
1421
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
1421
1422
|
}
|
|
1422
1423
|
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
1423
1424
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
1424
|
-
throw new PromptbookSyntaxError(
|
|
1425
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
1425
1426
|
}
|
|
1426
1427
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1427
1428
|
var parameterName = parametersMatch.groups.parameterName;
|
|
@@ -1432,7 +1433,7 @@
|
|
|
1432
1433
|
}
|
|
1433
1434
|
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
1434
1435
|
if (listItemParts.length !== 2) {
|
|
1435
|
-
throw new PromptbookSyntaxError(
|
|
1436
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
1436
1437
|
}
|
|
1437
1438
|
var functionName = listItemParts.pop();
|
|
1438
1439
|
return {
|
|
@@ -1512,7 +1513,7 @@
|
|
|
1512
1513
|
if (!(error instanceof Error)) {
|
|
1513
1514
|
throw error;
|
|
1514
1515
|
}
|
|
1515
|
-
throw new PromptbookSyntaxError(
|
|
1516
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
1516
1517
|
}
|
|
1517
1518
|
/*
|
|
1518
1519
|
} else if (type.startsWith('__________________')) {
|
|
@@ -1520,7 +1521,7 @@
|
|
|
1520
1521
|
*/
|
|
1521
1522
|
}
|
|
1522
1523
|
else {
|
|
1523
|
-
throw new PromptbookSyntaxError(
|
|
1524
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
|
|
1524
1525
|
}
|
|
1525
1526
|
}
|
|
1526
1527
|
|
|
@@ -1556,7 +1557,7 @@
|
|
|
1556
1557
|
existingParameter.description &&
|
|
1557
1558
|
existingParameter.description !== parameterDescription &&
|
|
1558
1559
|
parameterDescription) {
|
|
1559
|
-
throw new PromptbookSyntaxError(
|
|
1560
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
1560
1561
|
}
|
|
1561
1562
|
if (existingParameter) {
|
|
1562
1563
|
if (parameterDescription) {
|
|
@@ -1577,7 +1578,7 @@
|
|
|
1577
1578
|
var markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1578
1579
|
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1579
1580
|
if (markdownStructureDeepness !== 2) {
|
|
1580
|
-
throw new PromptbookSyntaxError(
|
|
1581
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1581
1582
|
}
|
|
1582
1583
|
promptbookJson.title = markdownStructure.title;
|
|
1583
1584
|
// TODO: [1] DRY description
|
|
@@ -1586,7 +1587,7 @@
|
|
|
1586
1587
|
description = description.split(/^```.*^```/gms).join('');
|
|
1587
1588
|
//Note: Remove lists and return statement
|
|
1588
1589
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1589
|
-
description =
|
|
1590
|
+
description = spaceTrim.spaceTrim(description);
|
|
1590
1591
|
if (description === '') {
|
|
1591
1592
|
description = undefined;
|
|
1592
1593
|
}
|
|
@@ -1701,13 +1702,13 @@
|
|
|
1701
1702
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1702
1703
|
}
|
|
1703
1704
|
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1704
|
-
throw new PromptbookSyntaxError(
|
|
1705
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
1705
1706
|
}
|
|
1706
1707
|
}
|
|
1707
1708
|
var lastLine = section.content.split('\n').pop();
|
|
1708
1709
|
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1709
1710
|
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1710
|
-
throw new PromptbookSyntaxError(
|
|
1711
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1711
1712
|
// TODO: Show code of invalid sections each time + DRY
|
|
1712
1713
|
section.content
|
|
1713
1714
|
.split('\n')
|
|
@@ -1721,7 +1722,7 @@
|
|
|
1721
1722
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1722
1723
|
//Note: Remove lists and return statement
|
|
1723
1724
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1724
|
-
description_1 =
|
|
1725
|
+
description_1 = spaceTrim.spaceTrim(description_1);
|
|
1725
1726
|
if (description_1 === '') {
|
|
1726
1727
|
description_1 = undefined;
|
|
1727
1728
|
}
|
|
@@ -1801,6 +1802,12 @@
|
|
|
1801
1802
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
1802
1803
|
*/
|
|
1803
1804
|
|
|
1805
|
+
/**
|
|
1806
|
+
* Converts promptbook in JSON format to string format
|
|
1807
|
+
*
|
|
1808
|
+
* @param promptbookJson Promptbook in JSON format (.ptbk.json)
|
|
1809
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
1810
|
+
*/
|
|
1804
1811
|
function promptbookJsonToString(promptbookJson) {
|
|
1805
1812
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
1806
1813
|
var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
|
|
@@ -1853,7 +1860,7 @@
|
|
|
1853
1860
|
}
|
|
1854
1861
|
// TODO:> const commands: Array<Command>
|
|
1855
1862
|
var commands_1 = [];
|
|
1856
|
-
var contentLanguage = '
|
|
1863
|
+
var contentLanguage = 'text';
|
|
1857
1864
|
if (executionType === 'PROMPT_TEMPLATE') {
|
|
1858
1865
|
var modelRequirements = promptTemplate.modelRequirements;
|
|
1859
1866
|
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
@@ -1948,7 +1955,9 @@
|
|
|
1948
1955
|
promptbookString += '\n\n';
|
|
1949
1956
|
promptbookString += '```' + contentLanguage;
|
|
1950
1957
|
promptbookString += '\n';
|
|
1951
|
-
promptbookString += content;
|
|
1958
|
+
promptbookString += spaceTrim__default["default"](content);
|
|
1959
|
+
// <- TODO: !!! Escape
|
|
1960
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1952
1961
|
promptbookString += '\n';
|
|
1953
1962
|
promptbookString += '```';
|
|
1954
1963
|
promptbookString += '\n\n';
|
|
@@ -1976,9 +1985,6 @@
|
|
|
1976
1985
|
return parameterString;
|
|
1977
1986
|
}
|
|
1978
1987
|
/**
|
|
1979
|
-
* TODO: !!!!! Implement
|
|
1980
|
-
* TODO: !!!!! Annotate and warn
|
|
1981
|
-
* TODO: !!!!! Test + test together with promptbookStringToJson
|
|
1982
1988
|
* TODO: Escape all
|
|
1983
1989
|
*/
|
|
1984
1990
|
|
|
@@ -2037,12 +2043,12 @@
|
|
|
2037
2043
|
if (!parameter.isInput &&
|
|
2038
2044
|
!parameter.isOutput &&
|
|
2039
2045
|
!promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
2040
|
-
throw new PromptbookLogicError(
|
|
2046
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
|
|
2041
2047
|
}
|
|
2042
2048
|
// Note: Testing that parameter is either input or result of some template
|
|
2043
2049
|
if (!parameter.isInput &&
|
|
2044
2050
|
!promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
2045
|
-
throw new PromptbookLogicError(
|
|
2051
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
|
|
2046
2052
|
}
|
|
2047
2053
|
};
|
|
2048
2054
|
try {
|
|
@@ -2077,7 +2083,7 @@
|
|
|
2077
2083
|
if (template.executionType === 'PROMPT_TEMPLATE' &&
|
|
2078
2084
|
(template.modelRequirements.modelVariant === undefined ||
|
|
2079
2085
|
template.modelRequirements.modelName === undefined)) {
|
|
2080
|
-
throw new PromptbookLogicError(
|
|
2086
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT and MODEL NAME in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
2081
2087
|
}
|
|
2082
2088
|
if (template.jokers && template.jokers.length > 0) {
|
|
2083
2089
|
if (!template.expectFormat &&
|
|
@@ -2152,7 +2158,7 @@
|
|
|
2152
2158
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
2153
2159
|
});
|
|
2154
2160
|
if (currentlyResovedTemplates.length === 0) {
|
|
2155
|
-
throw new PromptbookLogicError(
|
|
2161
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
2156
2162
|
.map(function (_a) {
|
|
2157
2163
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
2158
2164
|
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
@@ -2326,7 +2332,7 @@
|
|
|
2326
2332
|
throw errors[0];
|
|
2327
2333
|
}
|
|
2328
2334
|
else {
|
|
2329
|
-
throw new PromptbookExecutionError(
|
|
2335
|
+
throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
|
|
2330
2336
|
}
|
|
2331
2337
|
}
|
|
2332
2338
|
});
|
|
@@ -2410,7 +2416,7 @@
|
|
|
2410
2416
|
throw scriptExecutionErrors[0];
|
|
2411
2417
|
}
|
|
2412
2418
|
else {
|
|
2413
|
-
throw new PromptbookExecutionError(
|
|
2419
|
+
throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
2414
2420
|
.map(function (error) { return '- ' + error.message; })
|
|
2415
2421
|
.join('\n\n')), "\n "); }));
|
|
2416
2422
|
}
|
|
@@ -2550,7 +2556,7 @@
|
|
|
2550
2556
|
return [7 /*endfinally*/];
|
|
2551
2557
|
case 47:
|
|
2552
2558
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
2553
|
-
throw new PromptbookExecutionError(
|
|
2559
|
+
throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
2554
2560
|
}
|
|
2555
2561
|
_o.label = 48;
|
|
2556
2562
|
case 48:
|
|
@@ -2619,7 +2625,7 @@
|
|
|
2619
2625
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
2620
2626
|
});
|
|
2621
2627
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
2622
|
-
throw new UnexpectedError(
|
|
2628
|
+
throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
|
|
2623
2629
|
case 1:
|
|
2624
2630
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2625
2631
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -2719,7 +2725,7 @@
|
|
|
2719
2725
|
case 1:
|
|
2720
2726
|
answer = _a.sent();
|
|
2721
2727
|
if (this.options.isVerbose) {
|
|
2722
|
-
console.info(
|
|
2728
|
+
console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
2723
2729
|
}
|
|
2724
2730
|
return [2 /*return*/, answer];
|
|
2725
2731
|
}
|
|
@@ -2746,9 +2752,9 @@
|
|
|
2746
2752
|
return __awaiter(this, void 0, void 0, function () {
|
|
2747
2753
|
var answer;
|
|
2748
2754
|
return __generator(this, function (_a) {
|
|
2749
|
-
answer = window.prompt(
|
|
2755
|
+
answer = window.prompt(spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
|
|
2750
2756
|
if (this.options.isVerbose) {
|
|
2751
|
-
console.info(
|
|
2757
|
+
console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
|
|
2752
2758
|
}
|
|
2753
2759
|
if (answer === null) {
|
|
2754
2760
|
throw new PromptbookExecutionError('User cancelled prompt');
|
|
@@ -2814,7 +2820,7 @@
|
|
|
2814
2820
|
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
2815
2821
|
var promptbook = promptbooks_1_1.value;
|
|
2816
2822
|
if (promptbook.promptbookUrl === undefined) {
|
|
2817
|
-
throw new PromptbookReferenceError(
|
|
2823
|
+
throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
|
|
2818
2824
|
}
|
|
2819
2825
|
validatePromptbookJson(promptbook);
|
|
2820
2826
|
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
@@ -2843,7 +2849,7 @@
|
|
|
2843
2849
|
var _this = this;
|
|
2844
2850
|
var promptbook = this.library.get(url);
|
|
2845
2851
|
if (!promptbook) {
|
|
2846
|
-
throw new PromptbookNotFoundError(
|
|
2852
|
+
throw new PromptbookNotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
2847
2853
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
2848
2854
|
.join('\n')), "\n\n "); }));
|
|
2849
2855
|
}
|
|
@@ -3021,7 +3027,7 @@
|
|
|
3021
3027
|
case 0:
|
|
3022
3028
|
if (!!predicate(url)) return [3 /*break*/, 2];
|
|
3023
3029
|
_a = PromptbookNotFoundError.bind;
|
|
3024
|
-
return [4 /*yield*/,
|
|
3030
|
+
return [4 /*yield*/, spaceTrim.spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
|
|
3025
3031
|
var _a, _b, _c, _d, _e, _f;
|
|
3026
3032
|
return __generator(this, function (_g) {
|
|
3027
3033
|
switch (_g.label) {
|