@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/umd/index.umd.js
CHANGED
|
@@ -129,6 +129,69 @@
|
|
|
129
129
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Removes HTML or Markdown comments from a string.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} content - The string to remove comments from.
|
|
136
|
+
* @returns {string} The input string with all comments removed.
|
|
137
|
+
*/
|
|
138
|
+
function removeContentComments(content) {
|
|
139
|
+
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Add or modify an auto-generated section in a markdown file
|
|
144
|
+
*
|
|
145
|
+
* @private within the library
|
|
146
|
+
*/
|
|
147
|
+
function addAutoGeneratedSection(content, options) {
|
|
148
|
+
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
149
|
+
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
150
|
+
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
151
|
+
var sectionMatch = content.match(sectionRegex);
|
|
152
|
+
if (sectionMatch) {
|
|
153
|
+
return content.replace(sectionRegex, spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
154
|
+
}
|
|
155
|
+
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
156
|
+
if (!placeForSection) {
|
|
157
|
+
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
158
|
+
}
|
|
159
|
+
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
160
|
+
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Prettify the html code
|
|
165
|
+
*
|
|
166
|
+
* @param content raw html code
|
|
167
|
+
* @returns formatted html code
|
|
168
|
+
*/
|
|
169
|
+
function prettifyMarkdown(content) {
|
|
170
|
+
try {
|
|
171
|
+
return prettier.format(content, {
|
|
172
|
+
parser: 'markdown',
|
|
173
|
+
plugins: [parserHtml__default["default"]],
|
|
174
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
175
|
+
endOfLine: 'lf',
|
|
176
|
+
tabWidth: 4,
|
|
177
|
+
singleQuote: true,
|
|
178
|
+
trailingComma: 'all',
|
|
179
|
+
arrowParens: 'always',
|
|
180
|
+
printWidth: 120,
|
|
181
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
182
|
+
jsxBracketSameLine: false,
|
|
183
|
+
bracketSpacing: true,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
188
|
+
error: error,
|
|
189
|
+
html: content,
|
|
190
|
+
});
|
|
191
|
+
return content;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
132
195
|
/**
|
|
133
196
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
134
197
|
*/
|
|
@@ -143,6 +206,32 @@
|
|
|
143
206
|
return PromptbookSyntaxError;
|
|
144
207
|
}(Error));
|
|
145
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Returns the same value that is passed as argument.
|
|
211
|
+
* No side effects.
|
|
212
|
+
*
|
|
213
|
+
* Note: It can be usefull for leveling indentation
|
|
214
|
+
*
|
|
215
|
+
* @param value any values
|
|
216
|
+
* @returns the same values
|
|
217
|
+
*/
|
|
218
|
+
function just(value) {
|
|
219
|
+
if (value === undefined) {
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
|
|
227
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
229
|
+
return __generator(this, function (_a) {
|
|
230
|
+
return [2 /*return*/, []];
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
146
235
|
/**
|
|
147
236
|
* Supported script languages
|
|
148
237
|
*/
|
|
@@ -403,16 +492,6 @@
|
|
|
403
492
|
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
404
493
|
*/
|
|
405
494
|
|
|
406
|
-
/**
|
|
407
|
-
* Removes HTML or Markdown comments from a string.
|
|
408
|
-
*
|
|
409
|
-
* @param {string} content - The string to remove comments from.
|
|
410
|
-
* @returns {string} The input string with all comments removed.
|
|
411
|
-
*/
|
|
412
|
-
function removeContentComments(content) {
|
|
413
|
-
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
414
|
-
}
|
|
415
|
-
|
|
416
495
|
/**
|
|
417
496
|
* Creates a new set with all elements that are present in either set
|
|
418
497
|
*/
|
|
@@ -454,7 +533,7 @@
|
|
|
454
533
|
/**
|
|
455
534
|
* The version of the Promptbook library
|
|
456
535
|
*/
|
|
457
|
-
var PROMPTBOOK_VERSION = '0.
|
|
536
|
+
var PROMPTBOOK_VERSION = '0.59.0-0';
|
|
458
537
|
|
|
459
538
|
/**
|
|
460
539
|
* Parses the template and returns the list of all parameter names
|
|
@@ -1325,250 +1404,267 @@
|
|
|
1325
1404
|
}
|
|
1326
1405
|
|
|
1327
1406
|
/**
|
|
1328
|
-
*
|
|
1407
|
+
* Compile promptbook from string (markdown) format to JSON format
|
|
1329
1408
|
*
|
|
1409
|
+
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1410
|
+
* @param options - Options and tools for the compilation
|
|
1411
|
+
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1330
1412
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1331
1413
|
*
|
|
1332
1414
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1415
|
+
* Note: This function acts as compilation process
|
|
1333
1416
|
*/
|
|
1334
|
-
function promptbookStringToJson(promptbookString) {
|
|
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
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1417
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
1418
|
+
if (options === void 0) { options = {}; }
|
|
1419
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1420
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1421
|
+
var e_1, _c, e_2, _d;
|
|
1422
|
+
return __generator(this, function (_e) {
|
|
1423
|
+
switch (_e.label) {
|
|
1424
|
+
case 0:
|
|
1425
|
+
llmTools = options.llmTools;
|
|
1426
|
+
promptbookJson = {
|
|
1427
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1428
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
1429
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
1430
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
1431
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1432
|
+
parameters: [],
|
|
1433
|
+
promptTemplates: [],
|
|
1434
|
+
knowledge: [],
|
|
1435
|
+
};
|
|
1436
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
1437
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
|
|
1438
|
+
case 1:
|
|
1439
|
+
knowledge = _e.sent();
|
|
1440
|
+
console.info('!!!! knowledge', knowledge);
|
|
1441
|
+
_e.label = 2;
|
|
1442
|
+
case 2:
|
|
1443
|
+
// =============================================================
|
|
1444
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1445
|
+
promptbookString = removeContentComments(promptbookString);
|
|
1446
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1447
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1448
|
+
addParam = function (parameterCommand) {
|
|
1449
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1450
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1451
|
+
if (existingParameter &&
|
|
1452
|
+
existingParameter.description &&
|
|
1453
|
+
existingParameter.description !== parameterDescription &&
|
|
1454
|
+
parameterDescription) {
|
|
1455
|
+
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 "); }));
|
|
1456
|
+
}
|
|
1457
|
+
if (existingParameter) {
|
|
1458
|
+
if (parameterDescription) {
|
|
1459
|
+
existingParameter.description = parameterDescription;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
else {
|
|
1463
|
+
promptbookJson.parameters.push({
|
|
1464
|
+
name: parameterName,
|
|
1465
|
+
description: parameterDescription || undefined,
|
|
1466
|
+
isInput: isInput,
|
|
1467
|
+
isOutput: isOutput,
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1472
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1473
|
+
if (markdownStructureDeepness !== 2) {
|
|
1474
|
+
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 ")));
|
|
1475
|
+
}
|
|
1476
|
+
promptbookJson.title = markdownStructure.title;
|
|
1477
|
+
description = markdownStructure.content;
|
|
1478
|
+
// Note: Remove codeblocks
|
|
1479
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
1480
|
+
//Note: Remove lists and return statement
|
|
1481
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1482
|
+
description = spaceTrim.spaceTrim(description);
|
|
1483
|
+
if (description === '') {
|
|
1484
|
+
description = undefined;
|
|
1485
|
+
}
|
|
1486
|
+
promptbookJson.description = description;
|
|
1487
|
+
defaultModelRequirements = {};
|
|
1488
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1489
|
+
try {
|
|
1490
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1491
|
+
listItem = listItems_1_1.value;
|
|
1492
|
+
command = parseCommand(listItem);
|
|
1493
|
+
switch (command.type) {
|
|
1494
|
+
case 'PROMPTBOOK_URL':
|
|
1495
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1496
|
+
break;
|
|
1497
|
+
case 'PROMPTBOOK_VERSION':
|
|
1498
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1499
|
+
break;
|
|
1500
|
+
case 'MODEL':
|
|
1501
|
+
defaultModelRequirements[command.key] = command.value;
|
|
1502
|
+
break;
|
|
1503
|
+
case 'PARAMETER':
|
|
1504
|
+
addParam(command);
|
|
1505
|
+
break;
|
|
1506
|
+
default:
|
|
1507
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1512
|
+
finally {
|
|
1513
|
+
try {
|
|
1514
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1515
|
+
}
|
|
1516
|
+
finally { if (e_1) throw e_1.error; }
|
|
1517
|
+
}
|
|
1518
|
+
_loop_1 = function (section) {
|
|
1519
|
+
var e_3, _f;
|
|
1520
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1521
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1522
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1523
|
+
var dependentParameterNames = new Set();
|
|
1524
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
1525
|
+
var jokers = [];
|
|
1526
|
+
var postprocessing = [];
|
|
1527
|
+
var expectAmount = {};
|
|
1528
|
+
var expectFormat = undefined;
|
|
1529
|
+
var isExecutionTypeChanged = false;
|
|
1530
|
+
try {
|
|
1531
|
+
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()) {
|
|
1532
|
+
var listItem = listItems_2_1.value;
|
|
1533
|
+
var command = parseCommand(listItem);
|
|
1534
|
+
switch (command.type) {
|
|
1535
|
+
case 'JOKER':
|
|
1536
|
+
jokers.push(command.parameterName);
|
|
1537
|
+
dependentParameterNames.add(command.parameterName);
|
|
1538
|
+
break;
|
|
1539
|
+
case 'EXECUTE':
|
|
1540
|
+
if (isExecutionTypeChanged) {
|
|
1541
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1542
|
+
}
|
|
1543
|
+
executionType = command.executionType;
|
|
1544
|
+
isExecutionTypeChanged = true;
|
|
1545
|
+
break;
|
|
1546
|
+
case 'MODEL':
|
|
1547
|
+
templateModelRequirements[command.key] = command.value;
|
|
1548
|
+
break;
|
|
1549
|
+
case 'PARAMETER':
|
|
1550
|
+
// Note: This is just for detecting resulitng parameter name
|
|
1551
|
+
addParam(command);
|
|
1552
|
+
break;
|
|
1553
|
+
case 'POSTPROCESS':
|
|
1554
|
+
postprocessing.push(command.functionName);
|
|
1555
|
+
break;
|
|
1556
|
+
case 'EXPECT_AMOUNT':
|
|
1557
|
+
// eslint-disable-next-line no-case-declarations
|
|
1558
|
+
var unit = command.unit.toLowerCase();
|
|
1559
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
1560
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1561
|
+
if (expectAmount[unit].min !== undefined) {
|
|
1562
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1563
|
+
}
|
|
1564
|
+
expectAmount[unit].min = command.amount;
|
|
1565
|
+
} /* not else */
|
|
1566
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1567
|
+
if (expectAmount[unit].max !== undefined) {
|
|
1568
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1569
|
+
}
|
|
1570
|
+
expectAmount[unit].max = command.amount;
|
|
1571
|
+
}
|
|
1572
|
+
break;
|
|
1573
|
+
case 'EXPECT_FORMAT':
|
|
1574
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1575
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1576
|
+
}
|
|
1577
|
+
expectFormat = command.format;
|
|
1578
|
+
break;
|
|
1579
|
+
default:
|
|
1580
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1585
|
+
finally {
|
|
1586
|
+
try {
|
|
1587
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1588
|
+
}
|
|
1589
|
+
finally { if (e_3) throw e_3.error; }
|
|
1449
1590
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
templateModelRequirements[command.key] = command.value;
|
|
1455
|
-
break;
|
|
1456
|
-
case 'PARAMETER':
|
|
1457
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1458
|
-
addParam(command);
|
|
1459
|
-
break;
|
|
1460
|
-
case 'POSTPROCESS':
|
|
1461
|
-
postprocessing.push(command.functionName);
|
|
1462
|
-
break;
|
|
1463
|
-
case 'EXPECT_AMOUNT':
|
|
1464
|
-
// eslint-disable-next-line no-case-declarations
|
|
1465
|
-
var unit = command.unit.toLowerCase();
|
|
1466
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1467
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1468
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1469
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1591
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1592
|
+
if (executionType === 'SCRIPT') {
|
|
1593
|
+
if (!language) {
|
|
1594
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1470
1595
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1474
|
-
if (expectAmount[unit].max !== undefined) {
|
|
1475
|
-
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1596
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1597
|
+
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 "); }));
|
|
1476
1598
|
}
|
|
1477
|
-
expectAmount[unit].max = command.amount;
|
|
1478
1599
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
if (
|
|
1482
|
-
throw new PromptbookSyntaxError(
|
|
1600
|
+
var lastLine = section.content.split('\n').pop();
|
|
1601
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1602
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1603
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1604
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
1605
|
+
section.content
|
|
1606
|
+
.split('\n')
|
|
1607
|
+
.map(function (line) { return "> ".concat(line); })
|
|
1608
|
+
.join('\n')), "\n "); }));
|
|
1483
1609
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1610
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
1611
|
+
// TODO: [1] DRY description
|
|
1612
|
+
var description_1 = section.content;
|
|
1613
|
+
// Note: Remove codeblocks
|
|
1614
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1615
|
+
//Note: Remove lists and return statement
|
|
1616
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1617
|
+
description_1 = spaceTrim.spaceTrim(description_1);
|
|
1618
|
+
if (description_1 === '') {
|
|
1619
|
+
description_1 = undefined;
|
|
1620
|
+
}
|
|
1621
|
+
if (Object.keys(jokers).length === 0) {
|
|
1622
|
+
jokers = undefined;
|
|
1623
|
+
}
|
|
1624
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
1625
|
+
expectAmount = undefined;
|
|
1626
|
+
}
|
|
1627
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
1628
|
+
postprocessing = undefined;
|
|
1629
|
+
}
|
|
1630
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1631
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
1632
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
1633
|
+
}
|
|
1634
|
+
promptbookJson.promptTemplates.push({
|
|
1635
|
+
name: titleToName(section.title),
|
|
1636
|
+
title: section.title,
|
|
1637
|
+
description: description_1,
|
|
1638
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1639
|
+
executionType: executionType,
|
|
1640
|
+
jokers: jokers,
|
|
1641
|
+
postprocessing: postprocessing,
|
|
1642
|
+
expectations: expectAmount,
|
|
1643
|
+
expectFormat: expectFormat,
|
|
1644
|
+
modelRequirements: templateModelRequirements,
|
|
1645
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1646
|
+
content: content,
|
|
1647
|
+
resultingParameterName: resultingParameterName,
|
|
1648
|
+
});
|
|
1649
|
+
};
|
|
1650
|
+
try {
|
|
1651
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1652
|
+
section = _b.value;
|
|
1653
|
+
_loop_1(section);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1657
|
+
finally {
|
|
1658
|
+
try {
|
|
1659
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1660
|
+
}
|
|
1661
|
+
finally { if (e_2) throw e_2.error; }
|
|
1662
|
+
}
|
|
1663
|
+
// =============================================================
|
|
1664
|
+
return [2 /*return*/, promptbookJson];
|
|
1505
1665
|
}
|
|
1506
|
-
}
|
|
1507
|
-
var lastLine = section.content.split('\n').pop();
|
|
1508
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1509
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1510
|
-
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1511
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1512
|
-
section.content
|
|
1513
|
-
.split('\n')
|
|
1514
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1515
|
-
.join('\n')), "\n "); }));
|
|
1516
|
-
}
|
|
1517
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1518
|
-
// TODO: [1] DRY description
|
|
1519
|
-
var description_1 = section.content;
|
|
1520
|
-
// Note: Remove codeblocks
|
|
1521
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1522
|
-
//Note: Remove lists and return statement
|
|
1523
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1524
|
-
description_1 = spaceTrim.spaceTrim(description_1);
|
|
1525
|
-
if (description_1 === '') {
|
|
1526
|
-
description_1 = undefined;
|
|
1527
|
-
}
|
|
1528
|
-
if (Object.keys(jokers).length === 0) {
|
|
1529
|
-
jokers = undefined;
|
|
1530
|
-
}
|
|
1531
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1532
|
-
expectAmount = undefined;
|
|
1533
|
-
}
|
|
1534
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1535
|
-
postprocessing = undefined;
|
|
1536
|
-
}
|
|
1537
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1538
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1539
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1540
|
-
}
|
|
1541
|
-
promptbookJson.promptTemplates.push({
|
|
1542
|
-
name: titleToName(section.title),
|
|
1543
|
-
title: section.title,
|
|
1544
|
-
description: description_1,
|
|
1545
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1546
|
-
executionType: executionType,
|
|
1547
|
-
jokers: jokers,
|
|
1548
|
-
postprocessing: postprocessing,
|
|
1549
|
-
expectations: expectAmount,
|
|
1550
|
-
expectFormat: expectFormat,
|
|
1551
|
-
modelRequirements: templateModelRequirements,
|
|
1552
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1553
|
-
content: content,
|
|
1554
|
-
resultingParameterName: resultingParameterName,
|
|
1555
1666
|
});
|
|
1556
|
-
};
|
|
1557
|
-
try {
|
|
1558
|
-
for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1559
|
-
var section = _d.value;
|
|
1560
|
-
_loop_1(section);
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1564
|
-
finally {
|
|
1565
|
-
try {
|
|
1566
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1567
|
-
}
|
|
1568
|
-
finally { if (e_2) throw e_2.error; }
|
|
1569
|
-
}
|
|
1570
|
-
// =============================================================
|
|
1571
|
-
return promptbookJson;
|
|
1667
|
+
});
|
|
1572
1668
|
}
|
|
1573
1669
|
/**
|
|
1574
1670
|
* TODO: Report here line/column of error
|
|
@@ -1576,59 +1672,6 @@
|
|
|
1576
1672
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
1577
1673
|
*/
|
|
1578
1674
|
|
|
1579
|
-
/**
|
|
1580
|
-
* Add or modify an auto-generated section in a markdown file
|
|
1581
|
-
*
|
|
1582
|
-
* @private within the library
|
|
1583
|
-
*/
|
|
1584
|
-
function addAutoGeneratedSection(content, options) {
|
|
1585
|
-
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
1586
|
-
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
1587
|
-
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
1588
|
-
var sectionMatch = content.match(sectionRegex);
|
|
1589
|
-
if (sectionMatch) {
|
|
1590
|
-
return content.replace(sectionRegex, spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
1591
|
-
}
|
|
1592
|
-
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
1593
|
-
if (!placeForSection) {
|
|
1594
|
-
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
1595
|
-
}
|
|
1596
|
-
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
1597
|
-
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
/**
|
|
1601
|
-
* Prettify the html code
|
|
1602
|
-
*
|
|
1603
|
-
* @param content raw html code
|
|
1604
|
-
* @returns formatted html code
|
|
1605
|
-
*/
|
|
1606
|
-
function prettifyMarkdown(content) {
|
|
1607
|
-
try {
|
|
1608
|
-
return prettier.format(content, {
|
|
1609
|
-
parser: 'markdown',
|
|
1610
|
-
plugins: [parserHtml__default["default"]],
|
|
1611
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1612
|
-
endOfLine: 'lf',
|
|
1613
|
-
tabWidth: 4,
|
|
1614
|
-
singleQuote: true,
|
|
1615
|
-
trailingComma: 'all',
|
|
1616
|
-
arrowParens: 'always',
|
|
1617
|
-
printWidth: 120,
|
|
1618
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
1619
|
-
jsxBracketSameLine: false,
|
|
1620
|
-
bracketSpacing: true,
|
|
1621
|
-
});
|
|
1622
|
-
}
|
|
1623
|
-
catch (error) {
|
|
1624
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1625
|
-
error: error,
|
|
1626
|
-
html: content,
|
|
1627
|
-
});
|
|
1628
|
-
return content;
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
1675
|
/* tslint:disable */
|
|
1633
1676
|
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
1634
1677
|
var e_1, _a;
|
|
@@ -1746,24 +1789,35 @@
|
|
|
1746
1789
|
* Prettyfies Promptbook string and adds Mermaid graph
|
|
1747
1790
|
*/
|
|
1748
1791
|
function prettifyPromptbookString(promptbookString, options) {
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1792
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1793
|
+
var isGraphAdded, isPrettifyed, promptbookJson, promptbookMermaid_1, promptbookMermaidBlock;
|
|
1794
|
+
return __generator(this, function (_a) {
|
|
1795
|
+
switch (_a.label) {
|
|
1796
|
+
case 0:
|
|
1797
|
+
isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
|
|
1798
|
+
if (!isGraphAdded) return [3 /*break*/, 2];
|
|
1799
|
+
return [4 /*yield*/, promptbookStringToJson(promptbookString /* , {!!!!} */)];
|
|
1800
|
+
case 1:
|
|
1801
|
+
promptbookJson = _a.sent();
|
|
1802
|
+
promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
|
|
1803
|
+
linkPromptTemplate: function (promptTemplate) {
|
|
1804
|
+
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
1805
|
+
},
|
|
1806
|
+
});
|
|
1807
|
+
promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1808
|
+
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1809
|
+
sectionName: 'Graph',
|
|
1810
|
+
sectionContent: promptbookMermaidBlock,
|
|
1811
|
+
});
|
|
1812
|
+
_a.label = 2;
|
|
1813
|
+
case 2:
|
|
1814
|
+
if (isPrettifyed) {
|
|
1815
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1816
|
+
}
|
|
1817
|
+
return [2 /*return*/, promptbookString];
|
|
1818
|
+
}
|
|
1761
1819
|
});
|
|
1762
|
-
}
|
|
1763
|
-
if (isPrettifyed) {
|
|
1764
|
-
promptbookString = prettifyMarkdown(promptbookString);
|
|
1765
|
-
}
|
|
1766
|
-
return promptbookString;
|
|
1820
|
+
});
|
|
1767
1821
|
}
|
|
1768
1822
|
/**
|
|
1769
1823
|
* TODO: Maybe use some Mermaid library instead of string templating
|
|
@@ -3142,11 +3196,29 @@
|
|
|
3142
3196
|
*/
|
|
3143
3197
|
|
|
3144
3198
|
/**
|
|
3145
|
-
*
|
|
3146
|
-
*
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3199
|
+
* Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
|
|
3200
|
+
*
|
|
3201
|
+
* Note: This is an estimate based of theese sources:
|
|
3202
|
+
* - https://jecas.cz/doba-cteni
|
|
3203
|
+
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3204
|
+
*/
|
|
3205
|
+
function usageToWorktime(usage) {
|
|
3206
|
+
var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
|
|
3207
|
+
usage.output.wordsCount.value / (40 /* words per minute */ * 60);
|
|
3208
|
+
var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
|
|
3209
|
+
var uncertainNumber = { value: value };
|
|
3210
|
+
if (isUncertain === true) {
|
|
3211
|
+
uncertainNumber.isUncertain = true;
|
|
3212
|
+
}
|
|
3213
|
+
return uncertainNumber;
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
/**
|
|
3217
|
+
* Delagates the user interaction to a async callback function
|
|
3218
|
+
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
3219
|
+
*/
|
|
3220
|
+
var CallbackInterfaceTools = /** @class */ (function () {
|
|
3221
|
+
function CallbackInterfaceTools(options) {
|
|
3150
3222
|
this.options = options;
|
|
3151
3223
|
}
|
|
3152
3224
|
/**
|
|
@@ -3179,6 +3251,7 @@
|
|
|
3179
3251
|
*/
|
|
3180
3252
|
var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
3181
3253
|
function SimplePromptInterfaceTools(options) {
|
|
3254
|
+
if (options === void 0) { options = {}; }
|
|
3182
3255
|
this.options = options;
|
|
3183
3256
|
}
|
|
3184
3257
|
/**
|
|
@@ -3203,22 +3276,135 @@
|
|
|
3203
3276
|
}());
|
|
3204
3277
|
|
|
3205
3278
|
/**
|
|
3206
|
-
*
|
|
3279
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
3207
3280
|
*
|
|
3208
|
-
*
|
|
3209
|
-
* - https://jecas.cz/doba-cteni
|
|
3210
|
-
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3281
|
+
* @see https://github.com/webgptorg/promptbook#multiple-server
|
|
3211
3282
|
*/
|
|
3212
|
-
function
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3283
|
+
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
3284
|
+
/**
|
|
3285
|
+
* Gets array of execution tools in order of priority
|
|
3286
|
+
*/
|
|
3287
|
+
function MultipleLlmExecutionTools() {
|
|
3288
|
+
var llmExecutionTools = [];
|
|
3289
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3290
|
+
llmExecutionTools[_i] = arguments[_i];
|
|
3291
|
+
}
|
|
3292
|
+
this.llmExecutionTools = llmExecutionTools;
|
|
3219
3293
|
}
|
|
3220
|
-
|
|
3221
|
-
|
|
3294
|
+
/**
|
|
3295
|
+
* Calls the best available chat model
|
|
3296
|
+
*/
|
|
3297
|
+
MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
|
|
3298
|
+
return this.gptCommon(prompt);
|
|
3299
|
+
};
|
|
3300
|
+
/**
|
|
3301
|
+
* Calls the best available completion model
|
|
3302
|
+
*/
|
|
3303
|
+
MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
|
|
3304
|
+
return this.gptCommon(prompt);
|
|
3305
|
+
};
|
|
3306
|
+
/**
|
|
3307
|
+
* Calls the best available model
|
|
3308
|
+
*/
|
|
3309
|
+
MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
|
|
3310
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3311
|
+
var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
|
|
3312
|
+
var e_1, _c;
|
|
3313
|
+
return __generator(this, function (_d) {
|
|
3314
|
+
switch (_d.label) {
|
|
3315
|
+
case 0:
|
|
3316
|
+
errors = [];
|
|
3317
|
+
_d.label = 1;
|
|
3318
|
+
case 1:
|
|
3319
|
+
_d.trys.push([1, 11, 12, 13]);
|
|
3320
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3321
|
+
_d.label = 2;
|
|
3322
|
+
case 2:
|
|
3323
|
+
if (!!_b.done) return [3 /*break*/, 10];
|
|
3324
|
+
llmExecutionTools = _b.value;
|
|
3325
|
+
_d.label = 3;
|
|
3326
|
+
case 3:
|
|
3327
|
+
_d.trys.push([3, 8, , 9]);
|
|
3328
|
+
if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
|
|
3329
|
+
return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
|
|
3330
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
3331
|
+
case 5:
|
|
3332
|
+
if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
|
|
3333
|
+
return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
|
|
3334
|
+
case 6: return [2 /*return*/, _d.sent()];
|
|
3335
|
+
case 7: return [3 /*break*/, 9];
|
|
3336
|
+
case 8:
|
|
3337
|
+
error_1 = _d.sent();
|
|
3338
|
+
if (!(error_1 instanceof Error)) {
|
|
3339
|
+
throw error_1;
|
|
3340
|
+
}
|
|
3341
|
+
errors.push(error_1);
|
|
3342
|
+
return [3 /*break*/, 9];
|
|
3343
|
+
case 9:
|
|
3344
|
+
_b = _a.next();
|
|
3345
|
+
return [3 /*break*/, 2];
|
|
3346
|
+
case 10: return [3 /*break*/, 13];
|
|
3347
|
+
case 11:
|
|
3348
|
+
e_1_1 = _d.sent();
|
|
3349
|
+
e_1 = { error: e_1_1 };
|
|
3350
|
+
return [3 /*break*/, 13];
|
|
3351
|
+
case 12:
|
|
3352
|
+
try {
|
|
3353
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3354
|
+
}
|
|
3355
|
+
finally { if (e_1) throw e_1.error; }
|
|
3356
|
+
return [7 /*endfinally*/];
|
|
3357
|
+
case 13: throw new Error(spaceTrim__default["default"](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 "); }));
|
|
3358
|
+
}
|
|
3359
|
+
});
|
|
3360
|
+
});
|
|
3361
|
+
};
|
|
3362
|
+
/**
|
|
3363
|
+
* List all available models that can be used
|
|
3364
|
+
* This liost is a combination of all available models from all execution tools
|
|
3365
|
+
*/
|
|
3366
|
+
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
3367
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3368
|
+
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
3369
|
+
var e_2, _c;
|
|
3370
|
+
return __generator(this, function (_d) {
|
|
3371
|
+
switch (_d.label) {
|
|
3372
|
+
case 0:
|
|
3373
|
+
availableModels = [];
|
|
3374
|
+
_d.label = 1;
|
|
3375
|
+
case 1:
|
|
3376
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
3377
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3378
|
+
_d.label = 2;
|
|
3379
|
+
case 2:
|
|
3380
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
3381
|
+
llmExecutionTools = _b.value;
|
|
3382
|
+
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
3383
|
+
case 3:
|
|
3384
|
+
models = _d.sent();
|
|
3385
|
+
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
3386
|
+
_d.label = 4;
|
|
3387
|
+
case 4:
|
|
3388
|
+
_b = _a.next();
|
|
3389
|
+
return [3 /*break*/, 2];
|
|
3390
|
+
case 5: return [3 /*break*/, 8];
|
|
3391
|
+
case 6:
|
|
3392
|
+
e_2_1 = _d.sent();
|
|
3393
|
+
e_2 = { error: e_2_1 };
|
|
3394
|
+
return [3 /*break*/, 8];
|
|
3395
|
+
case 7:
|
|
3396
|
+
try {
|
|
3397
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3398
|
+
}
|
|
3399
|
+
finally { if (e_2) throw e_2.error; }
|
|
3400
|
+
return [7 /*endfinally*/];
|
|
3401
|
+
case 8: return [2 /*return*/, availableModels];
|
|
3402
|
+
}
|
|
3403
|
+
});
|
|
3404
|
+
});
|
|
3405
|
+
};
|
|
3406
|
+
return MultipleLlmExecutionTools;
|
|
3407
|
+
}());
|
|
3222
3408
|
|
|
3223
3409
|
/**
|
|
3224
3410
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
@@ -3309,36 +3495,61 @@
|
|
|
3309
3495
|
* @returns PromptbookLibrary
|
|
3310
3496
|
*/
|
|
3311
3497
|
function createPromptbookLibraryFromSources() {
|
|
3312
|
-
var e_1, _a;
|
|
3313
3498
|
var promptbookSources = [];
|
|
3314
3499
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3315
3500
|
promptbookSources[_i] = arguments[_i];
|
|
3316
3501
|
}
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3502
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3503
|
+
var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
|
|
3504
|
+
var e_1, _a;
|
|
3505
|
+
return __generator(this, function (_b) {
|
|
3506
|
+
switch (_b.label) {
|
|
3507
|
+
case 0:
|
|
3508
|
+
promptbooks = new Array();
|
|
3509
|
+
_b.label = 1;
|
|
3510
|
+
case 1:
|
|
3511
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
3512
|
+
promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
|
|
3513
|
+
_b.label = 2;
|
|
3514
|
+
case 2:
|
|
3515
|
+
if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
|
|
3516
|
+
source = promptbookSources_1_1.value;
|
|
3517
|
+
promptbook = void 0;
|
|
3518
|
+
if (!(typeof source === 'string')) return [3 /*break*/, 4];
|
|
3519
|
+
return [4 /*yield*/, promptbookStringToJson(source)];
|
|
3520
|
+
case 3:
|
|
3521
|
+
// Note: When directly creating from string, no need to validate the source
|
|
3522
|
+
// The validation is performed always before execution
|
|
3523
|
+
promptbook = _b.sent();
|
|
3524
|
+
return [3 /*break*/, 5];
|
|
3525
|
+
case 4:
|
|
3526
|
+
promptbook = source;
|
|
3527
|
+
_b.label = 5;
|
|
3528
|
+
case 5:
|
|
3529
|
+
promptbooks.push(promptbook);
|
|
3530
|
+
_b.label = 6;
|
|
3531
|
+
case 6:
|
|
3532
|
+
promptbookSources_1_1 = promptbookSources_1.next();
|
|
3533
|
+
return [3 /*break*/, 2];
|
|
3534
|
+
case 7: return [3 /*break*/, 10];
|
|
3535
|
+
case 8:
|
|
3536
|
+
e_1_1 = _b.sent();
|
|
3537
|
+
e_1 = { error: e_1_1 };
|
|
3538
|
+
return [3 /*break*/, 10];
|
|
3539
|
+
case 9:
|
|
3540
|
+
try {
|
|
3541
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
3542
|
+
}
|
|
3543
|
+
finally { if (e_1) throw e_1.error; }
|
|
3544
|
+
return [7 /*endfinally*/];
|
|
3545
|
+
case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
3329
3546
|
}
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
}
|
|
3333
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3334
|
-
finally {
|
|
3335
|
-
try {
|
|
3336
|
-
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
3337
|
-
}
|
|
3338
|
-
finally { if (e_1) throw e_1.error; }
|
|
3339
|
-
}
|
|
3340
|
-
return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
3547
|
+
});
|
|
3548
|
+
});
|
|
3341
3549
|
}
|
|
3550
|
+
/**
|
|
3551
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3552
|
+
*/
|
|
3342
3553
|
|
|
3343
3554
|
/**
|
|
3344
3555
|
* Constructs Promptbook from async sources
|
|
@@ -3374,7 +3585,9 @@
|
|
|
3374
3585
|
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3375
3586
|
case 1:
|
|
3376
3587
|
promptbookSources = _a.sent();
|
|
3377
|
-
|
|
3588
|
+
return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
|
|
3589
|
+
case 2:
|
|
3590
|
+
library = _a.sent();
|
|
3378
3591
|
return [2 /*return*/];
|
|
3379
3592
|
}
|
|
3380
3593
|
});
|
|
@@ -3422,6 +3635,9 @@
|
|
|
3422
3635
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3423
3636
|
};
|
|
3424
3637
|
}
|
|
3638
|
+
/**
|
|
3639
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3640
|
+
*/
|
|
3425
3641
|
|
|
3426
3642
|
/**
|
|
3427
3643
|
* Constructs Promptbook from remote Promptbase URL
|
|
@@ -3454,6 +3670,9 @@
|
|
|
3454
3670
|
});
|
|
3455
3671
|
});
|
|
3456
3672
|
}
|
|
3673
|
+
/**
|
|
3674
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3675
|
+
*/
|
|
3457
3676
|
|
|
3458
3677
|
/**
|
|
3459
3678
|
* Creates PromptbookLibrary as a subset of another PromptbookLibrary
|
|
@@ -3534,137 +3753,6 @@
|
|
|
3534
3753
|
};
|
|
3535
3754
|
}
|
|
3536
3755
|
|
|
3537
|
-
/**
|
|
3538
|
-
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
3539
|
-
*
|
|
3540
|
-
* @see https://github.com/webgptorg/promptbook#multiple-server
|
|
3541
|
-
*/
|
|
3542
|
-
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
3543
|
-
/**
|
|
3544
|
-
* Gets array of execution tools in order of priority
|
|
3545
|
-
*/
|
|
3546
|
-
function MultipleLlmExecutionTools() {
|
|
3547
|
-
var llmExecutionTools = [];
|
|
3548
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3549
|
-
llmExecutionTools[_i] = arguments[_i];
|
|
3550
|
-
}
|
|
3551
|
-
this.llmExecutionTools = llmExecutionTools;
|
|
3552
|
-
}
|
|
3553
|
-
/**
|
|
3554
|
-
* Calls the best available chat model
|
|
3555
|
-
*/
|
|
3556
|
-
MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
|
|
3557
|
-
return this.gptCommon(prompt);
|
|
3558
|
-
};
|
|
3559
|
-
/**
|
|
3560
|
-
* Calls the best available completion model
|
|
3561
|
-
*/
|
|
3562
|
-
MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
|
|
3563
|
-
return this.gptCommon(prompt);
|
|
3564
|
-
};
|
|
3565
|
-
/**
|
|
3566
|
-
* Calls the best available model
|
|
3567
|
-
*/
|
|
3568
|
-
MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
|
|
3569
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3570
|
-
var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
|
|
3571
|
-
var e_1, _c;
|
|
3572
|
-
return __generator(this, function (_d) {
|
|
3573
|
-
switch (_d.label) {
|
|
3574
|
-
case 0:
|
|
3575
|
-
errors = [];
|
|
3576
|
-
_d.label = 1;
|
|
3577
|
-
case 1:
|
|
3578
|
-
_d.trys.push([1, 11, 12, 13]);
|
|
3579
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3580
|
-
_d.label = 2;
|
|
3581
|
-
case 2:
|
|
3582
|
-
if (!!_b.done) return [3 /*break*/, 10];
|
|
3583
|
-
llmExecutionTools = _b.value;
|
|
3584
|
-
_d.label = 3;
|
|
3585
|
-
case 3:
|
|
3586
|
-
_d.trys.push([3, 8, , 9]);
|
|
3587
|
-
if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
|
|
3588
|
-
return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
|
|
3589
|
-
case 4: return [2 /*return*/, _d.sent()];
|
|
3590
|
-
case 5:
|
|
3591
|
-
if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
|
|
3592
|
-
return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
|
|
3593
|
-
case 6: return [2 /*return*/, _d.sent()];
|
|
3594
|
-
case 7: return [3 /*break*/, 9];
|
|
3595
|
-
case 8:
|
|
3596
|
-
error_1 = _d.sent();
|
|
3597
|
-
if (!(error_1 instanceof Error)) {
|
|
3598
|
-
throw error_1;
|
|
3599
|
-
}
|
|
3600
|
-
errors.push(error_1);
|
|
3601
|
-
return [3 /*break*/, 9];
|
|
3602
|
-
case 9:
|
|
3603
|
-
_b = _a.next();
|
|
3604
|
-
return [3 /*break*/, 2];
|
|
3605
|
-
case 10: return [3 /*break*/, 13];
|
|
3606
|
-
case 11:
|
|
3607
|
-
e_1_1 = _d.sent();
|
|
3608
|
-
e_1 = { error: e_1_1 };
|
|
3609
|
-
return [3 /*break*/, 13];
|
|
3610
|
-
case 12:
|
|
3611
|
-
try {
|
|
3612
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3613
|
-
}
|
|
3614
|
-
finally { if (e_1) throw e_1.error; }
|
|
3615
|
-
return [7 /*endfinally*/];
|
|
3616
|
-
case 13: throw new Error(spaceTrim__default["default"](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 "); }));
|
|
3617
|
-
}
|
|
3618
|
-
});
|
|
3619
|
-
});
|
|
3620
|
-
};
|
|
3621
|
-
/**
|
|
3622
|
-
* List all available models that can be used
|
|
3623
|
-
* This liost is a combination of all available models from all execution tools
|
|
3624
|
-
*/
|
|
3625
|
-
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
3626
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3627
|
-
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
3628
|
-
var e_2, _c;
|
|
3629
|
-
return __generator(this, function (_d) {
|
|
3630
|
-
switch (_d.label) {
|
|
3631
|
-
case 0:
|
|
3632
|
-
availableModels = [];
|
|
3633
|
-
_d.label = 1;
|
|
3634
|
-
case 1:
|
|
3635
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
3636
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3637
|
-
_d.label = 2;
|
|
3638
|
-
case 2:
|
|
3639
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
3640
|
-
llmExecutionTools = _b.value;
|
|
3641
|
-
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
3642
|
-
case 3:
|
|
3643
|
-
models = _d.sent();
|
|
3644
|
-
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
3645
|
-
_d.label = 4;
|
|
3646
|
-
case 4:
|
|
3647
|
-
_b = _a.next();
|
|
3648
|
-
return [3 /*break*/, 2];
|
|
3649
|
-
case 5: return [3 /*break*/, 8];
|
|
3650
|
-
case 6:
|
|
3651
|
-
e_2_1 = _d.sent();
|
|
3652
|
-
e_2 = { error: e_2_1 };
|
|
3653
|
-
return [3 /*break*/, 8];
|
|
3654
|
-
case 7:
|
|
3655
|
-
try {
|
|
3656
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3657
|
-
}
|
|
3658
|
-
finally { if (e_2) throw e_2.error; }
|
|
3659
|
-
return [7 /*endfinally*/];
|
|
3660
|
-
case 8: return [2 /*return*/, availableModels];
|
|
3661
|
-
}
|
|
3662
|
-
});
|
|
3663
|
-
});
|
|
3664
|
-
};
|
|
3665
|
-
return MultipleLlmExecutionTools;
|
|
3666
|
-
}());
|
|
3667
|
-
|
|
3668
3756
|
/**
|
|
3669
3757
|
* Format either small or big number
|
|
3670
3758
|
*
|
|
@@ -3685,23 +3773,6 @@
|
|
|
3685
3773
|
return value.toString();
|
|
3686
3774
|
}
|
|
3687
3775
|
|
|
3688
|
-
/**
|
|
3689
|
-
* Returns the same value that is passed as argument.
|
|
3690
|
-
* No side effects.
|
|
3691
|
-
*
|
|
3692
|
-
* Note: It can be usefull for leveling indentation
|
|
3693
|
-
*
|
|
3694
|
-
* @param value any values
|
|
3695
|
-
* @returns the same values
|
|
3696
|
-
*/
|
|
3697
|
-
function just(value) {
|
|
3698
|
-
if (value === undefined) {
|
|
3699
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3700
|
-
return undefined;
|
|
3701
|
-
}
|
|
3702
|
-
return value;
|
|
3703
|
-
}
|
|
3704
|
-
|
|
3705
3776
|
/**
|
|
3706
3777
|
* Create a markdown table from a 2D array of strings
|
|
3707
3778
|
*
|