@promptbook/node 0.68.0-4 → 0.68.0-5

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 CHANGED
@@ -14,7 +14,7 @@ import * as dotenv from 'dotenv';
14
14
  /**
15
15
  * The version of the Promptbook library
16
16
  */
17
- var PROMPTBOOK_VERSION = '0.68.0-3';
17
+ var PROMPTBOOK_VERSION = '0.68.0-4';
18
18
  // TODO: !!!! List here all the versions and annotate + put into script
19
19
 
20
20
  /*! *****************************************************************************
@@ -874,7 +874,7 @@ function forEachAsync(array, options, callbackfunction) {
874
874
  });
875
875
  }
876
876
 
877
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.68.0-3",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.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.68.0-3",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.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.68.0-3",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.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.68.0-3",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## Sample\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.ptbk.md"}];
877
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.68.0-4",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.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.68.0-4",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.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.68.0-4",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.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.68.0-4",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## Sample\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.ptbk.md"}];
878
878
 
879
879
  /**
880
880
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -4583,12 +4583,11 @@ var templateCommandParser = {
4583
4583
  * Note: `$` is used to indicate that this function mutates given `templateJson`
4584
4584
  */
4585
4585
  $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
4586
- // TODO: !!!!!! Test multiple / no template type
4587
4586
  if ($templateJson.isTemplateTypeSet === true) {
4588
4587
  throw new ParseError(spaceTrim$1("\n Template type is already defined in the template.\n It can be defined only once.\n "));
4589
4588
  }
4590
4589
  $templateJson.isTemplateTypeSet = true;
4591
- // TODO: !!!!!! Rearrange better - but at bottom and unwrap from function
4590
+ // TODO: [🍧] Rearrange better - but at bottom and unwrap from function
4592
4591
  var expectResultingParameterName = function () {
4593
4592
  if ($templateJson.resultingParameterName) {
4594
4593
  return;
@@ -4629,12 +4628,6 @@ var templateCommandParser = {
4629
4628
  }
4630
4629
  expectResultingParameterName();
4631
4630
  $templateJson.templateType = command.templateType;
4632
- /*
4633
- TODO: !!!!!! Chat model variant should be applied in `createPipelineExecutor`
4634
- if (command.templateType ==='PROMPT_TEMPLATE' && templateModelRequirements.modelVariant === undefined) {
4635
- templateModelRequirements.modelVariant = 'CHAT';
4636
- }
4637
- */
4638
4631
  $templateJson.isTemplate = true;
4639
4632
  },
4640
4633
  /**
@@ -4657,7 +4650,15 @@ var templateCommandParser = {
4657
4650
  },
4658
4651
  };
4659
4652
  /**
4660
- * Note: [⛱] There are two types of KNOWLEDGE, ACTION and INSTRUMENT commands @@@!!!!!!
4653
+ * Note: [⛱] There are two types of KNOWLEDGE, ACTION and INSTRUMENT commands:
4654
+ * 1) There are commands `KNOWLEDGE`, `ACTION` and `INSTRUMENT` used in the pipeline head, they just define the knowledge, action or instrument as single line after the command
4655
+ * - KNOWLEDGE Look at https://en.wikipedia.org/wiki/Artificial_intelligence
4656
+ * 2) `KNOWLEDGE TEMPLATE` which has short form `KNOWLEDGE` is used in the template, does not refer the line itself, but the content of the template
4657
+ * - KNOWLEDGE TEMPLATE
4658
+ *
4659
+ * ```
4660
+ * Look at https://en.wikipedia.org/wiki/Artificial_intelligence
4661
+ * ```
4661
4662
  */
4662
4663
 
4663
4664
  /**
@@ -5205,8 +5206,16 @@ var modelCommandParser = {
5205
5206
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5206
5207
  */
5207
5208
  $applyToPipelineJson: function (command, $pipelineJson) {
5208
- // TODO: !!!!!! Error on redefine
5209
5209
  $pipelineJson.defaultModelRequirements = $pipelineJson.defaultModelRequirements || {};
5210
+ // TODO: [🚜] DRY
5211
+ if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
5212
+ if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
5213
+ console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
5214
+ }
5215
+ else {
5216
+ throw new ParseError(spaceTrim$1("\n Redefinition of MODEL `".concat(command.key, "` in the pipeline head\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
5217
+ }
5218
+ }
5210
5219
  $pipelineJson.defaultModelRequirements[command.key] = command.value;
5211
5220
  },
5212
5221
  /**
@@ -5214,13 +5223,23 @@ var modelCommandParser = {
5214
5223
  *
5215
5224
  * Note: `$` is used to indicate that this function mutates given `templateJson`
5216
5225
  */
5217
- $applyToTemplateJson: function (command, $templateJson) {
5226
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5218
5227
  if ($templateJson.templateType !== 'PROMPT_TEMPLATE') {
5219
5228
  throw new ParseError("MODEL command can only be used in PROMPT_TEMPLATE block");
5220
5229
  }
5221
- // TODO: !!!!!! Error on redefine
5222
- // TODO: Warn if setting same as default in `$pipelineJson`
5223
5230
  $templateJson.modelRequirements = $templateJson.modelRequirements || {};
5231
+ // TODO: [🚜] DRY
5232
+ if ($templateJson.modelRequirements[command.key] !== undefined) {
5233
+ if ($templateJson.modelRequirements[command.key] === command.value) {
5234
+ console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the template \"").concat($templateJson.title || $templateJson.name, "\""));
5235
+ }
5236
+ else {
5237
+ throw new ParseError(spaceTrim$1("\n Redefinition of MODEL `".concat(command.key, "` in the template \"").concat($templateJson.title || $templateJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($templateJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
5238
+ }
5239
+ }
5240
+ if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
5241
+ console.log(spaceTrim$1("\n Setting MODEL `".concat(command.key, "` in the template \"").concat($templateJson.title || $templateJson.name, "\" to the same value as in the pipeline head\n\n In pipeline head:\n - MODEL ").concat(command.key, " ").concat(($pipelineJson.defaultModelRequirements || {})[command.key], "\n\n But same value is used in the template:\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
5242
+ }
5224
5243
  $templateJson.modelRequirements[command.key] = command.value;
5225
5244
  },
5226
5245
  /**
@@ -5997,9 +6016,6 @@ var boilerplateCommandParser = {
5997
6016
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
5998
6017
  },
5999
6018
  };
6000
- /**
6001
- * TODO: !!!!!! Make .ptbk.md file with examples of the BOILERPLATE command and fail
6002
- */
6003
6019
 
6004
6020
  /**
6005
6021
  * All available command parsers
@@ -6022,6 +6038,7 @@ var COMMANDS = [
6022
6038
  personaCommandParser,
6023
6039
  foreachCommandParser,
6024
6040
  boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
6041
+ // <- Note: [♓️] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
6025
6042
  ];
6026
6043
 
6027
6044
  /**
@@ -6708,9 +6725,7 @@ function pipelineStringToJsonSync(pipelineString) {
6708
6725
  }
6709
6726
  };
6710
6727
  try {
6711
- // TODO: !!!!!! Test error situation when `PERSONA` is used before `SIMPLE TEMPLATE`
6712
- // TODO: !!!!!! Test error situation when `MODEL` is used before `SIMPLE TEMPLATE`
6713
- // TODO [♓️] List commands and before apply order them
6728
+ // TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
6714
6729
  for (var commands_1 = (e_3 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
6715
6730
  var _f = commands_1_1.value, listItem = _f.listItem, command = _f.command;
6716
6731
  _loop_3(listItem, command);
@@ -6723,7 +6738,7 @@ function pipelineStringToJsonSync(pipelineString) {
6723
6738
  }
6724
6739
  finally { if (e_3) throw e_3.error; }
6725
6740
  }
6726
- // TODO: [🍧] !!!!!! Should be done in TEMPLATE command
6741
+ // TODO: [🍧] Should be done in TEMPLATE command
6727
6742
  if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
6728
6743
  if (!language) {
6729
6744
  throw new ParseError(spaceTrim(function (block) { return "\n You must specify the language of the script in the SCRIPT TEMPLATE\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
@@ -6736,9 +6751,7 @@ function pipelineStringToJsonSync(pipelineString) {
6736
6751
  }
6737
6752
  $templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
6738
6753
  /*
6739
- // TODO: [🍧] !!!!!! This should be checked in `MODEL` command + better error message
6740
- // TODO: [🍧] !!!!!! Write error `.ptbk.md` file for `MODEL` and `PERSONA` command used in non-prompt template
6741
- // TODO: [🍧] !!!!!! `PERSONA` command should behave same as `MODEL` command - only usable in prompt template
6754
+ // TODO: [🍧] This should be checked in `MODEL` command + better error message
6742
6755
  if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
6743
6756
  throw new UnexpectedError(
6744
6757
  spaceTrim(