@promptbook/node 0.88.0-1 → 0.88.0-11

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
@@ -120,6 +120,14 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
120
120
  </tbody>
121
121
  </table>
122
122
 
123
+ Hello world examples:
124
+
125
+ - [Hello world](https://github.com/webgptorg/hello-world)
126
+ - [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
127
+ - [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
128
+
129
+
130
+
123
131
  We also have a community of developers and users of **Promptbook**:
124
132
 
125
133
  - [Discord community](https://discord.gg/x3QWNaa89N)
@@ -286,16 +294,9 @@ Or you can install them separately:
286
294
 
287
295
  ## 📚 Dictionary
288
296
 
289
-
290
-
291
-
292
-
293
-
294
- ### 📚 Dictionary
295
-
296
297
  The following glossary is used to clarify certain concepts:
297
298
 
298
- #### General LLM / AI terms
299
+ ### General LLM / AI terms
299
300
 
300
301
  - **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
302
  - **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 +309,11 @@ The following glossary is used to clarify certain concepts:
308
309
 
309
310
 
310
311
 
311
- _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
312
+ _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
312
313
 
313
314
 
314
315
 
315
- #### 💯 Core concepts
316
+ ### 💯 Core concepts
316
317
 
317
318
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
318
319
  - [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
@@ -325,7 +326,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
325
326
  - [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
326
327
  - [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
327
328
 
328
- ##### Advanced concepts
329
+ #### Advanced concepts
329
330
 
330
331
  - [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
331
332
  - [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
@@ -342,17 +343,9 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
342
343
 
343
344
 
344
345
 
345
- ### Terms specific to Promptbook TypeScript implementation
346
-
347
- - Anonymous mode
348
- - Application mode
349
-
346
+ ## 🚂 Promptbook Engine
350
347
 
351
-
352
- ## 🔌 Usage in Typescript / Javascript
353
-
354
- - [Simple usage](./examples/usage/simple-script)
355
- - [Usage with client and remote server](./examples/usage/remote)
348
+ ![Schema of Promptbook Engine](./documents/promptbook-engine.svg)
356
349
 
357
350
  ## ➕➖ When to use Promptbook?
358
351
 
@@ -418,13 +411,13 @@ See [TODO.md](./TODO.md)
418
411
  <div style="display: flex; align-items: center; gap: 20px;">
419
412
 
420
413
  <a href="https://promptbook.studio/">
421
- <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="100">
414
+ <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
422
415
  </a>
423
416
 
424
417
  <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">
418
+ <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
426
419
  </a>
427
-
420
+
428
421
  </div>
429
422
 
430
423
  ## 🖋️ Contributing
package/esm/index.es.js CHANGED
@@ -5,7 +5,7 @@ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
5
5
  import JSZip from 'jszip';
6
6
  import { format } from 'prettier';
7
7
  import parserHtml from 'prettier/parser-html';
8
- import { BehaviorSubject } from 'rxjs';
8
+ import { Subject } from 'rxjs';
9
9
  import { randomBytes } from 'crypto';
10
10
  import { forTime } from 'waitasecond';
11
11
  import { parse, unparse } from 'papaparse';
@@ -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-1';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-11';
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
@@ -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
  *
@@ -1870,21 +1900,43 @@ function assertsTaskSuccessful(executionResult) {
1870
1900
  function createTask(options) {
1871
1901
  const { taskType, taskProcessCallback } = options;
1872
1902
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1873
- const partialResultSubject = new BehaviorSubject({});
1903
+ let status = 'RUNNING';
1904
+ const createdAt = new Date();
1905
+ let updatedAt = createdAt;
1906
+ const errors = [];
1907
+ const warnings = [];
1908
+ let currentValue = {};
1909
+ const partialResultSubject = new Subject();
1910
+ // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
1874
1911
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
1912
+ Object.assign(currentValue, newOngoingResult);
1913
+ // <- TODO: assign deep
1875
1914
  partialResultSubject.next(newOngoingResult);
1876
1915
  });
1877
1916
  finalResultPromise
1878
1917
  .catch((error) => {
1918
+ errors.push(error);
1879
1919
  partialResultSubject.error(error);
1880
1920
  })
1881
- .then((value) => {
1882
- if (value) {
1921
+ .then((executionResult) => {
1922
+ if (executionResult) {
1883
1923
  try {
1884
- assertsTaskSuccessful(value);
1885
- partialResultSubject.next(value);
1924
+ updatedAt = new Date();
1925
+ errors.push(...executionResult.errors);
1926
+ warnings.push(...executionResult.warnings);
1927
+ // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
1928
+ // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
1929
+ // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
1930
+ // And delete `ExecutionTask.currentValue.preparedPipeline`
1931
+ assertsTaskSuccessful(executionResult);
1932
+ status = 'FINISHED';
1933
+ currentValue = jsonStringsToJsons(executionResult);
1934
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
1935
+ partialResultSubject.next(executionResult);
1886
1936
  }
1887
1937
  catch (error) {
1938
+ status = 'ERROR';
1939
+ errors.push(error);
1888
1940
  partialResultSubject.error(error);
1889
1941
  }
1890
1942
  }
@@ -1901,12 +1953,33 @@ function createTask(options) {
1901
1953
  return {
1902
1954
  taskType,
1903
1955
  taskId,
1956
+ get status() {
1957
+ return status;
1958
+ // <- Note: [1] Theese must be getters to allow changing the value in the future
1959
+ },
1960
+ get createdAt() {
1961
+ return createdAt;
1962
+ // <- Note: [1]
1963
+ },
1964
+ get updatedAt() {
1965
+ return updatedAt;
1966
+ // <- Note: [1]
1967
+ },
1904
1968
  asPromise,
1905
1969
  asObservable() {
1906
1970
  return partialResultSubject.asObservable();
1907
1971
  },
1972
+ get errors() {
1973
+ return errors;
1974
+ // <- Note: [1]
1975
+ },
1976
+ get warnings() {
1977
+ return warnings;
1978
+ // <- Note: [1]
1979
+ },
1908
1980
  get currentValue() {
1909
- return partialResultSubject.value;
1981
+ return currentValue;
1982
+ // <- Note: [1]
1910
1983
  },
1911
1984
  };
1912
1985
  }
@@ -3673,7 +3746,7 @@ async function executeAttempts(options) {
3673
3746
  Last result:
3674
3747
  ${block($ongoingTaskResult.$resultString === null
3675
3748
  ? 'null'
3676
- : $ongoingTaskResult.$resultString
3749
+ : spaceTrim$1($ongoingTaskResult.$resultString)
3677
3750
  .split('\n')
3678
3751
  .map((line) => `> ${line}`)
3679
3752
  .join('\n'))}