@promptbook/node 0.61.0-1 → 0.61.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +417 -150
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +118 -26
- package/esm/typings/src/_packages/core.index.d.ts +5 -1
- package/esm/typings/src/_packages/types.index.d.ts +5 -3
- package/esm/typings/src/_packages/utils.index.d.ts +1 -2
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +1 -1
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +12 -12
- package/esm/typings/src/config.d.ts +4 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +8 -5
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
- package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
- package/esm/typings/src/errors/VersionMismatch.d.ts +8 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/esm/typings/src/execution/PromptResult.d.ts +5 -5
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +3 -3
- package/esm/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -1
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +7 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/personas/preparePersona.d.ts +13 -0
- package/esm/typings/src/personas/preparePersona.test.d.ts +1 -0
- package/esm/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +15 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +8 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +2 -1
- package/esm/typings/src/types/Parameters.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -2
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +25 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +7 -1
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/esm/typings/src/types/typeAliases.d.ts +27 -13
- package/esm/typings/src/utils/FromtoItems.d.ts +3 -3
- package/esm/typings/src/utils/currentDate.d.ts +7 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/esm/typings/src/utils/organization/TODO.d.ts +4 -0
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +11 -0
- package/esm/typings/src/utils/organization/___.d.ts +4 -0
- package/esm/typings/src/utils/organization/really_any.d.ts +4 -0
- package/package.json +2 -2
- package/umd/index.umd.js +417 -150
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +118 -26
- package/umd/typings/src/_packages/core.index.d.ts +5 -1
- package/umd/typings/src/_packages/types.index.d.ts +5 -3
- package/umd/typings/src/_packages/utils.index.d.ts +1 -2
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +1 -1
- package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
- package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +12 -12
- package/umd/typings/src/config.d.ts +4 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +8 -5
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
- package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/umd/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
- package/umd/typings/src/errors/VersionMismatch.d.ts +8 -0
- package/umd/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/umd/typings/src/execution/PromptResult.d.ts +5 -5
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +3 -3
- package/umd/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -1
- package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
- package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
- package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +7 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +2 -2
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/personas/preparePersona.d.ts +13 -0
- package/umd/typings/src/personas/preparePersona.test.d.ts +1 -0
- package/umd/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +15 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +8 -0
- package/umd/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/umd/typings/src/types/ModelRequirements.d.ts +2 -1
- package/umd/typings/src/types/Parameters.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
- package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -2
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +25 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +7 -1
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/umd/typings/src/types/typeAliases.d.ts +27 -13
- package/umd/typings/src/utils/FromtoItems.d.ts +3 -3
- package/umd/typings/src/utils/currentDate.d.ts +7 -0
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/umd/typings/src/utils/organization/TODO.d.ts +4 -0
- package/umd/typings/src/utils/organization/TODO_USE.d.ts +11 -0
- package/umd/typings/src/utils/organization/___.d.ts +4 -0
- package/umd/typings/src/utils/organization/really_any.d.ts +4 -0
- package/esm/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/esm/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/esm/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- package/umd/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/umd/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/umd/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- /package/esm/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/esm/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
- /package/umd/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/umd/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -128,6 +128,10 @@ function __spreadArray(to, from, pack) {
|
|
|
128
128
|
* The maximum number of iterations for a loops
|
|
129
129
|
*/
|
|
130
130
|
var LOOP_LIMIT = 1000;
|
|
131
|
+
/**
|
|
132
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
133
|
+
*/
|
|
134
|
+
var MAX_PARALLEL_COUNT = 5;
|
|
131
135
|
/**
|
|
132
136
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
133
137
|
*/
|
|
@@ -141,7 +145,172 @@ var RESERVED_PARAMETER_NAMES = [
|
|
|
141
145
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
142
146
|
];
|
|
143
147
|
|
|
144
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Function `addUsage` will add multiple usages into one
|
|
150
|
+
*
|
|
151
|
+
* Note: If you provide 0 values, it returns void usage
|
|
152
|
+
*/
|
|
153
|
+
function addUsage() {
|
|
154
|
+
var usageItems = [];
|
|
155
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
156
|
+
usageItems[_i] = arguments[_i];
|
|
157
|
+
}
|
|
158
|
+
var initialStructure = {
|
|
159
|
+
price: { value: 0 },
|
|
160
|
+
input: {
|
|
161
|
+
tokensCount: { value: 0 },
|
|
162
|
+
charactersCount: { value: 0 },
|
|
163
|
+
wordsCount: { value: 0 },
|
|
164
|
+
sentencesCount: { value: 0 },
|
|
165
|
+
linesCount: { value: 0 },
|
|
166
|
+
paragraphsCount: { value: 0 },
|
|
167
|
+
pagesCount: { value: 0 },
|
|
168
|
+
},
|
|
169
|
+
output: {
|
|
170
|
+
tokensCount: { value: 0 },
|
|
171
|
+
charactersCount: { value: 0 },
|
|
172
|
+
wordsCount: { value: 0 },
|
|
173
|
+
sentencesCount: { value: 0 },
|
|
174
|
+
linesCount: { value: 0 },
|
|
175
|
+
paragraphsCount: { value: 0 },
|
|
176
|
+
pagesCount: { value: 0 },
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
return usageItems.reduce(function (acc, item) {
|
|
180
|
+
var e_1, _a, e_2, _b;
|
|
181
|
+
var _c;
|
|
182
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
183
|
+
try {
|
|
184
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
185
|
+
var key = _e.value;
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
187
|
+
//@ts-ignore
|
|
188
|
+
if (item.input[key]) {
|
|
189
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
190
|
+
//@ts-ignore
|
|
191
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
193
|
+
//@ts-ignore
|
|
194
|
+
if (item.input[key].isUncertain) {
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
196
|
+
//@ts-ignore
|
|
197
|
+
acc.input[key].isUncertain = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
203
|
+
finally {
|
|
204
|
+
try {
|
|
205
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
206
|
+
}
|
|
207
|
+
finally { if (e_1) throw e_1.error; }
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
211
|
+
var key = _g.value;
|
|
212
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
213
|
+
//@ts-ignore
|
|
214
|
+
if (item.output[key]) {
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
216
|
+
//@ts-ignore
|
|
217
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
218
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
219
|
+
//@ts-ignore
|
|
220
|
+
if (item.output[key].isUncertain) {
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
222
|
+
//@ts-ignore
|
|
223
|
+
acc.output[key].isUncertain = true;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
229
|
+
finally {
|
|
230
|
+
try {
|
|
231
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
232
|
+
}
|
|
233
|
+
finally { if (e_2) throw e_2.error; }
|
|
234
|
+
}
|
|
235
|
+
return acc;
|
|
236
|
+
}, initialStructure);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Async version of Array.forEach
|
|
241
|
+
*
|
|
242
|
+
* @param array - Array to iterate over
|
|
243
|
+
* @param options - Options for the function
|
|
244
|
+
* @param callbackfunction - Function to call for each item
|
|
245
|
+
*/
|
|
246
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
247
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
249
|
+
var e_1, _d;
|
|
250
|
+
return __generator(this, function (_e) {
|
|
251
|
+
switch (_e.label) {
|
|
252
|
+
case 0:
|
|
253
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
254
|
+
index = 0;
|
|
255
|
+
runningTasks = [];
|
|
256
|
+
tasks = [];
|
|
257
|
+
_loop_1 = function (item) {
|
|
258
|
+
var currentIndex, task;
|
|
259
|
+
return __generator(this, function (_f) {
|
|
260
|
+
switch (_f.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
currentIndex = index++;
|
|
263
|
+
task = callbackfunction(item, currentIndex, array);
|
|
264
|
+
tasks.push(task);
|
|
265
|
+
runningTasks.push(task);
|
|
266
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
267
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
268
|
+
});
|
|
269
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
270
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
271
|
+
case 1:
|
|
272
|
+
_f.sent();
|
|
273
|
+
_f.label = 2;
|
|
274
|
+
case 2: return [2 /*return*/];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
_e.label = 1;
|
|
279
|
+
case 1:
|
|
280
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
281
|
+
_b = __values(array), _c = _b.next();
|
|
282
|
+
_e.label = 2;
|
|
283
|
+
case 2:
|
|
284
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
285
|
+
item = _c.value;
|
|
286
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
287
|
+
case 3:
|
|
288
|
+
_e.sent();
|
|
289
|
+
_e.label = 4;
|
|
290
|
+
case 4:
|
|
291
|
+
_c = _b.next();
|
|
292
|
+
return [3 /*break*/, 2];
|
|
293
|
+
case 5: return [3 /*break*/, 8];
|
|
294
|
+
case 6:
|
|
295
|
+
e_1_1 = _e.sent();
|
|
296
|
+
e_1 = { error: e_1_1 };
|
|
297
|
+
return [3 /*break*/, 8];
|
|
298
|
+
case 7:
|
|
299
|
+
try {
|
|
300
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
301
|
+
}
|
|
302
|
+
finally { if (e_1) throw e_1.error; }
|
|
303
|
+
return [7 /*endfinally*/];
|
|
304
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
305
|
+
case 9:
|
|
306
|
+
_e.sent();
|
|
307
|
+
return [2 /*return*/];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
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"}];
|
|
145
314
|
|
|
146
315
|
/**
|
|
147
316
|
* Prettify the html code
|
|
@@ -1210,6 +1379,14 @@ function removeEmojis(text) {
|
|
|
1210
1379
|
* Function normalizes title to name which can be used as identifier
|
|
1211
1380
|
*/
|
|
1212
1381
|
function titleToName(value) {
|
|
1382
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
1383
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1384
|
+
return value;
|
|
1385
|
+
}
|
|
1386
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
1387
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1388
|
+
return value;
|
|
1389
|
+
}
|
|
1213
1390
|
value = removeEmojis(value);
|
|
1214
1391
|
value = normalizeToKebabCase(value);
|
|
1215
1392
|
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
@@ -1547,100 +1724,9 @@ function arrayableToArray(input) {
|
|
|
1547
1724
|
/**
|
|
1548
1725
|
* The version of the Promptbook library
|
|
1549
1726
|
*/
|
|
1550
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
1727
|
+
var PROMPTBOOK_VERSION = '0.61.0-9';
|
|
1551
1728
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1552
1729
|
|
|
1553
|
-
/**
|
|
1554
|
-
* Function `addUsage` will add multiple usages into one
|
|
1555
|
-
*
|
|
1556
|
-
* Note: If you provide 0 values, it returns void usage
|
|
1557
|
-
*/
|
|
1558
|
-
function addUsage() {
|
|
1559
|
-
var usageItems = [];
|
|
1560
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1561
|
-
usageItems[_i] = arguments[_i];
|
|
1562
|
-
}
|
|
1563
|
-
var initialStructure = {
|
|
1564
|
-
price: { value: 0 },
|
|
1565
|
-
input: {
|
|
1566
|
-
tokensCount: { value: 0 },
|
|
1567
|
-
charactersCount: { value: 0 },
|
|
1568
|
-
wordsCount: { value: 0 },
|
|
1569
|
-
sentencesCount: { value: 0 },
|
|
1570
|
-
linesCount: { value: 0 },
|
|
1571
|
-
paragraphsCount: { value: 0 },
|
|
1572
|
-
pagesCount: { value: 0 },
|
|
1573
|
-
},
|
|
1574
|
-
output: {
|
|
1575
|
-
tokensCount: { value: 0 },
|
|
1576
|
-
charactersCount: { value: 0 },
|
|
1577
|
-
wordsCount: { value: 0 },
|
|
1578
|
-
sentencesCount: { value: 0 },
|
|
1579
|
-
linesCount: { value: 0 },
|
|
1580
|
-
paragraphsCount: { value: 0 },
|
|
1581
|
-
pagesCount: { value: 0 },
|
|
1582
|
-
},
|
|
1583
|
-
};
|
|
1584
|
-
return usageItems.reduce(function (acc, item) {
|
|
1585
|
-
var e_1, _a, e_2, _b;
|
|
1586
|
-
var _c;
|
|
1587
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1588
|
-
try {
|
|
1589
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1590
|
-
var key = _e.value;
|
|
1591
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1592
|
-
//@ts-ignore
|
|
1593
|
-
if (item.input[key]) {
|
|
1594
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1595
|
-
//@ts-ignore
|
|
1596
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
1597
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1598
|
-
//@ts-ignore
|
|
1599
|
-
if (item.input[key].isUncertain) {
|
|
1600
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1601
|
-
//@ts-ignore
|
|
1602
|
-
acc.input[key].isUncertain = true;
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1608
|
-
finally {
|
|
1609
|
-
try {
|
|
1610
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1611
|
-
}
|
|
1612
|
-
finally { if (e_1) throw e_1.error; }
|
|
1613
|
-
}
|
|
1614
|
-
try {
|
|
1615
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1616
|
-
var key = _g.value;
|
|
1617
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1618
|
-
//@ts-ignore
|
|
1619
|
-
if (item.output[key]) {
|
|
1620
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1621
|
-
//@ts-ignore
|
|
1622
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
1623
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1624
|
-
//@ts-ignore
|
|
1625
|
-
if (item.output[key].isUncertain) {
|
|
1626
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1627
|
-
//@ts-ignore
|
|
1628
|
-
acc.output[key].isUncertain = true;
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1634
|
-
finally {
|
|
1635
|
-
try {
|
|
1636
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1637
|
-
}
|
|
1638
|
-
finally { if (e_2) throw e_2.error; }
|
|
1639
|
-
}
|
|
1640
|
-
return acc;
|
|
1641
|
-
}, initialStructure);
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
1730
|
/**
|
|
1645
1731
|
* Counts number of characters in the text
|
|
1646
1732
|
*/
|
|
@@ -1823,8 +1909,6 @@ function createPipelineExecutor(options) {
|
|
|
1823
1909
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1824
1910
|
// TODO: !!!!! Implement new commands
|
|
1825
1911
|
validatePipeline(pipeline);
|
|
1826
|
-
// TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
|
|
1827
|
-
// TODO: !!!!! Do here personaToModelRequirements
|
|
1828
1912
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
1829
1913
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1830
1914
|
function executeSingleTemplate(currentTemplate) {
|
|
@@ -2345,53 +2429,74 @@ function createPipelineExecutor(options) {
|
|
|
2345
2429
|
return pipelineExecutor;
|
|
2346
2430
|
}
|
|
2347
2431
|
/**
|
|
2432
|
+
* TODO: [🪂] Pass maxParallelCount here
|
|
2348
2433
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2349
2434
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2350
2435
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2351
2436
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2352
2437
|
*/
|
|
2353
2438
|
|
|
2354
|
-
|
|
2439
|
+
/**
|
|
2440
|
+
* Just marks a place of place where should be something implemented
|
|
2441
|
+
* No side effects.
|
|
2442
|
+
*
|
|
2443
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2444
|
+
*
|
|
2445
|
+
* @param value any values
|
|
2446
|
+
* @returns void
|
|
2447
|
+
*/
|
|
2448
|
+
function TODO_USE() {
|
|
2449
|
+
var value = [];
|
|
2450
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2451
|
+
value[_i] = arguments[_i];
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
// TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
|
|
2455
|
+
|
|
2456
|
+
/**
|
|
2457
|
+
* @@@
|
|
2458
|
+
*/
|
|
2459
|
+
function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
2355
2460
|
return __awaiter(this, void 0, void 0, function () {
|
|
2356
|
-
var
|
|
2357
|
-
var
|
|
2461
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2462
|
+
var _f, _g, _h;
|
|
2358
2463
|
var _this = this;
|
|
2359
|
-
return __generator(this, function (
|
|
2360
|
-
switch (
|
|
2464
|
+
return __generator(this, function (_j) {
|
|
2465
|
+
switch (_j.label) {
|
|
2361
2466
|
case 0:
|
|
2362
|
-
|
|
2467
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2468
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2363
2469
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2364
|
-
_b = createPipelineExecutor;
|
|
2365
|
-
_e = {};
|
|
2366
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2367
|
-
case 1:
|
|
2368
|
-
prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
|
|
2369
|
-
_e.tools = {
|
|
2370
|
-
llm: llmTools,
|
|
2371
|
-
},
|
|
2372
|
-
_e)]);
|
|
2373
2470
|
_c = createPipelineExecutor;
|
|
2374
2471
|
_f = {};
|
|
2375
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2376
|
-
case
|
|
2377
|
-
|
|
2472
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2473
|
+
case 1:
|
|
2474
|
+
prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
|
|
2378
2475
|
_f.tools = {
|
|
2379
2476
|
llm: llmTools,
|
|
2380
2477
|
},
|
|
2381
2478
|
_f)]);
|
|
2382
2479
|
_d = createPipelineExecutor;
|
|
2383
2480
|
_g = {};
|
|
2384
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2385
|
-
case
|
|
2386
|
-
|
|
2481
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
|
|
2482
|
+
case 2:
|
|
2483
|
+
prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
|
|
2387
2484
|
_g.tools = {
|
|
2388
2485
|
llm: llmTools,
|
|
2389
2486
|
},
|
|
2390
2487
|
_g)]);
|
|
2488
|
+
_e = createPipelineExecutor;
|
|
2489
|
+
_h = {};
|
|
2490
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
|
|
2491
|
+
case 3:
|
|
2492
|
+
prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
|
|
2493
|
+
_h.tools = {
|
|
2494
|
+
llm: llmTools,
|
|
2495
|
+
},
|
|
2496
|
+
_h)]);
|
|
2391
2497
|
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
|
|
2392
2498
|
case 4:
|
|
2393
|
-
result =
|
|
2394
|
-
// TODO: [0] !!! Aggeregate usage
|
|
2499
|
+
result = _j.sent();
|
|
2395
2500
|
assertsExecutionSuccessful(result);
|
|
2396
2501
|
outputParameters = result.outputParameters;
|
|
2397
2502
|
knowledgeRaw = outputParameters.knowledge;
|
|
@@ -2400,9 +2505,9 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2400
2505
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2401
2506
|
}
|
|
2402
2507
|
return [4 /*yield*/, Promise.all(
|
|
2403
|
-
// TODO:
|
|
2508
|
+
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
2404
2509
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2405
|
-
var name, title, content, keywords, index,
|
|
2510
|
+
var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
2406
2511
|
return __generator(this, function (_c) {
|
|
2407
2512
|
switch (_c.label) {
|
|
2408
2513
|
case 0:
|
|
@@ -2411,12 +2516,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2411
2516
|
content = spaceTrim(knowledgeTextPiece);
|
|
2412
2517
|
keywords = [];
|
|
2413
2518
|
index = [];
|
|
2414
|
-
sources = [
|
|
2415
|
-
{
|
|
2416
|
-
title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
|
|
2417
|
-
href: '#' /* <- TODO: !!! Unhardcode */,
|
|
2418
|
-
},
|
|
2419
|
-
];
|
|
2420
2519
|
_c.label = 1;
|
|
2421
2520
|
case 1:
|
|
2422
2521
|
_c.trys.push([1, 7, , 8]);
|
|
@@ -2451,7 +2550,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2451
2550
|
})];
|
|
2452
2551
|
case 5:
|
|
2453
2552
|
embeddingResult = _c.sent();
|
|
2454
|
-
// TODO: [0] !!! Aggeregate usage embeddingResult.usage
|
|
2455
2553
|
index.push({
|
|
2456
2554
|
modelName: embeddingResult.modelName,
|
|
2457
2555
|
position: embeddingResult.content,
|
|
@@ -2469,20 +2567,186 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2469
2567
|
content: content,
|
|
2470
2568
|
keywords: keywords,
|
|
2471
2569
|
index: index,
|
|
2472
|
-
|
|
2570
|
+
// <- TODO: [☀] sources,
|
|
2473
2571
|
}];
|
|
2474
2572
|
}
|
|
2475
2573
|
});
|
|
2476
2574
|
}); }))];
|
|
2477
2575
|
case 5:
|
|
2478
|
-
knowledge =
|
|
2576
|
+
knowledge = _j.sent();
|
|
2479
2577
|
return [2 /*return*/, knowledge];
|
|
2480
2578
|
}
|
|
2481
2579
|
});
|
|
2482
2580
|
});
|
|
2483
2581
|
}
|
|
2484
2582
|
/**
|
|
2485
|
-
* 11:11
|
|
2583
|
+
* TODO: [🪂] Do it in parallel 11:11
|
|
2584
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2585
|
+
*/
|
|
2586
|
+
|
|
2587
|
+
/**
|
|
2588
|
+
* Prepares the knowle
|
|
2589
|
+
*
|
|
2590
|
+
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2591
|
+
* @private within the package
|
|
2592
|
+
*/
|
|
2593
|
+
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2594
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2595
|
+
var _a, maxParallelCount, knowledgePrepared;
|
|
2596
|
+
var _this = this;
|
|
2597
|
+
return __generator(this, function (_b) {
|
|
2598
|
+
switch (_b.label) {
|
|
2599
|
+
case 0:
|
|
2600
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2601
|
+
knowledgePrepared = [];
|
|
2602
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
2603
|
+
var partialPieces, pieces;
|
|
2604
|
+
return __generator(this, function (_a) {
|
|
2605
|
+
switch (_a.label) {
|
|
2606
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2607
|
+
options)];
|
|
2608
|
+
case 1:
|
|
2609
|
+
partialPieces = _a.sent();
|
|
2610
|
+
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
2611
|
+
{
|
|
2612
|
+
name: knowledgeSource.name,
|
|
2613
|
+
// line, column <- TODO: [☀]
|
|
2614
|
+
// <- TODO: [❎]
|
|
2615
|
+
},
|
|
2616
|
+
] })); });
|
|
2617
|
+
knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
|
|
2618
|
+
return [2 /*return*/];
|
|
2619
|
+
}
|
|
2620
|
+
});
|
|
2621
|
+
}); })];
|
|
2622
|
+
case 1:
|
|
2623
|
+
_b.sent();
|
|
2624
|
+
return [2 /*return*/, knowledgePrepared];
|
|
2625
|
+
}
|
|
2626
|
+
});
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
/*
|
|
2630
|
+
TODO: [🧊] This is how it can look in future
|
|
2631
|
+
> type PrepareKnowledgeKnowledge = {
|
|
2632
|
+
> /**
|
|
2633
|
+
> * Unprepared knowledge
|
|
2634
|
+
> * /
|
|
2635
|
+
> readonly knowledgeSources: Array<KnowledgeSourceJson>;
|
|
2636
|
+
> };
|
|
2637
|
+
>
|
|
2638
|
+
> export async function prepareKnowledgePieces(
|
|
2639
|
+
> knowledge: PrepareKnowledgeKnowledge,
|
|
2640
|
+
> options: PrepareOptions,
|
|
2641
|
+
> ):
|
|
2642
|
+
*/
|
|
2643
|
+
/**
|
|
2644
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2645
|
+
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2646
|
+
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
2647
|
+
* TODO: [🧠][❎] Do here propper M:N mapping
|
|
2648
|
+
* [x] One source can make multiple pieces
|
|
2649
|
+
* [ ] One piece can have multiple sources
|
|
2650
|
+
*/
|
|
2651
|
+
|
|
2652
|
+
/**
|
|
2653
|
+
* Prepares the persona for the pipeline
|
|
2654
|
+
*
|
|
2655
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2656
|
+
* @private within the package
|
|
2657
|
+
*/
|
|
2658
|
+
function preparePersona(personaDescription, options) {
|
|
2659
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2660
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose;
|
|
2661
|
+
return __generator(this, function (_c) {
|
|
2662
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2663
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2664
|
+
TODO_USE(personaDescription); // <- !!!!!
|
|
2665
|
+
TODO_USE(llmTools); // <- !!!!!
|
|
2666
|
+
TODO_USE(isVerbose); // <- !!!!!
|
|
2667
|
+
return [2 /*return*/, {
|
|
2668
|
+
modelVariant: 'CHAT',
|
|
2669
|
+
modelName: 'gpt-4',
|
|
2670
|
+
}];
|
|
2671
|
+
});
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2674
|
+
/**
|
|
2675
|
+
* TODO: [🪂] Do it in parallel
|
|
2676
|
+
*/
|
|
2677
|
+
|
|
2678
|
+
/**
|
|
2679
|
+
* Simple wrapper `new Date().toISOString()`
|
|
2680
|
+
*
|
|
2681
|
+
* @returns string_date branded type
|
|
2682
|
+
*/
|
|
2683
|
+
function $currentDate() {
|
|
2684
|
+
return new Date().toISOString();
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
/**
|
|
2688
|
+
* Prepare pipeline from string (markdown) format to JSON format
|
|
2689
|
+
*
|
|
2690
|
+
* Note: This function does not validate logic of the pipeline
|
|
2691
|
+
* Note: This function acts as part of compilation process
|
|
2692
|
+
*/
|
|
2693
|
+
function preparePipeline(pipeline, options) {
|
|
2694
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2695
|
+
var _a, maxParallelCount,
|
|
2696
|
+
/*
|
|
2697
|
+
<- TODO: [🧠][0] `promptbookVersion` */
|
|
2698
|
+
knowledgeSources /*
|
|
2699
|
+
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
2700
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
|
|
2701
|
+
var _this = this;
|
|
2702
|
+
return __generator(this, function (_b) {
|
|
2703
|
+
switch (_b.label) {
|
|
2704
|
+
case 0:
|
|
2705
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2706
|
+
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
2707
|
+
currentPreparation = {
|
|
2708
|
+
id: 1,
|
|
2709
|
+
date: $currentDate(),
|
|
2710
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2711
|
+
modelUsage: addUsage(),
|
|
2712
|
+
};
|
|
2713
|
+
preparations = [
|
|
2714
|
+
// ...preparations
|
|
2715
|
+
// <- TODO: [🧊]
|
|
2716
|
+
currentPreparation,
|
|
2717
|
+
];
|
|
2718
|
+
preparedPersonas = [];
|
|
2719
|
+
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 () {
|
|
2720
|
+
var modelRequirements, preparedPersona;
|
|
2721
|
+
return __generator(this, function (_a) {
|
|
2722
|
+
switch (_a.label) {
|
|
2723
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
|
|
2724
|
+
case 1:
|
|
2725
|
+
modelRequirements = _a.sent();
|
|
2726
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
2727
|
+
preparedPersonas.push(preparedPersona);
|
|
2728
|
+
return [2 /*return*/];
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
}); })];
|
|
2732
|
+
case 1:
|
|
2733
|
+
_b.sent();
|
|
2734
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2735
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
|
|
2736
|
+
case 2:
|
|
2737
|
+
partialknowledgePiecesPrepared = _b.sent();
|
|
2738
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2739
|
+
// ----- /Knowledge preparation -----
|
|
2740
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
2741
|
+
}
|
|
2742
|
+
});
|
|
2743
|
+
});
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* TODO: Write tests for `preparePipeline`
|
|
2747
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
2748
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2749
|
+
* TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
|
|
2486
2750
|
*/
|
|
2487
2751
|
|
|
2488
2752
|
/**
|
|
@@ -2669,6 +2933,7 @@ var blockCommandParser = {
|
|
|
2669
2933
|
|
|
2670
2934
|
/**
|
|
2671
2935
|
* Units of text measurement
|
|
2936
|
+
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
2672
2937
|
*/
|
|
2673
2938
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2674
2939
|
/**
|
|
@@ -2989,9 +3254,10 @@ var knowledgeCommandParser = {
|
|
|
2989
3254
|
|
|
2990
3255
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
2991
3256
|
/**
|
|
3257
|
+
* TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
|
|
2992
3258
|
* TODO: Maybe figure out better word than "variant"
|
|
2993
3259
|
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
2994
|
-
* TODO: [
|
|
3260
|
+
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
2995
3261
|
*/
|
|
2996
3262
|
|
|
2997
3263
|
/**
|
|
@@ -4134,14 +4400,14 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
4134
4400
|
*/
|
|
4135
4401
|
|
|
4136
4402
|
/**
|
|
4137
|
-
* Compile
|
|
4403
|
+
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4138
4404
|
*
|
|
4139
|
-
* Note: There are
|
|
4405
|
+
* Note: There are 3 similar functions:
|
|
4140
4406
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4141
4407
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
4408
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4142
4409
|
*
|
|
4143
4410
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4144
|
-
* @param options - Options and tools for the compilation
|
|
4145
4411
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
4146
4412
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
4147
4413
|
*
|
|
@@ -4157,7 +4423,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4157
4423
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
4158
4424
|
parameters: [],
|
|
4159
4425
|
promptTemplates: [],
|
|
4160
|
-
|
|
4426
|
+
knowledgeSources: [],
|
|
4427
|
+
knowledgePieces: [],
|
|
4428
|
+
personas: [],
|
|
4429
|
+
preparations: [],
|
|
4161
4430
|
};
|
|
4162
4431
|
// =============================================================
|
|
4163
4432
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
@@ -4425,6 +4694,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4425
4694
|
postprocessing: postprocessing,
|
|
4426
4695
|
expectations: expectAmount,
|
|
4427
4696
|
expectFormat: expectFormat,
|
|
4697
|
+
personaName: null,
|
|
4428
4698
|
modelRequirements: templateModelRequirements,
|
|
4429
4699
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4430
4700
|
content: content,
|
|
@@ -4504,11 +4774,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4504
4774
|
*/
|
|
4505
4775
|
|
|
4506
4776
|
/**
|
|
4507
|
-
* Compile
|
|
4777
|
+
* Compile pipeline from string (markdown) format to JSON format
|
|
4508
4778
|
*
|
|
4509
|
-
* Note: There are
|
|
4779
|
+
* Note: There are 3 similar functions:
|
|
4510
4780
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4511
4781
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
4782
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4512
4783
|
*
|
|
4513
4784
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4514
4785
|
* @param options - Options and tools for the compilation
|
|
@@ -4519,22 +4790,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4519
4790
|
* Note: This function acts as compilation process
|
|
4520
4791
|
*/
|
|
4521
4792
|
function pipelineStringToJson(pipelineString, options) {
|
|
4522
|
-
if (options === void 0) { options = {}; }
|
|
4793
|
+
if (options === void 0) { options = { llmTools: null }; }
|
|
4523
4794
|
return __awaiter(this, void 0, void 0, function () {
|
|
4524
|
-
var llmTools, pipelineJson
|
|
4795
|
+
var llmTools, pipelineJson;
|
|
4525
4796
|
return __generator(this, function (_a) {
|
|
4526
4797
|
switch (_a.label) {
|
|
4527
4798
|
case 0:
|
|
4528
4799
|
llmTools = options.llmTools;
|
|
4529
4800
|
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
4530
|
-
if (!llmTools) return [3 /*break*/, 2];
|
|
4531
|
-
return [4 /*yield*/,
|
|
4532
|
-
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
4533
|
-
llmTools: llmTools,
|
|
4534
|
-
})];
|
|
4801
|
+
if (!(llmTools !== null)) return [3 /*break*/, 2];
|
|
4802
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
|
|
4535
4803
|
case 1:
|
|
4536
|
-
|
|
4537
|
-
pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
|
|
4804
|
+
pipelineJson = _a.sent();
|
|
4538
4805
|
_a.label = 2;
|
|
4539
4806
|
case 2: return [2 /*return*/, pipelineJson];
|
|
4540
4807
|
}
|
|
@@ -4669,7 +4936,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
4669
4936
|
*/
|
|
4670
4937
|
function createCollectionFromDirectory(path, options) {
|
|
4671
4938
|
return __awaiter(this, void 0, void 0, function () {
|
|
4672
|
-
var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e,
|
|
4939
|
+
var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, collection;
|
|
4673
4940
|
var _this = this;
|
|
4674
4941
|
return __generator(this, function (_f) {
|
|
4675
4942
|
switch (_f.label) {
|
|
@@ -4690,7 +4957,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
4690
4957
|
colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
|
|
4691
4958
|
// TODO: !! Implement;
|
|
4692
4959
|
}
|
|
4693
|
-
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.
|
|
4960
|
+
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
|
|
4694
4961
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4695
4962
|
var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
4696
4963
|
var e_1, _a;
|
|
@@ -4752,7 +5019,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
4752
5019
|
if (isVerbose) {
|
|
4753
5020
|
console.info("Loading ".concat(fileName.split('\\').join('/')));
|
|
4754
5021
|
}
|
|
4755
|
-
if (!
|
|
5022
|
+
if (!isCrashedOnError) {
|
|
4756
5023
|
// Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
|
|
4757
5024
|
// But be handled in current try-catch block
|
|
4758
5025
|
validatePipeline(promptbook);
|
|
@@ -4768,7 +5035,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
4768
5035
|
throw error_1;
|
|
4769
5036
|
}
|
|
4770
5037
|
wrappedErrorMessage = spaceTrim(function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
4771
|
-
if (
|
|
5038
|
+
if (isCrashedOnError) {
|
|
4772
5039
|
throw new CollectionError(wrappedErrorMessage);
|
|
4773
5040
|
}
|
|
4774
5041
|
// TODO: [🟥] Detect browser / node and make it colorfull
|