@promptbook/core 0.58.0 → 0.59.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +556 -506
- 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 +7 -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/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/esm/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -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/package.json +2 -2
- package/umd/index.umd.js +556 -506
- 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 +7 -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/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/umd/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -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/esm/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +0 -1
- package/esm/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +0 -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/{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-missing.test.d.ts → umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.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
|
*/
|
|
@@ -148,6 +211,23 @@
|
|
|
148
211
|
*/
|
|
149
212
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
150
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Returns the same value that is passed as argument.
|
|
216
|
+
* No side effects.
|
|
217
|
+
*
|
|
218
|
+
* Note: It can be usefull for leveling indentation
|
|
219
|
+
*
|
|
220
|
+
* @param value any values
|
|
221
|
+
* @returns the same values
|
|
222
|
+
*/
|
|
223
|
+
function just(value) {
|
|
224
|
+
if (value === undefined) {
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
|
|
151
231
|
/**
|
|
152
232
|
* Computes the deepness of the markdown structure.
|
|
153
233
|
*
|
|
@@ -403,16 +483,6 @@
|
|
|
403
483
|
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
404
484
|
*/
|
|
405
485
|
|
|
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
486
|
/**
|
|
417
487
|
* Creates a new set with all elements that are present in either set
|
|
418
488
|
*/
|
|
@@ -454,7 +524,7 @@
|
|
|
454
524
|
/**
|
|
455
525
|
* The version of the Promptbook library
|
|
456
526
|
*/
|
|
457
|
-
var PROMPTBOOK_VERSION = '0.
|
|
527
|
+
var PROMPTBOOK_VERSION = '0.58.0';
|
|
458
528
|
|
|
459
529
|
/**
|
|
460
530
|
* Parses the template and returns the list of all parameter names
|
|
@@ -1325,250 +1395,255 @@
|
|
|
1325
1395
|
}
|
|
1326
1396
|
|
|
1327
1397
|
/**
|
|
1328
|
-
*
|
|
1398
|
+
* Compile promptbook from string (markdown) format to JSON format
|
|
1329
1399
|
*
|
|
1400
|
+
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1401
|
+
* @param llmTools {LlmExecutionTools} - tools for processing required for knowledge processing *(not for actual execution)*
|
|
1402
|
+
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1330
1403
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1331
1404
|
*
|
|
1332
1405
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1406
|
+
* Note: This function acts as compilation process
|
|
1333
1407
|
*/
|
|
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
|
-
existingParameter
|
|
1408
|
+
function promptbookStringToJson(promptbookString, llmTools) {
|
|
1409
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1410
|
+
var promptbookJson, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1411
|
+
var e_1, _c, e_2, _d;
|
|
1412
|
+
return __generator(this, function (_e) {
|
|
1413
|
+
promptbookJson = {
|
|
1414
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1415
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
1416
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
1417
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
1418
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1419
|
+
parameters: [],
|
|
1420
|
+
promptTemplates: [],
|
|
1421
|
+
knowledge: [],
|
|
1422
|
+
};
|
|
1423
|
+
// =============================================================
|
|
1424
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1425
|
+
promptbookString = removeContentComments(promptbookString);
|
|
1426
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1427
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1428
|
+
addParam = function (parameterCommand) {
|
|
1429
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1430
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1431
|
+
if (existingParameter &&
|
|
1432
|
+
existingParameter.description &&
|
|
1433
|
+
existingParameter.description !== parameterDescription &&
|
|
1434
|
+
parameterDescription) {
|
|
1435
|
+
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 "); }));
|
|
1436
|
+
}
|
|
1437
|
+
if (existingParameter) {
|
|
1438
|
+
if (parameterDescription) {
|
|
1439
|
+
existingParameter.description = parameterDescription;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
else {
|
|
1443
|
+
promptbookJson.parameters.push({
|
|
1444
|
+
name: parameterName,
|
|
1445
|
+
description: parameterDescription || undefined,
|
|
1446
|
+
isInput: isInput,
|
|
1447
|
+
isOutput: isOutput,
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1452
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1453
|
+
if (markdownStructureDeepness !== 2) {
|
|
1454
|
+
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 ")));
|
|
1455
|
+
}
|
|
1456
|
+
promptbookJson.title = markdownStructure.title;
|
|
1457
|
+
description = markdownStructure.content;
|
|
1458
|
+
// Note: Remove codeblocks
|
|
1459
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
1460
|
+
//Note: Remove lists and return statement
|
|
1461
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1462
|
+
description = spaceTrim.spaceTrim(description);
|
|
1463
|
+
if (description === '') {
|
|
1464
|
+
description = undefined;
|
|
1465
|
+
}
|
|
1466
|
+
promptbookJson.description = description;
|
|
1467
|
+
defaultModelRequirements = {};
|
|
1468
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1469
|
+
try {
|
|
1470
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1471
|
+
listItem = listItems_1_1.value;
|
|
1472
|
+
command = parseCommand(listItem);
|
|
1473
|
+
switch (command.type) {
|
|
1474
|
+
case 'PROMPTBOOK_URL':
|
|
1475
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1476
|
+
break;
|
|
1477
|
+
case 'PROMPTBOOK_VERSION':
|
|
1478
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1479
|
+
break;
|
|
1480
|
+
case 'MODEL':
|
|
1481
|
+
defaultModelRequirements[command.key] = command.value;
|
|
1482
|
+
break;
|
|
1483
|
+
case 'PARAMETER':
|
|
1484
|
+
addParam(command);
|
|
1485
|
+
break;
|
|
1486
|
+
default:
|
|
1487
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1364
1490
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
isOutput: isOutput,
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
// =============================================================
|
|
1376
|
-
// Note: 3️⃣ Parse the dynamic part - the template pipeline
|
|
1377
|
-
var markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1378
|
-
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1379
|
-
if (markdownStructureDeepness !== 2) {
|
|
1380
|
-
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 ")));
|
|
1381
|
-
}
|
|
1382
|
-
promptbookJson.title = markdownStructure.title;
|
|
1383
|
-
// TODO: [1] DRY description
|
|
1384
|
-
var description = markdownStructure.content;
|
|
1385
|
-
// Note: Remove codeblocks
|
|
1386
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1387
|
-
//Note: Remove lists and return statement
|
|
1388
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1389
|
-
description = spaceTrim.spaceTrim(description);
|
|
1390
|
-
if (description === '') {
|
|
1391
|
-
description = undefined;
|
|
1392
|
-
}
|
|
1393
|
-
promptbookJson.description = description;
|
|
1394
|
-
var defaultModelRequirements = {};
|
|
1395
|
-
var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1396
|
-
try {
|
|
1397
|
-
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1398
|
-
var listItem = listItems_1_1.value;
|
|
1399
|
-
var command = parseCommand(listItem);
|
|
1400
|
-
switch (command.type) {
|
|
1401
|
-
case 'PROMPTBOOK_URL':
|
|
1402
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1403
|
-
break;
|
|
1404
|
-
case 'PROMPTBOOK_VERSION':
|
|
1405
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1406
|
-
break;
|
|
1407
|
-
case 'MODEL':
|
|
1408
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1409
|
-
break;
|
|
1410
|
-
case 'PARAMETER':
|
|
1411
|
-
addParam(command);
|
|
1412
|
-
break;
|
|
1413
|
-
default:
|
|
1414
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1491
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1492
|
+
finally {
|
|
1493
|
+
try {
|
|
1494
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1495
|
+
}
|
|
1496
|
+
finally { if (e_1) throw e_1.error; }
|
|
1415
1497
|
}
|
|
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
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
break;
|
|
1480
|
-
case 'EXPECT_FORMAT':
|
|
1481
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1482
|
-
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1498
|
+
_loop_1 = function (section) {
|
|
1499
|
+
var e_3, _f;
|
|
1500
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1501
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1502
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1503
|
+
var dependentParameterNames = new Set();
|
|
1504
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
1505
|
+
var jokers = [];
|
|
1506
|
+
var postprocessing = [];
|
|
1507
|
+
var expectAmount = {};
|
|
1508
|
+
var expectFormat = undefined;
|
|
1509
|
+
var isExecutionTypeChanged = false;
|
|
1510
|
+
try {
|
|
1511
|
+
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()) {
|
|
1512
|
+
var listItem = listItems_2_1.value;
|
|
1513
|
+
var command = parseCommand(listItem);
|
|
1514
|
+
switch (command.type) {
|
|
1515
|
+
case 'JOKER':
|
|
1516
|
+
jokers.push(command.parameterName);
|
|
1517
|
+
dependentParameterNames.add(command.parameterName);
|
|
1518
|
+
break;
|
|
1519
|
+
case 'EXECUTE':
|
|
1520
|
+
if (isExecutionTypeChanged) {
|
|
1521
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1522
|
+
}
|
|
1523
|
+
executionType = command.executionType;
|
|
1524
|
+
isExecutionTypeChanged = true;
|
|
1525
|
+
break;
|
|
1526
|
+
case 'MODEL':
|
|
1527
|
+
templateModelRequirements[command.key] = command.value;
|
|
1528
|
+
break;
|
|
1529
|
+
case 'PARAMETER':
|
|
1530
|
+
// Note: This is just for detecting resulitng parameter name
|
|
1531
|
+
addParam(command);
|
|
1532
|
+
break;
|
|
1533
|
+
case 'POSTPROCESS':
|
|
1534
|
+
postprocessing.push(command.functionName);
|
|
1535
|
+
break;
|
|
1536
|
+
case 'EXPECT_AMOUNT':
|
|
1537
|
+
// eslint-disable-next-line no-case-declarations
|
|
1538
|
+
var unit = command.unit.toLowerCase();
|
|
1539
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
1540
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1541
|
+
if (expectAmount[unit].min !== undefined) {
|
|
1542
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1543
|
+
}
|
|
1544
|
+
expectAmount[unit].min = command.amount;
|
|
1545
|
+
} /* not else */
|
|
1546
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1547
|
+
if (expectAmount[unit].max !== undefined) {
|
|
1548
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1549
|
+
}
|
|
1550
|
+
expectAmount[unit].max = command.amount;
|
|
1551
|
+
}
|
|
1552
|
+
break;
|
|
1553
|
+
case 'EXPECT_FORMAT':
|
|
1554
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1555
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1556
|
+
}
|
|
1557
|
+
expectFormat = command.format;
|
|
1558
|
+
break;
|
|
1559
|
+
default:
|
|
1560
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1483
1561
|
}
|
|
1484
|
-
|
|
1485
|
-
break;
|
|
1486
|
-
default:
|
|
1487
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1562
|
+
}
|
|
1488
1563
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1564
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1565
|
+
finally {
|
|
1566
|
+
try {
|
|
1567
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1568
|
+
}
|
|
1569
|
+
finally { if (e_3) throw e_3.error; }
|
|
1570
|
+
}
|
|
1571
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1572
|
+
if (executionType === 'SCRIPT') {
|
|
1573
|
+
if (!language) {
|
|
1574
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1575
|
+
}
|
|
1576
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1577
|
+
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 "); }));
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
var lastLine = section.content.split('\n').pop();
|
|
1581
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1582
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1583
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1584
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
1585
|
+
section.content
|
|
1586
|
+
.split('\n')
|
|
1587
|
+
.map(function (line) { return "> ".concat(line); })
|
|
1588
|
+
.join('\n')), "\n "); }));
|
|
1589
|
+
}
|
|
1590
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
1591
|
+
// TODO: [1] DRY description
|
|
1592
|
+
var description_1 = section.content;
|
|
1593
|
+
// Note: Remove codeblocks
|
|
1594
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1595
|
+
//Note: Remove lists and return statement
|
|
1596
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1597
|
+
description_1 = spaceTrim.spaceTrim(description_1);
|
|
1598
|
+
if (description_1 === '') {
|
|
1599
|
+
description_1 = undefined;
|
|
1600
|
+
}
|
|
1601
|
+
if (Object.keys(jokers).length === 0) {
|
|
1602
|
+
jokers = undefined;
|
|
1603
|
+
}
|
|
1604
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
1605
|
+
expectAmount = undefined;
|
|
1606
|
+
}
|
|
1607
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
1608
|
+
postprocessing = undefined;
|
|
1609
|
+
}
|
|
1610
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1611
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
1612
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
1613
|
+
}
|
|
1614
|
+
promptbookJson.promptTemplates.push({
|
|
1615
|
+
name: titleToName(section.title),
|
|
1616
|
+
title: section.title,
|
|
1617
|
+
description: description_1,
|
|
1618
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1619
|
+
executionType: executionType,
|
|
1620
|
+
jokers: jokers,
|
|
1621
|
+
postprocessing: postprocessing,
|
|
1622
|
+
expectations: expectAmount,
|
|
1623
|
+
expectFormat: expectFormat,
|
|
1624
|
+
modelRequirements: templateModelRequirements,
|
|
1625
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1626
|
+
content: content,
|
|
1627
|
+
resultingParameterName: resultingParameterName,
|
|
1628
|
+
});
|
|
1629
|
+
};
|
|
1493
1630
|
try {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
1499
|
-
if (executionType === 'SCRIPT') {
|
|
1500
|
-
if (!language) {
|
|
1501
|
-
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1631
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1632
|
+
section = _b.value;
|
|
1633
|
+
_loop_1(section);
|
|
1634
|
+
}
|
|
1502
1635
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1636
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1637
|
+
finally {
|
|
1638
|
+
try {
|
|
1639
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1640
|
+
}
|
|
1641
|
+
finally { if (e_2) throw e_2.error; }
|
|
1505
1642
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
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,
|
|
1643
|
+
// =============================================================
|
|
1644
|
+
return [2 /*return*/, promptbookJson];
|
|
1555
1645
|
});
|
|
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;
|
|
1646
|
+
});
|
|
1572
1647
|
}
|
|
1573
1648
|
/**
|
|
1574
1649
|
* TODO: Report here line/column of error
|
|
@@ -1576,59 +1651,6 @@
|
|
|
1576
1651
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
1577
1652
|
*/
|
|
1578
1653
|
|
|
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
1654
|
/* tslint:disable */
|
|
1633
1655
|
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
1634
1656
|
var e_1, _a;
|
|
@@ -1746,24 +1768,35 @@
|
|
|
1746
1768
|
* Prettyfies Promptbook string and adds Mermaid graph
|
|
1747
1769
|
*/
|
|
1748
1770
|
function prettifyPromptbookString(promptbookString, options) {
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1771
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1772
|
+
var isGraphAdded, isPrettifyed, promptbookJson, promptbookMermaid_1, promptbookMermaidBlock;
|
|
1773
|
+
return __generator(this, function (_a) {
|
|
1774
|
+
switch (_a.label) {
|
|
1775
|
+
case 0:
|
|
1776
|
+
isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
|
|
1777
|
+
if (!isGraphAdded) return [3 /*break*/, 2];
|
|
1778
|
+
return [4 /*yield*/, promptbookStringToJson(promptbookString /* , {!!!!} */)];
|
|
1779
|
+
case 1:
|
|
1780
|
+
promptbookJson = _a.sent();
|
|
1781
|
+
promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
|
|
1782
|
+
linkPromptTemplate: function (promptTemplate) {
|
|
1783
|
+
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
1784
|
+
},
|
|
1785
|
+
});
|
|
1786
|
+
promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1787
|
+
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1788
|
+
sectionName: 'Graph',
|
|
1789
|
+
sectionContent: promptbookMermaidBlock,
|
|
1790
|
+
});
|
|
1791
|
+
_a.label = 2;
|
|
1792
|
+
case 2:
|
|
1793
|
+
if (isPrettifyed) {
|
|
1794
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1795
|
+
}
|
|
1796
|
+
return [2 /*return*/, promptbookString];
|
|
1797
|
+
}
|
|
1761
1798
|
});
|
|
1762
|
-
}
|
|
1763
|
-
if (isPrettifyed) {
|
|
1764
|
-
promptbookString = prettifyMarkdown(promptbookString);
|
|
1765
|
-
}
|
|
1766
|
-
return promptbookString;
|
|
1799
|
+
});
|
|
1767
1800
|
}
|
|
1768
1801
|
/**
|
|
1769
1802
|
* TODO: Maybe use some Mermaid library instead of string templating
|
|
@@ -3142,15 +3175,33 @@
|
|
|
3142
3175
|
*/
|
|
3143
3176
|
|
|
3144
3177
|
/**
|
|
3145
|
-
*
|
|
3146
|
-
*
|
|
3178
|
+
* Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
|
|
3179
|
+
*
|
|
3180
|
+
* Note: This is an estimate based of theese sources:
|
|
3181
|
+
* - https://jecas.cz/doba-cteni
|
|
3182
|
+
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3147
3183
|
*/
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3184
|
+
function usageToWorktime(usage) {
|
|
3185
|
+
var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
|
|
3186
|
+
usage.output.wordsCount.value / (40 /* words per minute */ * 60);
|
|
3187
|
+
var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
|
|
3188
|
+
var uncertainNumber = { value: value };
|
|
3189
|
+
if (isUncertain === true) {
|
|
3190
|
+
uncertainNumber.isUncertain = true;
|
|
3191
|
+
}
|
|
3192
|
+
return uncertainNumber;
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
/**
|
|
3196
|
+
* Delagates the user interaction to a async callback function
|
|
3197
|
+
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
3198
|
+
*/
|
|
3199
|
+
var CallbackInterfaceTools = /** @class */ (function () {
|
|
3200
|
+
function CallbackInterfaceTools(options) {
|
|
3201
|
+
this.options = options;
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* Trigger the custom callback function
|
|
3154
3205
|
*/
|
|
3155
3206
|
CallbackInterfaceTools.prototype.promptDialog = function (options) {
|
|
3156
3207
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3179,6 +3230,7 @@
|
|
|
3179
3230
|
*/
|
|
3180
3231
|
var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
3181
3232
|
function SimplePromptInterfaceTools(options) {
|
|
3233
|
+
if (options === void 0) { options = {}; }
|
|
3182
3234
|
this.options = options;
|
|
3183
3235
|
}
|
|
3184
3236
|
/**
|
|
@@ -3203,22 +3255,135 @@
|
|
|
3203
3255
|
}());
|
|
3204
3256
|
|
|
3205
3257
|
/**
|
|
3206
|
-
*
|
|
3258
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
3207
3259
|
*
|
|
3208
|
-
*
|
|
3209
|
-
* - https://jecas.cz/doba-cteni
|
|
3210
|
-
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3260
|
+
* @see https://github.com/webgptorg/promptbook#multiple-server
|
|
3211
3261
|
*/
|
|
3212
|
-
function
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3262
|
+
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
3263
|
+
/**
|
|
3264
|
+
* Gets array of execution tools in order of priority
|
|
3265
|
+
*/
|
|
3266
|
+
function MultipleLlmExecutionTools() {
|
|
3267
|
+
var llmExecutionTools = [];
|
|
3268
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3269
|
+
llmExecutionTools[_i] = arguments[_i];
|
|
3270
|
+
}
|
|
3271
|
+
this.llmExecutionTools = llmExecutionTools;
|
|
3219
3272
|
}
|
|
3220
|
-
|
|
3221
|
-
|
|
3273
|
+
/**
|
|
3274
|
+
* Calls the best available chat model
|
|
3275
|
+
*/
|
|
3276
|
+
MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
|
|
3277
|
+
return this.gptCommon(prompt);
|
|
3278
|
+
};
|
|
3279
|
+
/**
|
|
3280
|
+
* Calls the best available completion model
|
|
3281
|
+
*/
|
|
3282
|
+
MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
|
|
3283
|
+
return this.gptCommon(prompt);
|
|
3284
|
+
};
|
|
3285
|
+
/**
|
|
3286
|
+
* Calls the best available model
|
|
3287
|
+
*/
|
|
3288
|
+
MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
|
|
3289
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3290
|
+
var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
|
|
3291
|
+
var e_1, _c;
|
|
3292
|
+
return __generator(this, function (_d) {
|
|
3293
|
+
switch (_d.label) {
|
|
3294
|
+
case 0:
|
|
3295
|
+
errors = [];
|
|
3296
|
+
_d.label = 1;
|
|
3297
|
+
case 1:
|
|
3298
|
+
_d.trys.push([1, 11, 12, 13]);
|
|
3299
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3300
|
+
_d.label = 2;
|
|
3301
|
+
case 2:
|
|
3302
|
+
if (!!_b.done) return [3 /*break*/, 10];
|
|
3303
|
+
llmExecutionTools = _b.value;
|
|
3304
|
+
_d.label = 3;
|
|
3305
|
+
case 3:
|
|
3306
|
+
_d.trys.push([3, 8, , 9]);
|
|
3307
|
+
if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
|
|
3308
|
+
return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
|
|
3309
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
3310
|
+
case 5:
|
|
3311
|
+
if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
|
|
3312
|
+
return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
|
|
3313
|
+
case 6: return [2 /*return*/, _d.sent()];
|
|
3314
|
+
case 7: return [3 /*break*/, 9];
|
|
3315
|
+
case 8:
|
|
3316
|
+
error_1 = _d.sent();
|
|
3317
|
+
if (!(error_1 instanceof Error)) {
|
|
3318
|
+
throw error_1;
|
|
3319
|
+
}
|
|
3320
|
+
errors.push(error_1);
|
|
3321
|
+
return [3 /*break*/, 9];
|
|
3322
|
+
case 9:
|
|
3323
|
+
_b = _a.next();
|
|
3324
|
+
return [3 /*break*/, 2];
|
|
3325
|
+
case 10: return [3 /*break*/, 13];
|
|
3326
|
+
case 11:
|
|
3327
|
+
e_1_1 = _d.sent();
|
|
3328
|
+
e_1 = { error: e_1_1 };
|
|
3329
|
+
return [3 /*break*/, 13];
|
|
3330
|
+
case 12:
|
|
3331
|
+
try {
|
|
3332
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3333
|
+
}
|
|
3334
|
+
finally { if (e_1) throw e_1.error; }
|
|
3335
|
+
return [7 /*endfinally*/];
|
|
3336
|
+
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 "); }));
|
|
3337
|
+
}
|
|
3338
|
+
});
|
|
3339
|
+
});
|
|
3340
|
+
};
|
|
3341
|
+
/**
|
|
3342
|
+
* List all available models that can be used
|
|
3343
|
+
* This liost is a combination of all available models from all execution tools
|
|
3344
|
+
*/
|
|
3345
|
+
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
3346
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3347
|
+
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
3348
|
+
var e_2, _c;
|
|
3349
|
+
return __generator(this, function (_d) {
|
|
3350
|
+
switch (_d.label) {
|
|
3351
|
+
case 0:
|
|
3352
|
+
availableModels = [];
|
|
3353
|
+
_d.label = 1;
|
|
3354
|
+
case 1:
|
|
3355
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
3356
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3357
|
+
_d.label = 2;
|
|
3358
|
+
case 2:
|
|
3359
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
3360
|
+
llmExecutionTools = _b.value;
|
|
3361
|
+
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
3362
|
+
case 3:
|
|
3363
|
+
models = _d.sent();
|
|
3364
|
+
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
3365
|
+
_d.label = 4;
|
|
3366
|
+
case 4:
|
|
3367
|
+
_b = _a.next();
|
|
3368
|
+
return [3 /*break*/, 2];
|
|
3369
|
+
case 5: return [3 /*break*/, 8];
|
|
3370
|
+
case 6:
|
|
3371
|
+
e_2_1 = _d.sent();
|
|
3372
|
+
e_2 = { error: e_2_1 };
|
|
3373
|
+
return [3 /*break*/, 8];
|
|
3374
|
+
case 7:
|
|
3375
|
+
try {
|
|
3376
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3377
|
+
}
|
|
3378
|
+
finally { if (e_2) throw e_2.error; }
|
|
3379
|
+
return [7 /*endfinally*/];
|
|
3380
|
+
case 8: return [2 /*return*/, availableModels];
|
|
3381
|
+
}
|
|
3382
|
+
});
|
|
3383
|
+
});
|
|
3384
|
+
};
|
|
3385
|
+
return MultipleLlmExecutionTools;
|
|
3386
|
+
}());
|
|
3222
3387
|
|
|
3223
3388
|
/**
|
|
3224
3389
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
@@ -3309,36 +3474,61 @@
|
|
|
3309
3474
|
* @returns PromptbookLibrary
|
|
3310
3475
|
*/
|
|
3311
3476
|
function createPromptbookLibraryFromSources() {
|
|
3312
|
-
var e_1, _a;
|
|
3313
3477
|
var promptbookSources = [];
|
|
3314
3478
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3315
3479
|
promptbookSources[_i] = arguments[_i];
|
|
3316
3480
|
}
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3481
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3482
|
+
var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
|
|
3483
|
+
var e_1, _a;
|
|
3484
|
+
return __generator(this, function (_b) {
|
|
3485
|
+
switch (_b.label) {
|
|
3486
|
+
case 0:
|
|
3487
|
+
promptbooks = new Array();
|
|
3488
|
+
_b.label = 1;
|
|
3489
|
+
case 1:
|
|
3490
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
3491
|
+
promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
|
|
3492
|
+
_b.label = 2;
|
|
3493
|
+
case 2:
|
|
3494
|
+
if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
|
|
3495
|
+
source = promptbookSources_1_1.value;
|
|
3496
|
+
promptbook = void 0;
|
|
3497
|
+
if (!(typeof source === 'string')) return [3 /*break*/, 4];
|
|
3498
|
+
return [4 /*yield*/, promptbookStringToJson(source)];
|
|
3499
|
+
case 3:
|
|
3500
|
+
// Note: When directly creating from string, no need to validate the source
|
|
3501
|
+
// The validation is performed always before execution
|
|
3502
|
+
promptbook = _b.sent();
|
|
3503
|
+
return [3 /*break*/, 5];
|
|
3504
|
+
case 4:
|
|
3505
|
+
promptbook = source;
|
|
3506
|
+
_b.label = 5;
|
|
3507
|
+
case 5:
|
|
3508
|
+
promptbooks.push(promptbook);
|
|
3509
|
+
_b.label = 6;
|
|
3510
|
+
case 6:
|
|
3511
|
+
promptbookSources_1_1 = promptbookSources_1.next();
|
|
3512
|
+
return [3 /*break*/, 2];
|
|
3513
|
+
case 7: return [3 /*break*/, 10];
|
|
3514
|
+
case 8:
|
|
3515
|
+
e_1_1 = _b.sent();
|
|
3516
|
+
e_1 = { error: e_1_1 };
|
|
3517
|
+
return [3 /*break*/, 10];
|
|
3518
|
+
case 9:
|
|
3519
|
+
try {
|
|
3520
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
3521
|
+
}
|
|
3522
|
+
finally { if (e_1) throw e_1.error; }
|
|
3523
|
+
return [7 /*endfinally*/];
|
|
3524
|
+
case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
3329
3525
|
}
|
|
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)))();
|
|
3526
|
+
});
|
|
3527
|
+
});
|
|
3341
3528
|
}
|
|
3529
|
+
/**
|
|
3530
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3531
|
+
*/
|
|
3342
3532
|
|
|
3343
3533
|
/**
|
|
3344
3534
|
* Constructs Promptbook from async sources
|
|
@@ -3374,7 +3564,9 @@
|
|
|
3374
3564
|
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3375
3565
|
case 1:
|
|
3376
3566
|
promptbookSources = _a.sent();
|
|
3377
|
-
|
|
3567
|
+
return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
|
|
3568
|
+
case 2:
|
|
3569
|
+
library = _a.sent();
|
|
3378
3570
|
return [2 /*return*/];
|
|
3379
3571
|
}
|
|
3380
3572
|
});
|
|
@@ -3422,6 +3614,9 @@
|
|
|
3422
3614
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3423
3615
|
};
|
|
3424
3616
|
}
|
|
3617
|
+
/**
|
|
3618
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3619
|
+
*/
|
|
3425
3620
|
|
|
3426
3621
|
/**
|
|
3427
3622
|
* Constructs Promptbook from remote Promptbase URL
|
|
@@ -3454,6 +3649,9 @@
|
|
|
3454
3649
|
});
|
|
3455
3650
|
});
|
|
3456
3651
|
}
|
|
3652
|
+
/**
|
|
3653
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3654
|
+
*/
|
|
3457
3655
|
|
|
3458
3656
|
/**
|
|
3459
3657
|
* Creates PromptbookLibrary as a subset of another PromptbookLibrary
|
|
@@ -3534,137 +3732,6 @@
|
|
|
3534
3732
|
};
|
|
3535
3733
|
}
|
|
3536
3734
|
|
|
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
3735
|
/**
|
|
3669
3736
|
* Format either small or big number
|
|
3670
3737
|
*
|
|
@@ -3685,23 +3752,6 @@
|
|
|
3685
3752
|
return value.toString();
|
|
3686
3753
|
}
|
|
3687
3754
|
|
|
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
3755
|
/**
|
|
3706
3756
|
* Create a markdown table from a 2D array of strings
|
|
3707
3757
|
*
|