@promptbook/node 0.74.0-7 → 0.74.0
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 +3 -15
- package/esm/index.es.js +163 -76
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +5 -1
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/run.d.ts +1 -1
- package/esm/typings/src/cli/main.d.ts +4 -1
- package/esm/typings/src/cli/promptbookCli.d.ts +1 -1
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- 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 +1 -1
- 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/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/utils/expectation-counters/config.d.ts +12 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -0
- package/package.json +2 -2
- package/umd/index.umd.js +163 -76
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/storage/{memory → local-storage}/utils/makePromptbookStorageFromWebStorage.d.ts +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
*
|
|
44
44
|
* @see https://github.com/webgptorg/promptbook
|
|
45
45
|
*/
|
|
46
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-
|
|
46
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-13';
|
|
47
47
|
/**
|
|
48
48
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
49
49
|
*/
|
|
@@ -380,6 +380,13 @@
|
|
|
380
380
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
381
381
|
*/
|
|
382
382
|
|
|
383
|
+
// <- TODO: [🐊] Pick the best claim
|
|
384
|
+
/**
|
|
385
|
+
* When the title is not provided, the default title is used
|
|
386
|
+
*
|
|
387
|
+
* @public exported from `@promptbook/core`
|
|
388
|
+
*/
|
|
389
|
+
var DEFAULT_TITLE = "Untitled";
|
|
383
390
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
384
391
|
/**
|
|
385
392
|
* The maximum number of iterations for a loops
|
|
@@ -529,13 +536,13 @@
|
|
|
529
536
|
/**
|
|
530
537
|
* Converts promptbook in JSON format to string format
|
|
531
538
|
*
|
|
532
|
-
* @param pipelineJson Promptbook in JSON format (.
|
|
533
|
-
* @returns Promptbook in string format (.
|
|
539
|
+
* @param pipelineJson Promptbook in JSON format (.book.json)
|
|
540
|
+
* @returns Promptbook in string format (.book.md)
|
|
534
541
|
* @public exported from `@promptbook/core`
|
|
535
542
|
*/
|
|
536
543
|
function pipelineJsonToString(pipelineJson) {
|
|
537
544
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
538
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl,
|
|
545
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
|
|
539
546
|
var pipelineString = "# ".concat(title);
|
|
540
547
|
if (description) {
|
|
541
548
|
pipelineString += '\n\n';
|
|
@@ -545,8 +552,10 @@
|
|
|
545
552
|
if (pipelineUrl) {
|
|
546
553
|
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
547
554
|
}
|
|
548
|
-
|
|
549
|
-
|
|
555
|
+
if (bookVersion !== "undefined") {
|
|
556
|
+
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
557
|
+
}
|
|
558
|
+
// TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
|
|
550
559
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
551
560
|
try {
|
|
552
561
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -726,7 +735,7 @@
|
|
|
726
735
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
727
736
|
* TODO: [🏛] Maybe make some markdown builder
|
|
728
737
|
* TODO: [🏛] Escape all
|
|
729
|
-
* TODO: [🧠] Should be in generated .
|
|
738
|
+
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
730
739
|
*/
|
|
731
740
|
|
|
732
741
|
/**
|
|
@@ -1364,7 +1373,7 @@
|
|
|
1364
1373
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
1365
1374
|
*/
|
|
1366
1375
|
|
|
1367
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.
|
|
1376
|
+
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"}];
|
|
1368
1377
|
|
|
1369
1378
|
/**
|
|
1370
1379
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1539,7 +1548,7 @@
|
|
|
1539
1548
|
if (!url.startsWith('https://')) {
|
|
1540
1549
|
return false;
|
|
1541
1550
|
}
|
|
1542
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.
|
|
1551
|
+
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
1543
1552
|
return false;
|
|
1544
1553
|
}
|
|
1545
1554
|
if (url.includes('#')) {
|
|
@@ -1608,9 +1617,9 @@
|
|
|
1608
1617
|
// <- Note: [🚲]
|
|
1609
1618
|
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1610
1619
|
}
|
|
1611
|
-
if (pipeline.
|
|
1620
|
+
if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
|
|
1612
1621
|
// <- Note: [🚲]
|
|
1613
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.
|
|
1622
|
+
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1614
1623
|
}
|
|
1615
1624
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1616
1625
|
if (!Array.isArray(pipeline.parameters)) {
|
|
@@ -3003,28 +3012,42 @@
|
|
|
3003
3012
|
return text.length;
|
|
3004
3013
|
}
|
|
3005
3014
|
|
|
3015
|
+
/**
|
|
3016
|
+
* Number of characters per standard line with 11pt Arial font size.
|
|
3017
|
+
*
|
|
3018
|
+
* @public exported from `@promptbook/utils`
|
|
3019
|
+
*/
|
|
3020
|
+
var CHARACTERS_PER_STANDARD_LINE = 63;
|
|
3021
|
+
/**
|
|
3022
|
+
* Number of lines per standard A4 page with 11pt Arial font size and standard margins and spacing.
|
|
3023
|
+
*
|
|
3024
|
+
* @public exported from `@promptbook/utils`
|
|
3025
|
+
*/
|
|
3026
|
+
var LINES_PER_STANDARD_PAGE = 44;
|
|
3027
|
+
|
|
3006
3028
|
/**
|
|
3007
3029
|
* Counts number of lines in the text
|
|
3008
3030
|
*
|
|
3031
|
+
* Note: This does not check only for the presence of newlines, but also for the length of the standard line.
|
|
3032
|
+
*
|
|
3009
3033
|
* @public exported from `@promptbook/utils`
|
|
3010
3034
|
*/
|
|
3011
3035
|
function countLines(text) {
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
return
|
|
3036
|
+
text = text.replace('\r\n', '\n');
|
|
3037
|
+
text = text.replace('\r', '\n');
|
|
3038
|
+
var lines = text.split('\n');
|
|
3039
|
+
return lines.reduce(function (count, line) { return count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE); }, 0);
|
|
3016
3040
|
}
|
|
3017
3041
|
|
|
3018
3042
|
/**
|
|
3019
3043
|
* Counts number of pages in the text
|
|
3020
3044
|
*
|
|
3045
|
+
* Note: This does not check only for the count of newlines, but also for the length of the standard line and length of the standard page.
|
|
3046
|
+
*
|
|
3021
3047
|
* @public exported from `@promptbook/utils`
|
|
3022
3048
|
*/
|
|
3023
3049
|
function countPages(text) {
|
|
3024
|
-
|
|
3025
|
-
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
3026
|
-
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
3027
|
-
return pageCount;
|
|
3050
|
+
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
3028
3051
|
}
|
|
3029
3052
|
|
|
3030
3053
|
/**
|
|
@@ -3565,7 +3588,7 @@
|
|
|
3565
3588
|
promptTitle: template.title,
|
|
3566
3589
|
promptMessage: replaceParameters(template.description || '', parameters),
|
|
3567
3590
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3568
|
-
// TODO: [🧠] !! Figure out how to define placeholder in .
|
|
3591
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
3569
3592
|
placeholder: undefined,
|
|
3570
3593
|
priority: priority,
|
|
3571
3594
|
}))];
|
|
@@ -4131,7 +4154,7 @@
|
|
|
4131
4154
|
pipelineUrl: preparedPipeline.pipelineUrl,
|
|
4132
4155
|
title: preparedPipeline.title,
|
|
4133
4156
|
promptbookUsedVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
4134
|
-
promptbookRequestedVersion: preparedPipeline.
|
|
4157
|
+
promptbookRequestedVersion: preparedPipeline.bookVersion,
|
|
4135
4158
|
description: preparedPipeline.description,
|
|
4136
4159
|
promptExecutions: [],
|
|
4137
4160
|
};
|
|
@@ -4480,7 +4503,7 @@
|
|
|
4480
4503
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
4481
4504
|
_b = createPipelineExecutor;
|
|
4482
4505
|
_c = {};
|
|
4483
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.
|
|
4506
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book.md')];
|
|
4484
4507
|
case 1:
|
|
4485
4508
|
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
4486
4509
|
_c.tools = tools,
|
|
@@ -5237,12 +5260,12 @@
|
|
|
5237
5260
|
*/
|
|
5238
5261
|
function clonePipeline(pipeline) {
|
|
5239
5262
|
// Note: Not using spread operator (...) because @@@
|
|
5240
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title,
|
|
5263
|
+
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;
|
|
5241
5264
|
return {
|
|
5242
5265
|
pipelineUrl: pipelineUrl,
|
|
5243
5266
|
sourceFile: sourceFile,
|
|
5244
5267
|
title: title,
|
|
5245
|
-
|
|
5268
|
+
bookVersion: bookVersion,
|
|
5246
5269
|
description: description,
|
|
5247
5270
|
parameters: parameters,
|
|
5248
5271
|
templates: templates,
|
|
@@ -5454,7 +5477,7 @@
|
|
|
5454
5477
|
throw new ParseError("Source not valid");
|
|
5455
5478
|
}
|
|
5456
5479
|
if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
|
|
5457
|
-
throw new ParseError("Source cannot be outside of the .
|
|
5480
|
+
throw new ParseError("Source cannot be outside of the .book.md folder");
|
|
5458
5481
|
}
|
|
5459
5482
|
return {
|
|
5460
5483
|
type: 'KNOWLEDGE',
|
|
@@ -6104,7 +6127,7 @@
|
|
|
6104
6127
|
/**
|
|
6105
6128
|
* Parses the foreach command
|
|
6106
6129
|
*
|
|
6107
|
-
* Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.
|
|
6130
|
+
* Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.book.md` file
|
|
6108
6131
|
*
|
|
6109
6132
|
* @see `documentationUrl` for more details
|
|
6110
6133
|
* @private within the commands folder
|
|
@@ -6254,7 +6277,7 @@
|
|
|
6254
6277
|
},
|
|
6255
6278
|
};
|
|
6256
6279
|
/**
|
|
6257
|
-
* TODO: [🍭] Make .
|
|
6280
|
+
* TODO: [🍭] Make .book.md file with examples of the FOREACH with wrong parsing and logic
|
|
6258
6281
|
*/
|
|
6259
6282
|
|
|
6260
6283
|
/**
|
|
@@ -6888,7 +6911,7 @@
|
|
|
6888
6911
|
/**
|
|
6889
6912
|
* Description of the BOOK_VERSION command
|
|
6890
6913
|
*/
|
|
6891
|
-
description: "Which version of the Book language is the .
|
|
6914
|
+
description: "Which version of the Book language is the .book.md using",
|
|
6892
6915
|
/**
|
|
6893
6916
|
* Link to documentation
|
|
6894
6917
|
*/
|
|
@@ -6902,19 +6925,19 @@
|
|
|
6902
6925
|
*/
|
|
6903
6926
|
parse: function (input) {
|
|
6904
6927
|
var args = input.args;
|
|
6905
|
-
var
|
|
6906
|
-
if (
|
|
6928
|
+
var bookVersion = args.pop();
|
|
6929
|
+
if (bookVersion === undefined) {
|
|
6907
6930
|
throw new ParseError("Version is required");
|
|
6908
6931
|
}
|
|
6909
|
-
if (!isValidPromptbookVersion(
|
|
6910
|
-
throw new ParseError("Invalid Promptbook version \"".concat(
|
|
6932
|
+
if (!isValidPromptbookVersion(bookVersion)) {
|
|
6933
|
+
throw new ParseError("Invalid Promptbook version \"".concat(bookVersion, "\""));
|
|
6911
6934
|
}
|
|
6912
6935
|
if (args.length > 0 && !(((args.length === 1 && args[0]) || '').toUpperCase() === 'VERSION')) {
|
|
6913
6936
|
throw new ParseError("Can not have more than one Promptbook version");
|
|
6914
6937
|
}
|
|
6915
6938
|
return {
|
|
6916
6939
|
type: 'BOOK_VERSION',
|
|
6917
|
-
|
|
6940
|
+
bookVersion: bookVersion,
|
|
6918
6941
|
};
|
|
6919
6942
|
},
|
|
6920
6943
|
/**
|
|
@@ -6924,7 +6947,7 @@
|
|
|
6924
6947
|
*/
|
|
6925
6948
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
6926
6949
|
// TODO: Warn if the version is overridden
|
|
6927
|
-
$pipelineJson.
|
|
6950
|
+
$pipelineJson.bookVersion = command.bookVersion;
|
|
6928
6951
|
},
|
|
6929
6952
|
/**
|
|
6930
6953
|
* Converts the BOOK_VERSION command back to string
|
|
@@ -6977,9 +7000,9 @@
|
|
|
6977
7000
|
* Example usages of the URL command
|
|
6978
7001
|
*/
|
|
6979
7002
|
examples: [
|
|
6980
|
-
'PIPELINE URL https://promptbook.studio/library/write-cv.
|
|
6981
|
-
'URL https://promptbook.studio/library/write-cv.
|
|
6982
|
-
'https://promptbook.studio/library/write-cv.
|
|
7003
|
+
'PIPELINE URL https://promptbook.studio/library/write-cv.book.md',
|
|
7004
|
+
'URL https://promptbook.studio/library/write-cv.book.md',
|
|
7005
|
+
'https://promptbook.studio/library/write-cv.book.md',
|
|
6983
7006
|
],
|
|
6984
7007
|
/**
|
|
6985
7008
|
* Parses the URL command
|
|
@@ -7180,7 +7203,7 @@
|
|
|
7180
7203
|
/**
|
|
7181
7204
|
* Parses the boilerplate command
|
|
7182
7205
|
*
|
|
7183
|
-
* Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.
|
|
7206
|
+
* Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.book.md` file
|
|
7184
7207
|
*
|
|
7185
7208
|
* @see `documentationUrl` for more details
|
|
7186
7209
|
* @private within the commands folder
|
|
@@ -7234,7 +7257,7 @@
|
|
|
7234
7257
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
7235
7258
|
*/
|
|
7236
7259
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
7237
|
-
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .
|
|
7260
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
|
|
7238
7261
|
},
|
|
7239
7262
|
/**
|
|
7240
7263
|
* Apply the BOILERPLATE command to the `pipelineJson`
|
|
@@ -7242,7 +7265,7 @@
|
|
|
7242
7265
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
7243
7266
|
*/
|
|
7244
7267
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
7245
|
-
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .
|
|
7268
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
|
|
7246
7269
|
},
|
|
7247
7270
|
/**
|
|
7248
7271
|
* Converts the BOILERPLATE command back to string
|
|
@@ -7258,7 +7281,7 @@
|
|
|
7258
7281
|
* Note: This is used in `pipelineJsonToString` utility
|
|
7259
7282
|
*/
|
|
7260
7283
|
takeFromPipelineJson: function (pipelineJson) {
|
|
7261
|
-
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .
|
|
7284
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
|
|
7262
7285
|
},
|
|
7263
7286
|
/**
|
|
7264
7287
|
* Reads the BOILERPLATE command from the `TemplateJson`
|
|
@@ -7266,7 +7289,7 @@
|
|
|
7266
7289
|
* Note: This is used in `pipelineJsonToString` utility
|
|
7267
7290
|
*/
|
|
7268
7291
|
takeFromTemplateJson: function ($templateJson) {
|
|
7269
|
-
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .
|
|
7292
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
|
|
7270
7293
|
},
|
|
7271
7294
|
};
|
|
7272
7295
|
|
|
@@ -7595,7 +7618,7 @@
|
|
|
7595
7618
|
return;
|
|
7596
7619
|
}
|
|
7597
7620
|
if (!section.startsWith('#')) {
|
|
7598
|
-
section = "#
|
|
7621
|
+
section = "# ".concat(DEFAULT_TITLE, "\n\n").concat(section);
|
|
7599
7622
|
}
|
|
7600
7623
|
sections.push(section);
|
|
7601
7624
|
buffer = [];
|
|
@@ -7659,7 +7682,7 @@
|
|
|
7659
7682
|
var e_1, _a;
|
|
7660
7683
|
var sections = splitMarkdownIntoSections(markdown);
|
|
7661
7684
|
if (sections.length === 0) {
|
|
7662
|
-
return
|
|
7685
|
+
return "# ".concat(DEFAULT_TITLE);
|
|
7663
7686
|
}
|
|
7664
7687
|
var flattenedMarkdown = '';
|
|
7665
7688
|
var parsedSections = sections.map(parseMarkdownSection);
|
|
@@ -7670,7 +7693,7 @@
|
|
|
7670
7693
|
}
|
|
7671
7694
|
else {
|
|
7672
7695
|
parsedSections.unshift(firstSection);
|
|
7673
|
-
flattenedMarkdown += "#
|
|
7696
|
+
flattenedMarkdown += "# ".concat(DEFAULT_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
|
|
7674
7697
|
}
|
|
7675
7698
|
try {
|
|
7676
7699
|
for (var parsedSections_1 = __values(parsedSections), parsedSections_1_1 = parsedSections_1.next(); !parsedSections_1_1.done; parsedSections_1_1 = parsedSections_1.next()) {
|
|
@@ -7742,17 +7765,17 @@
|
|
|
7742
7765
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
7743
7766
|
* Note: This function acts as compilation process
|
|
7744
7767
|
*
|
|
7745
|
-
* @param pipelineString {Promptbook} in string markdown format (.
|
|
7746
|
-
* @returns {Promptbook} compiled in JSON format (.
|
|
7768
|
+
* @param pipelineString {Promptbook} in string markdown format (.book.md)
|
|
7769
|
+
* @returns {Promptbook} compiled in JSON format (.book.json)
|
|
7747
7770
|
* @throws {ParseError} if the promptbook string is not valid
|
|
7748
7771
|
* @public exported from `@promptbook/core`
|
|
7749
7772
|
*/
|
|
7750
7773
|
function pipelineStringToJsonSync(pipelineString) {
|
|
7751
|
-
var e_1, _a, e_2, _b;
|
|
7774
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
7752
7775
|
var $pipelineJson = {
|
|
7753
7776
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
7754
7777
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
7755
|
-
|
|
7778
|
+
bookVersion: undefined /* <- Note: By default no explicit version */,
|
|
7756
7779
|
description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
|
|
7757
7780
|
parameters: [],
|
|
7758
7781
|
templates: [],
|
|
@@ -7776,7 +7799,7 @@
|
|
|
7776
7799
|
// =============================================================
|
|
7777
7800
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
7778
7801
|
if (pipelineString.startsWith('#!')) {
|
|
7779
|
-
var
|
|
7802
|
+
var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
|
|
7780
7803
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
7781
7804
|
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
7782
7805
|
}
|
|
@@ -7786,7 +7809,7 @@
|
|
|
7786
7809
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
7787
7810
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
7788
7811
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
7789
|
-
var
|
|
7812
|
+
var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
|
|
7790
7813
|
if (pipelineHead === undefined) {
|
|
7791
7814
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
7792
7815
|
}
|
|
@@ -7814,6 +7837,8 @@
|
|
|
7814
7837
|
if (parameterDescription) {
|
|
7815
7838
|
existingParameter.description = parameterDescription;
|
|
7816
7839
|
}
|
|
7840
|
+
existingParameter.isInput = existingParameter.isInput || isInput;
|
|
7841
|
+
existingParameter.isOutput = existingParameter.isOutput || isOutput;
|
|
7817
7842
|
}
|
|
7818
7843
|
else {
|
|
7819
7844
|
$pipelineJson.parameters.push({
|
|
@@ -7876,10 +7901,10 @@
|
|
|
7876
7901
|
finally { if (e_1) throw e_1.error; }
|
|
7877
7902
|
}
|
|
7878
7903
|
var _loop_2 = function (section) {
|
|
7879
|
-
var
|
|
7904
|
+
var e_5, _l, e_6, _m;
|
|
7880
7905
|
// TODO: Parse template description (the content out of the codeblock and lists)
|
|
7881
7906
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
7882
|
-
var
|
|
7907
|
+
var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
|
|
7883
7908
|
// TODO: [🎾][1] DRY description
|
|
7884
7909
|
var description_1 = section.content;
|
|
7885
7910
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -7920,7 +7945,7 @@
|
|
|
7920
7945
|
}) === false) {
|
|
7921
7946
|
templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
7922
7947
|
}
|
|
7923
|
-
var
|
|
7948
|
+
var _loop_4 = function (listItem, command) {
|
|
7924
7949
|
var commandParser = getParserForCommand(command);
|
|
7925
7950
|
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
7926
7951
|
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " is not allowed in the template of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
@@ -7943,17 +7968,17 @@
|
|
|
7943
7968
|
};
|
|
7944
7969
|
try {
|
|
7945
7970
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
7946
|
-
for (var commands_1 = (
|
|
7947
|
-
var
|
|
7948
|
-
|
|
7971
|
+
for (var commands_1 = (e_5 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
|
|
7972
|
+
var _p = commands_1_1.value, listItem = _p.listItem, command = _p.command;
|
|
7973
|
+
_loop_4(listItem, command);
|
|
7949
7974
|
}
|
|
7950
7975
|
}
|
|
7951
|
-
catch (
|
|
7976
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
7952
7977
|
finally {
|
|
7953
7978
|
try {
|
|
7954
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
7979
|
+
if (commands_1_1 && !commands_1_1.done && (_l = commands_1.return)) _l.call(commands_1);
|
|
7955
7980
|
}
|
|
7956
|
-
finally { if (
|
|
7981
|
+
finally { if (e_5) throw e_5.error; }
|
|
7957
7982
|
}
|
|
7958
7983
|
// TODO: [🍧] Should be done in TEMPLATE command
|
|
7959
7984
|
if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
|
|
@@ -7967,6 +7992,26 @@
|
|
|
7967
7992
|
language;
|
|
7968
7993
|
}
|
|
7969
7994
|
$templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
|
|
7995
|
+
try {
|
|
7996
|
+
for (var _q = (e_6 = void 0, __values($templateJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
7997
|
+
var parameterName = _r.value;
|
|
7998
|
+
// TODO: [🧠] This definition should be made first in the template
|
|
7999
|
+
defineParam({
|
|
8000
|
+
parameterName: parameterName,
|
|
8001
|
+
parameterDescription: null,
|
|
8002
|
+
isInput: false,
|
|
8003
|
+
isOutput: false,
|
|
8004
|
+
// <- Note: In this case null+false+false means that we do not know yet if it is input or output and we will set it later
|
|
8005
|
+
});
|
|
8006
|
+
}
|
|
8007
|
+
}
|
|
8008
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
8009
|
+
finally {
|
|
8010
|
+
try {
|
|
8011
|
+
if (_r && !_r.done && (_m = _q.return)) _m.call(_q);
|
|
8012
|
+
}
|
|
8013
|
+
finally { if (e_6) throw e_6.error; }
|
|
8014
|
+
}
|
|
7970
8015
|
/*
|
|
7971
8016
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
7972
8017
|
if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
@@ -8008,9 +8053,51 @@
|
|
|
8008
8053
|
finally { if (e_2) throw e_2.error; }
|
|
8009
8054
|
}
|
|
8010
8055
|
// =============================================================
|
|
8011
|
-
// Note: 5️⃣
|
|
8056
|
+
// Note: 5️⃣ Mark parameters as INPUT if not explicitly set
|
|
8057
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8058
|
+
var _loop_3 = function (parameter) {
|
|
8059
|
+
var isThisParameterResulting = $pipelineJson.templates.some(function (template) { return template.resultingParameterName === parameter.name; });
|
|
8060
|
+
if (!isThisParameterResulting) {
|
|
8061
|
+
parameter.isInput = true;
|
|
8062
|
+
}
|
|
8063
|
+
};
|
|
8064
|
+
try {
|
|
8065
|
+
for (var _g = __values($pipelineJson.parameters), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
8066
|
+
var parameter = _h.value;
|
|
8067
|
+
_loop_3(parameter);
|
|
8068
|
+
}
|
|
8069
|
+
}
|
|
8070
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
8071
|
+
finally {
|
|
8072
|
+
try {
|
|
8073
|
+
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
8074
|
+
}
|
|
8075
|
+
finally { if (e_3) throw e_3.error; }
|
|
8076
|
+
}
|
|
8077
|
+
}
|
|
8078
|
+
// =============================================================
|
|
8079
|
+
// Note: 6️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8080
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8081
|
+
try {
|
|
8082
|
+
for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
8083
|
+
var parameter = _k.value;
|
|
8084
|
+
if (!parameter.isInput) {
|
|
8085
|
+
parameter.isOutput = true;
|
|
8086
|
+
}
|
|
8087
|
+
}
|
|
8088
|
+
}
|
|
8089
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8090
|
+
finally {
|
|
8091
|
+
try {
|
|
8092
|
+
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
|
|
8093
|
+
}
|
|
8094
|
+
finally { if (e_4) throw e_4.error; }
|
|
8095
|
+
}
|
|
8096
|
+
}
|
|
8097
|
+
// =============================================================
|
|
8098
|
+
// Note: 7️⃣ Cleanup of undefined values
|
|
8012
8099
|
$pipelineJson.templates.forEach(function (templates) {
|
|
8013
|
-
var
|
|
8100
|
+
var e_7, _a;
|
|
8014
8101
|
try {
|
|
8015
8102
|
for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8016
8103
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8019,16 +8106,16 @@
|
|
|
8019
8106
|
}
|
|
8020
8107
|
}
|
|
8021
8108
|
}
|
|
8022
|
-
catch (
|
|
8109
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8023
8110
|
finally {
|
|
8024
8111
|
try {
|
|
8025
8112
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8026
8113
|
}
|
|
8027
|
-
finally { if (
|
|
8114
|
+
finally { if (e_7) throw e_7.error; }
|
|
8028
8115
|
}
|
|
8029
8116
|
});
|
|
8030
8117
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8031
|
-
var
|
|
8118
|
+
var e_8, _a;
|
|
8032
8119
|
try {
|
|
8033
8120
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8034
8121
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8037,12 +8124,12 @@
|
|
|
8037
8124
|
}
|
|
8038
8125
|
}
|
|
8039
8126
|
}
|
|
8040
|
-
catch (
|
|
8127
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8041
8128
|
finally {
|
|
8042
8129
|
try {
|
|
8043
8130
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8044
8131
|
}
|
|
8045
|
-
finally { if (
|
|
8132
|
+
finally { if (e_8) throw e_8.error; }
|
|
8046
8133
|
}
|
|
8047
8134
|
});
|
|
8048
8135
|
// =============================================================
|
|
@@ -8071,10 +8158,10 @@
|
|
|
8071
8158
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
8072
8159
|
* Note: This function acts as compilation process
|
|
8073
8160
|
*
|
|
8074
|
-
* @param pipelineString {Promptbook} in string markdown format (.
|
|
8161
|
+
* @param pipelineString {Promptbook} in string markdown format (.book.md)
|
|
8075
8162
|
* @param tools - Tools for the preparation and scraping - if not provided together with `llm`, the preparation will be skipped
|
|
8076
8163
|
* @param options - Options and tools for the compilation
|
|
8077
|
-
* @returns {Promptbook} compiled in JSON format (.
|
|
8164
|
+
* @returns {Promptbook} compiled in JSON format (.book.json)
|
|
8078
8165
|
* @throws {ParseError} if the promptbook string is not valid
|
|
8079
8166
|
* @public exported from `@promptbook/core`
|
|
8080
8167
|
*/
|
|
@@ -9455,13 +9542,13 @@
|
|
|
9455
9542
|
return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
|
|
9456
9543
|
case 1:
|
|
9457
9544
|
fileNames = _b.sent();
|
|
9458
|
-
// Note: First load all .
|
|
9459
|
-
// .
|
|
9545
|
+
// Note: First load all .book.json and then .book.md files
|
|
9546
|
+
// .book.json can be prepared so it is faster to load
|
|
9460
9547
|
fileNames.sort(function (a, b) {
|
|
9461
|
-
if (a.endsWith('.
|
|
9548
|
+
if (a.endsWith('.book.json') && b.endsWith('.book.md')) {
|
|
9462
9549
|
return -1;
|
|
9463
9550
|
}
|
|
9464
|
-
if (a.endsWith('.
|
|
9551
|
+
if (a.endsWith('.book.md') && b.endsWith('.book.json')) {
|
|
9465
9552
|
return 1;
|
|
9466
9553
|
}
|
|
9467
9554
|
return 0;
|
|
@@ -9478,7 +9565,7 @@
|
|
|
9478
9565
|
case 1:
|
|
9479
9566
|
_e.trys.push([1, 8, , 9]);
|
|
9480
9567
|
pipeline = null;
|
|
9481
|
-
if (!fileName.endsWith('.
|
|
9568
|
+
if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
|
|
9482
9569
|
return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
|
|
9483
9570
|
case 2:
|
|
9484
9571
|
pipelineString = (_e.sent());
|
|
@@ -9490,7 +9577,7 @@
|
|
|
9490
9577
|
pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
|
|
9491
9578
|
return [3 /*break*/, 7];
|
|
9492
9579
|
case 4:
|
|
9493
|
-
if (!fileName.endsWith('.
|
|
9580
|
+
if (!fileName.endsWith('.book.json')) return [3 /*break*/, 6];
|
|
9494
9581
|
_d = (_c = JSON).parse;
|
|
9495
9582
|
return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
|
|
9496
9583
|
case 5:
|
|
@@ -9658,7 +9745,7 @@
|
|
|
9658
9745
|
return pipelineJsonStringified;
|
|
9659
9746
|
}
|
|
9660
9747
|
/**
|
|
9661
|
-
* TODO: [🐝] Not Working propperly @see https://promptbook.studio/examples/mixed-knowledge.
|
|
9748
|
+
* TODO: [🐝] Not Working propperly @see https://promptbook.studio/examples/mixed-knowledge.book.md
|
|
9662
9749
|
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
9663
9750
|
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
9664
9751
|
* TODO: [🍙] Make some standard order of json properties
|