@promptbook/pdf 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/pdf`
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
@@ -5,8 +5,8 @@ import hexEncoder from 'crypto-js/enc-hex';
5
5
  import { basename, join, dirname } from 'path';
6
6
  import { format } from 'prettier';
7
7
  import parserHtml from 'prettier/parser-html';
8
- import { Subject } from 'rxjs';
9
8
  import { randomBytes } from 'crypto';
9
+ import { Subject } from 'rxjs';
10
10
  import { forTime } from 'waitasecond';
11
11
  import sha256 from 'crypto-js/sha256';
12
12
  import { lookup, extension } from 'mime-types';
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -158,7 +158,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
158
158
  *
159
159
  * @public exported from `@promptbook/core`
160
160
  */
161
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
161
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
162
162
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
163
163
  /**
164
164
  * Where to store the temporary downloads
@@ -2016,6 +2016,21 @@ class MissingToolsError extends Error {
2016
2016
  }
2017
2017
  }
2018
2018
 
2019
+ /**
2020
+ * Generates random token
2021
+ *
2022
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
2023
+ *
2024
+ * @private internal helper function
2025
+ * @returns secure random token
2026
+ */
2027
+ function $randomToken(randomness) {
2028
+ return randomBytes(randomness).toString('hex');
2029
+ }
2030
+ /**
2031
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
2032
+ */
2033
+
2019
2034
  /**
2020
2035
  * This error indicates errors during the execution of the pipeline
2021
2036
  *
@@ -2023,11 +2038,17 @@ class MissingToolsError extends Error {
2023
2038
  */
2024
2039
  class PipelineExecutionError extends Error {
2025
2040
  constructor(message) {
2041
+ // Added id parameter
2026
2042
  super(message);
2027
2043
  this.name = 'PipelineExecutionError';
2044
+ // TODO: [🐙] DRY - Maybe $randomId
2045
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2028
2046
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
2029
2047
  }
2030
2048
  }
2049
+ /**
2050
+ * TODO: !!!!!! Add id to all errors
2051
+ */
2031
2052
 
2032
2053
  /**
2033
2054
  * Determine if the pipeline is fully prepared
@@ -2067,18 +2088,33 @@ function isPipelinePrepared(pipeline) {
2067
2088
  */
2068
2089
 
2069
2090
  /**
2070
- * Generates random token
2071
- *
2072
- * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
2073
- *
2074
- * @private internal helper function
2075
- * @returns secure random token
2091
+ * Recursively converts JSON strings to JSON objects
2092
+
2093
+ * @public exported from `@promptbook/utils`
2076
2094
  */
2077
- function $randomToken(randomness) {
2078
- return randomBytes(randomness).toString('hex');
2095
+ function jsonStringsToJsons(object) {
2096
+ if (object === null) {
2097
+ return object;
2098
+ }
2099
+ if (Array.isArray(object)) {
2100
+ return object.map(jsonStringsToJsons);
2101
+ }
2102
+ if (typeof object !== 'object') {
2103
+ return object;
2104
+ }
2105
+ const newObject = { ...object };
2106
+ for (const [key, value] of Object.entries(object)) {
2107
+ if (typeof value === 'string' && isValidJsonString(value)) {
2108
+ newObject[key] = JSON.parse(value);
2109
+ }
2110
+ else {
2111
+ newObject[key] = jsonStringsToJsons(value);
2112
+ }
2113
+ }
2114
+ return newObject;
2079
2115
  }
2080
2116
  /**
2081
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
2117
+ * TODO: Type the return type correctly
2082
2118
  */
2083
2119
 
2084
2120
  /**
@@ -2241,7 +2277,7 @@ const ALL_ERRORS = {
2241
2277
  * @public exported from `@promptbook/utils`
2242
2278
  */
2243
2279
  function deserializeError(error) {
2244
- const { name, stack } = error;
2280
+ const { name, stack, id } = error; // Added id
2245
2281
  let { message } = error;
2246
2282
  let ErrorClass = ALL_ERRORS[error.name];
2247
2283
  if (ErrorClass === undefined) {
@@ -2256,7 +2292,9 @@ function deserializeError(error) {
2256
2292
  ${block(stack || '')}
2257
2293
  `);
2258
2294
  }
2259
- return new ErrorClass(message);
2295
+ const deserializedError = new ErrorClass(message);
2296
+ deserializedError.id = id; // Assign id to the error object
2297
+ return deserializedError;
2260
2298
  }
2261
2299
 
2262
2300
  /**
@@ -2306,17 +2344,19 @@ function assertsTaskSuccessful(executionResult) {
2306
2344
  */
2307
2345
  function createTask(options) {
2308
2346
  const { taskType, taskProcessCallback } = options;
2347
+ // TODO: [🐙] DRY
2309
2348
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2310
2349
  let status = 'RUNNING';
2311
2350
  const createdAt = new Date();
2312
2351
  let updatedAt = createdAt;
2313
2352
  const errors = [];
2314
2353
  const warnings = [];
2315
- const currentValue = {};
2354
+ let currentValue = {};
2316
2355
  const partialResultSubject = new Subject();
2317
2356
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2318
2357
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2319
2358
  Object.assign(currentValue, newOngoingResult);
2359
+ // <- TODO: assign deep
2320
2360
  partialResultSubject.next(newOngoingResult);
2321
2361
  });
2322
2362
  finalResultPromise
@@ -2336,7 +2376,8 @@ function createTask(options) {
2336
2376
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2337
2377
  assertsTaskSuccessful(executionResult);
2338
2378
  status = 'FINISHED';
2339
- Object.assign(currentValue, executionResult);
2379
+ currentValue = jsonStringsToJsons(executionResult);
2380
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
2340
2381
  partialResultSubject.next(executionResult);
2341
2382
  }
2342
2383
  catch (error) {
@@ -2400,19 +2441,21 @@ function createTask(options) {
2400
2441
  */
2401
2442
  function serializeError(error) {
2402
2443
  const { name, message, stack } = error;
2444
+ const { id } = error;
2403
2445
  if (!Object.keys(ALL_ERRORS).includes(name)) {
2404
2446
  console.error(spaceTrim((block) => `
2405
-
2447
+
2406
2448
  Cannot serialize error with name "${name}"
2407
2449
 
2408
2450
  ${block(stack || message)}
2409
-
2451
+
2410
2452
  `));
2411
2453
  }
2412
2454
  return {
2413
2455
  name: name,
2414
2456
  message,
2415
2457
  stack,
2458
+ id, // Include id in the serialized object
2416
2459
  };
2417
2460
  }
2418
2461
 
@@ -4324,6 +4367,9 @@ function countCharacters(text) {
4324
4367
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4325
4368
  return text.length;
4326
4369
  }
4370
+ /**
4371
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4372
+ */
4327
4373
 
4328
4374
  /**
4329
4375
  * Number of characters per standard line with 11pt Arial font size.
@@ -4355,6 +4401,9 @@ function countLines(text) {
4355
4401
  const lines = text.split('\n');
4356
4402
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4357
4403
  }
4404
+ /**
4405
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4406
+ */
4358
4407
 
4359
4408
  /**
4360
4409
  * Counts number of pages in the text
@@ -4366,6 +4415,9 @@ function countLines(text) {
4366
4415
  function countPages(text) {
4367
4416
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4368
4417
  }
4418
+ /**
4419
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4420
+ */
4369
4421
 
4370
4422
  /**
4371
4423
  * Counts number of paragraphs in the text
@@ -4375,6 +4427,9 @@ function countPages(text) {
4375
4427
  function countParagraphs(text) {
4376
4428
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4377
4429
  }
4430
+ /**
4431
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4432
+ */
4378
4433
 
4379
4434
  /**
4380
4435
  * Split text into sentences
@@ -4392,6 +4447,9 @@ function splitIntoSentences(text) {
4392
4447
  function countSentences(text) {
4393
4448
  return splitIntoSentences(text).length;
4394
4449
  }
4450
+ /**
4451
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4452
+ */
4395
4453
 
4396
4454
  /**
4397
4455
  * Counts number of words in the text
@@ -4405,6 +4463,9 @@ function countWords(text) {
4405
4463
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4406
4464
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
4407
4465
  }
4466
+ /**
4467
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4468
+ */
4408
4469
 
4409
4470
  /**
4410
4471
  * Index of all counter functions