@promptbook/cli 0.88.0-9 → 0.88.0

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/README.md CHANGED
@@ -23,10 +23,6 @@
23
23
 
24
24
 
25
25
 
26
- <blockquote style="color: #ff8811">
27
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
- </blockquote>
29
-
30
26
  ## 📦 Package `@promptbook/cli`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -112,6 +108,8 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
112
108
 
113
109
  During the computer revolution, we have seen [multiple generations of computer languages](https://github.com/webgptorg/promptbook/discussions/180), from the physical rewiring of the vacuum tubes through low-level machine code to the high-level languages like Python or JavaScript. And now, we're on the edge of the **next revolution**!
114
110
 
111
+
112
+
115
113
  It's a revolution of writing software in **plain human language** that is understandable and executable by both humans and machines – and it's going to change everything!
116
114
 
117
115
  The incredible growth in power of microprocessors and the Moore's Law have been the driving force behind the ever-more powerful languages, and it's been an amazing journey! Similarly, the large language models (like GPT or Claude) are the next big thing in language technology, and they're set to transform the way we interact with computers.
@@ -122,6 +120,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
122
120
 
123
121
 
124
122
 
123
+
124
+
125
+
125
126
  ## 🚀 Get started
126
127
 
127
128
  Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
@@ -133,6 +134,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
133
134
 
134
135
 
135
136
 
137
+
138
+
136
139
  ## 💜 The Promptbook Project
137
140
 
138
141
  Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
@@ -168,22 +171,35 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
168
171
  </tbody>
169
172
  </table>
170
173
 
174
+ Hello world examples:
175
+
176
+ - [Hello world](https://github.com/webgptorg/hello-world)
177
+ - [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
178
+ - [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
179
+
180
+
181
+
171
182
  We also have a community of developers and users of **Promptbook**:
172
183
 
173
184
  - [Discord community](https://discord.gg/x3QWNaa89N)
174
185
  - [Landing page `ptbk.io`](https://ptbk.io)
175
186
  - [Github discussions](https://github.com/webgptorg/promptbook/discussions)
176
187
  - [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
177
- - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
188
+ - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
178
189
 
179
190
  And **Promptbook.studio** branded socials:
180
191
 
192
+
193
+
181
194
  - [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
182
195
 
183
196
  And **Promptujeme** sub-brand:
184
197
 
185
198
  _/Subbrand for Czech clients/_
186
199
 
200
+
201
+
202
+
187
203
  - [Promptujeme.cz](https://www.promptujeme.cz/)
188
204
  - [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
189
205
 
@@ -201,6 +217,8 @@ _/Sub-brand for images and graphics generated via Promptbook prompting/_
201
217
 
202
218
  ## 💙 The Book language
203
219
 
220
+
221
+
204
222
  Following is the documentation and blueprint of the [Book language](https://github.com/webgptorg/book).
205
223
 
206
224
  Book is a language that can be used to write AI applications, agents, workflows, automations, knowledgebases, translators, sheet processors, email automations and more. It allows you to harness the power of AI models in human-like terms, without the need to know the specifics and technicalities of the models.
@@ -250,6 +268,8 @@ Personas can have access to different knowledge, tools and actions. They can als
250
268
 
251
269
  - [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
252
270
 
271
+
272
+
253
273
  ### **How:** Knowledge, Instruments and Actions
254
274
 
255
275
  The resources used by the personas are used to do the work.
@@ -325,11 +345,9 @@ Or you can install them separately:
325
345
 
326
346
  ## 📚 Dictionary
327
347
 
328
- ### 📚 Dictionary
329
-
330
348
  The following glossary is used to clarify certain concepts:
331
349
 
332
- #### General LLM / AI terms
350
+ ### General LLM / AI terms
333
351
 
334
352
  - **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
335
353
  - **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
@@ -340,9 +358,13 @@ The following glossary is used to clarify certain concepts:
340
358
  - **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
341
359
  - **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
342
360
 
343
- _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
344
361
 
345
- #### 💯 Core concepts
362
+
363
+ _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
364
+
365
+
366
+
367
+ ### 💯 Core concepts
346
368
 
347
369
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
348
370
  - [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
@@ -355,7 +377,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
355
377
  - [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
356
378
  - [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
357
379
 
358
- ##### Advanced concepts
380
+ #### Advanced concepts
359
381
 
360
382
  - [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
361
383
  - [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
@@ -370,11 +392,6 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
370
392
  - [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
371
393
  - [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
372
394
 
373
- ### Terms specific to Promptbook TypeScript implementation
374
-
375
- - Anonymous mode
376
- - Application mode
377
-
378
395
 
379
396
 
380
397
  ## 🚂 Promptbook Engine
@@ -445,11 +462,11 @@ See [TODO.md](./TODO.md)
445
462
  <div style="display: flex; align-items: center; gap: 20px;">
446
463
 
447
464
  <a href="https://promptbook.studio/">
448
- <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="100">
465
+ <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
449
466
  </a>
450
467
 
451
468
  <a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
452
- <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
469
+ <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
453
470
  </a>
454
471
 
455
472
  </div>
package/esm/index.es.js CHANGED
@@ -6,13 +6,13 @@ import { basename, join, dirname, relative } from 'path';
6
6
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rename, rmdir } from 'fs/promises';
7
7
  import hexEncoder from 'crypto-js/enc-hex';
8
8
  import sha256 from 'crypto-js/sha256';
9
+ import { randomBytes } from 'crypto';
9
10
  import * as dotenv from 'dotenv';
10
11
  import { spawn } from 'child_process';
11
12
  import JSZip from 'jszip';
12
13
  import { format } from 'prettier';
13
14
  import parserHtml from 'prettier/parser-html';
14
15
  import { Subject } from 'rxjs';
15
- import { randomBytes } from 'crypto';
16
16
  import { parse, unparse } from 'papaparse';
17
17
  import { SHA256 } from 'crypto-js';
18
18
  import { lookup, extension } from 'mime-types';
@@ -44,7 +44,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
44
44
  * @generated
45
45
  * @see https://github.com/webgptorg/promptbook
46
46
  */
47
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-9';
47
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
48
48
  /**
49
49
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
50
50
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -204,7 +204,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
204
204
  *
205
205
  * @public exported from `@promptbook/core`
206
206
  */
207
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
207
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
208
208
  /**
209
209
  * Where to store your books
210
210
  * This is kind of a "src" for your books
@@ -1498,6 +1498,21 @@ class FileCacheStorage {
1498
1498
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
1499
1499
  */
1500
1500
 
1501
+ /**
1502
+ * Generates random token
1503
+ *
1504
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
1505
+ *
1506
+ * @private internal helper function
1507
+ * @returns secure random token
1508
+ */
1509
+ function $randomToken(randomness) {
1510
+ return randomBytes(randomness).toString('hex');
1511
+ }
1512
+ /**
1513
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1514
+ */
1515
+
1501
1516
  /**
1502
1517
  * This error indicates errors during the execution of the pipeline
1503
1518
  *
@@ -1505,11 +1520,17 @@ class FileCacheStorage {
1505
1520
  */
1506
1521
  class PipelineExecutionError extends Error {
1507
1522
  constructor(message) {
1523
+ // Added id parameter
1508
1524
  super(message);
1509
1525
  this.name = 'PipelineExecutionError';
1526
+ // TODO: [🐙] DRY - Maybe $randomId
1527
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1510
1528
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
1511
1529
  }
1512
1530
  }
1531
+ /**
1532
+ * TODO: !!!!!! Add id to all errors
1533
+ */
1513
1534
 
1514
1535
  /**
1515
1536
  * Stores data in memory (HEAP)
@@ -4073,21 +4094,6 @@ function isPipelinePrepared(pipeline) {
4073
4094
  * - [♨] Are tasks prepared
4074
4095
  */
4075
4096
 
4076
- /**
4077
- * Generates random token
4078
- *
4079
- * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
4080
- *
4081
- * @private internal helper function
4082
- * @returns secure random token
4083
- */
4084
- function $randomToken(randomness) {
4085
- return randomBytes(randomness).toString('hex');
4086
- }
4087
- /**
4088
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
4089
- */
4090
-
4091
4097
  /**
4092
4098
  * Recursively converts JSON strings to JSON objects
4093
4099
 
@@ -4268,7 +4274,7 @@ const ALL_ERRORS = {
4268
4274
  * @public exported from `@promptbook/utils`
4269
4275
  */
4270
4276
  function deserializeError(error) {
4271
- const { name, stack } = error;
4277
+ const { name, stack, id } = error; // Added id
4272
4278
  let { message } = error;
4273
4279
  let ErrorClass = ALL_ERRORS[error.name];
4274
4280
  if (ErrorClass === undefined) {
@@ -4283,7 +4289,9 @@ function deserializeError(error) {
4283
4289
  ${block(stack || '')}
4284
4290
  `);
4285
4291
  }
4286
- return new ErrorClass(message);
4292
+ const deserializedError = new ErrorClass(message);
4293
+ deserializedError.id = id; // Assign id to the error object
4294
+ return deserializedError;
4287
4295
  }
4288
4296
 
4289
4297
  /**
@@ -4333,6 +4341,7 @@ function assertsTaskSuccessful(executionResult) {
4333
4341
  */
4334
4342
  function createTask(options) {
4335
4343
  const { taskType, taskProcessCallback } = options;
4344
+ // TODO: [🐙] DRY
4336
4345
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
4337
4346
  let status = 'RUNNING';
4338
4347
  const createdAt = new Date();
@@ -4365,7 +4374,7 @@ function createTask(options) {
4365
4374
  assertsTaskSuccessful(executionResult);
4366
4375
  status = 'FINISHED';
4367
4376
  currentValue = jsonStringsToJsons(executionResult);
4368
- // <- TODO: Convert JSON values in string to JSON objects
4377
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
4369
4378
  partialResultSubject.next(executionResult);
4370
4379
  }
4371
4380
  catch (error) {
@@ -4429,19 +4438,21 @@ function createTask(options) {
4429
4438
  */
4430
4439
  function serializeError(error) {
4431
4440
  const { name, message, stack } = error;
4441
+ const { id } = error;
4432
4442
  if (!Object.keys(ALL_ERRORS).includes(name)) {
4433
4443
  console.error(spaceTrim((block) => `
4434
-
4444
+
4435
4445
  Cannot serialize error with name "${name}"
4436
4446
 
4437
4447
  ${block(stack || message)}
4438
-
4448
+
4439
4449
  `));
4440
4450
  }
4441
4451
  return {
4442
4452
  name: name,
4443
4453
  message,
4444
4454
  stack,
4455
+ id, // Include id in the serialized object
4445
4456
  };
4446
4457
  }
4447
4458
 
@@ -5174,6 +5185,9 @@ function countCharacters(text) {
5174
5185
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
5175
5186
  return text.length;
5176
5187
  }
5188
+ /**
5189
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
5190
+ */
5177
5191
 
5178
5192
  /**
5179
5193
  * Number of characters per standard line with 11pt Arial font size.
@@ -5205,6 +5219,9 @@ function countLines(text) {
5205
5219
  const lines = text.split('\n');
5206
5220
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
5207
5221
  }
5222
+ /**
5223
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
5224
+ */
5208
5225
 
5209
5226
  /**
5210
5227
  * Counts number of pages in the text
@@ -5216,6 +5233,9 @@ function countLines(text) {
5216
5233
  function countPages(text) {
5217
5234
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
5218
5235
  }
5236
+ /**
5237
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
5238
+ */
5219
5239
 
5220
5240
  /**
5221
5241
  * Counts number of paragraphs in the text
@@ -5225,6 +5245,9 @@ function countPages(text) {
5225
5245
  function countParagraphs(text) {
5226
5246
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
5227
5247
  }
5248
+ /**
5249
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
5250
+ */
5228
5251
 
5229
5252
  /**
5230
5253
  * Split text into sentences
@@ -5242,6 +5265,9 @@ function splitIntoSentences(text) {
5242
5265
  function countSentences(text) {
5243
5266
  return splitIntoSentences(text).length;
5244
5267
  }
5268
+ /**
5269
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
5270
+ */
5245
5271
 
5246
5272
  /**
5247
5273
  * Counts number of words in the text
@@ -5255,6 +5281,9 @@ function countWords(text) {
5255
5281
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
5256
5282
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
5257
5283
  }
5284
+ /**
5285
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
5286
+ */
5258
5287
 
5259
5288
  /**
5260
5289
  * Index of all counter functions
@@ -12341,7 +12370,7 @@ function $initializeRunCommand(program) {
12341
12370
  pipeline,
12342
12371
  tools,
12343
12372
  isNotPreparedWarningSupressed: true,
12344
- maxExecutionAttempts: 3,
12373
+ maxExecutionAttempts: DEFAULT_MAX_EXECUTION_ATTEMPTS,
12345
12374
  // <- TODO: Why "LLM execution failed undefinedx"
12346
12375
  maxParallelCount: 1, // <- TODO: Pass CLI argument
12347
12376
  });