@promptbook/cli 0.61.0-16 → 0.61.0-18

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
@@ -150,7 +150,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
150
150
  /**
151
151
  * The version of the Promptbook library
152
152
  */
153
- var PROMPTBOOK_VERSION = '0.61.0-15';
153
+ var PROMPTBOOK_VERSION = '0.61.0-17';
154
154
  // TODO: !!!! List here all the versions and annotate + put into script
155
155
 
156
156
  /**
@@ -492,7 +492,7 @@ function forEachAsync(array, options, callbackfunction) {
492
492
  });
493
493
  }
494
494
 
495
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-15",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-15",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-15",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-15",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-15",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-15",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-15",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-15",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
495
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-17",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-17",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-17",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-17",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
496
496
 
497
497
  /**
498
498
  * Prettify the html code
@@ -1101,11 +1101,11 @@ function validatePipeline(pipeline) {
1101
1101
  throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
1102
1102
  .map(function (_a) {
1103
1103
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1104
- return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
1104
+ return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
1105
1105
  .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
1106
- .join(', '));
1106
+ .join(' and '));
1107
1107
  })
1108
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
1108
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n "); }));
1109
1109
  }
1110
1110
  resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
1111
1111
  var resultingParameterName = _a.resultingParameterName;
@@ -1168,79 +1168,94 @@ var ReferenceError$1 = /** @class */ (function (_super) {
1168
1168
  }(Error));
1169
1169
 
1170
1170
  /**
1171
- * Library of promptbooks that groups together promptbooks for an application.
1172
- * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1171
+ * Unprepare just strips the preparation data of the pipeline
1172
+ */
1173
+ function unpreparePipeline(pipeline) {
1174
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
1175
+ personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1176
+ knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1177
+ return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1178
+ }
1179
+ /**
1180
+ * TODO: [🔼] !!! Export via `@promptbook/core`
1181
+ * TODO: Write tests for `preparePipeline`
1182
+ */
1183
+
1184
+ /**
1185
+ * Library of pipelines that groups together pipelines for an application.
1186
+ * This implementation is a very thin wrapper around the Array / Map of pipelines.
1173
1187
  *
1174
1188
  * @private use `createCollectionFromJson` instead
1175
- * @see https://github.com/webgptorg/promptbook#promptbook-collection
1189
+ * @see https://github.com/webgptorg/pipeline#pipeline-collection
1176
1190
  */
1177
1191
  var SimplePipelineCollection = /** @class */ (function () {
1178
1192
  /**
1179
- * Constructs a pipeline collection from promptbooks
1193
+ * Constructs a pipeline collection from pipelines
1180
1194
  *
1181
- * @param promptbooks @@@
1195
+ * @param pipelines @@@
1182
1196
  *
1183
1197
  * @private Use instead `createCollectionFromJson`
1184
- * Note: During the construction logic of all promptbooks are validated
1198
+ * Note: During the construction logic of all pipelines are validated
1185
1199
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
1186
1200
  */
1187
1201
  function SimplePipelineCollection() {
1188
1202
  var e_1, _a;
1189
- var promptbooks = [];
1203
+ var pipelines = [];
1190
1204
  for (var _i = 0; _i < arguments.length; _i++) {
1191
- promptbooks[_i] = arguments[_i];
1205
+ pipelines[_i] = arguments[_i];
1192
1206
  }
1193
1207
  this.collection = new Map();
1194
1208
  try {
1195
- for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
1196
- var promptbook = promptbooks_1_1.value;
1197
- if (promptbook.pipelineUrl === undefined) {
1198
- throw new ReferenceError$1(spaceTrim$1("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n File:\n ").concat(promptbook.sourceFile || 'Unknown', "\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the pipeline collection\n\n ")));
1209
+ for (var pipelines_1 = __values(pipelines), pipelines_1_1 = pipelines_1.next(); !pipelines_1_1.done; pipelines_1_1 = pipelines_1.next()) {
1210
+ var pipeline = pipelines_1_1.value;
1211
+ if (pipeline.pipelineUrl === undefined) {
1212
+ throw new ReferenceError$1(spaceTrim$1("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
1199
1213
  }
1200
- validatePipeline(promptbook);
1214
+ validatePipeline(pipeline);
1201
1215
  // Note: [🦄]
1202
- if (this.collection.has(promptbook.pipelineUrl) &&
1203
- pipelineJsonToString(promptbook) !== pipelineJsonToString(this.collection.get(promptbook.pipelineUrl))) {
1204
- var existing = this.collection.get(promptbook.pipelineUrl);
1205
- throw new ReferenceError$1(spaceTrim$1("\n Promptbook with URL \"".concat(promptbook.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(promptbook.sourceFile || 'Unknown', "\n\n Note: Promptbooks with the same URL are not allowed\n Only exepction is when the promptbooks are identical\n\n ")));
1216
+ if (this.collection.has(pipeline.pipelineUrl) &&
1217
+ pipelineJsonToString(unpreparePipeline(pipeline)) !==
1218
+ pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1219
+ var existing = this.collection.get(pipeline.pipelineUrl);
1220
+ throw new ReferenceError$1(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1206
1221
  }
1207
- this.collection.set(promptbook.pipelineUrl, promptbook);
1222
+ this.collection.set(pipeline.pipelineUrl, pipeline);
1208
1223
  }
1209
1224
  }
1210
1225
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1211
1226
  finally {
1212
1227
  try {
1213
- if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
1228
+ if (pipelines_1_1 && !pipelines_1_1.done && (_a = pipelines_1.return)) _a.call(pipelines_1);
1214
1229
  }
1215
1230
  finally { if (e_1) throw e_1.error; }
1216
1231
  }
1217
1232
  }
1218
1233
  /**
1219
- * Gets all promptbooks in the collection
1234
+ * Gets all pipelines in the collection
1220
1235
  */
1221
1236
  SimplePipelineCollection.prototype.listPipelines = function () {
1222
1237
  return Array.from(this.collection.keys());
1223
1238
  };
1224
1239
  /**
1225
- * Gets promptbook by its URL
1240
+ * Gets pipeline by its URL
1226
1241
  *
1227
1242
  * Note: This is not a direct fetching from the URL, but a lookup in the collection
1228
1243
  */
1229
1244
  SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
1230
1245
  var _this = this;
1231
- var promptbook = this.collection.get(url);
1232
- if (!promptbook) {
1246
+ var pipeline = this.collection.get(url);
1247
+ if (!pipeline) {
1233
1248
  if (this.listPipelines().length === 0) {
1234
- throw new NotFoundError(spaceTrim$1("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1249
+ throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1235
1250
  }
1236
- throw new NotFoundError(spaceTrim$1(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
1251
+ throw new NotFoundError(spaceTrim$1(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
1237
1252
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
1238
1253
  .join('\n')), "\n\n "); }));
1239
1254
  }
1240
- return promptbook;
1255
+ return pipeline;
1241
1256
  };
1242
1257
  /**
1243
- * Checks whether given prompt was defined in any promptbook in the collection
1258
+ * Checks whether given prompt was defined in any pipeline in the collection
1244
1259
  */
1245
1260
  SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
1246
1261
  return true;
@@ -2015,7 +2030,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
2015
2030
  throw new PipelineExecutionError(spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n\n "); }));
2016
2031
  }
2017
2032
  else {
2018
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No execution tools available for model variant \"".concat(prompt.modelRequirements.modelVariant, "\".\n\n tl;dr\n\n You have provided no LLM Execution Tools that support model variant \"").concat(prompt.modelRequirements.modelVariant, ":\n ").concat(block(_this.llmExecutionTools
2033
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
2019
2034
  .map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
2020
2035
  .join('\n')), "\n\n "); }));
2021
2036
  }
@@ -2094,7 +2109,7 @@ function joinLlmExecutionTools() {
2094
2109
  llmExecutionTools[_i] = arguments[_i];
2095
2110
  }
2096
2111
  if (llmExecutionTools.length === 0) {
2097
- var warningMessage = spaceTrim("\n You have provided no LLM Execution Tools.\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
2112
+ var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
2098
2113
  // TODO: [🟥] Detect browser / node and make it colorfull
2099
2114
  console.warn(warningMessage);
2100
2115
  /*
@@ -2128,9 +2143,11 @@ function isPipelinePrepared(pipeline) {
2128
2143
  // Note: Ignoring `pipeline.preparations` @@@
2129
2144
  // Note: Ignoring `pipeline.knowledgePieces` @@@
2130
2145
  if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2146
+ console.log('!!!!', 'Not all personas have modelRequirements');
2131
2147
  return false;
2132
2148
  }
2133
2149
  if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2150
+ console.log('!!!!', 'Not all knowledgeSources have preparationIds');
2134
2151
  return false;
2135
2152
  }
2136
2153
  // TODO: !!!!! Is context in each template
@@ -2139,6 +2156,7 @@ function isPipelinePrepared(pipeline) {
2139
2156
  return true;
2140
2157
  }
2141
2158
  /**
2159
+ * TODO: [🐠] Maybe base this on `makeValidator`
2142
2160
  * TODO: [🔼] Export via core or utils
2143
2161
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2144
2162
  */
@@ -5456,11 +5474,11 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
5456
5474
  }
5457
5475
 
5458
5476
  /**
5459
- * Constructs Promptbook from given directory
5477
+ * Constructs Pipeline from given directory
5460
5478
  *
5461
5479
  * Note: Works only in Node.js environment because it reads the file system
5462
5480
  *
5463
- * @param path - path to the directory with promptbooks
5481
+ * @param path - path to the directory with pipelines
5464
5482
  * @param options - Misc options for the collection
5465
5483
  * @returns PipelineCollection
5466
5484
  */
@@ -5490,20 +5508,31 @@ function createCollectionFromDirectory(path, options) {
5490
5508
  }
5491
5509
  _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
5492
5510
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
5493
- var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5511
+ var fileNames, pipelines, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5494
5512
  var e_1, _a;
5495
5513
  return __generator(this, function (_b) {
5496
5514
  switch (_b.label) {
5497
5515
  case 0:
5498
5516
  if (isVerbose) {
5499
- console.info("Creating pipeline collection from path ".concat(path.split('\\').join('/')));
5517
+ console.info(colors.cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
5500
5518
  }
5501
5519
  return [4 /*yield*/, listAllFiles(path, isRecursive)];
5502
5520
  case 1:
5503
5521
  fileNames = _b.sent();
5504
- promptbooks = [];
5522
+ // Note: First load all .ptbk.json and then .ptbk.md files
5523
+ // .ptbk.json can be prepared so it is faster to load
5524
+ fileNames.sort(function (a, b) {
5525
+ if (a.endsWith('.ptbk.json') && b.endsWith('.ptbk.md')) {
5526
+ return -1;
5527
+ }
5528
+ if (a.endsWith('.ptbk.md') && b.endsWith('.ptbk.json')) {
5529
+ return 1;
5530
+ }
5531
+ return 0;
5532
+ });
5533
+ pipelines = [];
5505
5534
  _loop_1 = function (fileName) {
5506
- var sourceFile, promptbook, pipelineString, _c, _d, error_1, wrappedErrorMessage;
5535
+ var sourceFile, pipeline, pipelineString, _c, _d, error_1, wrappedErrorMessage;
5507
5536
  return __generator(this, function (_e) {
5508
5537
  switch (_e.label) {
5509
5538
  case 0:
@@ -5511,53 +5540,52 @@ function createCollectionFromDirectory(path, options) {
5511
5540
  _e.label = 1;
5512
5541
  case 1:
5513
5542
  _e.trys.push([1, 8, , 9]);
5514
- promptbook = null;
5543
+ pipeline = null;
5515
5544
  if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 4];
5516
5545
  return [4 /*yield*/, readFile(fileName, 'utf8')];
5517
5546
  case 2:
5518
5547
  pipelineString = (_e.sent());
5519
5548
  return [4 /*yield*/, pipelineStringToJson(pipelineString, options)];
5520
5549
  case 3:
5521
- promptbook = _e.sent();
5522
- promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5550
+ pipeline = _e.sent();
5551
+ pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
5523
5552
  return [3 /*break*/, 7];
5524
5553
  case 4:
5525
5554
  if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 6];
5526
- if (isVerbose) {
5527
- console.info("Loading ".concat(fileName.split('\\').join('/')));
5528
- }
5529
5555
  _d = (_c = JSON).parse;
5530
5556
  return [4 /*yield*/, readFile(fileName, 'utf8')];
5531
5557
  case 5:
5532
5558
  // TODO: Handle non-valid JSON files
5533
- promptbook = _d.apply(_c, [_e.sent()]);
5559
+ pipeline = _d.apply(_c, [_e.sent()]);
5534
5560
  // TODO: [🌗]
5535
- promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5561
+ pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
5536
5562
  return [3 /*break*/, 7];
5537
5563
  case 6:
5538
5564
  if (isVerbose) {
5539
- console.info("Skipping file ".concat(fileName.split('\\').join('/')));
5565
+ console.info(colors.gray("Skipping file ".concat(fileName.split('\\').join('/'))));
5540
5566
  }
5541
5567
  _e.label = 7;
5542
5568
  case 7:
5543
5569
  // ---
5544
- if (promptbook !== null) {
5545
- if (!promptbook.pipelineUrl) {
5570
+ if (pipeline !== null) {
5571
+ if (!pipeline.pipelineUrl) {
5546
5572
  if (isVerbose) {
5547
- console.info("Not loading ".concat(fileName.split('\\').join('/'), " - missing URL"));
5573
+ console.info(colors.red("Can not load pipeline from ".concat(fileName
5574
+ .split('\\')
5575
+ .join('/'), " because of missing URL")));
5548
5576
  }
5549
5577
  }
5550
5578
  else {
5551
- if (isVerbose) {
5552
- console.info("Loading ".concat(fileName.split('\\').join('/')));
5553
- }
5554
5579
  if (!isCrashedOnError) {
5555
- // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
5580
+ // Note: Validate pipeline to check if it is logically correct to not crash on invalid pipelines
5556
5581
  // But be handled in current try-catch block
5557
- validatePipeline(promptbook);
5582
+ validatePipeline(pipeline);
5583
+ }
5584
+ if (isVerbose) {
5585
+ console.info(colors.green("Loading ".concat(fileName.split('\\').join('/'))));
5558
5586
  }
5559
- // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePipelineCollection
5560
- promptbooks.push(promptbook);
5587
+ // Note: [🦄] Pipeline with same url uniqueness will be checked automatically in SimplePipelineCollection
5588
+ pipelines.push(pipeline);
5561
5589
  }
5562
5590
  }
5563
5591
  return [3 /*break*/, 9];
@@ -5603,7 +5631,7 @@ function createCollectionFromDirectory(path, options) {
5603
5631
  }
5604
5632
  finally { if (e_1) throw e_1.error; }
5605
5633
  return [7 /*endfinally*/];
5606
- case 9: return [2 /*return*/, promptbooks];
5634
+ case 9: return [2 /*return*/, pipelines];
5607
5635
  }
5608
5636
  });
5609
5637
  }); });
@@ -5677,8 +5705,8 @@ function listAllFiles(path, isRecursive) {
5677
5705
  });
5678
5706
  }
5679
5707
  /**
5680
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
5681
- * Note: [🟢] This code should never be published outside of `@promptbook/node`
5708
+ * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json pipelines
5709
+ * Note: [🟢] This code should never be published outside of `@pipeline/node`
5682
5710
  */
5683
5711
 
5684
5712
  /**