@promptbook/node 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/node`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -74,6 +70,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
74
70
 
75
71
 
76
72
 
73
+
74
+
75
+
77
76
  ## 🚀 Get started
78
77
 
79
78
  Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
@@ -85,6 +84,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
85
84
 
86
85
 
87
86
 
87
+
88
+
88
89
  ## 💜 The Promptbook Project
89
90
 
90
91
  Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
@@ -120,6 +121,14 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
120
121
  </tbody>
121
122
  </table>
122
123
 
124
+ Hello world examples:
125
+
126
+ - [Hello world](https://github.com/webgptorg/hello-world)
127
+ - [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
128
+ - [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
129
+
130
+
131
+
123
132
  We also have a community of developers and users of **Promptbook**:
124
133
 
125
134
  - [Discord community](https://discord.gg/x3QWNaa89N)
@@ -286,16 +295,9 @@ Or you can install them separately:
286
295
 
287
296
  ## 📚 Dictionary
288
297
 
289
-
290
-
291
-
292
-
293
-
294
- ### 📚 Dictionary
295
-
296
298
  The following glossary is used to clarify certain concepts:
297
299
 
298
- #### General LLM / AI terms
300
+ ### General LLM / AI terms
299
301
 
300
302
  - **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.
301
303
  - **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.
@@ -308,11 +310,11 @@ The following glossary is used to clarify certain concepts:
308
310
 
309
311
 
310
312
 
311
- _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
313
+ _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
312
314
 
313
315
 
314
316
 
315
- #### 💯 Core concepts
317
+ ### 💯 Core concepts
316
318
 
317
319
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
318
320
  - [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
@@ -325,7 +327,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
325
327
  - [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
326
328
  - [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
327
329
 
328
- ##### Advanced concepts
330
+ #### Advanced concepts
329
331
 
330
332
  - [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
331
333
  - [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
@@ -342,17 +344,9 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
342
344
 
343
345
 
344
346
 
345
- ### Terms specific to Promptbook TypeScript implementation
346
-
347
- - Anonymous mode
348
- - Application mode
349
-
350
-
351
-
352
- ## 🔌 Usage in Typescript / Javascript
347
+ ## 🚂 Promptbook Engine
353
348
 
354
- - [Simple usage](./examples/usage/simple-script)
355
- - [Usage with client and remote server](./examples/usage/remote)
349
+ ![Schema of Promptbook Engine](./documents/promptbook-engine.svg)
356
350
 
357
351
  ## ➕➖ When to use Promptbook?
358
352
 
@@ -418,11 +412,11 @@ See [TODO.md](./TODO.md)
418
412
  <div style="display: flex; align-items: center; gap: 20px;">
419
413
 
420
414
  <a href="https://promptbook.studio/">
421
- <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="100">
415
+ <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
422
416
  </a>
423
417
 
424
418
  <a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
425
- <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
419
+ <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
426
420
  </a>
427
421
 
428
422
  </div>
package/esm/index.es.js CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -157,7 +157,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
157
157
  *
158
158
  * @public exported from `@promptbook/core`
159
159
  */
160
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
160
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
161
161
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
162
162
  /**
163
163
  * Where to store the temporary downloads
@@ -1605,6 +1605,36 @@ function $randomToken(randomness) {
1605
1605
  * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1606
1606
  */
1607
1607
 
1608
+ /**
1609
+ * Recursively converts JSON strings to JSON objects
1610
+
1611
+ * @public exported from `@promptbook/utils`
1612
+ */
1613
+ function jsonStringsToJsons(object) {
1614
+ if (object === null) {
1615
+ return object;
1616
+ }
1617
+ if (Array.isArray(object)) {
1618
+ return object.map(jsonStringsToJsons);
1619
+ }
1620
+ if (typeof object !== 'object') {
1621
+ return object;
1622
+ }
1623
+ const newObject = { ...object };
1624
+ for (const [key, value] of Object.entries(object)) {
1625
+ if (typeof value === 'string' && isValidJsonString(value)) {
1626
+ newObject[key] = JSON.parse(value);
1627
+ }
1628
+ else {
1629
+ newObject[key] = jsonStringsToJsons(value);
1630
+ }
1631
+ }
1632
+ return newObject;
1633
+ }
1634
+ /**
1635
+ * TODO: Type the return type correctly
1636
+ */
1637
+
1608
1638
  /**
1609
1639
  * This error indicates errors during the execution of the pipeline
1610
1640
  *
@@ -1612,11 +1642,17 @@ function $randomToken(randomness) {
1612
1642
  */
1613
1643
  class PipelineExecutionError extends Error {
1614
1644
  constructor(message) {
1645
+ // Added id parameter
1615
1646
  super(message);
1616
1647
  this.name = 'PipelineExecutionError';
1648
+ // TODO: [🐙] DRY - Maybe $randomId
1649
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1617
1650
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
1618
1651
  }
1619
1652
  }
1653
+ /**
1654
+ * TODO: !!!!!! Add id to all errors
1655
+ */
1620
1656
 
1621
1657
  /**
1622
1658
  * This error indicates problems parsing the format value
@@ -1804,7 +1840,7 @@ const ALL_ERRORS = {
1804
1840
  * @public exported from `@promptbook/utils`
1805
1841
  */
1806
1842
  function deserializeError(error) {
1807
- const { name, stack } = error;
1843
+ const { name, stack, id } = error; // Added id
1808
1844
  let { message } = error;
1809
1845
  let ErrorClass = ALL_ERRORS[error.name];
1810
1846
  if (ErrorClass === undefined) {
@@ -1819,7 +1855,9 @@ function deserializeError(error) {
1819
1855
  ${block(stack || '')}
1820
1856
  `);
1821
1857
  }
1822
- return new ErrorClass(message);
1858
+ const deserializedError = new ErrorClass(message);
1859
+ deserializedError.id = id; // Assign id to the error object
1860
+ return deserializedError;
1823
1861
  }
1824
1862
 
1825
1863
  /**
@@ -1869,17 +1907,19 @@ function assertsTaskSuccessful(executionResult) {
1869
1907
  */
1870
1908
  function createTask(options) {
1871
1909
  const { taskType, taskProcessCallback } = options;
1910
+ // TODO: [🐙] DRY
1872
1911
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1873
1912
  let status = 'RUNNING';
1874
1913
  const createdAt = new Date();
1875
1914
  let updatedAt = createdAt;
1876
1915
  const errors = [];
1877
1916
  const warnings = [];
1878
- const currentValue = {};
1917
+ let currentValue = {};
1879
1918
  const partialResultSubject = new Subject();
1880
1919
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
1881
1920
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
1882
1921
  Object.assign(currentValue, newOngoingResult);
1922
+ // <- TODO: assign deep
1883
1923
  partialResultSubject.next(newOngoingResult);
1884
1924
  });
1885
1925
  finalResultPromise
@@ -1899,7 +1939,8 @@ function createTask(options) {
1899
1939
  // And delete `ExecutionTask.currentValue.preparedPipeline`
1900
1940
  assertsTaskSuccessful(executionResult);
1901
1941
  status = 'FINISHED';
1902
- Object.assign(currentValue, executionResult);
1942
+ currentValue = jsonStringsToJsons(executionResult);
1943
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
1903
1944
  partialResultSubject.next(executionResult);
1904
1945
  }
1905
1946
  catch (error) {
@@ -1963,19 +2004,21 @@ function createTask(options) {
1963
2004
  */
1964
2005
  function serializeError(error) {
1965
2006
  const { name, message, stack } = error;
2007
+ const { id } = error;
1966
2008
  if (!Object.keys(ALL_ERRORS).includes(name)) {
1967
2009
  console.error(spaceTrim((block) => `
1968
-
2010
+
1969
2011
  Cannot serialize error with name "${name}"
1970
2012
 
1971
2013
  ${block(stack || message)}
1972
-
2014
+
1973
2015
  `));
1974
2016
  }
1975
2017
  return {
1976
2018
  name: name,
1977
2019
  message,
1978
2020
  stack,
2021
+ id, // Include id in the serialized object
1979
2022
  };
1980
2023
  }
1981
2024
 
@@ -3018,6 +3061,9 @@ function countCharacters(text) {
3018
3061
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
3019
3062
  return text.length;
3020
3063
  }
3064
+ /**
3065
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3066
+ */
3021
3067
 
3022
3068
  /**
3023
3069
  * Number of characters per standard line with 11pt Arial font size.
@@ -3049,6 +3095,9 @@ function countLines(text) {
3049
3095
  const lines = text.split('\n');
3050
3096
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
3051
3097
  }
3098
+ /**
3099
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3100
+ */
3052
3101
 
3053
3102
  /**
3054
3103
  * Counts number of pages in the text
@@ -3060,6 +3109,9 @@ function countLines(text) {
3060
3109
  function countPages(text) {
3061
3110
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
3062
3111
  }
3112
+ /**
3113
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3114
+ */
3063
3115
 
3064
3116
  /**
3065
3117
  * Counts number of paragraphs in the text
@@ -3069,6 +3121,9 @@ function countPages(text) {
3069
3121
  function countParagraphs(text) {
3070
3122
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
3071
3123
  }
3124
+ /**
3125
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3126
+ */
3072
3127
 
3073
3128
  /**
3074
3129
  * Split text into sentences
@@ -3086,6 +3141,9 @@ function splitIntoSentences(text) {
3086
3141
  function countSentences(text) {
3087
3142
  return splitIntoSentences(text).length;
3088
3143
  }
3144
+ /**
3145
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3146
+ */
3089
3147
 
3090
3148
  const defaultDiacriticsRemovalMap = [
3091
3149
  {
@@ -3360,6 +3418,9 @@ function countWords(text) {
3360
3418
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
3361
3419
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
3362
3420
  }
3421
+ /**
3422
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3423
+ */
3363
3424
 
3364
3425
  /**
3365
3426
  * Index of all counter functions