@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/esm/index.es.js
CHANGED
|
@@ -394,6 +394,10 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
394
394
|
* The maximum number of iterations for a loops
|
|
395
395
|
*/
|
|
396
396
|
var LOOP_LIMIT = 1000;
|
|
397
|
+
/**
|
|
398
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
399
|
+
*/
|
|
400
|
+
var MAX_PARALLEL_COUNT = 5;
|
|
397
401
|
/**
|
|
398
402
|
* The names of the parameters that are reserved for special purposes
|
|
399
403
|
*/
|
|
@@ -1119,7 +1123,172 @@ var BlockTypes = [
|
|
|
1119
1123
|
// <- [🩻]
|
|
1120
1124
|
];
|
|
1121
1125
|
|
|
1122
|
-
|
|
1126
|
+
/**
|
|
1127
|
+
* Function `addUsage` will add multiple usages into one
|
|
1128
|
+
*
|
|
1129
|
+
* Note: If you provide 0 values, it returns void usage
|
|
1130
|
+
*/
|
|
1131
|
+
function addUsage() {
|
|
1132
|
+
var usageItems = [];
|
|
1133
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1134
|
+
usageItems[_i] = arguments[_i];
|
|
1135
|
+
}
|
|
1136
|
+
var initialStructure = {
|
|
1137
|
+
price: { value: 0 },
|
|
1138
|
+
input: {
|
|
1139
|
+
tokensCount: { value: 0 },
|
|
1140
|
+
charactersCount: { value: 0 },
|
|
1141
|
+
wordsCount: { value: 0 },
|
|
1142
|
+
sentencesCount: { value: 0 },
|
|
1143
|
+
linesCount: { value: 0 },
|
|
1144
|
+
paragraphsCount: { value: 0 },
|
|
1145
|
+
pagesCount: { value: 0 },
|
|
1146
|
+
},
|
|
1147
|
+
output: {
|
|
1148
|
+
tokensCount: { value: 0 },
|
|
1149
|
+
charactersCount: { value: 0 },
|
|
1150
|
+
wordsCount: { value: 0 },
|
|
1151
|
+
sentencesCount: { value: 0 },
|
|
1152
|
+
linesCount: { value: 0 },
|
|
1153
|
+
paragraphsCount: { value: 0 },
|
|
1154
|
+
pagesCount: { value: 0 },
|
|
1155
|
+
},
|
|
1156
|
+
};
|
|
1157
|
+
return usageItems.reduce(function (acc, item) {
|
|
1158
|
+
var e_1, _a, e_2, _b;
|
|
1159
|
+
var _c;
|
|
1160
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1161
|
+
try {
|
|
1162
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1163
|
+
var key = _e.value;
|
|
1164
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1165
|
+
//@ts-ignore
|
|
1166
|
+
if (item.input[key]) {
|
|
1167
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1168
|
+
//@ts-ignore
|
|
1169
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
1170
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1171
|
+
//@ts-ignore
|
|
1172
|
+
if (item.input[key].isUncertain) {
|
|
1173
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1174
|
+
//@ts-ignore
|
|
1175
|
+
acc.input[key].isUncertain = true;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1181
|
+
finally {
|
|
1182
|
+
try {
|
|
1183
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1184
|
+
}
|
|
1185
|
+
finally { if (e_1) throw e_1.error; }
|
|
1186
|
+
}
|
|
1187
|
+
try {
|
|
1188
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1189
|
+
var key = _g.value;
|
|
1190
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1191
|
+
//@ts-ignore
|
|
1192
|
+
if (item.output[key]) {
|
|
1193
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1194
|
+
//@ts-ignore
|
|
1195
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
1196
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1197
|
+
//@ts-ignore
|
|
1198
|
+
if (item.output[key].isUncertain) {
|
|
1199
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1200
|
+
//@ts-ignore
|
|
1201
|
+
acc.output[key].isUncertain = true;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1207
|
+
finally {
|
|
1208
|
+
try {
|
|
1209
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1210
|
+
}
|
|
1211
|
+
finally { if (e_2) throw e_2.error; }
|
|
1212
|
+
}
|
|
1213
|
+
return acc;
|
|
1214
|
+
}, initialStructure);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
/**
|
|
1218
|
+
* Async version of Array.forEach
|
|
1219
|
+
*
|
|
1220
|
+
* @param array - Array to iterate over
|
|
1221
|
+
* @param options - Options for the function
|
|
1222
|
+
* @param callbackfunction - Function to call for each item
|
|
1223
|
+
*/
|
|
1224
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
1225
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1226
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
1227
|
+
var e_1, _d;
|
|
1228
|
+
return __generator(this, function (_e) {
|
|
1229
|
+
switch (_e.label) {
|
|
1230
|
+
case 0:
|
|
1231
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
1232
|
+
index = 0;
|
|
1233
|
+
runningTasks = [];
|
|
1234
|
+
tasks = [];
|
|
1235
|
+
_loop_1 = function (item) {
|
|
1236
|
+
var currentIndex, task;
|
|
1237
|
+
return __generator(this, function (_f) {
|
|
1238
|
+
switch (_f.label) {
|
|
1239
|
+
case 0:
|
|
1240
|
+
currentIndex = index++;
|
|
1241
|
+
task = callbackfunction(item, currentIndex, array);
|
|
1242
|
+
tasks.push(task);
|
|
1243
|
+
runningTasks.push(task);
|
|
1244
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
1245
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
1246
|
+
});
|
|
1247
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
1248
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
1249
|
+
case 1:
|
|
1250
|
+
_f.sent();
|
|
1251
|
+
_f.label = 2;
|
|
1252
|
+
case 2: return [2 /*return*/];
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
};
|
|
1256
|
+
_e.label = 1;
|
|
1257
|
+
case 1:
|
|
1258
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
1259
|
+
_b = __values(array), _c = _b.next();
|
|
1260
|
+
_e.label = 2;
|
|
1261
|
+
case 2:
|
|
1262
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
1263
|
+
item = _c.value;
|
|
1264
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
1265
|
+
case 3:
|
|
1266
|
+
_e.sent();
|
|
1267
|
+
_e.label = 4;
|
|
1268
|
+
case 4:
|
|
1269
|
+
_c = _b.next();
|
|
1270
|
+
return [3 /*break*/, 2];
|
|
1271
|
+
case 5: return [3 /*break*/, 8];
|
|
1272
|
+
case 6:
|
|
1273
|
+
e_1_1 = _e.sent();
|
|
1274
|
+
e_1 = { error: e_1_1 };
|
|
1275
|
+
return [3 /*break*/, 8];
|
|
1276
|
+
case 7:
|
|
1277
|
+
try {
|
|
1278
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
1279
|
+
}
|
|
1280
|
+
finally { if (e_1) throw e_1.error; }
|
|
1281
|
+
return [7 /*endfinally*/];
|
|
1282
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
1283
|
+
case 9:
|
|
1284
|
+
_e.sent();
|
|
1285
|
+
return [2 /*return*/];
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
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"}];
|
|
1123
1292
|
|
|
1124
1293
|
var defaultDiacriticsRemovalMap = [
|
|
1125
1294
|
{
|
|
@@ -1446,6 +1615,14 @@ function removeEmojis(text) {
|
|
|
1446
1615
|
* Function normalizes title to name which can be used as identifier
|
|
1447
1616
|
*/
|
|
1448
1617
|
function titleToName(value) {
|
|
1618
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
1619
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1620
|
+
return value;
|
|
1621
|
+
}
|
|
1622
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
1623
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1624
|
+
return value;
|
|
1625
|
+
}
|
|
1449
1626
|
value = removeEmojis(value);
|
|
1450
1627
|
value = normalizeToKebabCase(value);
|
|
1451
1628
|
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
@@ -1783,100 +1960,9 @@ function arrayableToArray(input) {
|
|
|
1783
1960
|
/**
|
|
1784
1961
|
* The version of the Promptbook library
|
|
1785
1962
|
*/
|
|
1786
|
-
var PROMPTBOOK_VERSION = '0.
|
|
1963
|
+
var PROMPTBOOK_VERSION = '0.61.0-9';
|
|
1787
1964
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1788
1965
|
|
|
1789
|
-
/**
|
|
1790
|
-
* Function `addUsage` will add multiple usages into one
|
|
1791
|
-
*
|
|
1792
|
-
* Note: If you provide 0 values, it returns void usage
|
|
1793
|
-
*/
|
|
1794
|
-
function addUsage() {
|
|
1795
|
-
var usageItems = [];
|
|
1796
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1797
|
-
usageItems[_i] = arguments[_i];
|
|
1798
|
-
}
|
|
1799
|
-
var initialStructure = {
|
|
1800
|
-
price: { value: 0 },
|
|
1801
|
-
input: {
|
|
1802
|
-
tokensCount: { value: 0 },
|
|
1803
|
-
charactersCount: { value: 0 },
|
|
1804
|
-
wordsCount: { value: 0 },
|
|
1805
|
-
sentencesCount: { value: 0 },
|
|
1806
|
-
linesCount: { value: 0 },
|
|
1807
|
-
paragraphsCount: { value: 0 },
|
|
1808
|
-
pagesCount: { value: 0 },
|
|
1809
|
-
},
|
|
1810
|
-
output: {
|
|
1811
|
-
tokensCount: { value: 0 },
|
|
1812
|
-
charactersCount: { value: 0 },
|
|
1813
|
-
wordsCount: { value: 0 },
|
|
1814
|
-
sentencesCount: { value: 0 },
|
|
1815
|
-
linesCount: { value: 0 },
|
|
1816
|
-
paragraphsCount: { value: 0 },
|
|
1817
|
-
pagesCount: { value: 0 },
|
|
1818
|
-
},
|
|
1819
|
-
};
|
|
1820
|
-
return usageItems.reduce(function (acc, item) {
|
|
1821
|
-
var e_1, _a, e_2, _b;
|
|
1822
|
-
var _c;
|
|
1823
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1824
|
-
try {
|
|
1825
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1826
|
-
var key = _e.value;
|
|
1827
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1828
|
-
//@ts-ignore
|
|
1829
|
-
if (item.input[key]) {
|
|
1830
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1831
|
-
//@ts-ignore
|
|
1832
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
1833
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1834
|
-
//@ts-ignore
|
|
1835
|
-
if (item.input[key].isUncertain) {
|
|
1836
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1837
|
-
//@ts-ignore
|
|
1838
|
-
acc.input[key].isUncertain = true;
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1844
|
-
finally {
|
|
1845
|
-
try {
|
|
1846
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1847
|
-
}
|
|
1848
|
-
finally { if (e_1) throw e_1.error; }
|
|
1849
|
-
}
|
|
1850
|
-
try {
|
|
1851
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1852
|
-
var key = _g.value;
|
|
1853
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1854
|
-
//@ts-ignore
|
|
1855
|
-
if (item.output[key]) {
|
|
1856
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1857
|
-
//@ts-ignore
|
|
1858
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
1859
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1860
|
-
//@ts-ignore
|
|
1861
|
-
if (item.output[key].isUncertain) {
|
|
1862
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1863
|
-
//@ts-ignore
|
|
1864
|
-
acc.output[key].isUncertain = true;
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1870
|
-
finally {
|
|
1871
|
-
try {
|
|
1872
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1873
|
-
}
|
|
1874
|
-
finally { if (e_2) throw e_2.error; }
|
|
1875
|
-
}
|
|
1876
|
-
return acc;
|
|
1877
|
-
}, initialStructure);
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
1966
|
/**
|
|
1881
1967
|
* Counts number of characters in the text
|
|
1882
1968
|
*/
|
|
@@ -2080,8 +2166,6 @@ function createPipelineExecutor(options) {
|
|
|
2080
2166
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
2081
2167
|
// TODO: !!!!! Implement new commands
|
|
2082
2168
|
validatePipeline(pipeline);
|
|
2083
|
-
// TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
|
|
2084
|
-
// TODO: !!!!! Do here personaToModelRequirements
|
|
2085
2169
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2086
2170
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2087
2171
|
function executeSingleTemplate(currentTemplate) {
|
|
@@ -2602,53 +2686,74 @@ function createPipelineExecutor(options) {
|
|
|
2602
2686
|
return pipelineExecutor;
|
|
2603
2687
|
}
|
|
2604
2688
|
/**
|
|
2689
|
+
* TODO: [🪂] Pass maxParallelCount here
|
|
2605
2690
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2606
2691
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2607
2692
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2608
2693
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2609
2694
|
*/
|
|
2610
2695
|
|
|
2611
|
-
|
|
2696
|
+
/**
|
|
2697
|
+
* Just marks a place of place where should be something implemented
|
|
2698
|
+
* No side effects.
|
|
2699
|
+
*
|
|
2700
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2701
|
+
*
|
|
2702
|
+
* @param value any values
|
|
2703
|
+
* @returns void
|
|
2704
|
+
*/
|
|
2705
|
+
function TODO_USE() {
|
|
2706
|
+
var value = [];
|
|
2707
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2708
|
+
value[_i] = arguments[_i];
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
// TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
|
|
2712
|
+
|
|
2713
|
+
/**
|
|
2714
|
+
* @@@
|
|
2715
|
+
*/
|
|
2716
|
+
function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
2612
2717
|
return __awaiter(this, void 0, void 0, function () {
|
|
2613
|
-
var
|
|
2614
|
-
var
|
|
2718
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2719
|
+
var _f, _g, _h;
|
|
2615
2720
|
var _this = this;
|
|
2616
|
-
return __generator(this, function (
|
|
2617
|
-
switch (
|
|
2721
|
+
return __generator(this, function (_j) {
|
|
2722
|
+
switch (_j.label) {
|
|
2618
2723
|
case 0:
|
|
2619
|
-
|
|
2724
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2725
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2620
2726
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2621
|
-
_b = createPipelineExecutor;
|
|
2622
|
-
_e = {};
|
|
2623
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2624
|
-
case 1:
|
|
2625
|
-
prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
|
|
2626
|
-
_e.tools = {
|
|
2627
|
-
llm: llmTools,
|
|
2628
|
-
},
|
|
2629
|
-
_e)]);
|
|
2630
2727
|
_c = createPipelineExecutor;
|
|
2631
2728
|
_f = {};
|
|
2632
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2633
|
-
case
|
|
2634
|
-
|
|
2729
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2730
|
+
case 1:
|
|
2731
|
+
prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
|
|
2635
2732
|
_f.tools = {
|
|
2636
2733
|
llm: llmTools,
|
|
2637
2734
|
},
|
|
2638
2735
|
_f)]);
|
|
2639
2736
|
_d = createPipelineExecutor;
|
|
2640
2737
|
_g = {};
|
|
2641
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2642
|
-
case
|
|
2643
|
-
|
|
2738
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
|
|
2739
|
+
case 2:
|
|
2740
|
+
prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
|
|
2644
2741
|
_g.tools = {
|
|
2645
2742
|
llm: llmTools,
|
|
2646
2743
|
},
|
|
2647
2744
|
_g)]);
|
|
2745
|
+
_e = createPipelineExecutor;
|
|
2746
|
+
_h = {};
|
|
2747
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
|
|
2748
|
+
case 3:
|
|
2749
|
+
prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
|
|
2750
|
+
_h.tools = {
|
|
2751
|
+
llm: llmTools,
|
|
2752
|
+
},
|
|
2753
|
+
_h)]);
|
|
2648
2754
|
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
|
|
2649
2755
|
case 4:
|
|
2650
|
-
result =
|
|
2651
|
-
// TODO: [0] !!! Aggeregate usage
|
|
2756
|
+
result = _j.sent();
|
|
2652
2757
|
assertsExecutionSuccessful(result);
|
|
2653
2758
|
outputParameters = result.outputParameters;
|
|
2654
2759
|
knowledgeRaw = outputParameters.knowledge;
|
|
@@ -2657,9 +2762,9 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2657
2762
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2658
2763
|
}
|
|
2659
2764
|
return [4 /*yield*/, Promise.all(
|
|
2660
|
-
// TODO:
|
|
2765
|
+
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
2661
2766
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2662
|
-
var name, title, content, keywords, index,
|
|
2767
|
+
var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
2663
2768
|
return __generator(this, function (_c) {
|
|
2664
2769
|
switch (_c.label) {
|
|
2665
2770
|
case 0:
|
|
@@ -2668,12 +2773,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2668
2773
|
content = spaceTrim(knowledgeTextPiece);
|
|
2669
2774
|
keywords = [];
|
|
2670
2775
|
index = [];
|
|
2671
|
-
sources = [
|
|
2672
|
-
{
|
|
2673
|
-
title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
|
|
2674
|
-
href: '#' /* <- TODO: !!! Unhardcode */,
|
|
2675
|
-
},
|
|
2676
|
-
];
|
|
2677
2776
|
_c.label = 1;
|
|
2678
2777
|
case 1:
|
|
2679
2778
|
_c.trys.push([1, 7, , 8]);
|
|
@@ -2708,7 +2807,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2708
2807
|
})];
|
|
2709
2808
|
case 5:
|
|
2710
2809
|
embeddingResult = _c.sent();
|
|
2711
|
-
// TODO: [0] !!! Aggeregate usage embeddingResult.usage
|
|
2712
2810
|
index.push({
|
|
2713
2811
|
modelName: embeddingResult.modelName,
|
|
2714
2812
|
position: embeddingResult.content,
|
|
@@ -2726,20 +2824,186 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2726
2824
|
content: content,
|
|
2727
2825
|
keywords: keywords,
|
|
2728
2826
|
index: index,
|
|
2729
|
-
|
|
2827
|
+
// <- TODO: [☀] sources,
|
|
2730
2828
|
}];
|
|
2731
2829
|
}
|
|
2732
2830
|
});
|
|
2733
2831
|
}); }))];
|
|
2734
2832
|
case 5:
|
|
2735
|
-
knowledge =
|
|
2833
|
+
knowledge = _j.sent();
|
|
2736
2834
|
return [2 /*return*/, knowledge];
|
|
2737
2835
|
}
|
|
2738
2836
|
});
|
|
2739
2837
|
});
|
|
2740
2838
|
}
|
|
2741
2839
|
/**
|
|
2742
|
-
* 11:11
|
|
2840
|
+
* TODO: [🪂] Do it in parallel 11:11
|
|
2841
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2842
|
+
*/
|
|
2843
|
+
|
|
2844
|
+
/**
|
|
2845
|
+
* Prepares the knowle
|
|
2846
|
+
*
|
|
2847
|
+
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2848
|
+
* @private within the package
|
|
2849
|
+
*/
|
|
2850
|
+
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2851
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2852
|
+
var _a, maxParallelCount, knowledgePrepared;
|
|
2853
|
+
var _this = this;
|
|
2854
|
+
return __generator(this, function (_b) {
|
|
2855
|
+
switch (_b.label) {
|
|
2856
|
+
case 0:
|
|
2857
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2858
|
+
knowledgePrepared = [];
|
|
2859
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
2860
|
+
var partialPieces, pieces;
|
|
2861
|
+
return __generator(this, function (_a) {
|
|
2862
|
+
switch (_a.label) {
|
|
2863
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2864
|
+
options)];
|
|
2865
|
+
case 1:
|
|
2866
|
+
partialPieces = _a.sent();
|
|
2867
|
+
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
2868
|
+
{
|
|
2869
|
+
name: knowledgeSource.name,
|
|
2870
|
+
// line, column <- TODO: [☀]
|
|
2871
|
+
// <- TODO: [❎]
|
|
2872
|
+
},
|
|
2873
|
+
] })); });
|
|
2874
|
+
knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
|
|
2875
|
+
return [2 /*return*/];
|
|
2876
|
+
}
|
|
2877
|
+
});
|
|
2878
|
+
}); })];
|
|
2879
|
+
case 1:
|
|
2880
|
+
_b.sent();
|
|
2881
|
+
return [2 /*return*/, knowledgePrepared];
|
|
2882
|
+
}
|
|
2883
|
+
});
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
/*
|
|
2887
|
+
TODO: [🧊] This is how it can look in future
|
|
2888
|
+
> type PrepareKnowledgeKnowledge = {
|
|
2889
|
+
> /**
|
|
2890
|
+
> * Unprepared knowledge
|
|
2891
|
+
> * /
|
|
2892
|
+
> readonly knowledgeSources: Array<KnowledgeSourceJson>;
|
|
2893
|
+
> };
|
|
2894
|
+
>
|
|
2895
|
+
> export async function prepareKnowledgePieces(
|
|
2896
|
+
> knowledge: PrepareKnowledgeKnowledge,
|
|
2897
|
+
> options: PrepareOptions,
|
|
2898
|
+
> ):
|
|
2899
|
+
*/
|
|
2900
|
+
/**
|
|
2901
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2902
|
+
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2903
|
+
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
2904
|
+
* TODO: [🧠][❎] Do here propper M:N mapping
|
|
2905
|
+
* [x] One source can make multiple pieces
|
|
2906
|
+
* [ ] One piece can have multiple sources
|
|
2907
|
+
*/
|
|
2908
|
+
|
|
2909
|
+
/**
|
|
2910
|
+
* Prepares the persona for the pipeline
|
|
2911
|
+
*
|
|
2912
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2913
|
+
* @private within the package
|
|
2914
|
+
*/
|
|
2915
|
+
function preparePersona(personaDescription, options) {
|
|
2916
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2917
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose;
|
|
2918
|
+
return __generator(this, function (_c) {
|
|
2919
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2920
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2921
|
+
TODO_USE(personaDescription); // <- !!!!!
|
|
2922
|
+
TODO_USE(llmTools); // <- !!!!!
|
|
2923
|
+
TODO_USE(isVerbose); // <- !!!!!
|
|
2924
|
+
return [2 /*return*/, {
|
|
2925
|
+
modelVariant: 'CHAT',
|
|
2926
|
+
modelName: 'gpt-4',
|
|
2927
|
+
}];
|
|
2928
|
+
});
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* TODO: [🪂] Do it in parallel
|
|
2933
|
+
*/
|
|
2934
|
+
|
|
2935
|
+
/**
|
|
2936
|
+
* Simple wrapper `new Date().toISOString()`
|
|
2937
|
+
*
|
|
2938
|
+
* @returns string_date branded type
|
|
2939
|
+
*/
|
|
2940
|
+
function $currentDate() {
|
|
2941
|
+
return new Date().toISOString();
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
/**
|
|
2945
|
+
* Prepare pipeline from string (markdown) format to JSON format
|
|
2946
|
+
*
|
|
2947
|
+
* Note: This function does not validate logic of the pipeline
|
|
2948
|
+
* Note: This function acts as part of compilation process
|
|
2949
|
+
*/
|
|
2950
|
+
function preparePipeline(pipeline, options) {
|
|
2951
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2952
|
+
var _a, maxParallelCount,
|
|
2953
|
+
/*
|
|
2954
|
+
<- TODO: [🧠][0] `promptbookVersion` */
|
|
2955
|
+
knowledgeSources /*
|
|
2956
|
+
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
2957
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
|
|
2958
|
+
var _this = this;
|
|
2959
|
+
return __generator(this, function (_b) {
|
|
2960
|
+
switch (_b.label) {
|
|
2961
|
+
case 0:
|
|
2962
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2963
|
+
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
2964
|
+
currentPreparation = {
|
|
2965
|
+
id: 1,
|
|
2966
|
+
date: $currentDate(),
|
|
2967
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2968
|
+
modelUsage: addUsage(),
|
|
2969
|
+
};
|
|
2970
|
+
preparations = [
|
|
2971
|
+
// ...preparations
|
|
2972
|
+
// <- TODO: [🧊]
|
|
2973
|
+
currentPreparation,
|
|
2974
|
+
];
|
|
2975
|
+
preparedPersonas = [];
|
|
2976
|
+
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 () {
|
|
2977
|
+
var modelRequirements, preparedPersona;
|
|
2978
|
+
return __generator(this, function (_a) {
|
|
2979
|
+
switch (_a.label) {
|
|
2980
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
|
|
2981
|
+
case 1:
|
|
2982
|
+
modelRequirements = _a.sent();
|
|
2983
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
2984
|
+
preparedPersonas.push(preparedPersona);
|
|
2985
|
+
return [2 /*return*/];
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
}); })];
|
|
2989
|
+
case 1:
|
|
2990
|
+
_b.sent();
|
|
2991
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2992
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
|
|
2993
|
+
case 2:
|
|
2994
|
+
partialknowledgePiecesPrepared = _b.sent();
|
|
2995
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2996
|
+
// ----- /Knowledge preparation -----
|
|
2997
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
2998
|
+
}
|
|
2999
|
+
});
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
/**
|
|
3003
|
+
* TODO: Write tests for `preparePipeline`
|
|
3004
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3005
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3006
|
+
* TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
|
|
2743
3007
|
*/
|
|
2744
3008
|
|
|
2745
3009
|
/**
|
|
@@ -2909,6 +3173,7 @@ var blockCommandParser = {
|
|
|
2909
3173
|
|
|
2910
3174
|
/**
|
|
2911
3175
|
* Units of text measurement
|
|
3176
|
+
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
2912
3177
|
*/
|
|
2913
3178
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2914
3179
|
/**
|
|
@@ -3229,9 +3494,10 @@ var knowledgeCommandParser = {
|
|
|
3229
3494
|
|
|
3230
3495
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3231
3496
|
/**
|
|
3497
|
+
* TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
|
|
3232
3498
|
* TODO: Maybe figure out better word than "variant"
|
|
3233
3499
|
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3234
|
-
* TODO: [
|
|
3500
|
+
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
3235
3501
|
*/
|
|
3236
3502
|
|
|
3237
3503
|
/**
|
|
@@ -4390,14 +4656,14 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
4390
4656
|
*/
|
|
4391
4657
|
|
|
4392
4658
|
/**
|
|
4393
|
-
* Compile
|
|
4659
|
+
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4394
4660
|
*
|
|
4395
|
-
* Note: There are
|
|
4661
|
+
* Note: There are 3 similar functions:
|
|
4396
4662
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4397
4663
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
4664
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4398
4665
|
*
|
|
4399
4666
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4400
|
-
* @param options - Options and tools for the compilation
|
|
4401
4667
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
4402
4668
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
4403
4669
|
*
|
|
@@ -4413,7 +4679,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4413
4679
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
4414
4680
|
parameters: [],
|
|
4415
4681
|
promptTemplates: [],
|
|
4416
|
-
|
|
4682
|
+
knowledgeSources: [],
|
|
4683
|
+
knowledgePieces: [],
|
|
4684
|
+
personas: [],
|
|
4685
|
+
preparations: [],
|
|
4417
4686
|
};
|
|
4418
4687
|
// =============================================================
|
|
4419
4688
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
@@ -4681,6 +4950,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4681
4950
|
postprocessing: postprocessing,
|
|
4682
4951
|
expectations: expectAmount,
|
|
4683
4952
|
expectFormat: expectFormat,
|
|
4953
|
+
personaName: null,
|
|
4684
4954
|
modelRequirements: templateModelRequirements,
|
|
4685
4955
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4686
4956
|
content: content,
|
|
@@ -4760,11 +5030,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4760
5030
|
*/
|
|
4761
5031
|
|
|
4762
5032
|
/**
|
|
4763
|
-
* Compile
|
|
5033
|
+
* Compile pipeline from string (markdown) format to JSON format
|
|
4764
5034
|
*
|
|
4765
|
-
* Note: There are
|
|
5035
|
+
* Note: There are 3 similar functions:
|
|
4766
5036
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4767
5037
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5038
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4768
5039
|
*
|
|
4769
5040
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4770
5041
|
* @param options - Options and tools for the compilation
|
|
@@ -4775,22 +5046,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4775
5046
|
* Note: This function acts as compilation process
|
|
4776
5047
|
*/
|
|
4777
5048
|
function pipelineStringToJson(pipelineString, options) {
|
|
4778
|
-
if (options === void 0) { options = {}; }
|
|
5049
|
+
if (options === void 0) { options = { llmTools: null }; }
|
|
4779
5050
|
return __awaiter(this, void 0, void 0, function () {
|
|
4780
|
-
var llmTools, pipelineJson
|
|
5051
|
+
var llmTools, pipelineJson;
|
|
4781
5052
|
return __generator(this, function (_a) {
|
|
4782
5053
|
switch (_a.label) {
|
|
4783
5054
|
case 0:
|
|
4784
5055
|
llmTools = options.llmTools;
|
|
4785
5056
|
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
4786
|
-
if (!llmTools) return [3 /*break*/, 2];
|
|
4787
|
-
return [4 /*yield*/,
|
|
4788
|
-
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
4789
|
-
llmTools: llmTools,
|
|
4790
|
-
})];
|
|
5057
|
+
if (!(llmTools !== null)) return [3 /*break*/, 2];
|
|
5058
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
|
|
4791
5059
|
case 1:
|
|
4792
|
-
|
|
4793
|
-
pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
|
|
5060
|
+
pipelineJson = _a.sent();
|
|
4794
5061
|
_a.label = 2;
|
|
4795
5062
|
case 2: return [2 /*return*/, pipelineJson];
|
|
4796
5063
|
}
|
|
@@ -4987,6 +5254,20 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
4987
5254
|
return CollectionError;
|
|
4988
5255
|
}(Error));
|
|
4989
5256
|
|
|
5257
|
+
/**
|
|
5258
|
+
* This error type indicates that the version of the pipeline is not matching the expected version
|
|
5259
|
+
*/
|
|
5260
|
+
var VersionMismatch = /** @class */ (function (_super) {
|
|
5261
|
+
__extends(VersionMismatch, _super);
|
|
5262
|
+
function VersionMismatch(message, expectedVersion) {
|
|
5263
|
+
var _this = _super.call(this, spaceTrim$1(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;
|
|
5264
|
+
_this.name = 'UnexpectedError';
|
|
5265
|
+
Object.setPrototypeOf(_this, VersionMismatch.prototype);
|
|
5266
|
+
return _this;
|
|
5267
|
+
}
|
|
5268
|
+
return VersionMismatch;
|
|
5269
|
+
}(Error));
|
|
5270
|
+
|
|
4990
5271
|
/**
|
|
4991
5272
|
* Pretty print an embedding vector for logging
|
|
4992
5273
|
*/
|
|
@@ -5075,6 +5356,19 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
5075
5356
|
return SimplePromptInterfaceTools;
|
|
5076
5357
|
}());
|
|
5077
5358
|
|
|
5359
|
+
/**
|
|
5360
|
+
* Unprepare just strips the preparation data of the pipeline
|
|
5361
|
+
*/
|
|
5362
|
+
function unpreparePipeline(pipeline) {
|
|
5363
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
|
|
5364
|
+
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
5365
|
+
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
5366
|
+
return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
5367
|
+
}
|
|
5368
|
+
/**
|
|
5369
|
+
* TODO: Write tests for `preparePipeline`
|
|
5370
|
+
*/
|
|
5371
|
+
|
|
5078
5372
|
/**
|
|
5079
5373
|
* Default options for generating an execution report string
|
|
5080
5374
|
*/
|
|
@@ -5385,5 +5679,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
5385
5679
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
5386
5680
|
*/
|
|
5387
5681
|
|
|
5388
|
-
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prettifyPipelineString, usageToWorktime, validatePipeline };
|
|
5682
|
+
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatch, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, unpreparePipeline, usageToWorktime, validatePipeline };
|
|
5389
5683
|
//# sourceMappingURL=index.es.js.map
|