@promptbook/cli 0.61.0-1 → 0.61.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/esm/index.es.js +417 -150
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +118 -26
- package/esm/typings/src/_packages/core.index.d.ts +5 -1
- package/esm/typings/src/_packages/types.index.d.ts +5 -3
- package/esm/typings/src/_packages/utils.index.d.ts +1 -2
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +1 -1
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +12 -12
- package/esm/typings/src/config.d.ts +4 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +8 -5
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
- package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
- package/esm/typings/src/errors/VersionMismatch.d.ts +8 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/esm/typings/src/execution/PromptResult.d.ts +5 -5
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +3 -3
- package/esm/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -1
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +7 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/personas/preparePersona.d.ts +13 -0
- package/esm/typings/src/personas/preparePersona.test.d.ts +1 -0
- package/esm/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +15 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +8 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +2 -1
- package/esm/typings/src/types/Parameters.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -2
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +25 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +7 -1
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/esm/typings/src/types/typeAliases.d.ts +27 -13
- package/esm/typings/src/utils/FromtoItems.d.ts +3 -3
- package/esm/typings/src/utils/currentDate.d.ts +7 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/esm/typings/src/utils/organization/TODO.d.ts +4 -0
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +11 -0
- package/esm/typings/src/utils/organization/___.d.ts +4 -0
- package/esm/typings/src/utils/organization/really_any.d.ts +4 -0
- package/package.json +2 -2
- package/umd/index.umd.js +417 -150
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +118 -26
- package/umd/typings/src/_packages/core.index.d.ts +5 -1
- package/umd/typings/src/_packages/types.index.d.ts +5 -3
- package/umd/typings/src/_packages/utils.index.d.ts +1 -2
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +1 -1
- package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
- package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +12 -12
- package/umd/typings/src/config.d.ts +4 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +8 -5
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
- package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/umd/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
- package/umd/typings/src/errors/VersionMismatch.d.ts +8 -0
- package/umd/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/umd/typings/src/execution/PromptResult.d.ts +5 -5
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +3 -3
- package/umd/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -1
- package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
- package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
- package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +7 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +2 -2
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/personas/preparePersona.d.ts +13 -0
- package/umd/typings/src/personas/preparePersona.test.d.ts +1 -0
- package/umd/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +15 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +8 -0
- package/umd/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/umd/typings/src/types/ModelRequirements.d.ts +2 -1
- package/umd/typings/src/types/Parameters.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
- package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -2
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +25 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +7 -1
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/umd/typings/src/types/typeAliases.d.ts +27 -13
- package/umd/typings/src/utils/FromtoItems.d.ts +3 -3
- package/umd/typings/src/utils/currentDate.d.ts +7 -0
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/umd/typings/src/utils/organization/TODO.d.ts +4 -0
- package/umd/typings/src/utils/organization/TODO_USE.d.ts +11 -0
- package/umd/typings/src/utils/organization/___.d.ts +4 -0
- package/umd/typings/src/utils/organization/really_any.d.ts +4 -0
- package/esm/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/esm/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/esm/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- package/umd/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/umd/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/umd/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- /package/esm/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/esm/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
- /package/umd/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/umd/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -146,7 +146,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
146
146
|
/**
|
|
147
147
|
* The version of the Promptbook library
|
|
148
148
|
*/
|
|
149
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
149
|
+
var PROMPTBOOK_VERSION = '0.61.0-9';
|
|
150
150
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
151
151
|
|
|
152
152
|
/**
|
|
@@ -212,6 +212,10 @@ var LOOP_LIMIT = 1000;
|
|
|
212
212
|
* The maximum number of iterations for a loops which adds characters one by one
|
|
213
213
|
*/
|
|
214
214
|
var CHARACTER_LOOP_LIMIT = 100000;
|
|
215
|
+
/**
|
|
216
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
217
|
+
*/
|
|
218
|
+
var MAX_PARALLEL_COUNT = 5;
|
|
215
219
|
/**
|
|
216
220
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
217
221
|
*/
|
|
@@ -225,7 +229,172 @@ var RESERVED_PARAMETER_NAMES = [
|
|
|
225
229
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
226
230
|
];
|
|
227
231
|
|
|
228
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Function `addUsage` will add multiple usages into one
|
|
234
|
+
*
|
|
235
|
+
* Note: If you provide 0 values, it returns void usage
|
|
236
|
+
*/
|
|
237
|
+
function addUsage() {
|
|
238
|
+
var usageItems = [];
|
|
239
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
240
|
+
usageItems[_i] = arguments[_i];
|
|
241
|
+
}
|
|
242
|
+
var initialStructure = {
|
|
243
|
+
price: { value: 0 },
|
|
244
|
+
input: {
|
|
245
|
+
tokensCount: { value: 0 },
|
|
246
|
+
charactersCount: { value: 0 },
|
|
247
|
+
wordsCount: { value: 0 },
|
|
248
|
+
sentencesCount: { value: 0 },
|
|
249
|
+
linesCount: { value: 0 },
|
|
250
|
+
paragraphsCount: { value: 0 },
|
|
251
|
+
pagesCount: { value: 0 },
|
|
252
|
+
},
|
|
253
|
+
output: {
|
|
254
|
+
tokensCount: { value: 0 },
|
|
255
|
+
charactersCount: { value: 0 },
|
|
256
|
+
wordsCount: { value: 0 },
|
|
257
|
+
sentencesCount: { value: 0 },
|
|
258
|
+
linesCount: { value: 0 },
|
|
259
|
+
paragraphsCount: { value: 0 },
|
|
260
|
+
pagesCount: { value: 0 },
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
return usageItems.reduce(function (acc, item) {
|
|
264
|
+
var e_1, _a, e_2, _b;
|
|
265
|
+
var _c;
|
|
266
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
267
|
+
try {
|
|
268
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
269
|
+
var key = _e.value;
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
271
|
+
//@ts-ignore
|
|
272
|
+
if (item.input[key]) {
|
|
273
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
274
|
+
//@ts-ignore
|
|
275
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
276
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
277
|
+
//@ts-ignore
|
|
278
|
+
if (item.input[key].isUncertain) {
|
|
279
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
280
|
+
//@ts-ignore
|
|
281
|
+
acc.input[key].isUncertain = true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
287
|
+
finally {
|
|
288
|
+
try {
|
|
289
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
290
|
+
}
|
|
291
|
+
finally { if (e_1) throw e_1.error; }
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
295
|
+
var key = _g.value;
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
297
|
+
//@ts-ignore
|
|
298
|
+
if (item.output[key]) {
|
|
299
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
300
|
+
//@ts-ignore
|
|
301
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
303
|
+
//@ts-ignore
|
|
304
|
+
if (item.output[key].isUncertain) {
|
|
305
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
306
|
+
//@ts-ignore
|
|
307
|
+
acc.output[key].isUncertain = true;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
313
|
+
finally {
|
|
314
|
+
try {
|
|
315
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
316
|
+
}
|
|
317
|
+
finally { if (e_2) throw e_2.error; }
|
|
318
|
+
}
|
|
319
|
+
return acc;
|
|
320
|
+
}, initialStructure);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Async version of Array.forEach
|
|
325
|
+
*
|
|
326
|
+
* @param array - Array to iterate over
|
|
327
|
+
* @param options - Options for the function
|
|
328
|
+
* @param callbackfunction - Function to call for each item
|
|
329
|
+
*/
|
|
330
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
333
|
+
var e_1, _d;
|
|
334
|
+
return __generator(this, function (_e) {
|
|
335
|
+
switch (_e.label) {
|
|
336
|
+
case 0:
|
|
337
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
338
|
+
index = 0;
|
|
339
|
+
runningTasks = [];
|
|
340
|
+
tasks = [];
|
|
341
|
+
_loop_1 = function (item) {
|
|
342
|
+
var currentIndex, task;
|
|
343
|
+
return __generator(this, function (_f) {
|
|
344
|
+
switch (_f.label) {
|
|
345
|
+
case 0:
|
|
346
|
+
currentIndex = index++;
|
|
347
|
+
task = callbackfunction(item, currentIndex, array);
|
|
348
|
+
tasks.push(task);
|
|
349
|
+
runningTasks.push(task);
|
|
350
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
351
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
352
|
+
});
|
|
353
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
354
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
355
|
+
case 1:
|
|
356
|
+
_f.sent();
|
|
357
|
+
_f.label = 2;
|
|
358
|
+
case 2: return [2 /*return*/];
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
_e.label = 1;
|
|
363
|
+
case 1:
|
|
364
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
365
|
+
_b = __values(array), _c = _b.next();
|
|
366
|
+
_e.label = 2;
|
|
367
|
+
case 2:
|
|
368
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
369
|
+
item = _c.value;
|
|
370
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
371
|
+
case 3:
|
|
372
|
+
_e.sent();
|
|
373
|
+
_e.label = 4;
|
|
374
|
+
case 4:
|
|
375
|
+
_c = _b.next();
|
|
376
|
+
return [3 /*break*/, 2];
|
|
377
|
+
case 5: return [3 /*break*/, 8];
|
|
378
|
+
case 6:
|
|
379
|
+
e_1_1 = _e.sent();
|
|
380
|
+
e_1 = { error: e_1_1 };
|
|
381
|
+
return [3 /*break*/, 8];
|
|
382
|
+
case 7:
|
|
383
|
+
try {
|
|
384
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
385
|
+
}
|
|
386
|
+
finally { if (e_1) throw e_1.error; }
|
|
387
|
+
return [7 /*endfinally*/];
|
|
388
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
389
|
+
case 9:
|
|
390
|
+
_e.sent();
|
|
391
|
+
return [2 /*return*/];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-9",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.966Z",promptbookVersion:"0.61.0-9",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-9",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.970Z",promptbookVersion:"0.61.0-9",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-9",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {content}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.976Z",promptbookVersion:"0.61.0-9",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"}];
|
|
229
398
|
|
|
230
399
|
/**
|
|
231
400
|
* Prettify the html code
|
|
@@ -1294,6 +1463,14 @@ function removeEmojis(text) {
|
|
|
1294
1463
|
* Function normalizes title to name which can be used as identifier
|
|
1295
1464
|
*/
|
|
1296
1465
|
function titleToName(value) {
|
|
1466
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
1467
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1468
|
+
return value;
|
|
1469
|
+
}
|
|
1470
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
1471
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1472
|
+
return value;
|
|
1473
|
+
}
|
|
1297
1474
|
value = removeEmojis(value);
|
|
1298
1475
|
value = normalizeToKebabCase(value);
|
|
1299
1476
|
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
@@ -1628,97 +1805,6 @@ function arrayableToArray(input) {
|
|
|
1628
1805
|
return [input];
|
|
1629
1806
|
}
|
|
1630
1807
|
|
|
1631
|
-
/**
|
|
1632
|
-
* Function `addUsage` will add multiple usages into one
|
|
1633
|
-
*
|
|
1634
|
-
* Note: If you provide 0 values, it returns void usage
|
|
1635
|
-
*/
|
|
1636
|
-
function addUsage() {
|
|
1637
|
-
var usageItems = [];
|
|
1638
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1639
|
-
usageItems[_i] = arguments[_i];
|
|
1640
|
-
}
|
|
1641
|
-
var initialStructure = {
|
|
1642
|
-
price: { value: 0 },
|
|
1643
|
-
input: {
|
|
1644
|
-
tokensCount: { value: 0 },
|
|
1645
|
-
charactersCount: { value: 0 },
|
|
1646
|
-
wordsCount: { value: 0 },
|
|
1647
|
-
sentencesCount: { value: 0 },
|
|
1648
|
-
linesCount: { value: 0 },
|
|
1649
|
-
paragraphsCount: { value: 0 },
|
|
1650
|
-
pagesCount: { value: 0 },
|
|
1651
|
-
},
|
|
1652
|
-
output: {
|
|
1653
|
-
tokensCount: { value: 0 },
|
|
1654
|
-
charactersCount: { value: 0 },
|
|
1655
|
-
wordsCount: { value: 0 },
|
|
1656
|
-
sentencesCount: { value: 0 },
|
|
1657
|
-
linesCount: { value: 0 },
|
|
1658
|
-
paragraphsCount: { value: 0 },
|
|
1659
|
-
pagesCount: { value: 0 },
|
|
1660
|
-
},
|
|
1661
|
-
};
|
|
1662
|
-
return usageItems.reduce(function (acc, item) {
|
|
1663
|
-
var e_1, _a, e_2, _b;
|
|
1664
|
-
var _c;
|
|
1665
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1666
|
-
try {
|
|
1667
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1668
|
-
var key = _e.value;
|
|
1669
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1670
|
-
//@ts-ignore
|
|
1671
|
-
if (item.input[key]) {
|
|
1672
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1673
|
-
//@ts-ignore
|
|
1674
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
1675
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1676
|
-
//@ts-ignore
|
|
1677
|
-
if (item.input[key].isUncertain) {
|
|
1678
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1679
|
-
//@ts-ignore
|
|
1680
|
-
acc.input[key].isUncertain = true;
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1686
|
-
finally {
|
|
1687
|
-
try {
|
|
1688
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1689
|
-
}
|
|
1690
|
-
finally { if (e_1) throw e_1.error; }
|
|
1691
|
-
}
|
|
1692
|
-
try {
|
|
1693
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1694
|
-
var key = _g.value;
|
|
1695
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1696
|
-
//@ts-ignore
|
|
1697
|
-
if (item.output[key]) {
|
|
1698
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1699
|
-
//@ts-ignore
|
|
1700
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
1701
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1702
|
-
//@ts-ignore
|
|
1703
|
-
if (item.output[key].isUncertain) {
|
|
1704
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1705
|
-
//@ts-ignore
|
|
1706
|
-
acc.output[key].isUncertain = true;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1712
|
-
finally {
|
|
1713
|
-
try {
|
|
1714
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1715
|
-
}
|
|
1716
|
-
finally { if (e_2) throw e_2.error; }
|
|
1717
|
-
}
|
|
1718
|
-
return acc;
|
|
1719
|
-
}, initialStructure);
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
1808
|
/**
|
|
1723
1809
|
* Counts number of characters in the text
|
|
1724
1810
|
*/
|
|
@@ -1922,8 +2008,6 @@ function createPipelineExecutor(options) {
|
|
|
1922
2008
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1923
2009
|
// TODO: !!!!! Implement new commands
|
|
1924
2010
|
validatePipeline(pipeline);
|
|
1925
|
-
// TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
|
|
1926
|
-
// TODO: !!!!! Do here personaToModelRequirements
|
|
1927
2011
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
1928
2012
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1929
2013
|
function executeSingleTemplate(currentTemplate) {
|
|
@@ -2444,53 +2528,74 @@ function createPipelineExecutor(options) {
|
|
|
2444
2528
|
return pipelineExecutor;
|
|
2445
2529
|
}
|
|
2446
2530
|
/**
|
|
2531
|
+
* TODO: [🪂] Pass maxParallelCount here
|
|
2447
2532
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2448
2533
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2449
2534
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2450
2535
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2451
2536
|
*/
|
|
2452
2537
|
|
|
2453
|
-
|
|
2538
|
+
/**
|
|
2539
|
+
* Just marks a place of place where should be something implemented
|
|
2540
|
+
* No side effects.
|
|
2541
|
+
*
|
|
2542
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2543
|
+
*
|
|
2544
|
+
* @param value any values
|
|
2545
|
+
* @returns void
|
|
2546
|
+
*/
|
|
2547
|
+
function TODO_USE() {
|
|
2548
|
+
var value = [];
|
|
2549
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2550
|
+
value[_i] = arguments[_i];
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
// TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
|
|
2554
|
+
|
|
2555
|
+
/**
|
|
2556
|
+
* @@@
|
|
2557
|
+
*/
|
|
2558
|
+
function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
2454
2559
|
return __awaiter(this, void 0, void 0, function () {
|
|
2455
|
-
var
|
|
2456
|
-
var
|
|
2560
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2561
|
+
var _f, _g, _h;
|
|
2457
2562
|
var _this = this;
|
|
2458
|
-
return __generator(this, function (
|
|
2459
|
-
switch (
|
|
2563
|
+
return __generator(this, function (_j) {
|
|
2564
|
+
switch (_j.label) {
|
|
2460
2565
|
case 0:
|
|
2461
|
-
|
|
2566
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2567
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2462
2568
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2463
|
-
_b = createPipelineExecutor;
|
|
2464
|
-
_e = {};
|
|
2465
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2466
|
-
case 1:
|
|
2467
|
-
prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
|
|
2468
|
-
_e.tools = {
|
|
2469
|
-
llm: llmTools,
|
|
2470
|
-
},
|
|
2471
|
-
_e)]);
|
|
2472
2569
|
_c = createPipelineExecutor;
|
|
2473
2570
|
_f = {};
|
|
2474
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2475
|
-
case
|
|
2476
|
-
|
|
2571
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2572
|
+
case 1:
|
|
2573
|
+
prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
|
|
2477
2574
|
_f.tools = {
|
|
2478
2575
|
llm: llmTools,
|
|
2479
2576
|
},
|
|
2480
2577
|
_f)]);
|
|
2481
2578
|
_d = createPipelineExecutor;
|
|
2482
2579
|
_g = {};
|
|
2483
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2484
|
-
case
|
|
2485
|
-
|
|
2580
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
|
|
2581
|
+
case 2:
|
|
2582
|
+
prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
|
|
2486
2583
|
_g.tools = {
|
|
2487
2584
|
llm: llmTools,
|
|
2488
2585
|
},
|
|
2489
2586
|
_g)]);
|
|
2587
|
+
_e = createPipelineExecutor;
|
|
2588
|
+
_h = {};
|
|
2589
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
|
|
2590
|
+
case 3:
|
|
2591
|
+
prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
|
|
2592
|
+
_h.tools = {
|
|
2593
|
+
llm: llmTools,
|
|
2594
|
+
},
|
|
2595
|
+
_h)]);
|
|
2490
2596
|
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
|
|
2491
2597
|
case 4:
|
|
2492
|
-
result =
|
|
2493
|
-
// TODO: [0] !!! Aggeregate usage
|
|
2598
|
+
result = _j.sent();
|
|
2494
2599
|
assertsExecutionSuccessful(result);
|
|
2495
2600
|
outputParameters = result.outputParameters;
|
|
2496
2601
|
knowledgeRaw = outputParameters.knowledge;
|
|
@@ -2499,9 +2604,9 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2499
2604
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2500
2605
|
}
|
|
2501
2606
|
return [4 /*yield*/, Promise.all(
|
|
2502
|
-
// TODO:
|
|
2607
|
+
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
2503
2608
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2504
|
-
var name, title, content, keywords, index,
|
|
2609
|
+
var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
2505
2610
|
return __generator(this, function (_c) {
|
|
2506
2611
|
switch (_c.label) {
|
|
2507
2612
|
case 0:
|
|
@@ -2510,12 +2615,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2510
2615
|
content = spaceTrim(knowledgeTextPiece);
|
|
2511
2616
|
keywords = [];
|
|
2512
2617
|
index = [];
|
|
2513
|
-
sources = [
|
|
2514
|
-
{
|
|
2515
|
-
title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
|
|
2516
|
-
href: '#' /* <- TODO: !!! Unhardcode */,
|
|
2517
|
-
},
|
|
2518
|
-
];
|
|
2519
2618
|
_c.label = 1;
|
|
2520
2619
|
case 1:
|
|
2521
2620
|
_c.trys.push([1, 7, , 8]);
|
|
@@ -2550,7 +2649,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2550
2649
|
})];
|
|
2551
2650
|
case 5:
|
|
2552
2651
|
embeddingResult = _c.sent();
|
|
2553
|
-
// TODO: [0] !!! Aggeregate usage embeddingResult.usage
|
|
2554
2652
|
index.push({
|
|
2555
2653
|
modelName: embeddingResult.modelName,
|
|
2556
2654
|
position: embeddingResult.content,
|
|
@@ -2568,20 +2666,186 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2568
2666
|
content: content,
|
|
2569
2667
|
keywords: keywords,
|
|
2570
2668
|
index: index,
|
|
2571
|
-
|
|
2669
|
+
// <- TODO: [☀] sources,
|
|
2572
2670
|
}];
|
|
2573
2671
|
}
|
|
2574
2672
|
});
|
|
2575
2673
|
}); }))];
|
|
2576
2674
|
case 5:
|
|
2577
|
-
knowledge =
|
|
2675
|
+
knowledge = _j.sent();
|
|
2578
2676
|
return [2 /*return*/, knowledge];
|
|
2579
2677
|
}
|
|
2580
2678
|
});
|
|
2581
2679
|
});
|
|
2582
2680
|
}
|
|
2583
2681
|
/**
|
|
2584
|
-
* 11:11
|
|
2682
|
+
* TODO: [🪂] Do it in parallel 11:11
|
|
2683
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2684
|
+
*/
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Prepares the knowle
|
|
2688
|
+
*
|
|
2689
|
+
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2690
|
+
* @private within the package
|
|
2691
|
+
*/
|
|
2692
|
+
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2693
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2694
|
+
var _a, maxParallelCount, knowledgePrepared;
|
|
2695
|
+
var _this = this;
|
|
2696
|
+
return __generator(this, function (_b) {
|
|
2697
|
+
switch (_b.label) {
|
|
2698
|
+
case 0:
|
|
2699
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2700
|
+
knowledgePrepared = [];
|
|
2701
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
2702
|
+
var partialPieces, pieces;
|
|
2703
|
+
return __generator(this, function (_a) {
|
|
2704
|
+
switch (_a.label) {
|
|
2705
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2706
|
+
options)];
|
|
2707
|
+
case 1:
|
|
2708
|
+
partialPieces = _a.sent();
|
|
2709
|
+
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
2710
|
+
{
|
|
2711
|
+
name: knowledgeSource.name,
|
|
2712
|
+
// line, column <- TODO: [☀]
|
|
2713
|
+
// <- TODO: [❎]
|
|
2714
|
+
},
|
|
2715
|
+
] })); });
|
|
2716
|
+
knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
|
|
2717
|
+
return [2 /*return*/];
|
|
2718
|
+
}
|
|
2719
|
+
});
|
|
2720
|
+
}); })];
|
|
2721
|
+
case 1:
|
|
2722
|
+
_b.sent();
|
|
2723
|
+
return [2 /*return*/, knowledgePrepared];
|
|
2724
|
+
}
|
|
2725
|
+
});
|
|
2726
|
+
});
|
|
2727
|
+
}
|
|
2728
|
+
/*
|
|
2729
|
+
TODO: [🧊] This is how it can look in future
|
|
2730
|
+
> type PrepareKnowledgeKnowledge = {
|
|
2731
|
+
> /**
|
|
2732
|
+
> * Unprepared knowledge
|
|
2733
|
+
> * /
|
|
2734
|
+
> readonly knowledgeSources: Array<KnowledgeSourceJson>;
|
|
2735
|
+
> };
|
|
2736
|
+
>
|
|
2737
|
+
> export async function prepareKnowledgePieces(
|
|
2738
|
+
> knowledge: PrepareKnowledgeKnowledge,
|
|
2739
|
+
> options: PrepareOptions,
|
|
2740
|
+
> ):
|
|
2741
|
+
*/
|
|
2742
|
+
/**
|
|
2743
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2744
|
+
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2745
|
+
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
2746
|
+
* TODO: [🧠][❎] Do here propper M:N mapping
|
|
2747
|
+
* [x] One source can make multiple pieces
|
|
2748
|
+
* [ ] One piece can have multiple sources
|
|
2749
|
+
*/
|
|
2750
|
+
|
|
2751
|
+
/**
|
|
2752
|
+
* Prepares the persona for the pipeline
|
|
2753
|
+
*
|
|
2754
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2755
|
+
* @private within the package
|
|
2756
|
+
*/
|
|
2757
|
+
function preparePersona(personaDescription, options) {
|
|
2758
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2759
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose;
|
|
2760
|
+
return __generator(this, function (_c) {
|
|
2761
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2762
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2763
|
+
TODO_USE(personaDescription); // <- !!!!!
|
|
2764
|
+
TODO_USE(llmTools); // <- !!!!!
|
|
2765
|
+
TODO_USE(isVerbose); // <- !!!!!
|
|
2766
|
+
return [2 /*return*/, {
|
|
2767
|
+
modelVariant: 'CHAT',
|
|
2768
|
+
modelName: 'gpt-4',
|
|
2769
|
+
}];
|
|
2770
|
+
});
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
/**
|
|
2774
|
+
* TODO: [🪂] Do it in parallel
|
|
2775
|
+
*/
|
|
2776
|
+
|
|
2777
|
+
/**
|
|
2778
|
+
* Simple wrapper `new Date().toISOString()`
|
|
2779
|
+
*
|
|
2780
|
+
* @returns string_date branded type
|
|
2781
|
+
*/
|
|
2782
|
+
function $currentDate() {
|
|
2783
|
+
return new Date().toISOString();
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
/**
|
|
2787
|
+
* Prepare pipeline from string (markdown) format to JSON format
|
|
2788
|
+
*
|
|
2789
|
+
* Note: This function does not validate logic of the pipeline
|
|
2790
|
+
* Note: This function acts as part of compilation process
|
|
2791
|
+
*/
|
|
2792
|
+
function preparePipeline(pipeline, options) {
|
|
2793
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2794
|
+
var _a, maxParallelCount,
|
|
2795
|
+
/*
|
|
2796
|
+
<- TODO: [🧠][0] `promptbookVersion` */
|
|
2797
|
+
knowledgeSources /*
|
|
2798
|
+
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
2799
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
|
|
2800
|
+
var _this = this;
|
|
2801
|
+
return __generator(this, function (_b) {
|
|
2802
|
+
switch (_b.label) {
|
|
2803
|
+
case 0:
|
|
2804
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2805
|
+
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
2806
|
+
currentPreparation = {
|
|
2807
|
+
id: 1,
|
|
2808
|
+
date: $currentDate(),
|
|
2809
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2810
|
+
modelUsage: addUsage(),
|
|
2811
|
+
};
|
|
2812
|
+
preparations = [
|
|
2813
|
+
// ...preparations
|
|
2814
|
+
// <- TODO: [🧊]
|
|
2815
|
+
currentPreparation,
|
|
2816
|
+
];
|
|
2817
|
+
preparedPersonas = [];
|
|
2818
|
+
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona) { return __awaiter(_this, void 0, void 0, function () {
|
|
2819
|
+
var modelRequirements, preparedPersona;
|
|
2820
|
+
return __generator(this, function (_a) {
|
|
2821
|
+
switch (_a.label) {
|
|
2822
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
|
|
2823
|
+
case 1:
|
|
2824
|
+
modelRequirements = _a.sent();
|
|
2825
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
2826
|
+
preparedPersonas.push(preparedPersona);
|
|
2827
|
+
return [2 /*return*/];
|
|
2828
|
+
}
|
|
2829
|
+
});
|
|
2830
|
+
}); })];
|
|
2831
|
+
case 1:
|
|
2832
|
+
_b.sent();
|
|
2833
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2834
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
|
|
2835
|
+
case 2:
|
|
2836
|
+
partialknowledgePiecesPrepared = _b.sent();
|
|
2837
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2838
|
+
// ----- /Knowledge preparation -----
|
|
2839
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
2840
|
+
}
|
|
2841
|
+
});
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
/**
|
|
2845
|
+
* TODO: Write tests for `preparePipeline`
|
|
2846
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
2847
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2848
|
+
* TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
|
|
2585
2849
|
*/
|
|
2586
2850
|
|
|
2587
2851
|
/**
|
|
@@ -2768,6 +3032,7 @@ var blockCommandParser = {
|
|
|
2768
3032
|
|
|
2769
3033
|
/**
|
|
2770
3034
|
* Units of text measurement
|
|
3035
|
+
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
2771
3036
|
*/
|
|
2772
3037
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2773
3038
|
/**
|
|
@@ -3088,9 +3353,10 @@ var knowledgeCommandParser = {
|
|
|
3088
3353
|
|
|
3089
3354
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3090
3355
|
/**
|
|
3356
|
+
* TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
|
|
3091
3357
|
* TODO: Maybe figure out better word than "variant"
|
|
3092
3358
|
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3093
|
-
* TODO: [
|
|
3359
|
+
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
3094
3360
|
*/
|
|
3095
3361
|
|
|
3096
3362
|
/**
|
|
@@ -4233,14 +4499,14 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
4233
4499
|
*/
|
|
4234
4500
|
|
|
4235
4501
|
/**
|
|
4236
|
-
* Compile
|
|
4502
|
+
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4237
4503
|
*
|
|
4238
|
-
* Note: There are
|
|
4504
|
+
* Note: There are 3 similar functions:
|
|
4239
4505
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4240
4506
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
4507
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4241
4508
|
*
|
|
4242
4509
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4243
|
-
* @param options - Options and tools for the compilation
|
|
4244
4510
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
4245
4511
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
4246
4512
|
*
|
|
@@ -4256,7 +4522,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4256
4522
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
4257
4523
|
parameters: [],
|
|
4258
4524
|
promptTemplates: [],
|
|
4259
|
-
|
|
4525
|
+
knowledgeSources: [],
|
|
4526
|
+
knowledgePieces: [],
|
|
4527
|
+
personas: [],
|
|
4528
|
+
preparations: [],
|
|
4260
4529
|
};
|
|
4261
4530
|
// =============================================================
|
|
4262
4531
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
@@ -4524,6 +4793,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4524
4793
|
postprocessing: postprocessing,
|
|
4525
4794
|
expectations: expectAmount,
|
|
4526
4795
|
expectFormat: expectFormat,
|
|
4796
|
+
personaName: null,
|
|
4527
4797
|
modelRequirements: templateModelRequirements,
|
|
4528
4798
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4529
4799
|
content: content,
|
|
@@ -4603,11 +4873,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4603
4873
|
*/
|
|
4604
4874
|
|
|
4605
4875
|
/**
|
|
4606
|
-
* Compile
|
|
4876
|
+
* Compile pipeline from string (markdown) format to JSON format
|
|
4607
4877
|
*
|
|
4608
|
-
* Note: There are
|
|
4878
|
+
* Note: There are 3 similar functions:
|
|
4609
4879
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4610
4880
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
4881
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4611
4882
|
*
|
|
4612
4883
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4613
4884
|
* @param options - Options and tools for the compilation
|
|
@@ -4618,22 +4889,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4618
4889
|
* Note: This function acts as compilation process
|
|
4619
4890
|
*/
|
|
4620
4891
|
function pipelineStringToJson(pipelineString, options) {
|
|
4621
|
-
if (options === void 0) { options = {}; }
|
|
4892
|
+
if (options === void 0) { options = { llmTools: null }; }
|
|
4622
4893
|
return __awaiter(this, void 0, void 0, function () {
|
|
4623
|
-
var llmTools, pipelineJson
|
|
4894
|
+
var llmTools, pipelineJson;
|
|
4624
4895
|
return __generator(this, function (_a) {
|
|
4625
4896
|
switch (_a.label) {
|
|
4626
4897
|
case 0:
|
|
4627
4898
|
llmTools = options.llmTools;
|
|
4628
4899
|
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
4629
|
-
if (!llmTools) return [3 /*break*/, 2];
|
|
4630
|
-
return [4 /*yield*/,
|
|
4631
|
-
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
4632
|
-
llmTools: llmTools,
|
|
4633
|
-
})];
|
|
4900
|
+
if (!(llmTools !== null)) return [3 /*break*/, 2];
|
|
4901
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
|
|
4634
4902
|
case 1:
|
|
4635
|
-
|
|
4636
|
-
pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
|
|
4903
|
+
pipelineJson = _a.sent();
|
|
4637
4904
|
_a.label = 2;
|
|
4638
4905
|
case 2: return [2 /*return*/, pipelineJson];
|
|
4639
4906
|
}
|
|
@@ -4755,7 +5022,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
4755
5022
|
*/
|
|
4756
5023
|
function createCollectionFromDirectory(path, options) {
|
|
4757
5024
|
return __awaiter(this, void 0, void 0, function () {
|
|
4758
|
-
var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e,
|
|
5025
|
+
var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, collection;
|
|
4759
5026
|
var _this = this;
|
|
4760
5027
|
return __generator(this, function (_f) {
|
|
4761
5028
|
switch (_f.label) {
|
|
@@ -4776,7 +5043,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
4776
5043
|
colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
|
|
4777
5044
|
// TODO: !! Implement;
|
|
4778
5045
|
}
|
|
4779
|
-
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.
|
|
5046
|
+
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
|
|
4780
5047
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4781
5048
|
var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
4782
5049
|
var e_1, _a;
|
|
@@ -4838,7 +5105,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
4838
5105
|
if (isVerbose) {
|
|
4839
5106
|
console.info("Loading ".concat(fileName.split('\\').join('/')));
|
|
4840
5107
|
}
|
|
4841
|
-
if (!
|
|
5108
|
+
if (!isCrashedOnError) {
|
|
4842
5109
|
// Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
|
|
4843
5110
|
// But be handled in current try-catch block
|
|
4844
5111
|
validatePipeline(promptbook);
|
|
@@ -4854,7 +5121,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
4854
5121
|
throw error_1;
|
|
4855
5122
|
}
|
|
4856
5123
|
wrappedErrorMessage = spaceTrim(function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
4857
|
-
if (
|
|
5124
|
+
if (isCrashedOnError) {
|
|
4858
5125
|
throw new CollectionError(wrappedErrorMessage);
|
|
4859
5126
|
}
|
|
4860
5127
|
// TODO: [🟥] Detect browser / node and make it colorfull
|