@promptbook/core 0.61.0-0 → 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/esm/index.es.js +441 -147
- 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 +1 -1
- package/umd/index.umd.js +443 -146
- 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/umd/index.umd.js
CHANGED
|
@@ -401,6 +401,10 @@
|
|
|
401
401
|
* The maximum number of iterations for a loops
|
|
402
402
|
*/
|
|
403
403
|
var LOOP_LIMIT = 1000;
|
|
404
|
+
/**
|
|
405
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
406
|
+
*/
|
|
407
|
+
var MAX_PARALLEL_COUNT = 5;
|
|
404
408
|
/**
|
|
405
409
|
* The names of the parameters that are reserved for special purposes
|
|
406
410
|
*/
|
|
@@ -1126,7 +1130,172 @@
|
|
|
1126
1130
|
// <- [🩻]
|
|
1127
1131
|
];
|
|
1128
1132
|
|
|
1129
|
-
|
|
1133
|
+
/**
|
|
1134
|
+
* Function `addUsage` will add multiple usages into one
|
|
1135
|
+
*
|
|
1136
|
+
* Note: If you provide 0 values, it returns void usage
|
|
1137
|
+
*/
|
|
1138
|
+
function addUsage() {
|
|
1139
|
+
var usageItems = [];
|
|
1140
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1141
|
+
usageItems[_i] = arguments[_i];
|
|
1142
|
+
}
|
|
1143
|
+
var initialStructure = {
|
|
1144
|
+
price: { value: 0 },
|
|
1145
|
+
input: {
|
|
1146
|
+
tokensCount: { value: 0 },
|
|
1147
|
+
charactersCount: { value: 0 },
|
|
1148
|
+
wordsCount: { value: 0 },
|
|
1149
|
+
sentencesCount: { value: 0 },
|
|
1150
|
+
linesCount: { value: 0 },
|
|
1151
|
+
paragraphsCount: { value: 0 },
|
|
1152
|
+
pagesCount: { value: 0 },
|
|
1153
|
+
},
|
|
1154
|
+
output: {
|
|
1155
|
+
tokensCount: { value: 0 },
|
|
1156
|
+
charactersCount: { value: 0 },
|
|
1157
|
+
wordsCount: { value: 0 },
|
|
1158
|
+
sentencesCount: { value: 0 },
|
|
1159
|
+
linesCount: { value: 0 },
|
|
1160
|
+
paragraphsCount: { value: 0 },
|
|
1161
|
+
pagesCount: { value: 0 },
|
|
1162
|
+
},
|
|
1163
|
+
};
|
|
1164
|
+
return usageItems.reduce(function (acc, item) {
|
|
1165
|
+
var e_1, _a, e_2, _b;
|
|
1166
|
+
var _c;
|
|
1167
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1168
|
+
try {
|
|
1169
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1170
|
+
var key = _e.value;
|
|
1171
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1172
|
+
//@ts-ignore
|
|
1173
|
+
if (item.input[key]) {
|
|
1174
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1175
|
+
//@ts-ignore
|
|
1176
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
1177
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1178
|
+
//@ts-ignore
|
|
1179
|
+
if (item.input[key].isUncertain) {
|
|
1180
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1181
|
+
//@ts-ignore
|
|
1182
|
+
acc.input[key].isUncertain = true;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1188
|
+
finally {
|
|
1189
|
+
try {
|
|
1190
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1191
|
+
}
|
|
1192
|
+
finally { if (e_1) throw e_1.error; }
|
|
1193
|
+
}
|
|
1194
|
+
try {
|
|
1195
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1196
|
+
var key = _g.value;
|
|
1197
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1198
|
+
//@ts-ignore
|
|
1199
|
+
if (item.output[key]) {
|
|
1200
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1201
|
+
//@ts-ignore
|
|
1202
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
1203
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1204
|
+
//@ts-ignore
|
|
1205
|
+
if (item.output[key].isUncertain) {
|
|
1206
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1207
|
+
//@ts-ignore
|
|
1208
|
+
acc.output[key].isUncertain = true;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1214
|
+
finally {
|
|
1215
|
+
try {
|
|
1216
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1217
|
+
}
|
|
1218
|
+
finally { if (e_2) throw e_2.error; }
|
|
1219
|
+
}
|
|
1220
|
+
return acc;
|
|
1221
|
+
}, initialStructure);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Async version of Array.forEach
|
|
1226
|
+
*
|
|
1227
|
+
* @param array - Array to iterate over
|
|
1228
|
+
* @param options - Options for the function
|
|
1229
|
+
* @param callbackfunction - Function to call for each item
|
|
1230
|
+
*/
|
|
1231
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
1232
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1233
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
1234
|
+
var e_1, _d;
|
|
1235
|
+
return __generator(this, function (_e) {
|
|
1236
|
+
switch (_e.label) {
|
|
1237
|
+
case 0:
|
|
1238
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
1239
|
+
index = 0;
|
|
1240
|
+
runningTasks = [];
|
|
1241
|
+
tasks = [];
|
|
1242
|
+
_loop_1 = function (item) {
|
|
1243
|
+
var currentIndex, task;
|
|
1244
|
+
return __generator(this, function (_f) {
|
|
1245
|
+
switch (_f.label) {
|
|
1246
|
+
case 0:
|
|
1247
|
+
currentIndex = index++;
|
|
1248
|
+
task = callbackfunction(item, currentIndex, array);
|
|
1249
|
+
tasks.push(task);
|
|
1250
|
+
runningTasks.push(task);
|
|
1251
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
1252
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
1253
|
+
});
|
|
1254
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
1255
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
1256
|
+
case 1:
|
|
1257
|
+
_f.sent();
|
|
1258
|
+
_f.label = 2;
|
|
1259
|
+
case 2: return [2 /*return*/];
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
};
|
|
1263
|
+
_e.label = 1;
|
|
1264
|
+
case 1:
|
|
1265
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
1266
|
+
_b = __values(array), _c = _b.next();
|
|
1267
|
+
_e.label = 2;
|
|
1268
|
+
case 2:
|
|
1269
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
1270
|
+
item = _c.value;
|
|
1271
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
1272
|
+
case 3:
|
|
1273
|
+
_e.sent();
|
|
1274
|
+
_e.label = 4;
|
|
1275
|
+
case 4:
|
|
1276
|
+
_c = _b.next();
|
|
1277
|
+
return [3 /*break*/, 2];
|
|
1278
|
+
case 5: return [3 /*break*/, 8];
|
|
1279
|
+
case 6:
|
|
1280
|
+
e_1_1 = _e.sent();
|
|
1281
|
+
e_1 = { error: e_1_1 };
|
|
1282
|
+
return [3 /*break*/, 8];
|
|
1283
|
+
case 7:
|
|
1284
|
+
try {
|
|
1285
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
1286
|
+
}
|
|
1287
|
+
finally { if (e_1) throw e_1.error; }
|
|
1288
|
+
return [7 /*endfinally*/];
|
|
1289
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
1290
|
+
case 9:
|
|
1291
|
+
_e.sent();
|
|
1292
|
+
return [2 /*return*/];
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
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"}];
|
|
1130
1299
|
|
|
1131
1300
|
var defaultDiacriticsRemovalMap = [
|
|
1132
1301
|
{
|
|
@@ -1453,6 +1622,14 @@
|
|
|
1453
1622
|
* Function normalizes title to name which can be used as identifier
|
|
1454
1623
|
*/
|
|
1455
1624
|
function titleToName(value) {
|
|
1625
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
1626
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1627
|
+
return value;
|
|
1628
|
+
}
|
|
1629
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
1630
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1631
|
+
return value;
|
|
1632
|
+
}
|
|
1456
1633
|
value = removeEmojis(value);
|
|
1457
1634
|
value = normalizeToKebabCase(value);
|
|
1458
1635
|
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
@@ -1790,100 +1967,9 @@
|
|
|
1790
1967
|
/**
|
|
1791
1968
|
* The version of the Promptbook library
|
|
1792
1969
|
*/
|
|
1793
|
-
var PROMPTBOOK_VERSION = '0.
|
|
1970
|
+
var PROMPTBOOK_VERSION = '0.61.0-9';
|
|
1794
1971
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1795
1972
|
|
|
1796
|
-
/**
|
|
1797
|
-
* Function `addUsage` will add multiple usages into one
|
|
1798
|
-
*
|
|
1799
|
-
* Note: If you provide 0 values, it returns void usage
|
|
1800
|
-
*/
|
|
1801
|
-
function addUsage() {
|
|
1802
|
-
var usageItems = [];
|
|
1803
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1804
|
-
usageItems[_i] = arguments[_i];
|
|
1805
|
-
}
|
|
1806
|
-
var initialStructure = {
|
|
1807
|
-
price: { value: 0 },
|
|
1808
|
-
input: {
|
|
1809
|
-
tokensCount: { value: 0 },
|
|
1810
|
-
charactersCount: { value: 0 },
|
|
1811
|
-
wordsCount: { value: 0 },
|
|
1812
|
-
sentencesCount: { value: 0 },
|
|
1813
|
-
linesCount: { value: 0 },
|
|
1814
|
-
paragraphsCount: { value: 0 },
|
|
1815
|
-
pagesCount: { value: 0 },
|
|
1816
|
-
},
|
|
1817
|
-
output: {
|
|
1818
|
-
tokensCount: { value: 0 },
|
|
1819
|
-
charactersCount: { value: 0 },
|
|
1820
|
-
wordsCount: { value: 0 },
|
|
1821
|
-
sentencesCount: { value: 0 },
|
|
1822
|
-
linesCount: { value: 0 },
|
|
1823
|
-
paragraphsCount: { value: 0 },
|
|
1824
|
-
pagesCount: { value: 0 },
|
|
1825
|
-
},
|
|
1826
|
-
};
|
|
1827
|
-
return usageItems.reduce(function (acc, item) {
|
|
1828
|
-
var e_1, _a, e_2, _b;
|
|
1829
|
-
var _c;
|
|
1830
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1831
|
-
try {
|
|
1832
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1833
|
-
var key = _e.value;
|
|
1834
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1835
|
-
//@ts-ignore
|
|
1836
|
-
if (item.input[key]) {
|
|
1837
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1838
|
-
//@ts-ignore
|
|
1839
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
1840
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1841
|
-
//@ts-ignore
|
|
1842
|
-
if (item.input[key].isUncertain) {
|
|
1843
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1844
|
-
//@ts-ignore
|
|
1845
|
-
acc.input[key].isUncertain = true;
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1851
|
-
finally {
|
|
1852
|
-
try {
|
|
1853
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1854
|
-
}
|
|
1855
|
-
finally { if (e_1) throw e_1.error; }
|
|
1856
|
-
}
|
|
1857
|
-
try {
|
|
1858
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1859
|
-
var key = _g.value;
|
|
1860
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1861
|
-
//@ts-ignore
|
|
1862
|
-
if (item.output[key]) {
|
|
1863
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1864
|
-
//@ts-ignore
|
|
1865
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
1866
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1867
|
-
//@ts-ignore
|
|
1868
|
-
if (item.output[key].isUncertain) {
|
|
1869
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1870
|
-
//@ts-ignore
|
|
1871
|
-
acc.output[key].isUncertain = true;
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1877
|
-
finally {
|
|
1878
|
-
try {
|
|
1879
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1880
|
-
}
|
|
1881
|
-
finally { if (e_2) throw e_2.error; }
|
|
1882
|
-
}
|
|
1883
|
-
return acc;
|
|
1884
|
-
}, initialStructure);
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
1973
|
/**
|
|
1888
1974
|
* Counts number of characters in the text
|
|
1889
1975
|
*/
|
|
@@ -2087,8 +2173,6 @@
|
|
|
2087
2173
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
2088
2174
|
// TODO: !!!!! Implement new commands
|
|
2089
2175
|
validatePipeline(pipeline);
|
|
2090
|
-
// TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
|
|
2091
|
-
// TODO: !!!!! Do here personaToModelRequirements
|
|
2092
2176
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2093
2177
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2094
2178
|
function executeSingleTemplate(currentTemplate) {
|
|
@@ -2609,53 +2693,74 @@
|
|
|
2609
2693
|
return pipelineExecutor;
|
|
2610
2694
|
}
|
|
2611
2695
|
/**
|
|
2696
|
+
* TODO: [🪂] Pass maxParallelCount here
|
|
2612
2697
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2613
2698
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2614
2699
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2615
2700
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2616
2701
|
*/
|
|
2617
2702
|
|
|
2618
|
-
|
|
2703
|
+
/**
|
|
2704
|
+
* Just marks a place of place where should be something implemented
|
|
2705
|
+
* No side effects.
|
|
2706
|
+
*
|
|
2707
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2708
|
+
*
|
|
2709
|
+
* @param value any values
|
|
2710
|
+
* @returns void
|
|
2711
|
+
*/
|
|
2712
|
+
function TODO_USE() {
|
|
2713
|
+
var value = [];
|
|
2714
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2715
|
+
value[_i] = arguments[_i];
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
// TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
|
|
2719
|
+
|
|
2720
|
+
/**
|
|
2721
|
+
* @@@
|
|
2722
|
+
*/
|
|
2723
|
+
function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
2619
2724
|
return __awaiter(this, void 0, void 0, function () {
|
|
2620
|
-
var
|
|
2621
|
-
var
|
|
2725
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2726
|
+
var _f, _g, _h;
|
|
2622
2727
|
var _this = this;
|
|
2623
|
-
return __generator(this, function (
|
|
2624
|
-
switch (
|
|
2728
|
+
return __generator(this, function (_j) {
|
|
2729
|
+
switch (_j.label) {
|
|
2625
2730
|
case 0:
|
|
2626
|
-
|
|
2731
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2732
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2627
2733
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2628
|
-
_b = createPipelineExecutor;
|
|
2629
|
-
_e = {};
|
|
2630
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2631
|
-
case 1:
|
|
2632
|
-
prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
|
|
2633
|
-
_e.tools = {
|
|
2634
|
-
llm: llmTools,
|
|
2635
|
-
},
|
|
2636
|
-
_e)]);
|
|
2637
2734
|
_c = createPipelineExecutor;
|
|
2638
2735
|
_f = {};
|
|
2639
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2640
|
-
case
|
|
2641
|
-
|
|
2736
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2737
|
+
case 1:
|
|
2738
|
+
prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
|
|
2642
2739
|
_f.tools = {
|
|
2643
2740
|
llm: llmTools,
|
|
2644
2741
|
},
|
|
2645
2742
|
_f)]);
|
|
2646
2743
|
_d = createPipelineExecutor;
|
|
2647
2744
|
_g = {};
|
|
2648
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2649
|
-
case
|
|
2650
|
-
|
|
2745
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
|
|
2746
|
+
case 2:
|
|
2747
|
+
prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
|
|
2651
2748
|
_g.tools = {
|
|
2652
2749
|
llm: llmTools,
|
|
2653
2750
|
},
|
|
2654
2751
|
_g)]);
|
|
2752
|
+
_e = createPipelineExecutor;
|
|
2753
|
+
_h = {};
|
|
2754
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
|
|
2755
|
+
case 3:
|
|
2756
|
+
prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
|
|
2757
|
+
_h.tools = {
|
|
2758
|
+
llm: llmTools,
|
|
2759
|
+
},
|
|
2760
|
+
_h)]);
|
|
2655
2761
|
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
|
|
2656
2762
|
case 4:
|
|
2657
|
-
result =
|
|
2658
|
-
// TODO: [0] !!! Aggeregate usage
|
|
2763
|
+
result = _j.sent();
|
|
2659
2764
|
assertsExecutionSuccessful(result);
|
|
2660
2765
|
outputParameters = result.outputParameters;
|
|
2661
2766
|
knowledgeRaw = outputParameters.knowledge;
|
|
@@ -2664,9 +2769,9 @@
|
|
|
2664
2769
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2665
2770
|
}
|
|
2666
2771
|
return [4 /*yield*/, Promise.all(
|
|
2667
|
-
// TODO:
|
|
2772
|
+
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
2668
2773
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2669
|
-
var name, title, content, keywords, index,
|
|
2774
|
+
var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
2670
2775
|
return __generator(this, function (_c) {
|
|
2671
2776
|
switch (_c.label) {
|
|
2672
2777
|
case 0:
|
|
@@ -2675,12 +2780,6 @@
|
|
|
2675
2780
|
content = spaceTrim__default["default"](knowledgeTextPiece);
|
|
2676
2781
|
keywords = [];
|
|
2677
2782
|
index = [];
|
|
2678
|
-
sources = [
|
|
2679
|
-
{
|
|
2680
|
-
title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
|
|
2681
|
-
href: '#' /* <- TODO: !!! Unhardcode */,
|
|
2682
|
-
},
|
|
2683
|
-
];
|
|
2684
2783
|
_c.label = 1;
|
|
2685
2784
|
case 1:
|
|
2686
2785
|
_c.trys.push([1, 7, , 8]);
|
|
@@ -2715,7 +2814,6 @@
|
|
|
2715
2814
|
})];
|
|
2716
2815
|
case 5:
|
|
2717
2816
|
embeddingResult = _c.sent();
|
|
2718
|
-
// TODO: [0] !!! Aggeregate usage embeddingResult.usage
|
|
2719
2817
|
index.push({
|
|
2720
2818
|
modelName: embeddingResult.modelName,
|
|
2721
2819
|
position: embeddingResult.content,
|
|
@@ -2733,20 +2831,186 @@
|
|
|
2733
2831
|
content: content,
|
|
2734
2832
|
keywords: keywords,
|
|
2735
2833
|
index: index,
|
|
2736
|
-
|
|
2834
|
+
// <- TODO: [☀] sources,
|
|
2737
2835
|
}];
|
|
2738
2836
|
}
|
|
2739
2837
|
});
|
|
2740
2838
|
}); }))];
|
|
2741
2839
|
case 5:
|
|
2742
|
-
knowledge =
|
|
2840
|
+
knowledge = _j.sent();
|
|
2743
2841
|
return [2 /*return*/, knowledge];
|
|
2744
2842
|
}
|
|
2745
2843
|
});
|
|
2746
2844
|
});
|
|
2747
2845
|
}
|
|
2748
2846
|
/**
|
|
2749
|
-
* 11:11
|
|
2847
|
+
* TODO: [🪂] Do it in parallel 11:11
|
|
2848
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2849
|
+
*/
|
|
2850
|
+
|
|
2851
|
+
/**
|
|
2852
|
+
* Prepares the knowle
|
|
2853
|
+
*
|
|
2854
|
+
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2855
|
+
* @private within the package
|
|
2856
|
+
*/
|
|
2857
|
+
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2858
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2859
|
+
var _a, maxParallelCount, knowledgePrepared;
|
|
2860
|
+
var _this = this;
|
|
2861
|
+
return __generator(this, function (_b) {
|
|
2862
|
+
switch (_b.label) {
|
|
2863
|
+
case 0:
|
|
2864
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2865
|
+
knowledgePrepared = [];
|
|
2866
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
2867
|
+
var partialPieces, pieces;
|
|
2868
|
+
return __generator(this, function (_a) {
|
|
2869
|
+
switch (_a.label) {
|
|
2870
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2871
|
+
options)];
|
|
2872
|
+
case 1:
|
|
2873
|
+
partialPieces = _a.sent();
|
|
2874
|
+
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
2875
|
+
{
|
|
2876
|
+
name: knowledgeSource.name,
|
|
2877
|
+
// line, column <- TODO: [☀]
|
|
2878
|
+
// <- TODO: [❎]
|
|
2879
|
+
},
|
|
2880
|
+
] })); });
|
|
2881
|
+
knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
|
|
2882
|
+
return [2 /*return*/];
|
|
2883
|
+
}
|
|
2884
|
+
});
|
|
2885
|
+
}); })];
|
|
2886
|
+
case 1:
|
|
2887
|
+
_b.sent();
|
|
2888
|
+
return [2 /*return*/, knowledgePrepared];
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2893
|
+
/*
|
|
2894
|
+
TODO: [🧊] This is how it can look in future
|
|
2895
|
+
> type PrepareKnowledgeKnowledge = {
|
|
2896
|
+
> /**
|
|
2897
|
+
> * Unprepared knowledge
|
|
2898
|
+
> * /
|
|
2899
|
+
> readonly knowledgeSources: Array<KnowledgeSourceJson>;
|
|
2900
|
+
> };
|
|
2901
|
+
>
|
|
2902
|
+
> export async function prepareKnowledgePieces(
|
|
2903
|
+
> knowledge: PrepareKnowledgeKnowledge,
|
|
2904
|
+
> options: PrepareOptions,
|
|
2905
|
+
> ):
|
|
2906
|
+
*/
|
|
2907
|
+
/**
|
|
2908
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2909
|
+
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2910
|
+
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
2911
|
+
* TODO: [🧠][❎] Do here propper M:N mapping
|
|
2912
|
+
* [x] One source can make multiple pieces
|
|
2913
|
+
* [ ] One piece can have multiple sources
|
|
2914
|
+
*/
|
|
2915
|
+
|
|
2916
|
+
/**
|
|
2917
|
+
* Prepares the persona for the pipeline
|
|
2918
|
+
*
|
|
2919
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2920
|
+
* @private within the package
|
|
2921
|
+
*/
|
|
2922
|
+
function preparePersona(personaDescription, options) {
|
|
2923
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2924
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose;
|
|
2925
|
+
return __generator(this, function (_c) {
|
|
2926
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2927
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2928
|
+
TODO_USE(personaDescription); // <- !!!!!
|
|
2929
|
+
TODO_USE(llmTools); // <- !!!!!
|
|
2930
|
+
TODO_USE(isVerbose); // <- !!!!!
|
|
2931
|
+
return [2 /*return*/, {
|
|
2932
|
+
modelVariant: 'CHAT',
|
|
2933
|
+
modelName: 'gpt-4',
|
|
2934
|
+
}];
|
|
2935
|
+
});
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
/**
|
|
2939
|
+
* TODO: [🪂] Do it in parallel
|
|
2940
|
+
*/
|
|
2941
|
+
|
|
2942
|
+
/**
|
|
2943
|
+
* Simple wrapper `new Date().toISOString()`
|
|
2944
|
+
*
|
|
2945
|
+
* @returns string_date branded type
|
|
2946
|
+
*/
|
|
2947
|
+
function $currentDate() {
|
|
2948
|
+
return new Date().toISOString();
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
/**
|
|
2952
|
+
* Prepare pipeline from string (markdown) format to JSON format
|
|
2953
|
+
*
|
|
2954
|
+
* Note: This function does not validate logic of the pipeline
|
|
2955
|
+
* Note: This function acts as part of compilation process
|
|
2956
|
+
*/
|
|
2957
|
+
function preparePipeline(pipeline, options) {
|
|
2958
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2959
|
+
var _a, maxParallelCount,
|
|
2960
|
+
/*
|
|
2961
|
+
<- TODO: [🧠][0] `promptbookVersion` */
|
|
2962
|
+
knowledgeSources /*
|
|
2963
|
+
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
2964
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
|
|
2965
|
+
var _this = this;
|
|
2966
|
+
return __generator(this, function (_b) {
|
|
2967
|
+
switch (_b.label) {
|
|
2968
|
+
case 0:
|
|
2969
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2970
|
+
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
2971
|
+
currentPreparation = {
|
|
2972
|
+
id: 1,
|
|
2973
|
+
date: $currentDate(),
|
|
2974
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2975
|
+
modelUsage: addUsage(),
|
|
2976
|
+
};
|
|
2977
|
+
preparations = [
|
|
2978
|
+
// ...preparations
|
|
2979
|
+
// <- TODO: [🧊]
|
|
2980
|
+
currentPreparation,
|
|
2981
|
+
];
|
|
2982
|
+
preparedPersonas = [];
|
|
2983
|
+
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 () {
|
|
2984
|
+
var modelRequirements, preparedPersona;
|
|
2985
|
+
return __generator(this, function (_a) {
|
|
2986
|
+
switch (_a.label) {
|
|
2987
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
|
|
2988
|
+
case 1:
|
|
2989
|
+
modelRequirements = _a.sent();
|
|
2990
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
2991
|
+
preparedPersonas.push(preparedPersona);
|
|
2992
|
+
return [2 /*return*/];
|
|
2993
|
+
}
|
|
2994
|
+
});
|
|
2995
|
+
}); })];
|
|
2996
|
+
case 1:
|
|
2997
|
+
_b.sent();
|
|
2998
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2999
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
|
|
3000
|
+
case 2:
|
|
3001
|
+
partialknowledgePiecesPrepared = _b.sent();
|
|
3002
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3003
|
+
// ----- /Knowledge preparation -----
|
|
3004
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3005
|
+
}
|
|
3006
|
+
});
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
/**
|
|
3010
|
+
* TODO: Write tests for `preparePipeline`
|
|
3011
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3012
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3013
|
+
* TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
|
|
2750
3014
|
*/
|
|
2751
3015
|
|
|
2752
3016
|
/**
|
|
@@ -2916,6 +3180,7 @@
|
|
|
2916
3180
|
|
|
2917
3181
|
/**
|
|
2918
3182
|
* Units of text measurement
|
|
3183
|
+
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
2919
3184
|
*/
|
|
2920
3185
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2921
3186
|
/**
|
|
@@ -3236,9 +3501,10 @@
|
|
|
3236
3501
|
|
|
3237
3502
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3238
3503
|
/**
|
|
3504
|
+
* TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
|
|
3239
3505
|
* TODO: Maybe figure out better word than "variant"
|
|
3240
3506
|
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3241
|
-
* TODO: [
|
|
3507
|
+
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
3242
3508
|
*/
|
|
3243
3509
|
|
|
3244
3510
|
/**
|
|
@@ -4397,14 +4663,14 @@
|
|
|
4397
4663
|
*/
|
|
4398
4664
|
|
|
4399
4665
|
/**
|
|
4400
|
-
* Compile
|
|
4666
|
+
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4401
4667
|
*
|
|
4402
|
-
* Note: There are
|
|
4668
|
+
* Note: There are 3 similar functions:
|
|
4403
4669
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4404
4670
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
4671
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4405
4672
|
*
|
|
4406
4673
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4407
|
-
* @param options - Options and tools for the compilation
|
|
4408
4674
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
4409
4675
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
4410
4676
|
*
|
|
@@ -4420,7 +4686,10 @@
|
|
|
4420
4686
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
4421
4687
|
parameters: [],
|
|
4422
4688
|
promptTemplates: [],
|
|
4423
|
-
|
|
4689
|
+
knowledgeSources: [],
|
|
4690
|
+
knowledgePieces: [],
|
|
4691
|
+
personas: [],
|
|
4692
|
+
preparations: [],
|
|
4424
4693
|
};
|
|
4425
4694
|
// =============================================================
|
|
4426
4695
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
@@ -4688,6 +4957,7 @@
|
|
|
4688
4957
|
postprocessing: postprocessing,
|
|
4689
4958
|
expectations: expectAmount,
|
|
4690
4959
|
expectFormat: expectFormat,
|
|
4960
|
+
personaName: null,
|
|
4691
4961
|
modelRequirements: templateModelRequirements,
|
|
4692
4962
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4693
4963
|
content: content,
|
|
@@ -4767,11 +5037,12 @@
|
|
|
4767
5037
|
*/
|
|
4768
5038
|
|
|
4769
5039
|
/**
|
|
4770
|
-
* Compile
|
|
5040
|
+
* Compile pipeline from string (markdown) format to JSON format
|
|
4771
5041
|
*
|
|
4772
|
-
* Note: There are
|
|
5042
|
+
* Note: There are 3 similar functions:
|
|
4773
5043
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4774
5044
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5045
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4775
5046
|
*
|
|
4776
5047
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4777
5048
|
* @param options - Options and tools for the compilation
|
|
@@ -4782,22 +5053,18 @@
|
|
|
4782
5053
|
* Note: This function acts as compilation process
|
|
4783
5054
|
*/
|
|
4784
5055
|
function pipelineStringToJson(pipelineString, options) {
|
|
4785
|
-
if (options === void 0) { options = {}; }
|
|
5056
|
+
if (options === void 0) { options = { llmTools: null }; }
|
|
4786
5057
|
return __awaiter(this, void 0, void 0, function () {
|
|
4787
|
-
var llmTools, pipelineJson
|
|
5058
|
+
var llmTools, pipelineJson;
|
|
4788
5059
|
return __generator(this, function (_a) {
|
|
4789
5060
|
switch (_a.label) {
|
|
4790
5061
|
case 0:
|
|
4791
5062
|
llmTools = options.llmTools;
|
|
4792
5063
|
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
4793
|
-
if (!llmTools) return [3 /*break*/, 2];
|
|
4794
|
-
return [4 /*yield*/,
|
|
4795
|
-
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
4796
|
-
llmTools: llmTools,
|
|
4797
|
-
})];
|
|
5064
|
+
if (!(llmTools !== null)) return [3 /*break*/, 2];
|
|
5065
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
|
|
4798
5066
|
case 1:
|
|
4799
|
-
|
|
4800
|
-
pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
|
|
5067
|
+
pipelineJson = _a.sent();
|
|
4801
5068
|
_a.label = 2;
|
|
4802
5069
|
case 2: return [2 /*return*/, pipelineJson];
|
|
4803
5070
|
}
|
|
@@ -4994,6 +5261,20 @@
|
|
|
4994
5261
|
return CollectionError;
|
|
4995
5262
|
}(Error));
|
|
4996
5263
|
|
|
5264
|
+
/**
|
|
5265
|
+
* This error type indicates that the version of the pipeline is not matching the expected version
|
|
5266
|
+
*/
|
|
5267
|
+
var VersionMismatch = /** @class */ (function (_super) {
|
|
5268
|
+
__extends(VersionMismatch, _super);
|
|
5269
|
+
function VersionMismatch(message, expectedVersion) {
|
|
5270
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n This error indicates that there is error with compatibility\n\n Expected version:\n ").concat(expectedVersion, "\n\n Current version:\n ").concat(PROMPTBOOK_VERSION, "\n\n "); })) || this;
|
|
5271
|
+
_this.name = 'UnexpectedError';
|
|
5272
|
+
Object.setPrototypeOf(_this, VersionMismatch.prototype);
|
|
5273
|
+
return _this;
|
|
5274
|
+
}
|
|
5275
|
+
return VersionMismatch;
|
|
5276
|
+
}(Error));
|
|
5277
|
+
|
|
4997
5278
|
/**
|
|
4998
5279
|
* Pretty print an embedding vector for logging
|
|
4999
5280
|
*/
|
|
@@ -5082,6 +5363,19 @@
|
|
|
5082
5363
|
return SimplePromptInterfaceTools;
|
|
5083
5364
|
}());
|
|
5084
5365
|
|
|
5366
|
+
/**
|
|
5367
|
+
* Unprepare just strips the preparation data of the pipeline
|
|
5368
|
+
*/
|
|
5369
|
+
function unpreparePipeline(pipeline) {
|
|
5370
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
|
|
5371
|
+
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
5372
|
+
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
5373
|
+
return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
5374
|
+
}
|
|
5375
|
+
/**
|
|
5376
|
+
* TODO: Write tests for `preparePipeline`
|
|
5377
|
+
*/
|
|
5378
|
+
|
|
5085
5379
|
/**
|
|
5086
5380
|
* Default options for generating an execution report string
|
|
5087
5381
|
*/
|
|
@@ -5406,6 +5700,7 @@
|
|
|
5406
5700
|
exports.ReferenceError = ReferenceError$1;
|
|
5407
5701
|
exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
|
|
5408
5702
|
exports.UnexpectedError = UnexpectedError;
|
|
5703
|
+
exports.VersionMismatch = VersionMismatch;
|
|
5409
5704
|
exports.addUsage = addUsage;
|
|
5410
5705
|
exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
|
|
5411
5706
|
exports.checkExpectations = checkExpectations;
|
|
@@ -5423,7 +5718,9 @@
|
|
|
5423
5718
|
exports.pipelineStringToJson = pipelineStringToJson;
|
|
5424
5719
|
exports.pipelineStringToJsonSync = pipelineStringToJsonSync;
|
|
5425
5720
|
exports.prepareKnowledgeFromMarkdown = prepareKnowledgeFromMarkdown;
|
|
5721
|
+
exports.preparePipeline = preparePipeline;
|
|
5426
5722
|
exports.prettifyPipelineString = prettifyPipelineString;
|
|
5723
|
+
exports.unpreparePipeline = unpreparePipeline;
|
|
5427
5724
|
exports.usageToWorktime = usageToWorktime;
|
|
5428
5725
|
exports.validatePipeline = validatePipeline;
|
|
5429
5726
|
|