@promptbook/cli 0.69.0-18 → 0.69.0-19

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
@@ -21,7 +21,7 @@ import OpenAI from 'openai';
21
21
  /**
22
22
  * The version of the Promptbook library
23
23
  */
24
- var PROMPTBOOK_VERSION = '0.69.0-17';
24
+ var PROMPTBOOK_VERSION = '0.69.0-18';
25
25
  // TODO:[main] !!!! List here all the versions and annotate + put into script
26
26
 
27
27
  /*! *****************************************************************************
@@ -3898,15 +3898,15 @@ function executeFormatCells(options) {
3898
3898
  .join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
3899
3899
  }
3900
3900
  subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
3901
- return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.cellName);
3901
+ return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.subformatName);
3902
3902
  });
3903
3903
  if (subvalueDefinition === undefined) {
3904
3904
  throw new UnexpectedError(
3905
3905
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
3906
- spaceTrim$1(function (block) { return "\n Unsupported cell name \"".concat(template.foreach.cellName, "\" for format \"").concat(template.foreach.formatName, "\"\n\n Available cell names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
3906
+ spaceTrim$1(function (block) { return "\n Unsupported subformat name \"".concat(template.foreach.subformatName, "\" for format \"").concat(template.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
3907
3907
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
3908
3908
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
3909
- .join('\n')), "\n\n [\u26F7] This should never happen because cell name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
3909
+ .join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
3910
3910
  }
3911
3911
  if (formatDefinition.formatName === 'CSV') {
3912
3912
  formatSettings = settings.csvSettings;
@@ -3951,8 +3951,6 @@ function executeFormatCells(options) {
3951
3951
  /**
3952
3952
  * TODO: !!!!!! Make pipelineIdentification more precise
3953
3953
  * TODO: !!!!!! How FOREACH execution looks in the report
3954
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
3955
- * TODO: []
3956
3954
  */
3957
3955
 
3958
3956
  /**
@@ -5815,6 +5813,29 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
5815
5813
  * TODO: [🌺] Use some intermediate util splitWords
5816
5814
  */
5817
5815
 
5816
+ /**
5817
+ * Removes quotes from a string
5818
+ *
5819
+ * Tip: This is very usefull for post-processing of the result of the LLM model
5820
+ * Note: This function removes only the same quotes from the beginning and the end of the string
5821
+ * Note: There are two simmilar functions:
5822
+ * - `removeQuotes` which removes only bounding quotes
5823
+ * - `unwrapResult` which removes whole introduce sentence
5824
+ *
5825
+ * @param text optionally quoted text
5826
+ * @returns text without quotes
5827
+ * @public exported from `@promptbook/utils`
5828
+ */
5829
+ function removeQuotes(text) {
5830
+ if (text.startsWith('"') && text.endsWith('"')) {
5831
+ return text.slice(1, -1);
5832
+ }
5833
+ if (text.startsWith('\'') && text.endsWith('\'')) {
5834
+ return text.slice(1, -1);
5835
+ }
5836
+ return text;
5837
+ }
5838
+
5818
5839
  /**
5819
5840
  * Function `validateParameterName` will @@@
5820
5841
  *
@@ -5873,6 +5894,9 @@ function validateParameterName(parameterName) {
5873
5894
  parameterName.includes(']')) {
5874
5895
  throw new ParseError("Parameter name cannot contain braces");
5875
5896
  }
5897
+ parameterName = removeDiacritics(parameterName);
5898
+ parameterName = removeEmojis(parameterName);
5899
+ parameterName = removeQuotes(parameterName);
5876
5900
  parameterName = normalizeTo_camelCase(parameterName);
5877
5901
  if (parameterName === '') {
5878
5902
  throw new ParseError("Parameter name cannot be empty");
@@ -5926,7 +5950,7 @@ var foreachCommandParser = {
5926
5950
  examples: [
5927
5951
  'FOREACH Text Line `{customers}` -> `{customer}`',
5928
5952
  'FOR Csv Row `{customers}` -> `{firstName}`, `{lastName}`',
5929
- 'EACH Csv Cell `{customers}` -> `{cell}`',
5953
+ 'EACH Csv Cell `{customers}` -> `{subformat}`',
5930
5954
  ],
5931
5955
  /**
5932
5956
  * Parses the FOREACH command
@@ -5934,8 +5958,8 @@ var foreachCommandParser = {
5934
5958
  parse: function (input) {
5935
5959
  var args = input.args;
5936
5960
  var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
5937
- var cellName = normalizeTo_SCREAMING_CASE(args[1] || '');
5938
- var parameterNameWrapped = args[2];
5961
+ var subformatName = normalizeTo_SCREAMING_CASE(args[1] || '');
5962
+ var parameterNameArg = args[2] || '';
5939
5963
  var assignSign = args[3];
5940
5964
  var formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
5941
5965
  return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
@@ -5947,24 +5971,19 @@ var foreachCommandParser = {
5947
5971
  // <- TODO: [🏢] List all supported format names
5948
5972
  }
5949
5973
  var subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
5950
- return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(cellName);
5974
+ return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
5951
5975
  });
5952
5976
  if (subvalueDefinition === undefined) {
5953
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unsupported cell name \"".concat(cellName, "\" for format \"").concat(formatName, "\"\n\n Available cell names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
5977
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Unsupported subformat name \"".concat(subformatName, "\" for format \"").concat(formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
5954
5978
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
5955
5979
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
5956
5980
  .join('\n')), "\n "); }));
5957
- // <- TODO: [🏢] List all supported cell names for the format
5981
+ // <- TODO: [🏢] List all supported subformat names for the format
5958
5982
  }
5959
5983
  if (assignSign !== '->') {
5960
5984
  throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
5961
5985
  }
5962
- // TODO: !!! Replace with propper parameter name validation `validateParameterName`
5963
- if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
5964
- (parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
5965
- throw new ParseError("Invalid parameter name \"".concat(parameterNameWrapped, "\" - must be wrapped in curly brackets: {parameterName}"));
5966
- }
5967
- var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
5986
+ var parameterName = validateParameterName(parameterNameArg);
5968
5987
  var subparameterNames = args
5969
5988
  .slice(4)
5970
5989
  .map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
@@ -5976,7 +5995,7 @@ var foreachCommandParser = {
5976
5995
  return {
5977
5996
  type: 'FOREACH',
5978
5997
  formatName: formatName,
5979
- cellName: cellName,
5998
+ subformatName: subformatName,
5980
5999
  parameterName: parameterName,
5981
6000
  subparameterNames: subparameterNames,
5982
6001
  };
@@ -5987,10 +6006,10 @@ var foreachCommandParser = {
5987
6006
  * Note: `$` is used to indicate that this function mutates given `templateJson`
5988
6007
  */
5989
6008
  $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5990
- var formatName = command.formatName, cellName = command.cellName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
5991
- // TODO: !!!!!! Detect double use
5992
- // TODO: !!!!!! Detect usage with JOKER and don't allow it
5993
- $templateJson.foreach = { formatName: formatName, cellName: cellName, parameterName: parameterName, subparameterNames: subparameterNames };
6009
+ var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
6010
+ // TODO: [🍭] Detect double use
6011
+ // TODO: [🍭] Detect usage with JOKER and don't allow it
6012
+ $templateJson.foreach = { formatName: formatName, subformatName: subformatName, parameterName: parameterName, subparameterNames: subparameterNames };
5994
6013
  keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
5995
6014
  // Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
5996
6015
  },
@@ -6014,8 +6033,7 @@ var foreachCommandParser = {
6014
6033
  },
6015
6034
  };
6016
6035
  /**
6017
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
6018
- * TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
6036
+ * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
6019
6037
  */
6020
6038
 
6021
6039
  /**
@@ -6125,12 +6143,11 @@ var jokerCommandParser = {
6125
6143
  */
6126
6144
  parse: function (input) {
6127
6145
  var args = input.args;
6128
- // TODO: !!!!!! Replace with propper parameter name validation `validateParameterName`
6129
- var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
6130
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
6131
- throw new ParseError("Invalid joker");
6146
+ if (args.length !== 1) {
6147
+ throw new ParseError("JOKE command expects exactly one parameter name");
6132
6148
  }
6133
- var parameterName = parametersMatch.groups.parameterName;
6149
+ var parameterNameArg = args[0] || '';
6150
+ var parameterName = validateParameterName(parameterNameArg);
6134
6151
  return {
6135
6152
  type: 'JOKER',
6136
6153
  parameterName: parameterName,
@@ -6354,14 +6371,13 @@ var parameterCommandParser = {
6354
6371
  * Parses the PARAMETER command
6355
6372
  */
6356
6373
  parse: function (input) {
6357
- var normalized = input.normalized, raw = input.raw;
6358
- var parametersMatch = raw.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
6359
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
6360
- throw new ParseError("Invalid parameter");
6361
- }
6362
- var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
6363
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
6364
- throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
6374
+ var normalized = input.normalized, args = input.args, raw = input.raw;
6375
+ var parameterNameRaw = args.shift() || '';
6376
+ var parameterDescriptionRaw = args.join(' ');
6377
+ // <- TODO: When [🥶] fixed, change to:
6378
+ // > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
6379
+ if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
6380
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterNameRaw, "} can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
6365
6381
  }
6366
6382
  var isInput = normalized.startsWith('INPUT');
6367
6383
  var isOutput = normalized.startsWith('OUTPUT');
@@ -6369,11 +6385,12 @@ var parameterCommandParser = {
6369
6385
  isInput = false;
6370
6386
  isOutput = false;
6371
6387
  }
6372
- // TODO: !!!!!! Add parameter name validation
6388
+ var parameterName = validateParameterName(parameterNameRaw);
6389
+ var parameterDescription = parameterDescriptionRaw.trim() || null;
6373
6390
  return {
6374
6391
  type: 'PARAMETER',
6375
6392
  parameterName: parameterName,
6376
- parameterDescription: parameterDescription.trim() || null,
6393
+ parameterDescription: parameterDescription,
6377
6394
  isInput: isInput,
6378
6395
  isOutput: isOutput,
6379
6396
  };
@@ -7181,7 +7198,9 @@ function parseCommand(raw, usagePlace) {
7181
7198
  for (var commandNameSegmentsCount = 0; commandNameSegmentsCount < Math.min(items.length, 3); commandNameSegmentsCount++) {
7182
7199
  var commandNameRaw = items.slice(0, commandNameSegmentsCount + 1).join('_');
7183
7200
  var args = items.slice(commandNameSegmentsCount + 1);
7184
- var rawArgs = raw.substring(commandNameRaw.length).trim();
7201
+ var rawArgs = raw
7202
+ .substring(commandNameRaw.length)
7203
+ .trim();
7185
7204
  var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
7186
7205
  if (command !== null) {
7187
7206
  return command;
@@ -7192,7 +7211,9 @@ function parseCommand(raw, usagePlace) {
7192
7211
  {
7193
7212
  var commandNameRaw = items.slice(-1).join('_');
7194
7213
  var args = items.slice(0, -1); // <- Note: This is probbably not correct
7195
- var rawArgs = raw.substring(0, raw.length - commandNameRaw.length).trim();
7214
+ var rawArgs = raw
7215
+ .substring(0, raw.length - commandNameRaw.length)
7216
+ .trim();
7196
7217
  var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
7197
7218
  if (command !== null) {
7198
7219
  return command;
@@ -9266,9 +9287,9 @@ function renderPromptbookMermaid(pipelineJson, options) {
9266
9287
  return promptbookMermaid;
9267
9288
  }
9268
9289
  /**
9269
- * TODO: !!!!!! FOREACH in mermaid graph
9270
- * TODO: !!!!!! Knowledge in mermaid graph
9271
- * TODO: !!!!!! Personas in mermaid graph
9290
+ * TODO: !!!!! FOREACH in mermaid graph
9291
+ * TODO: !!!!! Knowledge in mermaid graph
9292
+ * TODO: !!!!! Personas in mermaid graph
9272
9293
  * TODO: Maybe use some Mermaid package instead of string templating
9273
9294
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
9274
9295
  */