@promptbook/core 0.58.0 → 0.59.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 +1 -1
- package/esm/index.es.js +575 -504
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +9 -10
- package/esm/typings/_packages/node.index.d.ts +1 -1
- package/esm/typings/_packages/types.index.d.ts +11 -70
- package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/esm/typings/conversion/promptbookStringToJson.d.ts +17 -2
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
- package/esm/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
- package/esm/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
- package/esm/typings/formats/_common/FormatDefinition.d.ts +20 -4
- package/esm/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
- package/esm/typings/formats/json/JsonFormatDefinition.d.ts +5 -1
- package/esm/typings/formats/list/ListFormatDefinition.d.ts +13 -0
- package/esm/typings/formats/xml/XmlFormatDefinition.d.ts +4 -0
- package/{umd/typings/knowledgebase → esm/typings/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/esm/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
- package/esm/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
- package/esm/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/esm/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
- package/esm/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
- package/esm/typings/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/esm/typings/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/esm/typings/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
- package/esm/typings/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
- package/{umd/typings/library → esm/typings/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
- package/{umd/typings/library → esm/typings/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
- package/esm/typings/scripting/python/PythonExecutionTools.d.ts +1 -1
- package/esm/typings/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
- package/esm/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
- package/esm/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
- package/esm/typings/types/typeAliases.d.ts +7 -1
- package/package.json +2 -2
- package/umd/index.umd.js +575 -504
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +9 -10
- package/umd/typings/_packages/node.index.d.ts +1 -1
- package/umd/typings/_packages/types.index.d.ts +11 -70
- package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/umd/typings/conversion/promptbookStringToJson.d.ts +17 -2
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
- package/umd/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
- package/umd/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
- package/umd/typings/formats/_common/FormatDefinition.d.ts +20 -4
- package/umd/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
- package/umd/typings/formats/json/JsonFormatDefinition.d.ts +5 -1
- package/umd/typings/formats/list/ListFormatDefinition.d.ts +13 -0
- package/umd/typings/formats/xml/XmlFormatDefinition.d.ts +4 -0
- package/{esm/typings/knowledgebase → umd/typings/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/umd/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
- package/umd/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
- package/umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
- package/umd/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
- package/umd/typings/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/umd/typings/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/umd/typings/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
- package/umd/typings/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
- package/{esm/typings/library → umd/typings/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
- package/{esm/typings/library → umd/typings/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
- package/umd/typings/scripting/python/PythonExecutionTools.d.ts +1 -1
- package/umd/typings/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
- package/umd/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
- package/umd/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
- package/umd/typings/types/typeAliases.d.ts +7 -1
- package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +0 -1
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +0 -1
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +0 -1
- /package/esm/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- /package/esm/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- /package/esm/typings/{knowledgebase → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts → knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools/custom-function-missing.test.d.ts → knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- /package/esm/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/umd/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- /package/umd/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- /package/umd/typings/{knowledgebase → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- /package/{esm/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts → umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
- /package/{esm/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts → umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- /package/umd/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -122,6 +122,69 @@ function __spreadArray(to, from, pack) {
|
|
|
122
122
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Removes HTML or Markdown comments from a string.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} content - The string to remove comments from.
|
|
129
|
+
* @returns {string} The input string with all comments removed.
|
|
130
|
+
*/
|
|
131
|
+
function removeContentComments(content) {
|
|
132
|
+
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Add or modify an auto-generated section in a markdown file
|
|
137
|
+
*
|
|
138
|
+
* @private within the library
|
|
139
|
+
*/
|
|
140
|
+
function addAutoGeneratedSection(content, options) {
|
|
141
|
+
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
142
|
+
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
143
|
+
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
144
|
+
var sectionMatch = content.match(sectionRegex);
|
|
145
|
+
if (sectionMatch) {
|
|
146
|
+
return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
147
|
+
}
|
|
148
|
+
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
149
|
+
if (!placeForSection) {
|
|
150
|
+
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
151
|
+
}
|
|
152
|
+
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
153
|
+
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Prettify the html code
|
|
158
|
+
*
|
|
159
|
+
* @param content raw html code
|
|
160
|
+
* @returns formatted html code
|
|
161
|
+
*/
|
|
162
|
+
function prettifyMarkdown(content) {
|
|
163
|
+
try {
|
|
164
|
+
return format(content, {
|
|
165
|
+
parser: 'markdown',
|
|
166
|
+
plugins: [parserHtml],
|
|
167
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
168
|
+
endOfLine: 'lf',
|
|
169
|
+
tabWidth: 4,
|
|
170
|
+
singleQuote: true,
|
|
171
|
+
trailingComma: 'all',
|
|
172
|
+
arrowParens: 'always',
|
|
173
|
+
printWidth: 120,
|
|
174
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
175
|
+
jsxBracketSameLine: false,
|
|
176
|
+
bracketSpacing: true,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
181
|
+
error: error,
|
|
182
|
+
html: content,
|
|
183
|
+
});
|
|
184
|
+
return content;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
125
188
|
/**
|
|
126
189
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
127
190
|
*/
|
|
@@ -136,6 +199,32 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
136
199
|
return PromptbookSyntaxError;
|
|
137
200
|
}(Error));
|
|
138
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Returns the same value that is passed as argument.
|
|
204
|
+
* No side effects.
|
|
205
|
+
*
|
|
206
|
+
* Note: It can be usefull for leveling indentation
|
|
207
|
+
*
|
|
208
|
+
* @param value any values
|
|
209
|
+
* @returns the same values
|
|
210
|
+
*/
|
|
211
|
+
function just(value) {
|
|
212
|
+
if (value === undefined) {
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
|
|
220
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
+
return __generator(this, function (_a) {
|
|
223
|
+
return [2 /*return*/, []];
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
139
228
|
/**
|
|
140
229
|
* Supported script languages
|
|
141
230
|
*/
|
|
@@ -396,16 +485,6 @@ function extractOneBlockFromMarkdown(markdown) {
|
|
|
396
485
|
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
397
486
|
*/
|
|
398
487
|
|
|
399
|
-
/**
|
|
400
|
-
* Removes HTML or Markdown comments from a string.
|
|
401
|
-
*
|
|
402
|
-
* @param {string} content - The string to remove comments from.
|
|
403
|
-
* @returns {string} The input string with all comments removed.
|
|
404
|
-
*/
|
|
405
|
-
function removeContentComments(content) {
|
|
406
|
-
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
407
|
-
}
|
|
408
|
-
|
|
409
488
|
/**
|
|
410
489
|
* Creates a new set with all elements that are present in either set
|
|
411
490
|
*/
|
|
@@ -447,7 +526,7 @@ function union() {
|
|
|
447
526
|
/**
|
|
448
527
|
* The version of the Promptbook library
|
|
449
528
|
*/
|
|
450
|
-
var PROMPTBOOK_VERSION = '0.
|
|
529
|
+
var PROMPTBOOK_VERSION = '0.59.0-0';
|
|
451
530
|
|
|
452
531
|
/**
|
|
453
532
|
* Parses the template and returns the list of all parameter names
|
|
@@ -1318,250 +1397,267 @@ function titleToName(value) {
|
|
|
1318
1397
|
}
|
|
1319
1398
|
|
|
1320
1399
|
/**
|
|
1321
|
-
*
|
|
1400
|
+
* Compile promptbook from string (markdown) format to JSON format
|
|
1322
1401
|
*
|
|
1402
|
+
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1403
|
+
* @param options - Options and tools for the compilation
|
|
1404
|
+
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1323
1405
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1324
1406
|
*
|
|
1325
1407
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1408
|
+
* Note: This function acts as compilation process
|
|
1326
1409
|
*/
|
|
1327
|
-
function promptbookStringToJson(promptbookString) {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1410
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
1411
|
+
if (options === void 0) { options = {}; }
|
|
1412
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1413
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1414
|
+
var e_1, _c, e_2, _d;
|
|
1415
|
+
return __generator(this, function (_e) {
|
|
1416
|
+
switch (_e.label) {
|
|
1417
|
+
case 0:
|
|
1418
|
+
llmTools = options.llmTools;
|
|
1419
|
+
promptbookJson = {
|
|
1420
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1421
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
1422
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
1423
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
1424
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1425
|
+
parameters: [],
|
|
1426
|
+
promptTemplates: [],
|
|
1427
|
+
knowledge: [],
|
|
1428
|
+
};
|
|
1429
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
1430
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
|
|
1431
|
+
case 1:
|
|
1432
|
+
knowledge = _e.sent();
|
|
1433
|
+
console.info('!!!! knowledge', knowledge);
|
|
1434
|
+
_e.label = 2;
|
|
1435
|
+
case 2:
|
|
1436
|
+
// =============================================================
|
|
1437
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1438
|
+
promptbookString = removeContentComments(promptbookString);
|
|
1439
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1440
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1441
|
+
addParam = function (parameterCommand) {
|
|
1442
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1443
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1444
|
+
if (existingParameter &&
|
|
1445
|
+
existingParameter.description &&
|
|
1446
|
+
existingParameter.description !== parameterDescription &&
|
|
1447
|
+
parameterDescription) {
|
|
1448
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
1449
|
+
}
|
|
1450
|
+
if (existingParameter) {
|
|
1451
|
+
if (parameterDescription) {
|
|
1452
|
+
existingParameter.description = parameterDescription;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
else {
|
|
1456
|
+
promptbookJson.parameters.push({
|
|
1457
|
+
name: parameterName,
|
|
1458
|
+
description: parameterDescription || undefined,
|
|
1459
|
+
isInput: isInput,
|
|
1460
|
+
isOutput: isOutput,
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1465
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1466
|
+
if (markdownStructureDeepness !== 2) {
|
|
1467
|
+
throw new PromptbookSyntaxError(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 ")));
|
|
1468
|
+
}
|
|
1469
|
+
promptbookJson.title = markdownStructure.title;
|
|
1470
|
+
description = markdownStructure.content;
|
|
1471
|
+
// Note: Remove codeblocks
|
|
1472
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
1473
|
+
//Note: Remove lists and return statement
|
|
1474
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1475
|
+
description = spaceTrim(description);
|
|
1476
|
+
if (description === '') {
|
|
1477
|
+
description = undefined;
|
|
1478
|
+
}
|
|
1479
|
+
promptbookJson.description = description;
|
|
1480
|
+
defaultModelRequirements = {};
|
|
1481
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1482
|
+
try {
|
|
1483
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1484
|
+
listItem = listItems_1_1.value;
|
|
1485
|
+
command = parseCommand(listItem);
|
|
1486
|
+
switch (command.type) {
|
|
1487
|
+
case 'PROMPTBOOK_URL':
|
|
1488
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1489
|
+
break;
|
|
1490
|
+
case 'PROMPTBOOK_VERSION':
|
|
1491
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1492
|
+
break;
|
|
1493
|
+
case 'MODEL':
|
|
1494
|
+
defaultModelRequirements[command.key] = command.value;
|
|
1495
|
+
break;
|
|
1496
|
+
case 'PARAMETER':
|
|
1497
|
+
addParam(command);
|
|
1498
|
+
break;
|
|
1499
|
+
default:
|
|
1500
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1505
|
+
finally {
|
|
1506
|
+
try {
|
|
1507
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1508
|
+
}
|
|
1509
|
+
finally { if (e_1) throw e_1.error; }
|
|
1510
|
+
}
|
|
1511
|
+
_loop_1 = function (section) {
|
|
1512
|
+
var e_3, _f;
|
|
1513
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1514
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1515
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1516
|
+
var dependentParameterNames = new Set();
|
|
1517
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
1518
|
+
var jokers = [];
|
|
1519
|
+
var postprocessing = [];
|
|
1520
|
+
var expectAmount = {};
|
|
1521
|
+
var expectFormat = undefined;
|
|
1522
|
+
var isExecutionTypeChanged = false;
|
|
1523
|
+
try {
|
|
1524
|
+
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()) {
|
|
1525
|
+
var listItem = listItems_2_1.value;
|
|
1526
|
+
var command = parseCommand(listItem);
|
|
1527
|
+
switch (command.type) {
|
|
1528
|
+
case 'JOKER':
|
|
1529
|
+
jokers.push(command.parameterName);
|
|
1530
|
+
dependentParameterNames.add(command.parameterName);
|
|
1531
|
+
break;
|
|
1532
|
+
case 'EXECUTE':
|
|
1533
|
+
if (isExecutionTypeChanged) {
|
|
1534
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1535
|
+
}
|
|
1536
|
+
executionType = command.executionType;
|
|
1537
|
+
isExecutionTypeChanged = true;
|
|
1538
|
+
break;
|
|
1539
|
+
case 'MODEL':
|
|
1540
|
+
templateModelRequirements[command.key] = command.value;
|
|
1541
|
+
break;
|
|
1542
|
+
case 'PARAMETER':
|
|
1543
|
+
// Note: This is just for detecting resulitng parameter name
|
|
1544
|
+
addParam(command);
|
|
1545
|
+
break;
|
|
1546
|
+
case 'POSTPROCESS':
|
|
1547
|
+
postprocessing.push(command.functionName);
|
|
1548
|
+
break;
|
|
1549
|
+
case 'EXPECT_AMOUNT':
|
|
1550
|
+
// eslint-disable-next-line no-case-declarations
|
|
1551
|
+
var unit = command.unit.toLowerCase();
|
|
1552
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
1553
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1554
|
+
if (expectAmount[unit].min !== undefined) {
|
|
1555
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1556
|
+
}
|
|
1557
|
+
expectAmount[unit].min = command.amount;
|
|
1558
|
+
} /* not else */
|
|
1559
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1560
|
+
if (expectAmount[unit].max !== undefined) {
|
|
1561
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1562
|
+
}
|
|
1563
|
+
expectAmount[unit].max = command.amount;
|
|
1564
|
+
}
|
|
1565
|
+
break;
|
|
1566
|
+
case 'EXPECT_FORMAT':
|
|
1567
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1568
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1569
|
+
}
|
|
1570
|
+
expectFormat = command.format;
|
|
1571
|
+
break;
|
|
1572
|
+
default:
|
|
1573
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1578
|
+
finally {
|
|
1579
|
+
try {
|
|
1580
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1581
|
+
}
|
|
1582
|
+
finally { if (e_3) throw e_3.error; }
|
|
1442
1583
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
templateModelRequirements[command.key] = command.value;
|
|
1448
|
-
break;
|
|
1449
|
-
case 'PARAMETER':
|
|
1450
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1451
|
-
addParam(command);
|
|
1452
|
-
break;
|
|
1453
|
-
case 'POSTPROCESS':
|
|
1454
|
-
postprocessing.push(command.functionName);
|
|
1455
|
-
break;
|
|
1456
|
-
case 'EXPECT_AMOUNT':
|
|
1457
|
-
// eslint-disable-next-line no-case-declarations
|
|
1458
|
-
var unit = command.unit.toLowerCase();
|
|
1459
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1460
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1461
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1462
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1584
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1585
|
+
if (executionType === 'SCRIPT') {
|
|
1586
|
+
if (!language) {
|
|
1587
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1463
1588
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1467
|
-
if (expectAmount[unit].max !== undefined) {
|
|
1468
|
-
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1589
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1590
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
1469
1591
|
}
|
|
1470
|
-
expectAmount[unit].max = command.amount;
|
|
1471
1592
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
if (
|
|
1475
|
-
throw new PromptbookSyntaxError(
|
|
1593
|
+
var lastLine = section.content.split('\n').pop();
|
|
1594
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1595
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1596
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1597
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
1598
|
+
section.content
|
|
1599
|
+
.split('\n')
|
|
1600
|
+
.map(function (line) { return "> ".concat(line); })
|
|
1601
|
+
.join('\n')), "\n "); }));
|
|
1476
1602
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1603
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
1604
|
+
// TODO: [1] DRY description
|
|
1605
|
+
var description_1 = section.content;
|
|
1606
|
+
// Note: Remove codeblocks
|
|
1607
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1608
|
+
//Note: Remove lists and return statement
|
|
1609
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1610
|
+
description_1 = spaceTrim(description_1);
|
|
1611
|
+
if (description_1 === '') {
|
|
1612
|
+
description_1 = undefined;
|
|
1613
|
+
}
|
|
1614
|
+
if (Object.keys(jokers).length === 0) {
|
|
1615
|
+
jokers = undefined;
|
|
1616
|
+
}
|
|
1617
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
1618
|
+
expectAmount = undefined;
|
|
1619
|
+
}
|
|
1620
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
1621
|
+
postprocessing = undefined;
|
|
1622
|
+
}
|
|
1623
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1624
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
1625
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
1626
|
+
}
|
|
1627
|
+
promptbookJson.promptTemplates.push({
|
|
1628
|
+
name: titleToName(section.title),
|
|
1629
|
+
title: section.title,
|
|
1630
|
+
description: description_1,
|
|
1631
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1632
|
+
executionType: executionType,
|
|
1633
|
+
jokers: jokers,
|
|
1634
|
+
postprocessing: postprocessing,
|
|
1635
|
+
expectations: expectAmount,
|
|
1636
|
+
expectFormat: expectFormat,
|
|
1637
|
+
modelRequirements: templateModelRequirements,
|
|
1638
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1639
|
+
content: content,
|
|
1640
|
+
resultingParameterName: resultingParameterName,
|
|
1641
|
+
});
|
|
1642
|
+
};
|
|
1643
|
+
try {
|
|
1644
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1645
|
+
section = _b.value;
|
|
1646
|
+
_loop_1(section);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1650
|
+
finally {
|
|
1651
|
+
try {
|
|
1652
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1653
|
+
}
|
|
1654
|
+
finally { if (e_2) throw e_2.error; }
|
|
1655
|
+
}
|
|
1656
|
+
// =============================================================
|
|
1657
|
+
return [2 /*return*/, promptbookJson];
|
|
1498
1658
|
}
|
|
1499
|
-
}
|
|
1500
|
-
var lastLine = section.content.split('\n').pop();
|
|
1501
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1502
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1503
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1504
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1505
|
-
section.content
|
|
1506
|
-
.split('\n')
|
|
1507
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1508
|
-
.join('\n')), "\n "); }));
|
|
1509
|
-
}
|
|
1510
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1511
|
-
// TODO: [1] DRY description
|
|
1512
|
-
var description_1 = section.content;
|
|
1513
|
-
// Note: Remove codeblocks
|
|
1514
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1515
|
-
//Note: Remove lists and return statement
|
|
1516
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1517
|
-
description_1 = spaceTrim(description_1);
|
|
1518
|
-
if (description_1 === '') {
|
|
1519
|
-
description_1 = undefined;
|
|
1520
|
-
}
|
|
1521
|
-
if (Object.keys(jokers).length === 0) {
|
|
1522
|
-
jokers = undefined;
|
|
1523
|
-
}
|
|
1524
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1525
|
-
expectAmount = undefined;
|
|
1526
|
-
}
|
|
1527
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1528
|
-
postprocessing = undefined;
|
|
1529
|
-
}
|
|
1530
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1531
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1532
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1533
|
-
}
|
|
1534
|
-
promptbookJson.promptTemplates.push({
|
|
1535
|
-
name: titleToName(section.title),
|
|
1536
|
-
title: section.title,
|
|
1537
|
-
description: description_1,
|
|
1538
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1539
|
-
executionType: executionType,
|
|
1540
|
-
jokers: jokers,
|
|
1541
|
-
postprocessing: postprocessing,
|
|
1542
|
-
expectations: expectAmount,
|
|
1543
|
-
expectFormat: expectFormat,
|
|
1544
|
-
modelRequirements: templateModelRequirements,
|
|
1545
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1546
|
-
content: content,
|
|
1547
|
-
resultingParameterName: resultingParameterName,
|
|
1548
1659
|
});
|
|
1549
|
-
};
|
|
1550
|
-
try {
|
|
1551
|
-
for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1552
|
-
var section = _d.value;
|
|
1553
|
-
_loop_1(section);
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1557
|
-
finally {
|
|
1558
|
-
try {
|
|
1559
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1560
|
-
}
|
|
1561
|
-
finally { if (e_2) throw e_2.error; }
|
|
1562
|
-
}
|
|
1563
|
-
// =============================================================
|
|
1564
|
-
return promptbookJson;
|
|
1660
|
+
});
|
|
1565
1661
|
}
|
|
1566
1662
|
/**
|
|
1567
1663
|
* TODO: Report here line/column of error
|
|
@@ -1569,59 +1665,6 @@ function promptbookStringToJson(promptbookString) {
|
|
|
1569
1665
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
1570
1666
|
*/
|
|
1571
1667
|
|
|
1572
|
-
/**
|
|
1573
|
-
* Add or modify an auto-generated section in a markdown file
|
|
1574
|
-
*
|
|
1575
|
-
* @private within the library
|
|
1576
|
-
*/
|
|
1577
|
-
function addAutoGeneratedSection(content, options) {
|
|
1578
|
-
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
1579
|
-
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
1580
|
-
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
1581
|
-
var sectionMatch = content.match(sectionRegex);
|
|
1582
|
-
if (sectionMatch) {
|
|
1583
|
-
return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
1584
|
-
}
|
|
1585
|
-
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
1586
|
-
if (!placeForSection) {
|
|
1587
|
-
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
1588
|
-
}
|
|
1589
|
-
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
1590
|
-
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
/**
|
|
1594
|
-
* Prettify the html code
|
|
1595
|
-
*
|
|
1596
|
-
* @param content raw html code
|
|
1597
|
-
* @returns formatted html code
|
|
1598
|
-
*/
|
|
1599
|
-
function prettifyMarkdown(content) {
|
|
1600
|
-
try {
|
|
1601
|
-
return format(content, {
|
|
1602
|
-
parser: 'markdown',
|
|
1603
|
-
plugins: [parserHtml],
|
|
1604
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1605
|
-
endOfLine: 'lf',
|
|
1606
|
-
tabWidth: 4,
|
|
1607
|
-
singleQuote: true,
|
|
1608
|
-
trailingComma: 'all',
|
|
1609
|
-
arrowParens: 'always',
|
|
1610
|
-
printWidth: 120,
|
|
1611
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
1612
|
-
jsxBracketSameLine: false,
|
|
1613
|
-
bracketSpacing: true,
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1616
|
-
catch (error) {
|
|
1617
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1618
|
-
error: error,
|
|
1619
|
-
html: content,
|
|
1620
|
-
});
|
|
1621
|
-
return content;
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
1668
|
/* tslint:disable */
|
|
1626
1669
|
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
1627
1670
|
var e_1, _a;
|
|
@@ -1739,24 +1782,35 @@ function renderPromptbookMermaid(promptbookJson, options) {
|
|
|
1739
1782
|
* Prettyfies Promptbook string and adds Mermaid graph
|
|
1740
1783
|
*/
|
|
1741
1784
|
function prettifyPromptbookString(promptbookString, options) {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1785
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1786
|
+
var isGraphAdded, isPrettifyed, promptbookJson, promptbookMermaid_1, promptbookMermaidBlock;
|
|
1787
|
+
return __generator(this, function (_a) {
|
|
1788
|
+
switch (_a.label) {
|
|
1789
|
+
case 0:
|
|
1790
|
+
isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
|
|
1791
|
+
if (!isGraphAdded) return [3 /*break*/, 2];
|
|
1792
|
+
return [4 /*yield*/, promptbookStringToJson(promptbookString /* , {!!!!} */)];
|
|
1793
|
+
case 1:
|
|
1794
|
+
promptbookJson = _a.sent();
|
|
1795
|
+
promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
|
|
1796
|
+
linkPromptTemplate: function (promptTemplate) {
|
|
1797
|
+
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
1798
|
+
},
|
|
1799
|
+
});
|
|
1800
|
+
promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1801
|
+
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1802
|
+
sectionName: 'Graph',
|
|
1803
|
+
sectionContent: promptbookMermaidBlock,
|
|
1804
|
+
});
|
|
1805
|
+
_a.label = 2;
|
|
1806
|
+
case 2:
|
|
1807
|
+
if (isPrettifyed) {
|
|
1808
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1809
|
+
}
|
|
1810
|
+
return [2 /*return*/, promptbookString];
|
|
1811
|
+
}
|
|
1754
1812
|
});
|
|
1755
|
-
}
|
|
1756
|
-
if (isPrettifyed) {
|
|
1757
|
-
promptbookString = prettifyMarkdown(promptbookString);
|
|
1758
|
-
}
|
|
1759
|
-
return promptbookString;
|
|
1813
|
+
});
|
|
1760
1814
|
}
|
|
1761
1815
|
/**
|
|
1762
1816
|
* TODO: Maybe use some Mermaid library instead of string templating
|
|
@@ -3135,11 +3189,29 @@ function createPromptbookExecutor(options) {
|
|
|
3135
3189
|
*/
|
|
3136
3190
|
|
|
3137
3191
|
/**
|
|
3138
|
-
*
|
|
3139
|
-
*
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3192
|
+
* Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
|
|
3193
|
+
*
|
|
3194
|
+
* Note: This is an estimate based of theese sources:
|
|
3195
|
+
* - https://jecas.cz/doba-cteni
|
|
3196
|
+
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3197
|
+
*/
|
|
3198
|
+
function usageToWorktime(usage) {
|
|
3199
|
+
var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
|
|
3200
|
+
usage.output.wordsCount.value / (40 /* words per minute */ * 60);
|
|
3201
|
+
var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
|
|
3202
|
+
var uncertainNumber = { value: value };
|
|
3203
|
+
if (isUncertain === true) {
|
|
3204
|
+
uncertainNumber.isUncertain = true;
|
|
3205
|
+
}
|
|
3206
|
+
return uncertainNumber;
|
|
3207
|
+
}
|
|
3208
|
+
|
|
3209
|
+
/**
|
|
3210
|
+
* Delagates the user interaction to a async callback function
|
|
3211
|
+
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
3212
|
+
*/
|
|
3213
|
+
var CallbackInterfaceTools = /** @class */ (function () {
|
|
3214
|
+
function CallbackInterfaceTools(options) {
|
|
3143
3215
|
this.options = options;
|
|
3144
3216
|
}
|
|
3145
3217
|
/**
|
|
@@ -3172,6 +3244,7 @@ var CallbackInterfaceTools = /** @class */ (function () {
|
|
|
3172
3244
|
*/
|
|
3173
3245
|
var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
3174
3246
|
function SimplePromptInterfaceTools(options) {
|
|
3247
|
+
if (options === void 0) { options = {}; }
|
|
3175
3248
|
this.options = options;
|
|
3176
3249
|
}
|
|
3177
3250
|
/**
|
|
@@ -3196,22 +3269,135 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
3196
3269
|
}());
|
|
3197
3270
|
|
|
3198
3271
|
/**
|
|
3199
|
-
*
|
|
3272
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
3200
3273
|
*
|
|
3201
|
-
*
|
|
3202
|
-
* - https://jecas.cz/doba-cteni
|
|
3203
|
-
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3274
|
+
* @see https://github.com/webgptorg/promptbook#multiple-server
|
|
3204
3275
|
*/
|
|
3205
|
-
function
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3276
|
+
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
3277
|
+
/**
|
|
3278
|
+
* Gets array of execution tools in order of priority
|
|
3279
|
+
*/
|
|
3280
|
+
function MultipleLlmExecutionTools() {
|
|
3281
|
+
var llmExecutionTools = [];
|
|
3282
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3283
|
+
llmExecutionTools[_i] = arguments[_i];
|
|
3284
|
+
}
|
|
3285
|
+
this.llmExecutionTools = llmExecutionTools;
|
|
3212
3286
|
}
|
|
3213
|
-
|
|
3214
|
-
|
|
3287
|
+
/**
|
|
3288
|
+
* Calls the best available chat model
|
|
3289
|
+
*/
|
|
3290
|
+
MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
|
|
3291
|
+
return this.gptCommon(prompt);
|
|
3292
|
+
};
|
|
3293
|
+
/**
|
|
3294
|
+
* Calls the best available completion model
|
|
3295
|
+
*/
|
|
3296
|
+
MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
|
|
3297
|
+
return this.gptCommon(prompt);
|
|
3298
|
+
};
|
|
3299
|
+
/**
|
|
3300
|
+
* Calls the best available model
|
|
3301
|
+
*/
|
|
3302
|
+
MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
|
|
3303
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3304
|
+
var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
|
|
3305
|
+
var e_1, _c;
|
|
3306
|
+
return __generator(this, function (_d) {
|
|
3307
|
+
switch (_d.label) {
|
|
3308
|
+
case 0:
|
|
3309
|
+
errors = [];
|
|
3310
|
+
_d.label = 1;
|
|
3311
|
+
case 1:
|
|
3312
|
+
_d.trys.push([1, 11, 12, 13]);
|
|
3313
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3314
|
+
_d.label = 2;
|
|
3315
|
+
case 2:
|
|
3316
|
+
if (!!_b.done) return [3 /*break*/, 10];
|
|
3317
|
+
llmExecutionTools = _b.value;
|
|
3318
|
+
_d.label = 3;
|
|
3319
|
+
case 3:
|
|
3320
|
+
_d.trys.push([3, 8, , 9]);
|
|
3321
|
+
if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
|
|
3322
|
+
return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
|
|
3323
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
3324
|
+
case 5:
|
|
3325
|
+
if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
|
|
3326
|
+
return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
|
|
3327
|
+
case 6: return [2 /*return*/, _d.sent()];
|
|
3328
|
+
case 7: return [3 /*break*/, 9];
|
|
3329
|
+
case 8:
|
|
3330
|
+
error_1 = _d.sent();
|
|
3331
|
+
if (!(error_1 instanceof Error)) {
|
|
3332
|
+
throw error_1;
|
|
3333
|
+
}
|
|
3334
|
+
errors.push(error_1);
|
|
3335
|
+
return [3 /*break*/, 9];
|
|
3336
|
+
case 9:
|
|
3337
|
+
_b = _a.next();
|
|
3338
|
+
return [3 /*break*/, 2];
|
|
3339
|
+
case 10: return [3 /*break*/, 13];
|
|
3340
|
+
case 11:
|
|
3341
|
+
e_1_1 = _d.sent();
|
|
3342
|
+
e_1 = { error: e_1_1 };
|
|
3343
|
+
return [3 /*break*/, 13];
|
|
3344
|
+
case 12:
|
|
3345
|
+
try {
|
|
3346
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3347
|
+
}
|
|
3348
|
+
finally { if (e_1) throw e_1.error; }
|
|
3349
|
+
return [7 /*endfinally*/];
|
|
3350
|
+
case 13: throw new Error(spaceTrim$1(function (block) { return "\n All execution tools failed:\n \n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n \n "); }));
|
|
3351
|
+
}
|
|
3352
|
+
});
|
|
3353
|
+
});
|
|
3354
|
+
};
|
|
3355
|
+
/**
|
|
3356
|
+
* List all available models that can be used
|
|
3357
|
+
* This liost is a combination of all available models from all execution tools
|
|
3358
|
+
*/
|
|
3359
|
+
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
3360
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3361
|
+
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
3362
|
+
var e_2, _c;
|
|
3363
|
+
return __generator(this, function (_d) {
|
|
3364
|
+
switch (_d.label) {
|
|
3365
|
+
case 0:
|
|
3366
|
+
availableModels = [];
|
|
3367
|
+
_d.label = 1;
|
|
3368
|
+
case 1:
|
|
3369
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
3370
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3371
|
+
_d.label = 2;
|
|
3372
|
+
case 2:
|
|
3373
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
3374
|
+
llmExecutionTools = _b.value;
|
|
3375
|
+
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
3376
|
+
case 3:
|
|
3377
|
+
models = _d.sent();
|
|
3378
|
+
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
3379
|
+
_d.label = 4;
|
|
3380
|
+
case 4:
|
|
3381
|
+
_b = _a.next();
|
|
3382
|
+
return [3 /*break*/, 2];
|
|
3383
|
+
case 5: return [3 /*break*/, 8];
|
|
3384
|
+
case 6:
|
|
3385
|
+
e_2_1 = _d.sent();
|
|
3386
|
+
e_2 = { error: e_2_1 };
|
|
3387
|
+
return [3 /*break*/, 8];
|
|
3388
|
+
case 7:
|
|
3389
|
+
try {
|
|
3390
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3391
|
+
}
|
|
3392
|
+
finally { if (e_2) throw e_2.error; }
|
|
3393
|
+
return [7 /*endfinally*/];
|
|
3394
|
+
case 8: return [2 /*return*/, availableModels];
|
|
3395
|
+
}
|
|
3396
|
+
});
|
|
3397
|
+
});
|
|
3398
|
+
};
|
|
3399
|
+
return MultipleLlmExecutionTools;
|
|
3400
|
+
}());
|
|
3215
3401
|
|
|
3216
3402
|
/**
|
|
3217
3403
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
@@ -3302,36 +3488,61 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
3302
3488
|
* @returns PromptbookLibrary
|
|
3303
3489
|
*/
|
|
3304
3490
|
function createPromptbookLibraryFromSources() {
|
|
3305
|
-
var e_1, _a;
|
|
3306
3491
|
var promptbookSources = [];
|
|
3307
3492
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3308
3493
|
promptbookSources[_i] = arguments[_i];
|
|
3309
3494
|
}
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3495
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3496
|
+
var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
|
|
3497
|
+
var e_1, _a;
|
|
3498
|
+
return __generator(this, function (_b) {
|
|
3499
|
+
switch (_b.label) {
|
|
3500
|
+
case 0:
|
|
3501
|
+
promptbooks = new Array();
|
|
3502
|
+
_b.label = 1;
|
|
3503
|
+
case 1:
|
|
3504
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
3505
|
+
promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
|
|
3506
|
+
_b.label = 2;
|
|
3507
|
+
case 2:
|
|
3508
|
+
if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
|
|
3509
|
+
source = promptbookSources_1_1.value;
|
|
3510
|
+
promptbook = void 0;
|
|
3511
|
+
if (!(typeof source === 'string')) return [3 /*break*/, 4];
|
|
3512
|
+
return [4 /*yield*/, promptbookStringToJson(source)];
|
|
3513
|
+
case 3:
|
|
3514
|
+
// Note: When directly creating from string, no need to validate the source
|
|
3515
|
+
// The validation is performed always before execution
|
|
3516
|
+
promptbook = _b.sent();
|
|
3517
|
+
return [3 /*break*/, 5];
|
|
3518
|
+
case 4:
|
|
3519
|
+
promptbook = source;
|
|
3520
|
+
_b.label = 5;
|
|
3521
|
+
case 5:
|
|
3522
|
+
promptbooks.push(promptbook);
|
|
3523
|
+
_b.label = 6;
|
|
3524
|
+
case 6:
|
|
3525
|
+
promptbookSources_1_1 = promptbookSources_1.next();
|
|
3526
|
+
return [3 /*break*/, 2];
|
|
3527
|
+
case 7: return [3 /*break*/, 10];
|
|
3528
|
+
case 8:
|
|
3529
|
+
e_1_1 = _b.sent();
|
|
3530
|
+
e_1 = { error: e_1_1 };
|
|
3531
|
+
return [3 /*break*/, 10];
|
|
3532
|
+
case 9:
|
|
3533
|
+
try {
|
|
3534
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
3535
|
+
}
|
|
3536
|
+
finally { if (e_1) throw e_1.error; }
|
|
3537
|
+
return [7 /*endfinally*/];
|
|
3538
|
+
case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
3322
3539
|
}
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
}
|
|
3326
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3327
|
-
finally {
|
|
3328
|
-
try {
|
|
3329
|
-
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
3330
|
-
}
|
|
3331
|
-
finally { if (e_1) throw e_1.error; }
|
|
3332
|
-
}
|
|
3333
|
-
return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
3540
|
+
});
|
|
3541
|
+
});
|
|
3334
3542
|
}
|
|
3543
|
+
/**
|
|
3544
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3545
|
+
*/
|
|
3335
3546
|
|
|
3336
3547
|
/**
|
|
3337
3548
|
* Constructs Promptbook from async sources
|
|
@@ -3367,7 +3578,9 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3367
3578
|
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3368
3579
|
case 1:
|
|
3369
3580
|
promptbookSources = _a.sent();
|
|
3370
|
-
|
|
3581
|
+
return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
|
|
3582
|
+
case 2:
|
|
3583
|
+
library = _a.sent();
|
|
3371
3584
|
return [2 /*return*/];
|
|
3372
3585
|
}
|
|
3373
3586
|
});
|
|
@@ -3415,6 +3628,9 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3415
3628
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3416
3629
|
};
|
|
3417
3630
|
}
|
|
3631
|
+
/**
|
|
3632
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3633
|
+
*/
|
|
3418
3634
|
|
|
3419
3635
|
/**
|
|
3420
3636
|
* Constructs Promptbook from remote Promptbase URL
|
|
@@ -3447,6 +3663,9 @@ function createPromptbookLibraryFromUrl(url, options) {
|
|
|
3447
3663
|
});
|
|
3448
3664
|
});
|
|
3449
3665
|
}
|
|
3666
|
+
/**
|
|
3667
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3668
|
+
*/
|
|
3450
3669
|
|
|
3451
3670
|
/**
|
|
3452
3671
|
* Creates PromptbookLibrary as a subset of another PromptbookLibrary
|
|
@@ -3527,137 +3746,6 @@ function createPromptbookSublibrary(library, predicate) {
|
|
|
3527
3746
|
};
|
|
3528
3747
|
}
|
|
3529
3748
|
|
|
3530
|
-
/**
|
|
3531
|
-
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
3532
|
-
*
|
|
3533
|
-
* @see https://github.com/webgptorg/promptbook#multiple-server
|
|
3534
|
-
*/
|
|
3535
|
-
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
3536
|
-
/**
|
|
3537
|
-
* Gets array of execution tools in order of priority
|
|
3538
|
-
*/
|
|
3539
|
-
function MultipleLlmExecutionTools() {
|
|
3540
|
-
var llmExecutionTools = [];
|
|
3541
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3542
|
-
llmExecutionTools[_i] = arguments[_i];
|
|
3543
|
-
}
|
|
3544
|
-
this.llmExecutionTools = llmExecutionTools;
|
|
3545
|
-
}
|
|
3546
|
-
/**
|
|
3547
|
-
* Calls the best available chat model
|
|
3548
|
-
*/
|
|
3549
|
-
MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
|
|
3550
|
-
return this.gptCommon(prompt);
|
|
3551
|
-
};
|
|
3552
|
-
/**
|
|
3553
|
-
* Calls the best available completion model
|
|
3554
|
-
*/
|
|
3555
|
-
MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
|
|
3556
|
-
return this.gptCommon(prompt);
|
|
3557
|
-
};
|
|
3558
|
-
/**
|
|
3559
|
-
* Calls the best available model
|
|
3560
|
-
*/
|
|
3561
|
-
MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
|
|
3562
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3563
|
-
var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
|
|
3564
|
-
var e_1, _c;
|
|
3565
|
-
return __generator(this, function (_d) {
|
|
3566
|
-
switch (_d.label) {
|
|
3567
|
-
case 0:
|
|
3568
|
-
errors = [];
|
|
3569
|
-
_d.label = 1;
|
|
3570
|
-
case 1:
|
|
3571
|
-
_d.trys.push([1, 11, 12, 13]);
|
|
3572
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3573
|
-
_d.label = 2;
|
|
3574
|
-
case 2:
|
|
3575
|
-
if (!!_b.done) return [3 /*break*/, 10];
|
|
3576
|
-
llmExecutionTools = _b.value;
|
|
3577
|
-
_d.label = 3;
|
|
3578
|
-
case 3:
|
|
3579
|
-
_d.trys.push([3, 8, , 9]);
|
|
3580
|
-
if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
|
|
3581
|
-
return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
|
|
3582
|
-
case 4: return [2 /*return*/, _d.sent()];
|
|
3583
|
-
case 5:
|
|
3584
|
-
if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
|
|
3585
|
-
return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
|
|
3586
|
-
case 6: return [2 /*return*/, _d.sent()];
|
|
3587
|
-
case 7: return [3 /*break*/, 9];
|
|
3588
|
-
case 8:
|
|
3589
|
-
error_1 = _d.sent();
|
|
3590
|
-
if (!(error_1 instanceof Error)) {
|
|
3591
|
-
throw error_1;
|
|
3592
|
-
}
|
|
3593
|
-
errors.push(error_1);
|
|
3594
|
-
return [3 /*break*/, 9];
|
|
3595
|
-
case 9:
|
|
3596
|
-
_b = _a.next();
|
|
3597
|
-
return [3 /*break*/, 2];
|
|
3598
|
-
case 10: return [3 /*break*/, 13];
|
|
3599
|
-
case 11:
|
|
3600
|
-
e_1_1 = _d.sent();
|
|
3601
|
-
e_1 = { error: e_1_1 };
|
|
3602
|
-
return [3 /*break*/, 13];
|
|
3603
|
-
case 12:
|
|
3604
|
-
try {
|
|
3605
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3606
|
-
}
|
|
3607
|
-
finally { if (e_1) throw e_1.error; }
|
|
3608
|
-
return [7 /*endfinally*/];
|
|
3609
|
-
case 13: throw new Error(spaceTrim$1(function (block) { return "\n All execution tools failed:\n \n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n \n "); }));
|
|
3610
|
-
}
|
|
3611
|
-
});
|
|
3612
|
-
});
|
|
3613
|
-
};
|
|
3614
|
-
/**
|
|
3615
|
-
* List all available models that can be used
|
|
3616
|
-
* This liost is a combination of all available models from all execution tools
|
|
3617
|
-
*/
|
|
3618
|
-
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
3619
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3620
|
-
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
3621
|
-
var e_2, _c;
|
|
3622
|
-
return __generator(this, function (_d) {
|
|
3623
|
-
switch (_d.label) {
|
|
3624
|
-
case 0:
|
|
3625
|
-
availableModels = [];
|
|
3626
|
-
_d.label = 1;
|
|
3627
|
-
case 1:
|
|
3628
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
3629
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3630
|
-
_d.label = 2;
|
|
3631
|
-
case 2:
|
|
3632
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
3633
|
-
llmExecutionTools = _b.value;
|
|
3634
|
-
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
3635
|
-
case 3:
|
|
3636
|
-
models = _d.sent();
|
|
3637
|
-
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
3638
|
-
_d.label = 4;
|
|
3639
|
-
case 4:
|
|
3640
|
-
_b = _a.next();
|
|
3641
|
-
return [3 /*break*/, 2];
|
|
3642
|
-
case 5: return [3 /*break*/, 8];
|
|
3643
|
-
case 6:
|
|
3644
|
-
e_2_1 = _d.sent();
|
|
3645
|
-
e_2 = { error: e_2_1 };
|
|
3646
|
-
return [3 /*break*/, 8];
|
|
3647
|
-
case 7:
|
|
3648
|
-
try {
|
|
3649
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3650
|
-
}
|
|
3651
|
-
finally { if (e_2) throw e_2.error; }
|
|
3652
|
-
return [7 /*endfinally*/];
|
|
3653
|
-
case 8: return [2 /*return*/, availableModels];
|
|
3654
|
-
}
|
|
3655
|
-
});
|
|
3656
|
-
});
|
|
3657
|
-
};
|
|
3658
|
-
return MultipleLlmExecutionTools;
|
|
3659
|
-
}());
|
|
3660
|
-
|
|
3661
3749
|
/**
|
|
3662
3750
|
* Format either small or big number
|
|
3663
3751
|
*
|
|
@@ -3678,23 +3766,6 @@ function formatNumber(value) {
|
|
|
3678
3766
|
return value.toString();
|
|
3679
3767
|
}
|
|
3680
3768
|
|
|
3681
|
-
/**
|
|
3682
|
-
* Returns the same value that is passed as argument.
|
|
3683
|
-
* No side effects.
|
|
3684
|
-
*
|
|
3685
|
-
* Note: It can be usefull for leveling indentation
|
|
3686
|
-
*
|
|
3687
|
-
* @param value any values
|
|
3688
|
-
* @returns the same values
|
|
3689
|
-
*/
|
|
3690
|
-
function just(value) {
|
|
3691
|
-
if (value === undefined) {
|
|
3692
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3693
|
-
return undefined;
|
|
3694
|
-
}
|
|
3695
|
-
return value;
|
|
3696
|
-
}
|
|
3697
|
-
|
|
3698
3769
|
/**
|
|
3699
3770
|
* Create a markdown table from a 2D array of strings
|
|
3700
3771
|
*
|