@promptbook/cli 0.59.0-27 → 0.59.0-29

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/umd/index.umd.js CHANGED
@@ -147,7 +147,7 @@
147
147
  /**
148
148
  * The version of the Promptbook library
149
149
  */
150
- var PROMPTBOOK_VERSION = '0.59.0-26';
150
+ var PROMPTBOOK_VERSION = '0.59.0-28';
151
151
 
152
152
  /**
153
153
  * Initializes testing `hello` command for Promptbook CLI utilities
@@ -441,7 +441,7 @@
441
441
  * > ex port function validatePromptbook(promptbook: unknown): asserts promptbook is PromptbookJson {
442
442
  */
443
443
 
444
- var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-26",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",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}",resultingParameterName:"knowledge"}],knowledge:[]}];
444
+ var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-28",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",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}",resultingParameterName:"knowledge"}],knowledge:[]}];
445
445
 
446
446
  /**
447
447
  * This error indicates errors during the execution of the promptbook
@@ -2007,7 +2007,9 @@
2007
2007
  case 0:
2008
2008
  content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2009
2009
  library = createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false));
2010
- promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
2010
+ return [4 /*yield*/, library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2011
+ case 1:
2012
+ promptbook = _b.sent();
2011
2013
  executor = createPromptbookExecutor({
2012
2014
  promptbook: promptbook,
2013
2015
  tools: {
@@ -2018,7 +2020,7 @@
2018
2020
  },
2019
2021
  });
2020
2022
  return [4 /*yield*/, executor({ content: content })];
2021
- case 1:
2023
+ case 2:
2022
2024
  result = _b.sent();
2023
2025
  assertsExecutionSuccessful(result);
2024
2026
  outputParameters = result.outputParameters;
@@ -2057,7 +2059,7 @@
2057
2059
  }];
2058
2060
  });
2059
2061
  }); }))];
2060
- case 2:
2062
+ case 3:
2061
2063
  knowledge = _b.sent();
2062
2064
  return [2 /*return*/, knowledge];
2063
2065
  }
@@ -3138,7 +3140,7 @@
3138
3140
  if (templateModelRequirements.modelVariant === undefined) {
3139
3141
  templateModelRequirements.modelVariant = 'CHAT';
3140
3142
  }
3141
- promptbookJson.promptTemplates.push({
3143
+ var template = {
3142
3144
  name: titleToName(section.title),
3143
3145
  title: section.title,
3144
3146
  description: description_1,
@@ -3152,7 +3154,12 @@
3152
3154
  contentLanguage: executionType === 'SCRIPT' ? language : undefined,
3153
3155
  content: content,
3154
3156
  resultingParameterName: resultingParameterName,
3155
- });
3157
+ };
3158
+ if (executionType !== 'PROMPT_TEMPLATE') {
3159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3160
+ delete template.modelRequirements;
3161
+ }
3162
+ promptbookJson.promptTemplates.push(template);
3156
3163
  };
3157
3164
  try {
3158
3165
  for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
@@ -3316,14 +3323,11 @@
3316
3323
  switch (_b.label) {
3317
3324
  case 0:
3318
3325
  if (isVerbose) {
3319
- console.info("Creating promptbook library from path ".concat(path$1));
3326
+ console.info("Creating promptbook library from path ".concat(path$1.split('\\').join('/')));
3320
3327
  }
3321
3328
  return [4 /*yield*/, listAllFiles(path$1, isRecursive)];
3322
3329
  case 1:
3323
3330
  fileNames = _b.sent();
3324
- if (isVerbose) {
3325
- console.info('createLibraryFromDirectory', { path: path$1, isRecursive: isRecursive, fileNames: fileNames });
3326
- }
3327
3331
  promptbooks = [];
3328
3332
  _loop_1 = function (fileName) {
3329
3333
  var promptbook, promptbookString, _c, _d, error_1, wrappedErrorMessage;
@@ -3343,7 +3347,7 @@
3343
3347
  case 3:
3344
3348
  if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 5];
3345
3349
  if (isVerbose) {
3346
- console.info("Loading ".concat(fileName));
3350
+ console.info("Loading ".concat(fileName.split('\\').join('/')));
3347
3351
  }
3348
3352
  _d = (_c = JSON).parse;
3349
3353
  return [4 /*yield*/, promises.readFile(fileName, 'utf8')];
@@ -3353,7 +3357,7 @@
3353
3357
  return [3 /*break*/, 6];
3354
3358
  case 5:
3355
3359
  if (isVerbose) {
3356
- console.info("Skipping file ".concat(fileName));
3360
+ console.info("Skipping file ".concat(fileName.split('\\').join('/')));
3357
3361
  }
3358
3362
  _e.label = 6;
3359
3363
  case 6:
@@ -3361,12 +3365,12 @@
3361
3365
  if (promptbook !== null) {
3362
3366
  if (!promptbook.promptbookUrl) {
3363
3367
  if (isVerbose) {
3364
- console.info("Not loading ".concat(fileName, " - missing URL"));
3368
+ console.info("Not loading ".concat(fileName.split('\\').join('/'), " - missing URL"));
3365
3369
  }
3366
3370
  }
3367
3371
  else {
3368
3372
  if (isVerbose) {
3369
- console.info("Loading ".concat(fileName));
3373
+ console.info("Loading ".concat(fileName.split('\\').join('/')));
3370
3374
  }
3371
3375
  if (!isCrashOnError) {
3372
3376
  // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
@@ -3532,9 +3536,10 @@
3532
3536
  helloCommand.option('-f, --format <format>', spaceTrim__default["default"]("\n Output format of builded library \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
3533
3537
  helloCommand.option('--no-validation', "Do not validate logic of promptbooks in library", true);
3534
3538
  helloCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
3539
+ helloCommand.option('--verbose', "Is verbose", false);
3535
3540
  // TODO: !!! Auto-detect AI api keys + explicit api keys as argv
3536
3541
  helloCommand.action(function (path$1, _a) {
3537
- var projectName = _a.projectName, format = _a.format, validation = _a.validation;
3542
+ var projectName = _a.projectName, format = _a.format, validation = _a.validation, verbose = _a.verbose;
3538
3543
  return __awaiter(_this, void 0, void 0, function () {
3539
3544
  var formats, validations, library, validations_1, validations_1_1, validation_1, _b, _c, promptbookUrl, promptbook, e_1_1, e_2_1, libraryJson, libraryJsonString, saveFile;
3540
3545
  var e_2, _d, e_1, _e;
@@ -3542,7 +3547,7 @@
3542
3547
  return __generator(this, function (_f) {
3543
3548
  switch (_f.label) {
3544
3549
  case 0:
3545
- console.info('!!!', { projectName: projectName, path: path$1, format: format, validation: validation });
3550
+ console.info('!!!', { projectName: projectName, path: path$1, format: format, validation: validation, verbose: verbose });
3546
3551
  formats = (format || '')
3547
3552
  .split(',')
3548
3553
  .map(function (_) { return _.trim(); })
@@ -3552,7 +3557,7 @@
3552
3557
  .map(function (_) { return _.trim(); })
3553
3558
  .filter(function (_) { return _ !== ''; });
3554
3559
  return [4 /*yield*/, createLibraryFromDirectory(path$1, {
3555
- isVerbose: true,
3560
+ isVerbose: verbose,
3556
3561
  isRecursive: true,
3557
3562
  })];
3558
3563
  case 1:
@@ -3581,6 +3586,9 @@
3581
3586
  promptbook = _f.sent();
3582
3587
  if (validation_1 === 'logic') {
3583
3588
  validatePromptbook(promptbook);
3589
+ if (verbose) {
3590
+ console.info(colors__default["default"].cyan("Validated logic of ".concat(promptbook.promptbookUrl)));
3591
+ }
3584
3592
  }
3585
3593
  _f.label = 8;
3586
3594
  case 8:
@@ -3624,7 +3632,8 @@
3624
3632
  return [4 /*yield*/, promises.writeFile(filePath, content, 'utf-8')];
3625
3633
  case 1:
3626
3634
  _a.sent();
3627
- console.info(colors__default["default"].green("Maked ".concat(filePath)));
3635
+ // Note: Log despite of verbose mode
3636
+ console.info(colors__default["default"].green("Maked ".concat(filePath.split('\\').join('/'))));
3628
3637
  return [2 /*return*/];
3629
3638
  }
3630
3639
  });
@@ -3635,19 +3644,18 @@
3635
3644
  _f.sent();
3636
3645
  _f.label = 19;
3637
3646
  case 19:
3638
- if (formats.includes('javascript')) {
3639
- // TODO: !!!!;
3640
- // TODO: !!! DRY javascript and typescript
3641
- formats.push('javascript');
3642
- }
3643
- if (!formats.includes('typescript')) return [3 /*break*/, 21];
3644
- // TODO: !!!!!!!! Javascript json
3645
- return [4 /*yield*/, saveFile('ts', spaceTrim__default["default"]("\n import { createLibraryFromJson } from '@promptbook/core';\n import type { PromptbookLibrary, SimplePromptbookLibrary } from '@promptbook/types';\n\n /**\n * Promptbook library for ".concat(projectName, "\n *\n * @private internal cache for `getPromptbookLibrary`\n */\n let promptbookLibrary: null | SimplePromptbookLibrary = null;\n\n\n /**\n * Get promptbook library for ").concat(projectName, "\n *\n * @returns {PromptbookLibrary} Library of promptbooks for ").concat(projectName, "\n * @generated by `@promptbook/cli`\n */\n export function getPromptbookLibrary(): PromptbookLibrary{\n if(promptbookLibrary===null){\n promptbookLibrary = createLibraryFromJson(").concat(libraryJsonString.substring(1, libraryJsonString.length - 1), ");\n }\n\n return promptbookLibrary;\n }\n ") + '\n'))];
3647
+ if (!formats.includes('javascript')) return [3 /*break*/, 21];
3648
+ return [4 /*yield*/, saveFile('js', spaceTrim__default["default"]("\n import { createLibraryFromJson } from '@promptbook/core';\n\n /**\n * Promptbook library for ".concat(projectName, "\n *\n * @private internal cache for `getPromptbookLibrary`\n */\n let promptbookLibrary = null;\n\n\n /**\n * Get promptbook library for ").concat(projectName, "\n *\n * @returns {PromptbookLibrary} Library of promptbooks for ").concat(projectName, "\n * @generated by `@promptbook/cli`\n */\n export function getPromptbookLibrary(){\n if(promptbookLibrary===null){\n promptbookLibrary = createLibraryFromJson(").concat(libraryJsonString.substring(1, libraryJsonString.length - 1), ");\n }\n\n return promptbookLibrary;\n }\n ") + '\n'))];
3646
3649
  case 20:
3647
- // TODO: !!!!!!!! Javascript json
3648
3650
  _f.sent();
3649
3651
  _f.label = 21;
3650
3652
  case 21:
3653
+ if (!formats.includes('typescript')) return [3 /*break*/, 23];
3654
+ return [4 /*yield*/, saveFile('ts', spaceTrim__default["default"]("\n import { createLibraryFromJson } from '@promptbook/core';\n import type { PromptbookLibrary } from '@promptbook/types';\n\n /**\n * Promptbook library for ".concat(projectName, "\n *\n * @private internal cache for `getPromptbookLibrary`\n */\n let promptbookLibrary: null | PromptbookLibrary = null;\n\n\n /**\n * Get promptbook library for ").concat(projectName, "\n *\n * @returns {PromptbookLibrary} Library of promptbooks for ").concat(projectName, "\n * @generated by `@promptbook/cli`\n */\n export function getPromptbookLibrary(): PromptbookLibrary{\n if(promptbookLibrary===null){\n promptbookLibrary = createLibraryFromJson(").concat(libraryJsonString.substring(1, libraryJsonString.length - 1), ");\n }\n\n return promptbookLibrary;\n }\n ") + '\n'))];
3655
+ case 22:
3656
+ _f.sent();
3657
+ _f.label = 23;
3658
+ case 23:
3651
3659
  process.exit(0);
3652
3660
  return [2 /*return*/];
3653
3661
  }