@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/esm/index.es.js CHANGED
@@ -143,7 +143,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
143
143
  /**
144
144
  * The version of the Promptbook library
145
145
  */
146
- var PROMPTBOOK_VERSION = '0.59.0-26';
146
+ var PROMPTBOOK_VERSION = '0.59.0-28';
147
147
 
148
148
  /**
149
149
  * Initializes testing `hello` command for Promptbook CLI utilities
@@ -437,7 +437,7 @@ function validatePromptbook(promptbook) {
437
437
  * > ex port function validatePromptbook(promptbook: unknown): asserts promptbook is PromptbookJson {
438
438
  */
439
439
 
440
- 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:[]}];
440
+ 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:[]}];
441
441
 
442
442
  /**
443
443
  * This error indicates errors during the execution of the promptbook
@@ -2003,7 +2003,9 @@ function prepareKnowledgeFromMarkdown(options) {
2003
2003
  case 0:
2004
2004
  content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2005
2005
  library = createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false));
2006
- promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
2006
+ return [4 /*yield*/, library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2007
+ case 1:
2008
+ promptbook = _b.sent();
2007
2009
  executor = createPromptbookExecutor({
2008
2010
  promptbook: promptbook,
2009
2011
  tools: {
@@ -2014,7 +2016,7 @@ function prepareKnowledgeFromMarkdown(options) {
2014
2016
  },
2015
2017
  });
2016
2018
  return [4 /*yield*/, executor({ content: content })];
2017
- case 1:
2019
+ case 2:
2018
2020
  result = _b.sent();
2019
2021
  assertsExecutionSuccessful(result);
2020
2022
  outputParameters = result.outputParameters;
@@ -2053,7 +2055,7 @@ function prepareKnowledgeFromMarkdown(options) {
2053
2055
  }];
2054
2056
  });
2055
2057
  }); }))];
2056
- case 2:
2058
+ case 3:
2057
2059
  knowledge = _b.sent();
2058
2060
  return [2 /*return*/, knowledge];
2059
2061
  }
@@ -3134,7 +3136,7 @@ function promptbookStringToJson(promptbookString, options) {
3134
3136
  if (templateModelRequirements.modelVariant === undefined) {
3135
3137
  templateModelRequirements.modelVariant = 'CHAT';
3136
3138
  }
3137
- promptbookJson.promptTemplates.push({
3139
+ var template = {
3138
3140
  name: titleToName(section.title),
3139
3141
  title: section.title,
3140
3142
  description: description_1,
@@ -3148,7 +3150,12 @@ function promptbookStringToJson(promptbookString, options) {
3148
3150
  contentLanguage: executionType === 'SCRIPT' ? language : undefined,
3149
3151
  content: content,
3150
3152
  resultingParameterName: resultingParameterName,
3151
- });
3153
+ };
3154
+ if (executionType !== 'PROMPT_TEMPLATE') {
3155
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3156
+ delete template.modelRequirements;
3157
+ }
3158
+ promptbookJson.promptTemplates.push(template);
3152
3159
  };
3153
3160
  try {
3154
3161
  for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
@@ -3312,14 +3319,11 @@ function createLibraryFromDirectory(path, options) {
3312
3319
  switch (_b.label) {
3313
3320
  case 0:
3314
3321
  if (isVerbose) {
3315
- console.info("Creating promptbook library from path ".concat(path));
3322
+ console.info("Creating promptbook library from path ".concat(path.split('\\').join('/')));
3316
3323
  }
3317
3324
  return [4 /*yield*/, listAllFiles(path, isRecursive)];
3318
3325
  case 1:
3319
3326
  fileNames = _b.sent();
3320
- if (isVerbose) {
3321
- console.info('createLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3322
- }
3323
3327
  promptbooks = [];
3324
3328
  _loop_1 = function (fileName) {
3325
3329
  var promptbook, promptbookString, _c, _d, error_1, wrappedErrorMessage;
@@ -3339,7 +3343,7 @@ function createLibraryFromDirectory(path, options) {
3339
3343
  case 3:
3340
3344
  if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 5];
3341
3345
  if (isVerbose) {
3342
- console.info("Loading ".concat(fileName));
3346
+ console.info("Loading ".concat(fileName.split('\\').join('/')));
3343
3347
  }
3344
3348
  _d = (_c = JSON).parse;
3345
3349
  return [4 /*yield*/, readFile(fileName, 'utf8')];
@@ -3349,7 +3353,7 @@ function createLibraryFromDirectory(path, options) {
3349
3353
  return [3 /*break*/, 6];
3350
3354
  case 5:
3351
3355
  if (isVerbose) {
3352
- console.info("Skipping file ".concat(fileName));
3356
+ console.info("Skipping file ".concat(fileName.split('\\').join('/')));
3353
3357
  }
3354
3358
  _e.label = 6;
3355
3359
  case 6:
@@ -3357,12 +3361,12 @@ function createLibraryFromDirectory(path, options) {
3357
3361
  if (promptbook !== null) {
3358
3362
  if (!promptbook.promptbookUrl) {
3359
3363
  if (isVerbose) {
3360
- console.info("Not loading ".concat(fileName, " - missing URL"));
3364
+ console.info("Not loading ".concat(fileName.split('\\').join('/'), " - missing URL"));
3361
3365
  }
3362
3366
  }
3363
3367
  else {
3364
3368
  if (isVerbose) {
3365
- console.info("Loading ".concat(fileName));
3369
+ console.info("Loading ".concat(fileName.split('\\').join('/')));
3366
3370
  }
3367
3371
  if (!isCrashOnError) {
3368
3372
  // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
@@ -3528,9 +3532,10 @@ function initializeMake(program) {
3528
3532
  helloCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded library \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
3529
3533
  helloCommand.option('--no-validation', "Do not validate logic of promptbooks in library", true);
3530
3534
  helloCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
3535
+ helloCommand.option('--verbose', "Is verbose", false);
3531
3536
  // TODO: !!! Auto-detect AI api keys + explicit api keys as argv
3532
3537
  helloCommand.action(function (path, _a) {
3533
- var projectName = _a.projectName, format = _a.format, validation = _a.validation;
3538
+ var projectName = _a.projectName, format = _a.format, validation = _a.validation, verbose = _a.verbose;
3534
3539
  return __awaiter(_this, void 0, void 0, function () {
3535
3540
  var formats, validations, library, validations_1, validations_1_1, validation_1, _b, _c, promptbookUrl, promptbook, e_1_1, e_2_1, libraryJson, libraryJsonString, saveFile;
3536
3541
  var e_2, _d, e_1, _e;
@@ -3538,7 +3543,7 @@ function initializeMake(program) {
3538
3543
  return __generator(this, function (_f) {
3539
3544
  switch (_f.label) {
3540
3545
  case 0:
3541
- console.info('!!!', { projectName: projectName, path: path, format: format, validation: validation });
3546
+ console.info('!!!', { projectName: projectName, path: path, format: format, validation: validation, verbose: verbose });
3542
3547
  formats = (format || '')
3543
3548
  .split(',')
3544
3549
  .map(function (_) { return _.trim(); })
@@ -3548,7 +3553,7 @@ function initializeMake(program) {
3548
3553
  .map(function (_) { return _.trim(); })
3549
3554
  .filter(function (_) { return _ !== ''; });
3550
3555
  return [4 /*yield*/, createLibraryFromDirectory(path, {
3551
- isVerbose: true,
3556
+ isVerbose: verbose,
3552
3557
  isRecursive: true,
3553
3558
  })];
3554
3559
  case 1:
@@ -3577,6 +3582,9 @@ function initializeMake(program) {
3577
3582
  promptbook = _f.sent();
3578
3583
  if (validation_1 === 'logic') {
3579
3584
  validatePromptbook(promptbook);
3585
+ if (verbose) {
3586
+ console.info(colors.cyan("Validated logic of ".concat(promptbook.promptbookUrl)));
3587
+ }
3580
3588
  }
3581
3589
  _f.label = 8;
3582
3590
  case 8:
@@ -3620,7 +3628,8 @@ function initializeMake(program) {
3620
3628
  return [4 /*yield*/, writeFile(filePath, content, 'utf-8')];
3621
3629
  case 1:
3622
3630
  _a.sent();
3623
- console.info(colors.green("Maked ".concat(filePath)));
3631
+ // Note: Log despite of verbose mode
3632
+ console.info(colors.green("Maked ".concat(filePath.split('\\').join('/'))));
3624
3633
  return [2 /*return*/];
3625
3634
  }
3626
3635
  });
@@ -3631,19 +3640,18 @@ function initializeMake(program) {
3631
3640
  _f.sent();
3632
3641
  _f.label = 19;
3633
3642
  case 19:
3634
- if (formats.includes('javascript')) {
3635
- // TODO: !!!!;
3636
- // TODO: !!! DRY javascript and typescript
3637
- formats.push('javascript');
3638
- }
3639
- if (!formats.includes('typescript')) return [3 /*break*/, 21];
3640
- // TODO: !!!!!!!! Javascript json
3641
- return [4 /*yield*/, saveFile('ts', spaceTrim("\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'))];
3643
+ if (!formats.includes('javascript')) return [3 /*break*/, 21];
3644
+ return [4 /*yield*/, saveFile('js', spaceTrim("\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'))];
3642
3645
  case 20:
3643
- // TODO: !!!!!!!! Javascript json
3644
3646
  _f.sent();
3645
3647
  _f.label = 21;
3646
3648
  case 21:
3649
+ if (!formats.includes('typescript')) return [3 /*break*/, 23];
3650
+ return [4 /*yield*/, saveFile('ts', spaceTrim("\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'))];
3651
+ case 22:
3652
+ _f.sent();
3653
+ _f.label = 23;
3654
+ case 23:
3647
3655
  process.exit(0);
3648
3656
  return [2 /*return*/];
3649
3657
  }