@promptbook/core 0.44.0-10 โ 0.44.0-11
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 +95 -46
- package/esm/index.es.js.map +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +6 -2
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +5 -1
- package/esm/typings/types/Prompt.d.ts +5 -0
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +136 -91
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +6 -2
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +5 -1
- package/umd/typings/types/Prompt.d.ts +5 -0
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +1 -0
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
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'), require('lorem-ipsum')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment', 'lorem-ipsum'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spacetrim, null, null, null, global.loremIpsum));
|
|
5
|
+
})(this, (function (exports, spacetrim, prettier, parserHtml, moment, loremIpsum) { 'use strict';
|
|
10
6
|
|
|
11
7
|
/*! *****************************************************************************
|
|
12
8
|
Copyright (c) Microsoft Corporation.
|
|
@@ -133,7 +129,7 @@
|
|
|
133
129
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
134
130
|
__extends(UnexpectedError, _super);
|
|
135
131
|
function UnexpectedError(message) {
|
|
136
|
-
var _this = _super.call(this,
|
|
132
|
+
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;
|
|
137
133
|
_this.name = 'UnexpectedError';
|
|
138
134
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
139
135
|
return _this;
|
|
@@ -148,7 +144,7 @@
|
|
|
148
144
|
* @returns {string} The input string with all comments removed.
|
|
149
145
|
*/
|
|
150
146
|
function removeContentComments(content) {
|
|
151
|
-
return
|
|
147
|
+
return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
/**
|
|
@@ -1123,7 +1119,7 @@
|
|
|
1123
1119
|
}
|
|
1124
1120
|
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
1125
1121
|
// [๐ป]
|
|
1126
|
-
throw new Error(
|
|
1122
|
+
throw new Error(spacetrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
1127
1123
|
}
|
|
1128
1124
|
parent_1 = parent_1.parent;
|
|
1129
1125
|
}
|
|
@@ -1157,7 +1153,7 @@
|
|
|
1157
1153
|
return {
|
|
1158
1154
|
level: level,
|
|
1159
1155
|
title: title,
|
|
1160
|
-
content:
|
|
1156
|
+
content: spacetrim.spaceTrim(contentLines.join('\n')),
|
|
1161
1157
|
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
1162
1158
|
};
|
|
1163
1159
|
}
|
|
@@ -1165,7 +1161,7 @@
|
|
|
1165
1161
|
/**
|
|
1166
1162
|
* The version of the Promptbook library
|
|
1167
1163
|
*/
|
|
1168
|
-
var PROMPTBOOK_VERSION = '0.44.0-
|
|
1164
|
+
var PROMPTBOOK_VERSION = '0.44.0-10';
|
|
1169
1165
|
|
|
1170
1166
|
/**
|
|
1171
1167
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -1210,7 +1206,7 @@
|
|
|
1210
1206
|
if (!(error instanceof Error)) {
|
|
1211
1207
|
throw error;
|
|
1212
1208
|
}
|
|
1213
|
-
throw new PromptbookSyntaxError(
|
|
1209
|
+
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 "); }));
|
|
1214
1210
|
}
|
|
1215
1211
|
return variables;
|
|
1216
1212
|
}
|
|
@@ -1275,15 +1271,15 @@
|
|
|
1275
1271
|
type.startsWith('PROMPTBOOKURL') ||
|
|
1276
1272
|
type.startsWith('HTTPS')) {
|
|
1277
1273
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
1278
|
-
throw new PromptbookSyntaxError(
|
|
1274
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
1279
1275
|
}
|
|
1280
1276
|
var promptbookUrlString = listItemParts.pop();
|
|
1281
1277
|
var promptbookUrl = new URL(promptbookUrlString);
|
|
1282
1278
|
if (promptbookUrl.protocol !== 'https:') {
|
|
1283
|
-
throw new PromptbookSyntaxError(
|
|
1279
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
1284
1280
|
}
|
|
1285
1281
|
if (promptbookUrl.hash !== '') {
|
|
1286
|
-
throw new PromptbookSyntaxError(
|
|
1282
|
+
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 ")));
|
|
1287
1283
|
}
|
|
1288
1284
|
return {
|
|
1289
1285
|
type: 'PROMPTBOOK_URL',
|
|
@@ -1292,7 +1288,7 @@
|
|
|
1292
1288
|
}
|
|
1293
1289
|
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
1294
1290
|
if (listItemParts.length !== 2) {
|
|
1295
|
-
throw new PromptbookSyntaxError(
|
|
1291
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
1296
1292
|
}
|
|
1297
1293
|
var promptbookVersion = listItemParts.pop();
|
|
1298
1294
|
// TODO: Validate version
|
|
@@ -1307,7 +1303,7 @@
|
|
|
1307
1303
|
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
1308
1304
|
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
1309
1305
|
if (executionTypes.length !== 1) {
|
|
1310
|
-
throw new PromptbookSyntaxError(
|
|
1306
|
+
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 "); }));
|
|
1311
1307
|
}
|
|
1312
1308
|
return {
|
|
1313
1309
|
type: 'EXECUTE',
|
|
@@ -1332,7 +1328,7 @@
|
|
|
1332
1328
|
};
|
|
1333
1329
|
}
|
|
1334
1330
|
else {
|
|
1335
|
-
throw new PromptbookSyntaxError(
|
|
1331
|
+
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 "); }));
|
|
1336
1332
|
}
|
|
1337
1333
|
}
|
|
1338
1334
|
if (type.startsWith('MODEL_NAME')) {
|
|
@@ -1343,7 +1339,7 @@
|
|
|
1343
1339
|
};
|
|
1344
1340
|
}
|
|
1345
1341
|
else {
|
|
1346
|
-
throw new PromptbookSyntaxError(
|
|
1342
|
+
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 "); }));
|
|
1347
1343
|
}
|
|
1348
1344
|
}
|
|
1349
1345
|
else if (type.startsWith('PARAM') ||
|
|
@@ -1353,12 +1349,12 @@
|
|
|
1353
1349
|
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
1354
1350
|
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
1355
1351
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
1356
|
-
throw new PromptbookSyntaxError(
|
|
1352
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
1357
1353
|
}
|
|
1358
1354
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1359
1355
|
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
1360
1356
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
1361
|
-
throw new PromptbookSyntaxError(
|
|
1357
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
1362
1358
|
}
|
|
1363
1359
|
var isInput = type.startsWith('INPUT');
|
|
1364
1360
|
var isOutput = type.startsWith('OUTPUT');
|
|
@@ -1376,11 +1372,11 @@
|
|
|
1376
1372
|
}
|
|
1377
1373
|
else if (type.startsWith('JOKER')) {
|
|
1378
1374
|
if (listItemParts.length !== 2) {
|
|
1379
|
-
throw new PromptbookSyntaxError(
|
|
1375
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
1380
1376
|
}
|
|
1381
1377
|
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
1382
1378
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
1383
|
-
throw new PromptbookSyntaxError(
|
|
1379
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
1384
1380
|
}
|
|
1385
1381
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1386
1382
|
var parameterName = parametersMatch.groups.parameterName;
|
|
@@ -1391,7 +1387,7 @@
|
|
|
1391
1387
|
}
|
|
1392
1388
|
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
1393
1389
|
if (listItemParts.length !== 2) {
|
|
1394
|
-
throw new PromptbookSyntaxError(
|
|
1390
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
1395
1391
|
}
|
|
1396
1392
|
var functionName = listItemParts.pop();
|
|
1397
1393
|
return {
|
|
@@ -1471,7 +1467,7 @@
|
|
|
1471
1467
|
if (!(error instanceof Error)) {
|
|
1472
1468
|
throw error;
|
|
1473
1469
|
}
|
|
1474
|
-
throw new PromptbookSyntaxError(
|
|
1470
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
1475
1471
|
}
|
|
1476
1472
|
/*
|
|
1477
1473
|
} else if (type.startsWith('__________________')) {
|
|
@@ -1479,7 +1475,7 @@
|
|
|
1479
1475
|
*/
|
|
1480
1476
|
}
|
|
1481
1477
|
else {
|
|
1482
|
-
throw new PromptbookSyntaxError(
|
|
1478
|
+
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 ")));
|
|
1483
1479
|
}
|
|
1484
1480
|
}
|
|
1485
1481
|
|
|
@@ -1515,7 +1511,7 @@
|
|
|
1515
1511
|
existingParameter.description &&
|
|
1516
1512
|
existingParameter.description !== parameterDescription &&
|
|
1517
1513
|
parameterDescription) {
|
|
1518
|
-
throw new PromptbookSyntaxError(
|
|
1514
|
+
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 "); }));
|
|
1519
1515
|
}
|
|
1520
1516
|
if (existingParameter) {
|
|
1521
1517
|
if (parameterDescription) {
|
|
@@ -1536,7 +1532,7 @@
|
|
|
1536
1532
|
var markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1537
1533
|
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1538
1534
|
if (markdownStructureDeepness !== 2) {
|
|
1539
|
-
throw new PromptbookSyntaxError(
|
|
1535
|
+
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 ")));
|
|
1540
1536
|
}
|
|
1541
1537
|
promptbookJson.title = markdownStructure.title;
|
|
1542
1538
|
// TODO: [1] DRY description
|
|
@@ -1545,7 +1541,7 @@
|
|
|
1545
1541
|
description = description.split(/^```.*^```/gms).join('');
|
|
1546
1542
|
//Note: Remove lists and return statement
|
|
1547
1543
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1548
|
-
description =
|
|
1544
|
+
description = spacetrim.spaceTrim(description);
|
|
1549
1545
|
if (description === '') {
|
|
1550
1546
|
description = undefined;
|
|
1551
1547
|
}
|
|
@@ -1660,13 +1656,13 @@
|
|
|
1660
1656
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1661
1657
|
}
|
|
1662
1658
|
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1663
|
-
throw new PromptbookSyntaxError(
|
|
1659
|
+
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 "); }));
|
|
1664
1660
|
}
|
|
1665
1661
|
}
|
|
1666
1662
|
var lastLine = section.content.split('\n').pop();
|
|
1667
1663
|
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1668
1664
|
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1669
|
-
throw new PromptbookSyntaxError(
|
|
1665
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1670
1666
|
// TODO: Show code of invalid sections each time + DRY
|
|
1671
1667
|
section.content
|
|
1672
1668
|
.split('\n')
|
|
@@ -1680,7 +1676,7 @@
|
|
|
1680
1676
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1681
1677
|
//Note: Remove lists and return statement
|
|
1682
1678
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1683
|
-
description_1 =
|
|
1679
|
+
description_1 = spacetrim.spaceTrim(description_1);
|
|
1684
1680
|
if (description_1 === '') {
|
|
1685
1681
|
description_1 = undefined;
|
|
1686
1682
|
}
|
|
@@ -1828,12 +1824,12 @@
|
|
|
1828
1824
|
if (!parameter.isInput &&
|
|
1829
1825
|
!parameter.isOutput &&
|
|
1830
1826
|
!promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
1831
|
-
throw new PromptbookLogicError(
|
|
1827
|
+
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 ")));
|
|
1832
1828
|
}
|
|
1833
1829
|
// Note: Testing that parameter is either input or result of some template
|
|
1834
1830
|
if (!parameter.isInput &&
|
|
1835
1831
|
!promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
1836
|
-
throw new PromptbookLogicError(
|
|
1832
|
+
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 ")));
|
|
1837
1833
|
}
|
|
1838
1834
|
};
|
|
1839
1835
|
try {
|
|
@@ -1868,7 +1864,7 @@
|
|
|
1868
1864
|
if (template.executionType === 'PROMPT_TEMPLATE' &&
|
|
1869
1865
|
(template.modelRequirements.modelVariant === undefined ||
|
|
1870
1866
|
template.modelRequirements.modelName === undefined)) {
|
|
1871
|
-
throw new PromptbookLogicError(
|
|
1867
|
+
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 ")));
|
|
1872
1868
|
}
|
|
1873
1869
|
if (template.jokers && template.jokers.length > 0) {
|
|
1874
1870
|
if (!template.expectFormat &&
|
|
@@ -1943,7 +1939,7 @@
|
|
|
1943
1939
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1944
1940
|
});
|
|
1945
1941
|
if (currentlyResovedTemplates.length === 0) {
|
|
1946
|
-
throw new PromptbookLogicError(
|
|
1942
|
+
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
|
|
1947
1943
|
.map(function (_a) {
|
|
1948
1944
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1949
1945
|
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
@@ -2138,7 +2134,7 @@
|
|
|
2138
2134
|
throw scriptExecutionErrors[0];
|
|
2139
2135
|
}
|
|
2140
2136
|
else {
|
|
2141
|
-
throw new PromptbookExecutionError(
|
|
2137
|
+
throw new PromptbookExecutionError(spacetrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
2142
2138
|
.map(function (error) { return '- ' + error.message; })
|
|
2143
2139
|
.join('\n\n')), "\n "); }));
|
|
2144
2140
|
}
|
|
@@ -2275,7 +2271,7 @@
|
|
|
2275
2271
|
return [7 /*endfinally*/];
|
|
2276
2272
|
case 47:
|
|
2277
2273
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
2278
|
-
throw new PromptbookExecutionError(
|
|
2274
|
+
throw new PromptbookExecutionError(spacetrim.spaceTrim(function (block) { return "\n Natural execution failed ".concat(maxExecutionAttempts, "x\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 "); }));
|
|
2279
2275
|
}
|
|
2280
2276
|
_o.label = 48;
|
|
2281
2277
|
case 48:
|
|
@@ -2344,7 +2340,7 @@
|
|
|
2344
2340
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
2345
2341
|
});
|
|
2346
2342
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
2347
|
-
throw new UnexpectedError(
|
|
2343
|
+
throw new UnexpectedError(spacetrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
|
|
2348
2344
|
case 1:
|
|
2349
2345
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2350
2346
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -2450,7 +2446,7 @@
|
|
|
2450
2446
|
console.info('๐ฌ Mocked gptChat call');
|
|
2451
2447
|
}
|
|
2452
2448
|
return [2 /*return*/, {
|
|
2453
|
-
content:
|
|
2449
|
+
content: spacetrim.spaceTrim(function (block) { return "\n You said:\n ".concat(block(prompt.content), "\n "); }),
|
|
2454
2450
|
model: 'mocked-echo',
|
|
2455
2451
|
timing: {
|
|
2456
2452
|
start: getCurrentIsoDate(),
|
|
@@ -2479,7 +2475,7 @@
|
|
|
2479
2475
|
console.info('๐ Mocked gptComplete call');
|
|
2480
2476
|
}
|
|
2481
2477
|
return [2 /*return*/, {
|
|
2482
|
-
content:
|
|
2478
|
+
content: spacetrim.spaceTrim(function (block) { return "\n ".concat(block(prompt.content), "\n And so on...\n "); }),
|
|
2483
2479
|
model: 'mocked-echo',
|
|
2484
2480
|
timing: {
|
|
2485
2481
|
start: getCurrentIsoDate(),
|
|
@@ -2507,29 +2503,73 @@
|
|
|
2507
2503
|
/**
|
|
2508
2504
|
* Gets the expectations and creates a fake text that meets the expectations
|
|
2509
2505
|
*
|
|
2506
|
+
* Note: You can provide postprocessing functions to modify the text before checking the expectations
|
|
2507
|
+
* The result will be the text BEFORE the postprocessing
|
|
2508
|
+
*
|
|
2510
2509
|
* @private internal util for MockedFackedNaturalExecutionTools
|
|
2511
2510
|
*/
|
|
2512
|
-
function $fakeTextToExpectations(expectations) {
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2511
|
+
function $fakeTextToExpectations(expectations, postprocessing) {
|
|
2512
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2513
|
+
var lorem, loremText, text, loopLimit, textToCheck, _a, _b, func, e_1_1;
|
|
2514
|
+
var e_1, _c;
|
|
2515
|
+
return __generator(this, function (_d) {
|
|
2516
|
+
switch (_d.label) {
|
|
2517
|
+
case 0:
|
|
2518
|
+
lorem = new loremIpsum.LoremIpsum({
|
|
2519
|
+
wordsPerSentence: { min: 5, max: 15 },
|
|
2520
|
+
sentencesPerParagraph: { min: 5, max: 15 },
|
|
2521
|
+
});
|
|
2522
|
+
loremText = '';
|
|
2523
|
+
text = '';
|
|
2524
|
+
loopLimit = CHARACTER_LOOP_LIMIT;
|
|
2525
|
+
_d.label = 1;
|
|
2526
|
+
case 1:
|
|
2527
|
+
if (!(loopLimit-- > 0)) return [3 /*break*/, 11];
|
|
2528
|
+
textToCheck = text;
|
|
2529
|
+
_d.label = 2;
|
|
2530
|
+
case 2:
|
|
2531
|
+
_d.trys.push([2, 7, 8, 9]);
|
|
2532
|
+
_a = (e_1 = void 0, __values(postprocessing || [])), _b = _a.next();
|
|
2533
|
+
_d.label = 3;
|
|
2534
|
+
case 3:
|
|
2535
|
+
if (!!_b.done) return [3 /*break*/, 6];
|
|
2536
|
+
func = _b.value;
|
|
2537
|
+
return [4 /*yield*/, func(textToCheck)];
|
|
2538
|
+
case 4:
|
|
2539
|
+
textToCheck = _d.sent();
|
|
2540
|
+
_d.label = 5;
|
|
2541
|
+
case 5:
|
|
2542
|
+
_b = _a.next();
|
|
2543
|
+
return [3 /*break*/, 3];
|
|
2544
|
+
case 6: return [3 /*break*/, 9];
|
|
2545
|
+
case 7:
|
|
2546
|
+
e_1_1 = _d.sent();
|
|
2547
|
+
e_1 = { error: e_1_1 };
|
|
2548
|
+
return [3 /*break*/, 9];
|
|
2549
|
+
case 8:
|
|
2550
|
+
try {
|
|
2551
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2552
|
+
}
|
|
2553
|
+
finally { if (e_1) throw e_1.error; }
|
|
2554
|
+
return [7 /*endfinally*/];
|
|
2555
|
+
case 9:
|
|
2556
|
+
if (isPassingExpectations(expectations, textToCheck)) {
|
|
2557
|
+
return [2 /*return*/, text]; // <- Note: Returning the text because the postprocessing
|
|
2558
|
+
}
|
|
2559
|
+
if (loremText === '') {
|
|
2560
|
+
loremText = lorem.generateParagraphs(1) + '\n\n';
|
|
2561
|
+
}
|
|
2562
|
+
text += loremText.substring(0, 1);
|
|
2563
|
+
loremText = loremText.substring(1);
|
|
2564
|
+
_d.label = 10;
|
|
2565
|
+
case 10: return [3 /*break*/, 1];
|
|
2566
|
+
case 11: throw new Error(spacetrim.spaceTrim(function (block) { return "\n Can not generate fake text to met the expectations\n\n Loop limit reached\n The expectations:\n ".concat(block(JSON.stringify(expectations, null, 4)), "\n\n The draft text:\n ").concat(block(text), "\n\n "); }));
|
|
2567
|
+
}
|
|
2568
|
+
});
|
|
2516
2569
|
});
|
|
2517
|
-
var loremText = '';
|
|
2518
|
-
var text = '';
|
|
2519
|
-
for (var loopLimit = CHARACTER_LOOP_LIMIT; loopLimit-- > 0;) {
|
|
2520
|
-
if (isPassingExpectations(expectations, text)) {
|
|
2521
|
-
return text;
|
|
2522
|
-
}
|
|
2523
|
-
if (loremText === '') {
|
|
2524
|
-
loremText = lorem.generateParagraphs(1) + '\n\n';
|
|
2525
|
-
}
|
|
2526
|
-
text += loremText.substring(0, 1);
|
|
2527
|
-
loremText = loremText.substring(1);
|
|
2528
|
-
}
|
|
2529
|
-
throw new Error(spaceTrim__default["default"](function (block) { return "\n Can not generate fake text to met the expectations\n\n Loop limit reached\n The expectations:\n ".concat(block(JSON.stringify(expectations, null, 4)), "\n\n The draft text:\n ").concat(block(text), "\n\n "); }));
|
|
2530
2570
|
}
|
|
2531
2571
|
/**
|
|
2532
|
-
* TODO: Implement better
|
|
2572
|
+
* TODO: Implement better - create FakeLLM from this
|
|
2533
2573
|
* TODO: [๐] Unite object for expecting amount and format - use here also a format
|
|
2534
2574
|
*/
|
|
2535
2575
|
|
|
@@ -2547,33 +2587,38 @@
|
|
|
2547
2587
|
return __awaiter(this, void 0, void 0, function () {
|
|
2548
2588
|
var content, result;
|
|
2549
2589
|
return __generator(this, function (_a) {
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2590
|
+
switch (_a.label) {
|
|
2591
|
+
case 0:
|
|
2592
|
+
if (this.options.isVerbose) {
|
|
2593
|
+
console.info('๐ฌ Mocked faked prompt', prompt);
|
|
2594
|
+
}
|
|
2595
|
+
return [4 /*yield*/, $fakeTextToExpectations(prompt.expectations || {
|
|
2596
|
+
sentences: { min: 1, max: 1 },
|
|
2597
|
+
}, prompt.postprocessing)];
|
|
2598
|
+
case 1:
|
|
2599
|
+
content = _a.sent();
|
|
2600
|
+
result = {
|
|
2601
|
+
content: content,
|
|
2602
|
+
model: 'mocked-facked',
|
|
2603
|
+
timing: {
|
|
2604
|
+
start: getCurrentIsoDate(),
|
|
2605
|
+
complete: getCurrentIsoDate(),
|
|
2606
|
+
},
|
|
2607
|
+
usage: {
|
|
2608
|
+
price: 0,
|
|
2609
|
+
inputTokens: 0,
|
|
2610
|
+
outputTokens: 0,
|
|
2611
|
+
},
|
|
2612
|
+
rawResponse: {
|
|
2613
|
+
note: 'This is mocked echo',
|
|
2614
|
+
},
|
|
2615
|
+
// <- [๐คนโโ๏ธ]
|
|
2616
|
+
};
|
|
2617
|
+
if (this.options.isVerbose) {
|
|
2618
|
+
console.info('๐ฌ Mocked faked result', result);
|
|
2619
|
+
}
|
|
2620
|
+
return [2 /*return*/, result];
|
|
2575
2621
|
}
|
|
2576
|
-
return [2 /*return*/, result];
|
|
2577
2622
|
});
|
|
2578
2623
|
});
|
|
2579
2624
|
};
|
|
@@ -2610,7 +2655,7 @@
|
|
|
2610
2655
|
case 1:
|
|
2611
2656
|
answer = _a.sent();
|
|
2612
2657
|
if (this.options.isVerbose) {
|
|
2613
|
-
console.info(
|
|
2658
|
+
console.info(spacetrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
2614
2659
|
}
|
|
2615
2660
|
return [2 /*return*/, answer];
|
|
2616
2661
|
}
|
|
@@ -2637,9 +2682,9 @@
|
|
|
2637
2682
|
return __awaiter(this, void 0, void 0, function () {
|
|
2638
2683
|
var answer;
|
|
2639
2684
|
return __generator(this, function (_a) {
|
|
2640
|
-
answer = window.prompt(
|
|
2685
|
+
answer = window.prompt(spacetrim.spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
|
|
2641
2686
|
if (this.options.isVerbose) {
|
|
2642
|
-
console.info(
|
|
2687
|
+
console.info(spacetrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '๐ซ User cancelled prompt'), "\n "); }));
|
|
2643
2688
|
}
|
|
2644
2689
|
if (answer === null) {
|
|
2645
2690
|
throw new PromptbookExecutionError('User cancelled prompt');
|
|
@@ -2704,7 +2749,7 @@
|
|
|
2704
2749
|
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
2705
2750
|
var promptbook = promptbooks_1_1.value;
|
|
2706
2751
|
if (promptbook.promptbookUrl === undefined) {
|
|
2707
|
-
throw new PromptbookReferenceError(
|
|
2752
|
+
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 ")));
|
|
2708
2753
|
}
|
|
2709
2754
|
validatePromptbookJson(promptbook);
|
|
2710
2755
|
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
@@ -2733,7 +2778,7 @@
|
|
|
2733
2778
|
var _this = this;
|
|
2734
2779
|
var promptbook = this.library.get(url);
|
|
2735
2780
|
if (!promptbook) {
|
|
2736
|
-
throw new PromptbookNotFoundError(
|
|
2781
|
+
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()
|
|
2737
2782
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
2738
2783
|
.join('\n')), "\n\n "); }));
|
|
2739
2784
|
}
|
|
@@ -2884,7 +2929,7 @@
|
|
|
2884
2929
|
case 0:
|
|
2885
2930
|
if (!!predicate(url)) return [3 /*break*/, 2];
|
|
2886
2931
|
_a = PromptbookNotFoundError.bind;
|
|
2887
|
-
return [4 /*yield*/,
|
|
2932
|
+
return [4 /*yield*/, spacetrim.spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
|
|
2888
2933
|
var _a, _b, _c, _d, _e, _f;
|
|
2889
2934
|
return __generator(this, function (_g) {
|
|
2890
2935
|
switch (_g.label) {
|