@promptbook/legacy-documents 0.88.0-8 → 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/legacy-documents`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -72,6 +68,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
72
68
 
73
69
 
74
70
 
71
+
72
+
73
+
75
74
  ## 🚀 Get started
76
75
 
77
76
  Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
@@ -83,6 +82,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
83
82
 
84
83
 
85
84
 
85
+
86
+
86
87
  ## 💜 The Promptbook Project
87
88
 
88
89
  Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
@@ -118,6 +119,14 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
118
119
  </tbody>
119
120
  </table>
120
121
 
122
+ Hello world examples:
123
+
124
+ - [Hello world](https://github.com/webgptorg/hello-world)
125
+ - [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
126
+ - [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
127
+
128
+
129
+
121
130
  We also have a community of developers and users of **Promptbook**:
122
131
 
123
132
  - [Discord community](https://discord.gg/x3QWNaa89N)
@@ -284,16 +293,9 @@ Or you can install them separately:
284
293
 
285
294
  ## 📚 Dictionary
286
295
 
287
-
288
-
289
-
290
-
291
-
292
- ### 📚 Dictionary
293
-
294
296
  The following glossary is used to clarify certain concepts:
295
297
 
296
- #### General LLM / AI terms
298
+ ### General LLM / AI terms
297
299
 
298
300
  - **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.
299
301
  - **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.
@@ -306,11 +308,11 @@ The following glossary is used to clarify certain concepts:
306
308
 
307
309
 
308
310
 
309
- _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
311
+ _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
310
312
 
311
313
 
312
314
 
313
- #### 💯 Core concepts
315
+ ### 💯 Core concepts
314
316
 
315
317
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
316
318
  - [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
@@ -323,7 +325,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
323
325
  - [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
324
326
  - [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
325
327
 
326
- ##### Advanced concepts
328
+ #### Advanced concepts
327
329
 
328
330
  - [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
329
331
  - [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
@@ -340,17 +342,9 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
340
342
 
341
343
 
342
344
 
343
- ### Terms specific to Promptbook TypeScript implementation
344
-
345
- - Anonymous mode
346
- - Application mode
347
-
348
-
349
-
350
- ## 🔌 Usage in Typescript / Javascript
345
+ ## 🚂 Promptbook Engine
351
346
 
352
- - [Simple usage](./examples/usage/simple-script)
353
- - [Usage with client and remote server](./examples/usage/remote)
347
+ ![Schema of Promptbook Engine](./documents/promptbook-engine.svg)
354
348
 
355
349
  ## ➕➖ When to use Promptbook?
356
350
 
@@ -416,11 +410,11 @@ See [TODO.md](./TODO.md)
416
410
  <div style="display: flex; align-items: center; gap: 20px;">
417
411
 
418
412
  <a href="https://promptbook.studio/">
419
- <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="100">
413
+ <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
420
414
  </a>
421
415
 
422
416
  <a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
423
- <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
417
+ <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
424
418
  </a>
425
419
 
426
420
  </div>
package/esm/index.es.js CHANGED
@@ -8,8 +8,8 @@ import { SHA256 } from 'crypto-js';
8
8
  import hexEncoder from 'crypto-js/enc-hex';
9
9
  import { format } from 'prettier';
10
10
  import parserHtml from 'prettier/parser-html';
11
- import { Subject } from 'rxjs';
12
11
  import { randomBytes } from 'crypto';
12
+ import { Subject } from 'rxjs';
13
13
  import sha256 from 'crypto-js/sha256';
14
14
  import { lookup, extension } from 'mime-types';
15
15
  import { parse, unparse } from 'papaparse';
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -160,7 +160,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
160
160
  *
161
161
  * @public exported from `@promptbook/core`
162
162
  */
163
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
163
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
164
164
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
165
165
  /**
166
166
  * Where to store the temporary downloads
@@ -2173,6 +2173,21 @@ function createCollectionFromJson(...promptbooks) {
2173
2173
  return new SimplePipelineCollection(...promptbooks);
2174
2174
  }
2175
2175
 
2176
+ /**
2177
+ * Generates random token
2178
+ *
2179
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
2180
+ *
2181
+ * @private internal helper function
2182
+ * @returns secure random token
2183
+ */
2184
+ function $randomToken(randomness) {
2185
+ return randomBytes(randomness).toString('hex');
2186
+ }
2187
+ /**
2188
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
2189
+ */
2190
+
2176
2191
  /**
2177
2192
  * This error indicates errors during the execution of the pipeline
2178
2193
  *
@@ -2180,11 +2195,17 @@ function createCollectionFromJson(...promptbooks) {
2180
2195
  */
2181
2196
  class PipelineExecutionError extends Error {
2182
2197
  constructor(message) {
2198
+ // Added id parameter
2183
2199
  super(message);
2184
2200
  this.name = 'PipelineExecutionError';
2201
+ // TODO: [🐙] DRY - Maybe $randomId
2202
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2185
2203
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
2186
2204
  }
2187
2205
  }
2206
+ /**
2207
+ * TODO: !!!!!! Add id to all errors
2208
+ */
2188
2209
 
2189
2210
  /**
2190
2211
  * Determine if the pipeline is fully prepared
@@ -2224,18 +2245,33 @@ function isPipelinePrepared(pipeline) {
2224
2245
  */
2225
2246
 
2226
2247
  /**
2227
- * Generates random token
2228
- *
2229
- * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
2230
- *
2231
- * @private internal helper function
2232
- * @returns secure random token
2248
+ * Recursively converts JSON strings to JSON objects
2249
+
2250
+ * @public exported from `@promptbook/utils`
2233
2251
  */
2234
- function $randomToken(randomness) {
2235
- return randomBytes(randomness).toString('hex');
2252
+ function jsonStringsToJsons(object) {
2253
+ if (object === null) {
2254
+ return object;
2255
+ }
2256
+ if (Array.isArray(object)) {
2257
+ return object.map(jsonStringsToJsons);
2258
+ }
2259
+ if (typeof object !== 'object') {
2260
+ return object;
2261
+ }
2262
+ const newObject = { ...object };
2263
+ for (const [key, value] of Object.entries(object)) {
2264
+ if (typeof value === 'string' && isValidJsonString(value)) {
2265
+ newObject[key] = JSON.parse(value);
2266
+ }
2267
+ else {
2268
+ newObject[key] = jsonStringsToJsons(value);
2269
+ }
2270
+ }
2271
+ return newObject;
2236
2272
  }
2237
2273
  /**
2238
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
2274
+ * TODO: Type the return type correctly
2239
2275
  */
2240
2276
 
2241
2277
  /**
@@ -2398,7 +2434,7 @@ const ALL_ERRORS = {
2398
2434
  * @public exported from `@promptbook/utils`
2399
2435
  */
2400
2436
  function deserializeError(error) {
2401
- const { name, stack } = error;
2437
+ const { name, stack, id } = error; // Added id
2402
2438
  let { message } = error;
2403
2439
  let ErrorClass = ALL_ERRORS[error.name];
2404
2440
  if (ErrorClass === undefined) {
@@ -2413,7 +2449,9 @@ function deserializeError(error) {
2413
2449
  ${block(stack || '')}
2414
2450
  `);
2415
2451
  }
2416
- return new ErrorClass(message);
2452
+ const deserializedError = new ErrorClass(message);
2453
+ deserializedError.id = id; // Assign id to the error object
2454
+ return deserializedError;
2417
2455
  }
2418
2456
 
2419
2457
  /**
@@ -2463,17 +2501,19 @@ function assertsTaskSuccessful(executionResult) {
2463
2501
  */
2464
2502
  function createTask(options) {
2465
2503
  const { taskType, taskProcessCallback } = options;
2504
+ // TODO: [🐙] DRY
2466
2505
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2467
2506
  let status = 'RUNNING';
2468
2507
  const createdAt = new Date();
2469
2508
  let updatedAt = createdAt;
2470
2509
  const errors = [];
2471
2510
  const warnings = [];
2472
- const currentValue = {};
2511
+ let currentValue = {};
2473
2512
  const partialResultSubject = new Subject();
2474
2513
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2475
2514
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2476
2515
  Object.assign(currentValue, newOngoingResult);
2516
+ // <- TODO: assign deep
2477
2517
  partialResultSubject.next(newOngoingResult);
2478
2518
  });
2479
2519
  finalResultPromise
@@ -2493,7 +2533,8 @@ function createTask(options) {
2493
2533
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2494
2534
  assertsTaskSuccessful(executionResult);
2495
2535
  status = 'FINISHED';
2496
- Object.assign(currentValue, executionResult);
2536
+ currentValue = jsonStringsToJsons(executionResult);
2537
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
2497
2538
  partialResultSubject.next(executionResult);
2498
2539
  }
2499
2540
  catch (error) {
@@ -2557,19 +2598,21 @@ function createTask(options) {
2557
2598
  */
2558
2599
  function serializeError(error) {
2559
2600
  const { name, message, stack } = error;
2601
+ const { id } = error;
2560
2602
  if (!Object.keys(ALL_ERRORS).includes(name)) {
2561
2603
  console.error(spaceTrim$1((block) => `
2562
-
2604
+
2563
2605
  Cannot serialize error with name "${name}"
2564
2606
 
2565
2607
  ${block(stack || message)}
2566
-
2608
+
2567
2609
  `));
2568
2610
  }
2569
2611
  return {
2570
2612
  name: name,
2571
2613
  message,
2572
2614
  stack,
2615
+ id, // Include id in the serialized object
2573
2616
  };
2574
2617
  }
2575
2618
 
@@ -4471,6 +4514,9 @@ function countCharacters(text) {
4471
4514
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4472
4515
  return text.length;
4473
4516
  }
4517
+ /**
4518
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4519
+ */
4474
4520
 
4475
4521
  /**
4476
4522
  * Number of characters per standard line with 11pt Arial font size.
@@ -4502,6 +4548,9 @@ function countLines(text) {
4502
4548
  const lines = text.split('\n');
4503
4549
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4504
4550
  }
4551
+ /**
4552
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4553
+ */
4505
4554
 
4506
4555
  /**
4507
4556
  * Counts number of pages in the text
@@ -4513,6 +4562,9 @@ function countLines(text) {
4513
4562
  function countPages(text) {
4514
4563
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4515
4564
  }
4565
+ /**
4566
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4567
+ */
4516
4568
 
4517
4569
  /**
4518
4570
  * Counts number of paragraphs in the text
@@ -4522,6 +4574,9 @@ function countPages(text) {
4522
4574
  function countParagraphs(text) {
4523
4575
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4524
4576
  }
4577
+ /**
4578
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4579
+ */
4525
4580
 
4526
4581
  /**
4527
4582
  * Split text into sentences
@@ -4539,6 +4594,9 @@ function splitIntoSentences(text) {
4539
4594
  function countSentences(text) {
4540
4595
  return splitIntoSentences(text).length;
4541
4596
  }
4597
+ /**
4598
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4599
+ */
4542
4600
 
4543
4601
  /**
4544
4602
  * Counts number of words in the text
@@ -4552,6 +4610,9 @@ function countWords(text) {
4552
4610
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4553
4611
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
4554
4612
  }
4613
+ /**
4614
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4615
+ */
4555
4616
 
4556
4617
  /**
4557
4618
  * Index of all counter functions