@promptbook/cli 0.69.0-17 β†’ 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/cli",
3
- "version": "0.69.0-17",
3
+ "version": "0.69.0-19",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -12,21 +12,25 @@
12
12
  "Pavol HejnΓ½ <me@pavolhejny.com> (https://www.pavolhejny.com/)"
13
13
  ],
14
14
  "keywords": [
15
- "autogpt",
16
- "openai",
17
- "gpt-3",
18
- "gpt-4",
19
- "chatgpt",
20
15
  "ai",
16
+ "llm",
17
+ "prompt",
18
+ "template",
19
+ "language-model",
20
+ "chatgpt",
21
+ "autogpt",
21
22
  "machine-learning",
22
23
  "natural-language-processing",
23
24
  "nlp",
24
- "prompt",
25
- "template",
26
- "pipeline",
27
- "automation",
28
- "text-generation",
29
- "language-model"
25
+ "openai",
26
+ "gpt-3",
27
+ "gpt-4",
28
+ "gpt-4o",
29
+ "gpt-4o-mini",
30
+ "o1",
31
+ "o1-mini",
32
+ "o1-preview",
33
+ "anthropic"
30
34
  ],
31
35
  "license": "CC-BY-4.0",
32
36
  "bugs": {
package/umd/index.umd.js CHANGED
@@ -39,7 +39,7 @@
39
39
  /**
40
40
  * The version of the Promptbook library
41
41
  */
42
- var PROMPTBOOK_VERSION = '0.69.0-16';
42
+ var PROMPTBOOK_VERSION = '0.69.0-18';
43
43
  // TODO:[main] !!!! List here all the versions and annotate + put into script
44
44
 
45
45
  /*! *****************************************************************************
@@ -3916,15 +3916,15 @@
3916
3916
  .join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
3917
3917
  }
3918
3918
  subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
3919
- return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.cellName);
3919
+ return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.subformatName);
3920
3920
  });
3921
3921
  if (subvalueDefinition === undefined) {
3922
3922
  throw new UnexpectedError(
3923
3923
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
3924
- 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
3924
+ 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
3925
3925
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
3926
3926
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
3927
- .join('\n')), "\n\n [\u26F7] This should never happen because cell name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
3927
+ .join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
3928
3928
  }
3929
3929
  if (formatDefinition.formatName === 'CSV') {
3930
3930
  formatSettings = settings.csvSettings;
@@ -3969,8 +3969,6 @@
3969
3969
  /**
3970
3970
  * TODO: !!!!!! Make pipelineIdentification more precise
3971
3971
  * TODO: !!!!!! How FOREACH execution looks in the report
3972
- * TODO: [🧠][πŸ¦₯] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
3973
- * TODO: []
3974
3972
  */
3975
3973
 
3976
3974
  /**
@@ -5833,6 +5831,29 @@
5833
5831
  * TODO: [🌺] Use some intermediate util splitWords
5834
5832
  */
5835
5833
 
5834
+ /**
5835
+ * Removes quotes from a string
5836
+ *
5837
+ * Tip: This is very usefull for post-processing of the result of the LLM model
5838
+ * Note: This function removes only the same quotes from the beginning and the end of the string
5839
+ * Note: There are two simmilar functions:
5840
+ * - `removeQuotes` which removes only bounding quotes
5841
+ * - `unwrapResult` which removes whole introduce sentence
5842
+ *
5843
+ * @param text optionally quoted text
5844
+ * @returns text without quotes
5845
+ * @public exported from `@promptbook/utils`
5846
+ */
5847
+ function removeQuotes(text) {
5848
+ if (text.startsWith('"') && text.endsWith('"')) {
5849
+ return text.slice(1, -1);
5850
+ }
5851
+ if (text.startsWith('\'') && text.endsWith('\'')) {
5852
+ return text.slice(1, -1);
5853
+ }
5854
+ return text;
5855
+ }
5856
+
5836
5857
  /**
5837
5858
  * Function `validateParameterName` will @@@
5838
5859
  *
@@ -5891,6 +5912,9 @@
5891
5912
  parameterName.includes(']')) {
5892
5913
  throw new ParseError("Parameter name cannot contain braces");
5893
5914
  }
5915
+ parameterName = removeDiacritics(parameterName);
5916
+ parameterName = removeEmojis(parameterName);
5917
+ parameterName = removeQuotes(parameterName);
5894
5918
  parameterName = normalizeTo_camelCase(parameterName);
5895
5919
  if (parameterName === '') {
5896
5920
  throw new ParseError("Parameter name cannot be empty");
@@ -5944,7 +5968,7 @@
5944
5968
  examples: [
5945
5969
  'FOREACH Text Line `{customers}` -> `{customer}`',
5946
5970
  'FOR Csv Row `{customers}` -> `{firstName}`, `{lastName}`',
5947
- 'EACH Csv Cell `{customers}` -> `{cell}`',
5971
+ 'EACH Csv Cell `{customers}` -> `{subformat}`',
5948
5972
  ],
5949
5973
  /**
5950
5974
  * Parses the FOREACH command
@@ -5952,8 +5976,8 @@
5952
5976
  parse: function (input) {
5953
5977
  var args = input.args;
5954
5978
  var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
5955
- var cellName = normalizeTo_SCREAMING_CASE(args[1] || '');
5956
- var parameterNameWrapped = args[2];
5979
+ var subformatName = normalizeTo_SCREAMING_CASE(args[1] || '');
5980
+ var parameterNameArg = args[2] || '';
5957
5981
  var assignSign = args[3];
5958
5982
  var formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
5959
5983
  return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
@@ -5965,24 +5989,19 @@
5965
5989
  // <- TODO: [🏒] List all supported format names
5966
5990
  }
5967
5991
  var subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
5968
- return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(cellName);
5992
+ return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
5969
5993
  });
5970
5994
  if (subvalueDefinition === undefined) {
5971
- 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
5995
+ 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
5972
5996
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
5973
5997
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
5974
5998
  .join('\n')), "\n "); }));
5975
- // <- TODO: [🏒] List all supported cell names for the format
5999
+ // <- TODO: [🏒] List all supported subformat names for the format
5976
6000
  }
5977
6001
  if (assignSign !== '->') {
5978
6002
  throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
5979
6003
  }
5980
- // TODO: !!! Replace with propper parameter name validation `validateParameterName`
5981
- if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
5982
- (parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
5983
- throw new ParseError("Invalid parameter name \"".concat(parameterNameWrapped, "\" - must be wrapped in curly brackets: {parameterName}"));
5984
- }
5985
- var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
6004
+ var parameterName = validateParameterName(parameterNameArg);
5986
6005
  var subparameterNames = args
5987
6006
  .slice(4)
5988
6007
  .map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
@@ -5994,7 +6013,7 @@
5994
6013
  return {
5995
6014
  type: 'FOREACH',
5996
6015
  formatName: formatName,
5997
- cellName: cellName,
6016
+ subformatName: subformatName,
5998
6017
  parameterName: parameterName,
5999
6018
  subparameterNames: subparameterNames,
6000
6019
  };
@@ -6005,10 +6024,10 @@
6005
6024
  * Note: `$` is used to indicate that this function mutates given `templateJson`
6006
6025
  */
6007
6026
  $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6008
- var formatName = command.formatName, cellName = command.cellName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
6009
- // TODO: !!!!!! Detect double use
6010
- // TODO: !!!!!! Detect usage with JOKER and don't allow it
6011
- $templateJson.foreach = { formatName: formatName, cellName: cellName, parameterName: parameterName, subparameterNames: subparameterNames };
6027
+ var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
6028
+ // TODO: [🍭] Detect double use
6029
+ // TODO: [🍭] Detect usage with JOKER and don't allow it
6030
+ $templateJson.foreach = { formatName: formatName, subformatName: subformatName, parameterName: parameterName, subparameterNames: subparameterNames };
6012
6031
  keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
6013
6032
  // Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
6014
6033
  },
@@ -6032,8 +6051,7 @@
6032
6051
  },
6033
6052
  };
6034
6053
  /**
6035
- * TODO: [🧠][πŸ¦₯] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
6036
- * TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
6054
+ * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
6037
6055
  */
6038
6056
 
6039
6057
  /**
@@ -6143,12 +6161,11 @@
6143
6161
  */
6144
6162
  parse: function (input) {
6145
6163
  var args = input.args;
6146
- // TODO: !!!!!! Replace with propper parameter name validation `validateParameterName`
6147
- var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
6148
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
6149
- throw new ParseError("Invalid joker");
6164
+ if (args.length !== 1) {
6165
+ throw new ParseError("JOKE command expects exactly one parameter name");
6150
6166
  }
6151
- var parameterName = parametersMatch.groups.parameterName;
6167
+ var parameterNameArg = args[0] || '';
6168
+ var parameterName = validateParameterName(parameterNameArg);
6152
6169
  return {
6153
6170
  type: 'JOKER',
6154
6171
  parameterName: parameterName,
@@ -6372,14 +6389,13 @@
6372
6389
  * Parses the PARAMETER command
6373
6390
  */
6374
6391
  parse: function (input) {
6375
- var normalized = input.normalized, raw = input.raw;
6376
- var parametersMatch = raw.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
6377
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
6378
- throw new ParseError("Invalid parameter");
6379
- }
6380
- var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
6381
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
6382
- throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
6392
+ var normalized = input.normalized, args = input.args, raw = input.raw;
6393
+ var parameterNameRaw = args.shift() || '';
6394
+ var parameterDescriptionRaw = args.join(' ');
6395
+ // <- TODO: When [πŸ₯Ά] fixed, change to:
6396
+ // > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
6397
+ if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
6398
+ 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 "); }));
6383
6399
  }
6384
6400
  var isInput = normalized.startsWith('INPUT');
6385
6401
  var isOutput = normalized.startsWith('OUTPUT');
@@ -6387,11 +6403,12 @@
6387
6403
  isInput = false;
6388
6404
  isOutput = false;
6389
6405
  }
6390
- // TODO: !!!!!! Add parameter name validation
6406
+ var parameterName = validateParameterName(parameterNameRaw);
6407
+ var parameterDescription = parameterDescriptionRaw.trim() || null;
6391
6408
  return {
6392
6409
  type: 'PARAMETER',
6393
6410
  parameterName: parameterName,
6394
- parameterDescription: parameterDescription.trim() || null,
6411
+ parameterDescription: parameterDescription,
6395
6412
  isInput: isInput,
6396
6413
  isOutput: isOutput,
6397
6414
  };
@@ -7199,7 +7216,9 @@
7199
7216
  for (var commandNameSegmentsCount = 0; commandNameSegmentsCount < Math.min(items.length, 3); commandNameSegmentsCount++) {
7200
7217
  var commandNameRaw = items.slice(0, commandNameSegmentsCount + 1).join('_');
7201
7218
  var args = items.slice(commandNameSegmentsCount + 1);
7202
- var rawArgs = raw.substring(commandNameRaw.length).trim();
7219
+ var rawArgs = raw
7220
+ .substring(commandNameRaw.length)
7221
+ .trim();
7203
7222
  var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
7204
7223
  if (command !== null) {
7205
7224
  return command;
@@ -7210,7 +7229,9 @@
7210
7229
  {
7211
7230
  var commandNameRaw = items.slice(-1).join('_');
7212
7231
  var args = items.slice(0, -1); // <- Note: This is probbably not correct
7213
- var rawArgs = raw.substring(0, raw.length - commandNameRaw.length).trim();
7232
+ var rawArgs = raw
7233
+ .substring(0, raw.length - commandNameRaw.length)
7234
+ .trim();
7214
7235
  var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
7215
7236
  if (command !== null) {
7216
7237
  return command;
@@ -9284,9 +9305,9 @@
9284
9305
  return promptbookMermaid;
9285
9306
  }
9286
9307
  /**
9287
- * TODO: !!!!!! FOREACH in mermaid graph
9288
- * TODO: !!!!!! Knowledge in mermaid graph
9289
- * TODO: !!!!!! Personas in mermaid graph
9308
+ * TODO: !!!!! FOREACH in mermaid graph
9309
+ * TODO: !!!!! Knowledge in mermaid graph
9310
+ * TODO: !!!!! Personas in mermaid graph
9290
9311
  * TODO: Maybe use some Mermaid package instead of string templating
9291
9312
  * TODO: [πŸ•Œ] When more than 2 functionalities, split into separate functions
9292
9313
  */