@promptbook/core 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.
@@ -11,7 +11,7 @@ export type ForeachJson = {
11
11
  /**
12
12
  * @@@
13
13
  */
14
- readonly cellName: TODO_string;
14
+ readonly subformatName: TODO_string;
15
15
  /**
16
16
  * @@@
17
17
  */
@@ -21,6 +21,3 @@ export type ForeachJson = {
21
21
  */
22
22
  readonly subparameterNames: Array<string_parameter_name>;
23
23
  };
24
- /**
25
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
26
- */
@@ -1,4 +1 @@
1
1
  export {};
2
- /**
3
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
4
- */
@@ -10,6 +10,5 @@ import type { ForeachCommand } from './ForeachCommand';
10
10
  */
11
11
  export declare const foreachCommandParser: PipelineTemplateCommandParser<ForeachCommand>;
12
12
  /**
13
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
14
- * TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
13
+ * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
15
14
  */
@@ -22,9 +22,9 @@ export type renderPipelineMermaidOptions = {
22
22
  */
23
23
  export declare function renderPromptbookMermaid(pipelineJson: PipelineJson, options?: renderPipelineMermaidOptions): string;
24
24
  /**
25
- * TODO: !!!!!! FOREACH in mermaid graph
26
- * TODO: !!!!!! Knowledge in mermaid graph
27
- * TODO: !!!!!! Personas in mermaid graph
25
+ * TODO: !!!!! FOREACH in mermaid graph
26
+ * TODO: !!!!! Knowledge in mermaid graph
27
+ * TODO: !!!!! Personas in mermaid graph
28
28
  * TODO: Maybe use some Mermaid package instead of string templating
29
29
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
30
30
  */
@@ -16,6 +16,4 @@ export {};
16
16
  /**
17
17
  * TODO: !!!!!! Make pipelineIdentification more precise
18
18
  * TODO: !!!!!! How FOREACH execution looks in the report
19
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
20
- * TODO: []
21
19
  */
@@ -61,7 +61,6 @@ export type FormatDefinition<TValue extends TPartialValue, TPartialValue extends
61
61
  readonly subvalueDefinitions: Array<FormatSubvalueDefinition<TValue, TSettings>>;
62
62
  };
63
63
  /**
64
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
65
64
  * TODO: [♏] Add some prepare hook to modify prompt according to the format
66
65
  * TODO: [🍓]`name` and `aliases` should be UPPERCASE only and interpreted as case-insensitive (via normalization)
67
66
  * TODO: [🍓][👨‍⚖️] Compute TPartialValue dynamically - PartialString<TValue>
@@ -26,6 +26,5 @@ export type FormatSubvalueDefinition<TValue extends string, TSettings extends em
26
26
  mapValues(value: TValue, settings: TSettings, mapCallback: (subvalues: Parameters, index: number) => Promisable<string>): Promise<string>;
27
27
  };
28
28
  /**
29
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
30
29
  * Note: [👩🏾‍🤝‍🧑🏽]
31
30
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.69.0-18",
3
+ "version": "0.69.0-19",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -16,7 +16,7 @@
16
16
  /**
17
17
  * The version of the Promptbook library
18
18
  */
19
- var PROMPTBOOK_VERSION = '0.69.0-17';
19
+ var PROMPTBOOK_VERSION = '0.69.0-18';
20
20
  // TODO:[main] !!!! List here all the versions and annotate + put into script
21
21
 
22
22
  /*! *****************************************************************************
@@ -4073,15 +4073,15 @@
4073
4073
  .join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
4074
4074
  }
4075
4075
  subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
4076
- return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.cellName);
4076
+ return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.subformatName);
4077
4077
  });
4078
4078
  if (subvalueDefinition === undefined) {
4079
4079
  throw new UnexpectedError(
4080
4080
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
4081
- spaceTrim__default["default"](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
4081
+ spaceTrim__default["default"](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
4082
4082
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
4083
4083
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
4084
- .join('\n')), "\n\n [\u26F7] This should never happen because cell name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
4084
+ .join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
4085
4085
  }
4086
4086
  if (formatDefinition.formatName === 'CSV') {
4087
4087
  formatSettings = settings.csvSettings;
@@ -4126,8 +4126,6 @@
4126
4126
  /**
4127
4127
  * TODO: !!!!!! Make pipelineIdentification more precise
4128
4128
  * TODO: !!!!!! How FOREACH execution looks in the report
4129
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
4130
- * TODO: []
4131
4129
  */
4132
4130
 
4133
4131
  /**
@@ -5972,6 +5970,29 @@
5972
5970
  * TODO: [🌺] Use some intermediate util splitWords
5973
5971
  */
5974
5972
 
5973
+ /**
5974
+ * Removes quotes from a string
5975
+ *
5976
+ * Tip: This is very usefull for post-processing of the result of the LLM model
5977
+ * Note: This function removes only the same quotes from the beginning and the end of the string
5978
+ * Note: There are two simmilar functions:
5979
+ * - `removeQuotes` which removes only bounding quotes
5980
+ * - `unwrapResult` which removes whole introduce sentence
5981
+ *
5982
+ * @param text optionally quoted text
5983
+ * @returns text without quotes
5984
+ * @public exported from `@promptbook/utils`
5985
+ */
5986
+ function removeQuotes(text) {
5987
+ if (text.startsWith('"') && text.endsWith('"')) {
5988
+ return text.slice(1, -1);
5989
+ }
5990
+ if (text.startsWith('\'') && text.endsWith('\'')) {
5991
+ return text.slice(1, -1);
5992
+ }
5993
+ return text;
5994
+ }
5995
+
5975
5996
  /**
5976
5997
  * Function `validateParameterName` will @@@
5977
5998
  *
@@ -6030,6 +6051,9 @@
6030
6051
  parameterName.includes(']')) {
6031
6052
  throw new ParseError("Parameter name cannot contain braces");
6032
6053
  }
6054
+ parameterName = removeDiacritics(parameterName);
6055
+ parameterName = removeEmojis(parameterName);
6056
+ parameterName = removeQuotes(parameterName);
6033
6057
  parameterName = normalizeTo_camelCase(parameterName);
6034
6058
  if (parameterName === '') {
6035
6059
  throw new ParseError("Parameter name cannot be empty");
@@ -6083,7 +6107,7 @@
6083
6107
  examples: [
6084
6108
  'FOREACH Text Line `{customers}` -> `{customer}`',
6085
6109
  'FOR Csv Row `{customers}` -> `{firstName}`, `{lastName}`',
6086
- 'EACH Csv Cell `{customers}` -> `{cell}`',
6110
+ 'EACH Csv Cell `{customers}` -> `{subformat}`',
6087
6111
  ],
6088
6112
  /**
6089
6113
  * Parses the FOREACH command
@@ -6091,8 +6115,8 @@
6091
6115
  parse: function (input) {
6092
6116
  var args = input.args;
6093
6117
  var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
6094
- var cellName = normalizeTo_SCREAMING_CASE(args[1] || '');
6095
- var parameterNameWrapped = args[2];
6118
+ var subformatName = normalizeTo_SCREAMING_CASE(args[1] || '');
6119
+ var parameterNameArg = args[2] || '';
6096
6120
  var assignSign = args[3];
6097
6121
  var formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
6098
6122
  return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
@@ -6104,24 +6128,19 @@
6104
6128
  // <- TODO: [🏢] List all supported format names
6105
6129
  }
6106
6130
  var subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
6107
- return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(cellName);
6131
+ return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
6108
6132
  });
6109
6133
  if (subvalueDefinition === undefined) {
6110
- throw new ParseError(spaceTrim__default["default"](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
6134
+ throw new ParseError(spaceTrim__default["default"](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
6111
6135
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
6112
6136
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
6113
6137
  .join('\n')), "\n "); }));
6114
- // <- TODO: [🏢] List all supported cell names for the format
6138
+ // <- TODO: [🏢] List all supported subformat names for the format
6115
6139
  }
6116
6140
  if (assignSign !== '->') {
6117
6141
  throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
6118
6142
  }
6119
- // TODO: !!! Replace with propper parameter name validation `validateParameterName`
6120
- if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
6121
- (parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
6122
- throw new ParseError("Invalid parameter name \"".concat(parameterNameWrapped, "\" - must be wrapped in curly brackets: {parameterName}"));
6123
- }
6124
- var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
6143
+ var parameterName = validateParameterName(parameterNameArg);
6125
6144
  var subparameterNames = args
6126
6145
  .slice(4)
6127
6146
  .map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
@@ -6133,7 +6152,7 @@
6133
6152
  return {
6134
6153
  type: 'FOREACH',
6135
6154
  formatName: formatName,
6136
- cellName: cellName,
6155
+ subformatName: subformatName,
6137
6156
  parameterName: parameterName,
6138
6157
  subparameterNames: subparameterNames,
6139
6158
  };
@@ -6144,10 +6163,10 @@
6144
6163
  * Note: `$` is used to indicate that this function mutates given `templateJson`
6145
6164
  */
6146
6165
  $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6147
- var formatName = command.formatName, cellName = command.cellName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
6148
- // TODO: !!!!!! Detect double use
6149
- // TODO: !!!!!! Detect usage with JOKER and don't allow it
6150
- $templateJson.foreach = { formatName: formatName, cellName: cellName, parameterName: parameterName, subparameterNames: subparameterNames };
6166
+ var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
6167
+ // TODO: [🍭] Detect double use
6168
+ // TODO: [🍭] Detect usage with JOKER and don't allow it
6169
+ $templateJson.foreach = { formatName: formatName, subformatName: subformatName, parameterName: parameterName, subparameterNames: subparameterNames };
6151
6170
  keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
6152
6171
  // Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
6153
6172
  },
@@ -6171,8 +6190,7 @@
6171
6190
  },
6172
6191
  };
6173
6192
  /**
6174
- * TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
6175
- * TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
6193
+ * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
6176
6194
  */
6177
6195
 
6178
6196
  /**
@@ -6282,12 +6300,11 @@
6282
6300
  */
6283
6301
  parse: function (input) {
6284
6302
  var args = input.args;
6285
- // TODO: !!!!!! Replace with propper parameter name validation `validateParameterName`
6286
- var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
6287
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
6288
- throw new ParseError("Invalid joker");
6303
+ if (args.length !== 1) {
6304
+ throw new ParseError("JOKE command expects exactly one parameter name");
6289
6305
  }
6290
- var parameterName = parametersMatch.groups.parameterName;
6306
+ var parameterNameArg = args[0] || '';
6307
+ var parameterName = validateParameterName(parameterNameArg);
6291
6308
  return {
6292
6309
  type: 'JOKER',
6293
6310
  parameterName: parameterName,
@@ -6511,14 +6528,13 @@
6511
6528
  * Parses the PARAMETER command
6512
6529
  */
6513
6530
  parse: function (input) {
6514
- var normalized = input.normalized, raw = input.raw;
6515
- var parametersMatch = raw.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
6516
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
6517
- throw new ParseError("Invalid parameter");
6518
- }
6519
- var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
6520
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
6521
- throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
6531
+ var normalized = input.normalized, args = input.args, raw = input.raw;
6532
+ var parameterNameRaw = args.shift() || '';
6533
+ var parameterDescriptionRaw = args.join(' ');
6534
+ // <- TODO: When [🥶] fixed, change to:
6535
+ // > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
6536
+ if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
6537
+ throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Parameter {".concat(parameterNameRaw, "} can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
6522
6538
  }
6523
6539
  var isInput = normalized.startsWith('INPUT');
6524
6540
  var isOutput = normalized.startsWith('OUTPUT');
@@ -6526,11 +6542,12 @@
6526
6542
  isInput = false;
6527
6543
  isOutput = false;
6528
6544
  }
6529
- // TODO: !!!!!! Add parameter name validation
6545
+ var parameterName = validateParameterName(parameterNameRaw);
6546
+ var parameterDescription = parameterDescriptionRaw.trim() || null;
6530
6547
  return {
6531
6548
  type: 'PARAMETER',
6532
6549
  parameterName: parameterName,
6533
- parameterDescription: parameterDescription.trim() || null,
6550
+ parameterDescription: parameterDescription,
6534
6551
  isInput: isInput,
6535
6552
  isOutput: isOutput,
6536
6553
  };
@@ -7338,7 +7355,9 @@
7338
7355
  for (var commandNameSegmentsCount = 0; commandNameSegmentsCount < Math.min(items.length, 3); commandNameSegmentsCount++) {
7339
7356
  var commandNameRaw = items.slice(0, commandNameSegmentsCount + 1).join('_');
7340
7357
  var args = items.slice(commandNameSegmentsCount + 1);
7341
- var rawArgs = raw.substring(commandNameRaw.length).trim();
7358
+ var rawArgs = raw
7359
+ .substring(commandNameRaw.length)
7360
+ .trim();
7342
7361
  var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
7343
7362
  if (command !== null) {
7344
7363
  return command;
@@ -7349,7 +7368,9 @@
7349
7368
  {
7350
7369
  var commandNameRaw = items.slice(-1).join('_');
7351
7370
  var args = items.slice(0, -1); // <- Note: This is probbably not correct
7352
- var rawArgs = raw.substring(0, raw.length - commandNameRaw.length).trim();
7371
+ var rawArgs = raw
7372
+ .substring(0, raw.length - commandNameRaw.length)
7373
+ .trim();
7353
7374
  var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
7354
7375
  if (command !== null) {
7355
7376
  return command;
@@ -8104,9 +8125,9 @@
8104
8125
  return promptbookMermaid;
8105
8126
  }
8106
8127
  /**
8107
- * TODO: !!!!!! FOREACH in mermaid graph
8108
- * TODO: !!!!!! Knowledge in mermaid graph
8109
- * TODO: !!!!!! Personas in mermaid graph
8128
+ * TODO: !!!!! FOREACH in mermaid graph
8129
+ * TODO: !!!!! Knowledge in mermaid graph
8130
+ * TODO: !!!!! Personas in mermaid graph
8110
8131
  * TODO: Maybe use some Mermaid package instead of string templating
8111
8132
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
8112
8133
  */
@@ -8931,8 +8952,8 @@
8931
8952
  */
8932
8953
  function createMarkdownTable(table) {
8933
8954
  var columnWidths = table.reduce(function (widths, row) {
8934
- row.forEach(function (cell, columnIndex) {
8935
- var cellLength = cell.length;
8955
+ row.forEach(function (subformat, columnIndex) {
8956
+ var cellLength = subformat.length;
8936
8957
  if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
8937
8958
  widths[columnIndex] = cellLength;
8938
8959
  }
@@ -8940,12 +8961,12 @@
8940
8961
  return widths;
8941
8962
  }, []);
8942
8963
  var header = "| ".concat(table[0]
8943
- .map(function (cell, columnIndex) { return cell.padEnd(columnWidths[columnIndex]); })
8964
+ .map(function (subformat, columnIndex) { return subformat.padEnd(columnWidths[columnIndex]); })
8944
8965
  .join(' | '), " |");
8945
8966
  var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
8946
8967
  var rows = table.slice(1).map(function (row) {
8947
- var paddedRow = row.map(function (cell, columnIndex) {
8948
- return cell.padEnd(columnWidths[columnIndex]);
8968
+ var paddedRow = row.map(function (subformat, columnIndex) {
8969
+ return subformat.padEnd(columnWidths[columnIndex]);
8949
8970
  });
8950
8971
  return "| ".concat(paddedRow.join(' | '), " |");
8951
8972
  });