@promptbook/legacy-documents 0.74.0-0 → 0.74.0-12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -30
- package/esm/index.es.js +237 -305
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -2
- package/esm/typings/src/_packages/azure-openai.index.d.ts +2 -2
- package/esm/typings/src/_packages/browser.index.d.ts +2 -2
- package/esm/typings/src/_packages/cli.index.d.ts +2 -2
- package/esm/typings/src/_packages/core.index.d.ts +7 -3
- package/esm/typings/src/_packages/documents.index.d.ts +2 -2
- package/esm/typings/src/_packages/execute-javascript.index.d.ts +2 -2
- package/esm/typings/src/_packages/fake-llm.index.d.ts +2 -2
- package/esm/typings/src/_packages/langtail.index.d.ts +2 -2
- package/esm/typings/src/_packages/legacy-documents.index.d.ts +2 -2
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/node.index.d.ts +2 -2
- package/esm/typings/src/_packages/openai.index.d.ts +2 -2
- package/esm/typings/src/_packages/pdf.index.d.ts +2 -2
- package/esm/typings/src/_packages/remote-client.index.d.ts +2 -2
- package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/website-crawler.index.d.ts +2 -2
- package/esm/typings/src/cli/cli-commands/make.d.ts +0 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +14 -0
- package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +5 -2
- package/esm/typings/src/collection/collectionToJson.test.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
- package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +11 -0
- package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
- package/esm/typings/src/commands/index.d.ts +1 -1
- package/esm/typings/src/config.d.ts +6 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +3 -3
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -2
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -2
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +7 -7
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +1 -1
- package/esm/typings/src/storage/blackhole/BlackholeStorage.d.ts +33 -0
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +1 -1
- package/esm/typings/src/storage/{memory/utils → utils}/PrefixStorage.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +6 -4
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- package/esm/typings/src/version.d.ts +13 -2
- package/package.json +2 -2
- package/umd/index.umd.js +238 -305
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts +0 -11
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +0 -9
- /package/esm/typings/src/commands/{PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts → BOOK_VERSION/bookVersionCommand.test.d.ts} +0 -0
- /package/esm/typings/src/storage/{memory → local-storage}/utils/makePromptbookStorageFromWebStorage.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -13,10 +13,20 @@ import { unparse, parse } from 'papaparse';
|
|
|
13
13
|
|
|
14
14
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
15
15
|
/**
|
|
16
|
-
* The version of the
|
|
16
|
+
* The version of the Book language
|
|
17
|
+
*
|
|
18
|
+
* @see https://github.com/webgptorg/book
|
|
19
|
+
*/
|
|
20
|
+
var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
21
|
+
/**
|
|
22
|
+
* The version of the Promptbook engine
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/webgptorg/promptbook
|
|
25
|
+
*/
|
|
26
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-11';
|
|
27
|
+
/**
|
|
28
|
+
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
17
29
|
*/
|
|
18
|
-
var PROMPTBOOK_VERSION = '0.73.0';
|
|
19
|
-
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
20
30
|
|
|
21
31
|
/*! *****************************************************************************
|
|
22
32
|
Copyright (c) Microsoft Corporation.
|
|
@@ -560,12 +570,9 @@ function $execCommandNormalizeOptions(options) {
|
|
|
560
570
|
})
|
|
561
571
|
.filter(function (arg) { return arg !== ''; });
|
|
562
572
|
if (_.length > 1) {
|
|
563
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
564
573
|
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
565
574
|
}
|
|
566
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
567
575
|
if (options.args) {
|
|
568
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
569
576
|
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
570
577
|
}
|
|
571
578
|
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|
|
@@ -1147,23 +1154,6 @@ function nameToSubfolderPath(name) {
|
|
|
1147
1154
|
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
1148
1155
|
}
|
|
1149
1156
|
|
|
1150
|
-
/**
|
|
1151
|
-
* Just marks a place of place where should be something implemented
|
|
1152
|
-
* No side effects.
|
|
1153
|
-
*
|
|
1154
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
1155
|
-
*
|
|
1156
|
-
* @param value any values
|
|
1157
|
-
* @returns void
|
|
1158
|
-
* @private within the repository
|
|
1159
|
-
*/
|
|
1160
|
-
function TODO_USE() {
|
|
1161
|
-
var value = [];
|
|
1162
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1163
|
-
value[_i] = arguments[_i];
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
1157
|
/**
|
|
1168
1158
|
* Create a filename for intermediate cache for scrapers
|
|
1169
1159
|
*
|
|
@@ -1173,12 +1163,12 @@ function TODO_USE() {
|
|
|
1173
1163
|
*/
|
|
1174
1164
|
function getScraperIntermediateSource(source, options) {
|
|
1175
1165
|
return __awaiter(this, void 0, void 0, function () {
|
|
1176
|
-
var sourceFilename, url,
|
|
1166
|
+
var sourceFilename, url, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
|
|
1177
1167
|
return __generator(this, function (_a) {
|
|
1178
1168
|
switch (_a.label) {
|
|
1179
1169
|
case 0:
|
|
1180
1170
|
sourceFilename = source.filename, url = source.url;
|
|
1181
|
-
|
|
1171
|
+
options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
|
|
1182
1172
|
hash = SHA256(
|
|
1183
1173
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
1184
1174
|
hexEncoder.parse(sourceFilename || url || 'untitled'))
|
|
@@ -1187,8 +1177,6 @@ function getScraperIntermediateSource(source, options) {
|
|
|
1187
1177
|
semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
|
|
1188
1178
|
pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
|
|
1189
1179
|
name = pieces.join('-').split('--').join('-');
|
|
1190
|
-
// <- TODO: Use MAX_FILENAME_LENGTH
|
|
1191
|
-
TODO_USE(rootDirname); // <- TODO: [😡]
|
|
1192
1180
|
cacheFilename = join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
|
|
1193
1181
|
cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
|
|
1194
1182
|
.join('/') +
|
|
@@ -1237,7 +1225,7 @@ function getScraperIntermediateSource(source, options) {
|
|
|
1237
1225
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
1238
1226
|
*/
|
|
1239
1227
|
|
|
1240
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.
|
|
1228
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.book.md"}];
|
|
1241
1229
|
|
|
1242
1230
|
/**
|
|
1243
1231
|
* Prettify the html code
|
|
@@ -1285,13 +1273,13 @@ function capitalize(word) {
|
|
|
1285
1273
|
/**
|
|
1286
1274
|
* Converts promptbook in JSON format to string format
|
|
1287
1275
|
*
|
|
1288
|
-
* @param pipelineJson Promptbook in JSON format (.
|
|
1289
|
-
* @returns Promptbook in string format (.
|
|
1276
|
+
* @param pipelineJson Promptbook in JSON format (.book.json)
|
|
1277
|
+
* @returns Promptbook in string format (.book.md)
|
|
1290
1278
|
* @public exported from `@promptbook/core`
|
|
1291
1279
|
*/
|
|
1292
1280
|
function pipelineJsonToString(pipelineJson) {
|
|
1293
1281
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1294
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl,
|
|
1282
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
|
|
1295
1283
|
var pipelineString = "# ".concat(title);
|
|
1296
1284
|
if (description) {
|
|
1297
1285
|
pipelineString += '\n\n';
|
|
@@ -1301,8 +1289,10 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
1301
1289
|
if (pipelineUrl) {
|
|
1302
1290
|
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
1303
1291
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1292
|
+
if (bookVersion !== "undefined") {
|
|
1293
|
+
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
1294
|
+
}
|
|
1295
|
+
// TODO: [main] !!!!!! This increase size of the bundle and is probbably not necessary
|
|
1306
1296
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
1307
1297
|
try {
|
|
1308
1298
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -1482,7 +1472,7 @@ function templateParameterJsonToString(templateParameterJson) {
|
|
|
1482
1472
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
1483
1473
|
* TODO: [🏛] Maybe make some markdown builder
|
|
1484
1474
|
* TODO: [🏛] Escape all
|
|
1485
|
-
* TODO: [🧠] Should be in generated .
|
|
1475
|
+
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
1486
1476
|
*/
|
|
1487
1477
|
|
|
1488
1478
|
/**
|
|
@@ -1558,7 +1548,7 @@ function isValidPromptbookVersion(version) {
|
|
|
1558
1548
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
1559
1549
|
return false;
|
|
1560
1550
|
}
|
|
1561
|
-
// <- TODO: [main] !!! Check isValidPromptbookVersion against
|
|
1551
|
+
// <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
|
|
1562
1552
|
return true;
|
|
1563
1553
|
}
|
|
1564
1554
|
|
|
@@ -1629,7 +1619,7 @@ function isValidPipelineUrl(url) {
|
|
|
1629
1619
|
if (!url.startsWith('https://')) {
|
|
1630
1620
|
return false;
|
|
1631
1621
|
}
|
|
1632
|
-
if (!url.endsWith('.
|
|
1622
|
+
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
1633
1623
|
return false;
|
|
1634
1624
|
}
|
|
1635
1625
|
if (url.includes('#')) {
|
|
@@ -1698,9 +1688,9 @@ function validatePipelineCore(pipeline) {
|
|
|
1698
1688
|
// <- Note: [🚲]
|
|
1699
1689
|
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1700
1690
|
}
|
|
1701
|
-
if (pipeline.
|
|
1691
|
+
if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
|
|
1702
1692
|
// <- Note: [🚲]
|
|
1703
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.
|
|
1693
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1704
1694
|
}
|
|
1705
1695
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1706
1696
|
if (!Array.isArray(pipeline.parameters)) {
|
|
@@ -2418,6 +2408,188 @@ $deepFreeze({
|
|
|
2418
2408
|
},
|
|
2419
2409
|
});
|
|
2420
2410
|
|
|
2411
|
+
/**
|
|
2412
|
+
* @@@
|
|
2413
|
+
*
|
|
2414
|
+
* @public exported from `@promptbook/utils`
|
|
2415
|
+
*/
|
|
2416
|
+
function deepClone(objectValue) {
|
|
2417
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
2418
|
+
/*
|
|
2419
|
+
TODO: [🧠] Is there a better implementation?
|
|
2420
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
2421
|
+
> for (const propertyName of propertyNames) {
|
|
2422
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
2423
|
+
> if (value && typeof value === 'object') {
|
|
2424
|
+
> deepClone(value);
|
|
2425
|
+
> }
|
|
2426
|
+
> }
|
|
2427
|
+
> return Object.assign({}, objectValue);
|
|
2428
|
+
*/
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
2432
|
+
*/
|
|
2433
|
+
|
|
2434
|
+
/**
|
|
2435
|
+
* Function `addUsage` will add multiple usages into one
|
|
2436
|
+
*
|
|
2437
|
+
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
2438
|
+
*
|
|
2439
|
+
* @public exported from `@promptbook/core`
|
|
2440
|
+
*/
|
|
2441
|
+
function addUsage() {
|
|
2442
|
+
var usageItems = [];
|
|
2443
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2444
|
+
usageItems[_i] = arguments[_i];
|
|
2445
|
+
}
|
|
2446
|
+
return usageItems.reduce(function (acc, item) {
|
|
2447
|
+
var e_1, _a, e_2, _b;
|
|
2448
|
+
var _c;
|
|
2449
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
2450
|
+
try {
|
|
2451
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2452
|
+
var key = _e.value;
|
|
2453
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2454
|
+
//@ts-ignore
|
|
2455
|
+
if (item.input[key]) {
|
|
2456
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2457
|
+
//@ts-ignore
|
|
2458
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
2459
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2460
|
+
//@ts-ignore
|
|
2461
|
+
if (item.input[key].isUncertain) {
|
|
2462
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2463
|
+
//@ts-ignore
|
|
2464
|
+
acc.input[key].isUncertain = true;
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2470
|
+
finally {
|
|
2471
|
+
try {
|
|
2472
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2473
|
+
}
|
|
2474
|
+
finally { if (e_1) throw e_1.error; }
|
|
2475
|
+
}
|
|
2476
|
+
try {
|
|
2477
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2478
|
+
var key = _g.value;
|
|
2479
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2480
|
+
//@ts-ignore
|
|
2481
|
+
if (item.output[key]) {
|
|
2482
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2483
|
+
//@ts-ignore
|
|
2484
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
2485
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2486
|
+
//@ts-ignore
|
|
2487
|
+
if (item.output[key].isUncertain) {
|
|
2488
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2489
|
+
//@ts-ignore
|
|
2490
|
+
acc.output[key].isUncertain = true;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2496
|
+
finally {
|
|
2497
|
+
try {
|
|
2498
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2499
|
+
}
|
|
2500
|
+
finally { if (e_2) throw e_2.error; }
|
|
2501
|
+
}
|
|
2502
|
+
return acc;
|
|
2503
|
+
}, deepClone(ZERO_USAGE));
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/**
|
|
2507
|
+
* Intercepts LLM tools and counts total usage of the tools
|
|
2508
|
+
*
|
|
2509
|
+
* @param llmTools LLM tools to be intercepted with usage counting
|
|
2510
|
+
* @returns LLM tools with same functionality with added total cost counting
|
|
2511
|
+
* @public exported from `@promptbook/core`
|
|
2512
|
+
*/
|
|
2513
|
+
function countTotalUsage(llmTools) {
|
|
2514
|
+
var _this = this;
|
|
2515
|
+
var totalUsage = ZERO_USAGE;
|
|
2516
|
+
var proxyTools = {
|
|
2517
|
+
get title() {
|
|
2518
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
2519
|
+
return llmTools.title;
|
|
2520
|
+
},
|
|
2521
|
+
get description() {
|
|
2522
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
2523
|
+
return llmTools.description;
|
|
2524
|
+
},
|
|
2525
|
+
checkConfiguration: function () {
|
|
2526
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2527
|
+
return __generator(this, function (_a) {
|
|
2528
|
+
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
2529
|
+
});
|
|
2530
|
+
});
|
|
2531
|
+
},
|
|
2532
|
+
listModels: function () {
|
|
2533
|
+
return /* not await */ llmTools.listModels();
|
|
2534
|
+
},
|
|
2535
|
+
getTotalUsage: function () {
|
|
2536
|
+
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2537
|
+
return totalUsage;
|
|
2538
|
+
},
|
|
2539
|
+
};
|
|
2540
|
+
if (llmTools.callChatModel !== undefined) {
|
|
2541
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2542
|
+
var promptResult;
|
|
2543
|
+
return __generator(this, function (_a) {
|
|
2544
|
+
switch (_a.label) {
|
|
2545
|
+
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
2546
|
+
case 1:
|
|
2547
|
+
promptResult = _a.sent();
|
|
2548
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2549
|
+
return [2 /*return*/, promptResult];
|
|
2550
|
+
}
|
|
2551
|
+
});
|
|
2552
|
+
}); };
|
|
2553
|
+
}
|
|
2554
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
2555
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2556
|
+
var promptResult;
|
|
2557
|
+
return __generator(this, function (_a) {
|
|
2558
|
+
switch (_a.label) {
|
|
2559
|
+
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
2560
|
+
case 1:
|
|
2561
|
+
promptResult = _a.sent();
|
|
2562
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2563
|
+
return [2 /*return*/, promptResult];
|
|
2564
|
+
}
|
|
2565
|
+
});
|
|
2566
|
+
}); };
|
|
2567
|
+
}
|
|
2568
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
2569
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2570
|
+
var promptResult;
|
|
2571
|
+
return __generator(this, function (_a) {
|
|
2572
|
+
switch (_a.label) {
|
|
2573
|
+
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
2574
|
+
case 1:
|
|
2575
|
+
promptResult = _a.sent();
|
|
2576
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2577
|
+
return [2 /*return*/, promptResult];
|
|
2578
|
+
}
|
|
2579
|
+
});
|
|
2580
|
+
}); };
|
|
2581
|
+
}
|
|
2582
|
+
// <- Note: [🤖]
|
|
2583
|
+
return proxyTools;
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
2587
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
2588
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
2589
|
+
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
2590
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2591
|
+
*/
|
|
2592
|
+
|
|
2421
2593
|
/**
|
|
2422
2594
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2423
2595
|
*
|
|
@@ -2710,188 +2882,6 @@ function joinLlmExecutionTools() {
|
|
|
2710
2882
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2711
2883
|
*/
|
|
2712
2884
|
|
|
2713
|
-
/**
|
|
2714
|
-
* @@@
|
|
2715
|
-
*
|
|
2716
|
-
* @public exported from `@promptbook/utils`
|
|
2717
|
-
*/
|
|
2718
|
-
function deepClone(objectValue) {
|
|
2719
|
-
return JSON.parse(JSON.stringify(objectValue));
|
|
2720
|
-
/*
|
|
2721
|
-
TODO: [🧠] Is there a better implementation?
|
|
2722
|
-
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
2723
|
-
> for (const propertyName of propertyNames) {
|
|
2724
|
-
> const value = (objectValue as really_any)[propertyName];
|
|
2725
|
-
> if (value && typeof value === 'object') {
|
|
2726
|
-
> deepClone(value);
|
|
2727
|
-
> }
|
|
2728
|
-
> }
|
|
2729
|
-
> return Object.assign({}, objectValue);
|
|
2730
|
-
*/
|
|
2731
|
-
}
|
|
2732
|
-
/**
|
|
2733
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
2734
|
-
*/
|
|
2735
|
-
|
|
2736
|
-
/**
|
|
2737
|
-
* Function `addUsage` will add multiple usages into one
|
|
2738
|
-
*
|
|
2739
|
-
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
2740
|
-
*
|
|
2741
|
-
* @public exported from `@promptbook/core`
|
|
2742
|
-
*/
|
|
2743
|
-
function addUsage() {
|
|
2744
|
-
var usageItems = [];
|
|
2745
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2746
|
-
usageItems[_i] = arguments[_i];
|
|
2747
|
-
}
|
|
2748
|
-
return usageItems.reduce(function (acc, item) {
|
|
2749
|
-
var e_1, _a, e_2, _b;
|
|
2750
|
-
var _c;
|
|
2751
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
2752
|
-
try {
|
|
2753
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2754
|
-
var key = _e.value;
|
|
2755
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2756
|
-
//@ts-ignore
|
|
2757
|
-
if (item.input[key]) {
|
|
2758
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2759
|
-
//@ts-ignore
|
|
2760
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
2761
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2762
|
-
//@ts-ignore
|
|
2763
|
-
if (item.input[key].isUncertain) {
|
|
2764
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2765
|
-
//@ts-ignore
|
|
2766
|
-
acc.input[key].isUncertain = true;
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2772
|
-
finally {
|
|
2773
|
-
try {
|
|
2774
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2775
|
-
}
|
|
2776
|
-
finally { if (e_1) throw e_1.error; }
|
|
2777
|
-
}
|
|
2778
|
-
try {
|
|
2779
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2780
|
-
var key = _g.value;
|
|
2781
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2782
|
-
//@ts-ignore
|
|
2783
|
-
if (item.output[key]) {
|
|
2784
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2785
|
-
//@ts-ignore
|
|
2786
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
2787
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2788
|
-
//@ts-ignore
|
|
2789
|
-
if (item.output[key].isUncertain) {
|
|
2790
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2791
|
-
//@ts-ignore
|
|
2792
|
-
acc.output[key].isUncertain = true;
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2798
|
-
finally {
|
|
2799
|
-
try {
|
|
2800
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2801
|
-
}
|
|
2802
|
-
finally { if (e_2) throw e_2.error; }
|
|
2803
|
-
}
|
|
2804
|
-
return acc;
|
|
2805
|
-
}, deepClone(ZERO_USAGE));
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2808
|
-
/**
|
|
2809
|
-
* Intercepts LLM tools and counts total usage of the tools
|
|
2810
|
-
*
|
|
2811
|
-
* @param llmTools LLM tools to be intercepted with usage counting
|
|
2812
|
-
* @returns LLM tools with same functionality with added total cost counting
|
|
2813
|
-
* @public exported from `@promptbook/core`
|
|
2814
|
-
*/
|
|
2815
|
-
function countTotalUsage(llmTools) {
|
|
2816
|
-
var _this = this;
|
|
2817
|
-
var totalUsage = ZERO_USAGE;
|
|
2818
|
-
var proxyTools = {
|
|
2819
|
-
get title() {
|
|
2820
|
-
// TODO: [🧠] Maybe put here some suffix
|
|
2821
|
-
return llmTools.title;
|
|
2822
|
-
},
|
|
2823
|
-
get description() {
|
|
2824
|
-
// TODO: [🧠] Maybe put here some suffix
|
|
2825
|
-
return llmTools.description;
|
|
2826
|
-
},
|
|
2827
|
-
checkConfiguration: function () {
|
|
2828
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2829
|
-
return __generator(this, function (_a) {
|
|
2830
|
-
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
2831
|
-
});
|
|
2832
|
-
});
|
|
2833
|
-
},
|
|
2834
|
-
listModels: function () {
|
|
2835
|
-
return /* not await */ llmTools.listModels();
|
|
2836
|
-
},
|
|
2837
|
-
getTotalUsage: function () {
|
|
2838
|
-
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2839
|
-
return totalUsage;
|
|
2840
|
-
},
|
|
2841
|
-
};
|
|
2842
|
-
if (llmTools.callChatModel !== undefined) {
|
|
2843
|
-
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2844
|
-
var promptResult;
|
|
2845
|
-
return __generator(this, function (_a) {
|
|
2846
|
-
switch (_a.label) {
|
|
2847
|
-
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
2848
|
-
case 1:
|
|
2849
|
-
promptResult = _a.sent();
|
|
2850
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2851
|
-
return [2 /*return*/, promptResult];
|
|
2852
|
-
}
|
|
2853
|
-
});
|
|
2854
|
-
}); };
|
|
2855
|
-
}
|
|
2856
|
-
if (llmTools.callCompletionModel !== undefined) {
|
|
2857
|
-
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2858
|
-
var promptResult;
|
|
2859
|
-
return __generator(this, function (_a) {
|
|
2860
|
-
switch (_a.label) {
|
|
2861
|
-
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
2862
|
-
case 1:
|
|
2863
|
-
promptResult = _a.sent();
|
|
2864
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2865
|
-
return [2 /*return*/, promptResult];
|
|
2866
|
-
}
|
|
2867
|
-
});
|
|
2868
|
-
}); };
|
|
2869
|
-
}
|
|
2870
|
-
if (llmTools.callEmbeddingModel !== undefined) {
|
|
2871
|
-
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2872
|
-
var promptResult;
|
|
2873
|
-
return __generator(this, function (_a) {
|
|
2874
|
-
switch (_a.label) {
|
|
2875
|
-
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
2876
|
-
case 1:
|
|
2877
|
-
promptResult = _a.sent();
|
|
2878
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2879
|
-
return [2 /*return*/, promptResult];
|
|
2880
|
-
}
|
|
2881
|
-
});
|
|
2882
|
-
}); };
|
|
2883
|
-
}
|
|
2884
|
-
// <- Note: [🤖]
|
|
2885
|
-
return proxyTools;
|
|
2886
|
-
}
|
|
2887
|
-
/**
|
|
2888
|
-
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
2889
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
2890
|
-
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
2891
|
-
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
2892
|
-
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2893
|
-
*/
|
|
2894
|
-
|
|
2895
2885
|
/**
|
|
2896
2886
|
* Takes an item or an array of items and returns an array of items
|
|
2897
2887
|
*
|
|
@@ -2931,7 +2921,7 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
2931
2921
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2932
2922
|
_b = createPipelineExecutor;
|
|
2933
2923
|
_c = {};
|
|
2934
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.
|
|
2924
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book.md')];
|
|
2935
2925
|
case 1:
|
|
2936
2926
|
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
2937
2927
|
_c.tools = tools,
|
|
@@ -3281,16 +3271,13 @@ function extensionToMimeType(value) {
|
|
|
3281
3271
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3282
3272
|
var _a;
|
|
3283
3273
|
return __awaiter(this, void 0, void 0, function () {
|
|
3284
|
-
var sourceContent, name, _b, _c, rootDirname,
|
|
3285
|
-
// <- TODO: process.cwd() if running in Node.js
|
|
3286
|
-
isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3274
|
+
var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3287
3275
|
return __generator(this, function (_e) {
|
|
3288
3276
|
switch (_e.label) {
|
|
3289
3277
|
case 0:
|
|
3290
3278
|
sourceContent = knowledgeSource.sourceContent;
|
|
3291
3279
|
name = knowledgeSource.name;
|
|
3292
|
-
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c,
|
|
3293
|
-
TODO_USE(isVerbose);
|
|
3280
|
+
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
|
|
3294
3281
|
if (!name) {
|
|
3295
3282
|
name = sourceContentToName(sourceContent);
|
|
3296
3283
|
}
|
|
@@ -3544,12 +3531,12 @@ TODO: [🧊] This is how it can look in future
|
|
|
3544
3531
|
*/
|
|
3545
3532
|
function clonePipeline(pipeline) {
|
|
3546
3533
|
// Note: Not using spread operator (...) because @@@
|
|
3547
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title,
|
|
3534
|
+
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
3548
3535
|
return {
|
|
3549
3536
|
pipelineUrl: pipelineUrl,
|
|
3550
3537
|
sourceFile: sourceFile,
|
|
3551
3538
|
title: title,
|
|
3552
|
-
|
|
3539
|
+
bookVersion: bookVersion,
|
|
3553
3540
|
description: description,
|
|
3554
3541
|
parameters: parameters,
|
|
3555
3542
|
templates: templates,
|
|
@@ -3570,15 +3557,13 @@ function clonePipeline(pipeline) {
|
|
|
3570
3557
|
*/
|
|
3571
3558
|
function prepareTemplates(pipeline, tools, options) {
|
|
3572
3559
|
return __awaiter(this, void 0, void 0, function () {
|
|
3573
|
-
var _a, maxParallelCount, templates,
|
|
3560
|
+
var _a, maxParallelCount, templates, knowledgePiecesCount, templatesPrepared;
|
|
3574
3561
|
var _this = this;
|
|
3575
3562
|
return __generator(this, function (_b) {
|
|
3576
3563
|
switch (_b.label) {
|
|
3577
3564
|
case 0:
|
|
3578
3565
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
3579
|
-
templates = pipeline.templates,
|
|
3580
|
-
// TODO: [main] !! Apply examples to each template (if missing and is for the template defined)
|
|
3581
|
-
TODO_USE(parameters);
|
|
3566
|
+
templates = pipeline.templates, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3582
3567
|
templatesPrepared = new Array(templates.length);
|
|
3583
3568
|
return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3584
3569
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
@@ -3648,7 +3633,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3648
3633
|
currentPreparation = {
|
|
3649
3634
|
id: 1,
|
|
3650
3635
|
// TODO: [🍥]> date: $currentDate(),
|
|
3651
|
-
promptbookVersion:
|
|
3636
|
+
promptbookVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
3652
3637
|
usage: ZERO_USAGE,
|
|
3653
3638
|
};
|
|
3654
3639
|
preparations = [
|
|
@@ -3972,22 +3957,12 @@ var CsvFormatDefinition = {
|
|
|
3972
3957
|
formatName: 'CSV',
|
|
3973
3958
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
3974
3959
|
isValid: function (value, settings, schema) {
|
|
3975
|
-
// TODO: Implement CSV validation
|
|
3976
|
-
TODO_USE(value /* <- TODO: Use value here */);
|
|
3977
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3978
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3979
3960
|
return true;
|
|
3980
3961
|
},
|
|
3981
3962
|
canBeValid: function (partialValue, settings, schema) {
|
|
3982
|
-
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
3983
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3984
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3985
3963
|
return true;
|
|
3986
3964
|
},
|
|
3987
3965
|
heal: function (value, settings, schema) {
|
|
3988
|
-
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
3989
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3990
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3991
3966
|
throw new Error('Not implemented');
|
|
3992
3967
|
},
|
|
3993
3968
|
subvalueDefinitions: [
|
|
@@ -4106,20 +4081,12 @@ var JsonFormatDefinition = {
|
|
|
4106
4081
|
formatName: 'JSON',
|
|
4107
4082
|
mimeType: 'application/json',
|
|
4108
4083
|
isValid: function (value, settings, schema) {
|
|
4109
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4110
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4111
4084
|
return isValidJsonString(value);
|
|
4112
4085
|
},
|
|
4113
4086
|
canBeValid: function (partialValue, settings, schema) {
|
|
4114
|
-
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
4115
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4116
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4117
4087
|
return true;
|
|
4118
4088
|
},
|
|
4119
4089
|
heal: function (value, settings, schema) {
|
|
4120
|
-
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
4121
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4122
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4123
4090
|
throw new Error('Not implemented');
|
|
4124
4091
|
},
|
|
4125
4092
|
subvalueDefinitions: [],
|
|
@@ -4201,21 +4168,12 @@ var XmlFormatDefinition = {
|
|
|
4201
4168
|
formatName: 'XML',
|
|
4202
4169
|
mimeType: 'application/xml',
|
|
4203
4170
|
isValid: function (value, settings, schema) {
|
|
4204
|
-
TODO_USE(value /* <- TODO: Use value here */);
|
|
4205
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4206
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4207
4171
|
return true;
|
|
4208
4172
|
},
|
|
4209
4173
|
canBeValid: function (partialValue, settings, schema) {
|
|
4210
|
-
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
4211
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4212
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4213
4174
|
return true;
|
|
4214
4175
|
},
|
|
4215
4176
|
heal: function (value, settings, schema) {
|
|
4216
|
-
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
4217
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4218
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4219
4177
|
throw new Error('Not implemented');
|
|
4220
4178
|
},
|
|
4221
4179
|
subvalueDefinitions: [],
|
|
@@ -4429,27 +4387,6 @@ function extractJsonBlock(markdown) {
|
|
|
4429
4387
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
4430
4388
|
*/
|
|
4431
4389
|
|
|
4432
|
-
/**
|
|
4433
|
-
* Just says that the variable is not used but should be kept
|
|
4434
|
-
* No side effects.
|
|
4435
|
-
*
|
|
4436
|
-
* Note: It can be usefull for:
|
|
4437
|
-
*
|
|
4438
|
-
* 1) Suppressing eager optimization of unused imports
|
|
4439
|
-
* 2) Suppressing eslint errors of unused variables in the tests
|
|
4440
|
-
* 3) Keeping the type of the variable for type testing
|
|
4441
|
-
*
|
|
4442
|
-
* @param value any values
|
|
4443
|
-
* @returns void
|
|
4444
|
-
* @private within the repository
|
|
4445
|
-
*/
|
|
4446
|
-
function keepUnused() {
|
|
4447
|
-
var valuesToKeep = [];
|
|
4448
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4449
|
-
valuesToKeep[_i] = arguments[_i];
|
|
4450
|
-
}
|
|
4451
|
-
}
|
|
4452
|
-
|
|
4453
4390
|
/**
|
|
4454
4391
|
* Replaces parameters in template with values from parameters object
|
|
4455
4392
|
*
|
|
@@ -4562,10 +4499,12 @@ function countLines(text) {
|
|
|
4562
4499
|
* @public exported from `@promptbook/utils`
|
|
4563
4500
|
*/
|
|
4564
4501
|
function countPages(text) {
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4502
|
+
if (text === '') {
|
|
4503
|
+
return 0;
|
|
4504
|
+
}
|
|
4505
|
+
var pagesByLinesCount = Math.ceil(countLines(text) / 44);
|
|
4506
|
+
var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
|
|
4507
|
+
return Math.max(pagesByLinesCount, pagesByCharactersCount);
|
|
4569
4508
|
}
|
|
4570
4509
|
|
|
4571
4510
|
/**
|
|
@@ -4845,7 +4784,7 @@ function executeAttempts(options) {
|
|
|
4845
4784
|
promptTitle: template.title,
|
|
4846
4785
|
promptMessage: replaceParameters(template.description || '', parameters),
|
|
4847
4786
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
4848
|
-
// TODO: [🧠] !! Figure out how to define placeholder in .
|
|
4787
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
4849
4788
|
placeholder: undefined,
|
|
4850
4789
|
priority: priority,
|
|
4851
4790
|
}))];
|
|
@@ -4943,7 +4882,6 @@ function executeAttempts(options) {
|
|
|
4943
4882
|
$ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
|
|
4944
4883
|
}
|
|
4945
4884
|
catch (error) {
|
|
4946
|
-
keepUnused(error);
|
|
4947
4885
|
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
4948
4886
|
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
4949
4887
|
}
|
|
@@ -5121,7 +5059,6 @@ function executeFormatSubvalues(options) {
|
|
|
5121
5059
|
function getContextForTemplate(template) {
|
|
5122
5060
|
return __awaiter(this, void 0, void 0, function () {
|
|
5123
5061
|
return __generator(this, function (_a) {
|
|
5124
|
-
TODO_USE(template);
|
|
5125
5062
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
5126
5063
|
});
|
|
5127
5064
|
});
|
|
@@ -5134,11 +5071,9 @@ function getContextForTemplate(template) {
|
|
|
5134
5071
|
*/
|
|
5135
5072
|
function getKnowledgeForTemplate(options) {
|
|
5136
5073
|
return __awaiter(this, void 0, void 0, function () {
|
|
5137
|
-
var preparedPipeline
|
|
5074
|
+
var preparedPipeline;
|
|
5138
5075
|
return __generator(this, function (_a) {
|
|
5139
|
-
preparedPipeline = options.preparedPipeline,
|
|
5140
|
-
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {examples}
|
|
5141
|
-
TODO_USE(template);
|
|
5076
|
+
preparedPipeline = options.preparedPipeline, options.template;
|
|
5142
5077
|
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
5143
5078
|
var content = _a.content;
|
|
5144
5079
|
return "- ".concat(content);
|
|
@@ -5155,8 +5090,6 @@ function getKnowledgeForTemplate(options) {
|
|
|
5155
5090
|
function getExamplesForTemplate(template) {
|
|
5156
5091
|
return __awaiter(this, void 0, void 0, function () {
|
|
5157
5092
|
return __generator(this, function (_a) {
|
|
5158
|
-
// TODO: [♨] Implement Better - use real index and keyword search
|
|
5159
|
-
TODO_USE(template);
|
|
5160
5093
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
5161
5094
|
});
|
|
5162
5095
|
});
|
|
@@ -5175,13 +5108,13 @@ function getReservedParametersForTemplate(options) {
|
|
|
5175
5108
|
switch (_b.label) {
|
|
5176
5109
|
case 0:
|
|
5177
5110
|
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
5178
|
-
return [4 /*yield*/, getContextForTemplate(
|
|
5111
|
+
return [4 /*yield*/, getContextForTemplate()];
|
|
5179
5112
|
case 1:
|
|
5180
5113
|
context = _b.sent();
|
|
5181
5114
|
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
5182
5115
|
case 2:
|
|
5183
5116
|
knowledge = _b.sent();
|
|
5184
|
-
return [4 /*yield*/, getExamplesForTemplate(
|
|
5117
|
+
return [4 /*yield*/, getExamplesForTemplate()];
|
|
5185
5118
|
case 3:
|
|
5186
5119
|
examples = _b.sent();
|
|
5187
5120
|
currentDate = new Date().toISOString();
|
|
@@ -5416,8 +5349,8 @@ function executePipeline(options) {
|
|
|
5416
5349
|
executionReport = {
|
|
5417
5350
|
pipelineUrl: preparedPipeline.pipelineUrl,
|
|
5418
5351
|
title: preparedPipeline.title,
|
|
5419
|
-
promptbookUsedVersion:
|
|
5420
|
-
promptbookRequestedVersion: preparedPipeline.
|
|
5352
|
+
promptbookUsedVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
5353
|
+
promptbookRequestedVersion: preparedPipeline.bookVersion,
|
|
5421
5354
|
description: preparedPipeline.description,
|
|
5422
5355
|
promptExecutions: [],
|
|
5423
5356
|
};
|
|
@@ -5796,13 +5729,13 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
5796
5729
|
*/
|
|
5797
5730
|
MarkdownScraper.prototype.scrape = function (source) {
|
|
5798
5731
|
return __awaiter(this, void 0, void 0, function () {
|
|
5799
|
-
var _a,
|
|
5732
|
+
var _a, _c, isVerbose, llm, _llms, llmTools, collection, prepareKnowledgeFromMarkdownExecutor, _d, prepareTitleExecutor, _e, prepareKeywordsExecutor, _f, knowledgeContent, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
|
|
5800
5733
|
var _g, _h, _j;
|
|
5801
5734
|
var _this = this;
|
|
5802
5735
|
return __generator(this, function (_k) {
|
|
5803
5736
|
switch (_k.label) {
|
|
5804
5737
|
case 0:
|
|
5805
|
-
_a = this.options,
|
|
5738
|
+
_a = this.options, _a.maxParallelCount, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
|
|
5806
5739
|
llm = this.tools.llm;
|
|
5807
5740
|
if (llm === undefined) {
|
|
5808
5741
|
throw new MissingToolsError('LLM tools are required for scraping external files');
|
|
@@ -5810,11 +5743,10 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
5810
5743
|
}
|
|
5811
5744
|
_llms = arrayableToArray(llm);
|
|
5812
5745
|
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
5813
|
-
TODO_USE(maxParallelCount); // <- [🪂]
|
|
5814
5746
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
5815
5747
|
_d = createPipelineExecutor;
|
|
5816
5748
|
_g = {};
|
|
5817
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.
|
|
5749
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md')];
|
|
5818
5750
|
case 1:
|
|
5819
5751
|
prepareKnowledgeFromMarkdownExecutor = _d.apply(void 0, [(_g.pipeline = _k.sent(),
|
|
5820
5752
|
_g.tools = {
|
|
@@ -5823,7 +5755,7 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
5823
5755
|
_g)]);
|
|
5824
5756
|
_e = createPipelineExecutor;
|
|
5825
5757
|
_h = {};
|
|
5826
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.
|
|
5758
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.book.md')];
|
|
5827
5759
|
case 2:
|
|
5828
5760
|
prepareTitleExecutor = _e.apply(void 0, [(_h.pipeline = _k.sent(),
|
|
5829
5761
|
_h.tools = {
|
|
@@ -5832,7 +5764,7 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
5832
5764
|
_h)]);
|
|
5833
5765
|
_f = createPipelineExecutor;
|
|
5834
5766
|
_j = {};
|
|
5835
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.
|
|
5767
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md')];
|
|
5836
5768
|
case 3:
|
|
5837
5769
|
prepareKeywordsExecutor = _f.apply(void 0, [(_j.pipeline = _k.sent(),
|
|
5838
5770
|
_j.tools = {
|
|
@@ -6299,5 +6231,5 @@ var _LegacyDocumentScraperRegistration = $scrapersRegister.register(createLegacy
|
|
|
6299
6231
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
6300
6232
|
*/
|
|
6301
6233
|
|
|
6302
|
-
export { LegacyDocumentScraper,
|
|
6234
|
+
export { BOOK_LANGUAGE_VERSION, LegacyDocumentScraper, PROMPTBOOK_ENGINE_VERSION, _LegacyDocumentScraperRegistration, createLegacyDocumentScraper };
|
|
6303
6235
|
//# sourceMappingURL=index.es.js.map
|