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