@promptbook/remote-server 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 +21 -27
- package/esm/index.es.js +99 -38
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +5 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +5 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -0
- package/esm/typings/src/utils/serialization/jsonStringsToJsons.d.ts +9 -0
- package/esm/typings/src/utils/serialization/jsonStringsToJsons.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +102 -41
- package/umd/index.umd.js.map +1 -1
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/remote-server`
|
|
31
27
|
|
|
32
28
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -70,6 +66,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
|
|
|
70
66
|
|
|
71
67
|
|
|
72
68
|
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
73
72
|
## 🚀 Get started
|
|
74
73
|
|
|
75
74
|
Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
|
|
@@ -81,6 +80,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
|
|
|
81
80
|
|
|
82
81
|
|
|
83
82
|
|
|
83
|
+
|
|
84
|
+
|
|
84
85
|
## 💜 The Promptbook Project
|
|
85
86
|
|
|
86
87
|
Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
|
|
@@ -116,6 +117,14 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
|
|
|
116
117
|
</tbody>
|
|
117
118
|
</table>
|
|
118
119
|
|
|
120
|
+
Hello world examples:
|
|
121
|
+
|
|
122
|
+
- [Hello world](https://github.com/webgptorg/hello-world)
|
|
123
|
+
- [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
|
|
124
|
+
- [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
119
128
|
We also have a community of developers and users of **Promptbook**:
|
|
120
129
|
|
|
121
130
|
- [Discord community](https://discord.gg/x3QWNaa89N)
|
|
@@ -282,16 +291,9 @@ Or you can install them separately:
|
|
|
282
291
|
|
|
283
292
|
## 📚 Dictionary
|
|
284
293
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
### 📚 Dictionary
|
|
291
|
-
|
|
292
294
|
The following glossary is used to clarify certain concepts:
|
|
293
295
|
|
|
294
|
-
|
|
296
|
+
### General LLM / AI terms
|
|
295
297
|
|
|
296
298
|
- **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.
|
|
297
299
|
- **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.
|
|
@@ -304,11 +306,11 @@ The following glossary is used to clarify certain concepts:
|
|
|
304
306
|
|
|
305
307
|
|
|
306
308
|
|
|
307
|
-
_Note:
|
|
309
|
+
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
308
310
|
|
|
309
311
|
|
|
310
312
|
|
|
311
|
-
|
|
313
|
+
### 💯 Core concepts
|
|
312
314
|
|
|
313
315
|
- [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
|
|
314
316
|
- [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
|
|
@@ -321,7 +323,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
321
323
|
- [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
|
|
322
324
|
- [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
|
|
323
325
|
|
|
324
|
-
|
|
326
|
+
#### Advanced concepts
|
|
325
327
|
|
|
326
328
|
- [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
|
|
327
329
|
- [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
|
|
@@ -338,17 +340,9 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
338
340
|
|
|
339
341
|
|
|
340
342
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
- Anonymous mode
|
|
344
|
-
- Application mode
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
## 🔌 Usage in Typescript / Javascript
|
|
343
|
+
## 🚂 Promptbook Engine
|
|
349
344
|
|
|
350
|
-
|
|
351
|
-
- [Usage with client and remote server](./examples/usage/remote)
|
|
345
|
+

|
|
352
346
|
|
|
353
347
|
## ➕➖ When to use Promptbook?
|
|
354
348
|
|
|
@@ -414,11 +408,11 @@ See [TODO.md](./TODO.md)
|
|
|
414
408
|
<div style="display: flex; align-items: center; gap: 20px;">
|
|
415
409
|
|
|
416
410
|
<a href="https://promptbook.studio/">
|
|
417
|
-
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="
|
|
411
|
+
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
|
|
418
412
|
</a>
|
|
419
413
|
|
|
420
414
|
<a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
|
|
421
|
-
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="
|
|
415
|
+
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
|
|
422
416
|
</a>
|
|
423
417
|
|
|
424
418
|
</div>
|
package/esm/index.es.js
CHANGED
|
@@ -4,11 +4,11 @@ import http from 'http';
|
|
|
4
4
|
import { Server } from 'socket.io';
|
|
5
5
|
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
6
6
|
import { forTime } from 'waitasecond';
|
|
7
|
+
import { randomBytes } from 'crypto';
|
|
7
8
|
import { spawn } from 'child_process';
|
|
8
9
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
|
|
9
10
|
import { join, basename, dirname } from 'path';
|
|
10
11
|
import { Subject } from 'rxjs';
|
|
11
|
-
import { randomBytes } from 'crypto';
|
|
12
12
|
import { format } from 'prettier';
|
|
13
13
|
import parserHtml from 'prettier/parser-html';
|
|
14
14
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
@@ -31,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
31
31
|
* @generated
|
|
32
32
|
* @see https://github.com/webgptorg/promptbook
|
|
33
33
|
*/
|
|
34
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.88.0
|
|
34
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
|
|
35
35
|
/**
|
|
36
36
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
37
37
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -154,7 +154,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
154
154
|
*
|
|
155
155
|
* @public exported from `@promptbook/core`
|
|
156
156
|
*/
|
|
157
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
157
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
158
158
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
159
159
|
/**
|
|
160
160
|
* Where to store the temporary downloads
|
|
@@ -210,6 +210,21 @@ true);
|
|
|
210
210
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
211
211
|
*/
|
|
212
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Generates random token
|
|
215
|
+
*
|
|
216
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
217
|
+
*
|
|
218
|
+
* @private internal helper function
|
|
219
|
+
* @returns secure random token
|
|
220
|
+
*/
|
|
221
|
+
function $randomToken(randomness) {
|
|
222
|
+
return randomBytes(randomness).toString('hex');
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
226
|
+
*/
|
|
227
|
+
|
|
213
228
|
/**
|
|
214
229
|
* This error indicates errors during the execution of the pipeline
|
|
215
230
|
*
|
|
@@ -217,11 +232,17 @@ true);
|
|
|
217
232
|
*/
|
|
218
233
|
class PipelineExecutionError extends Error {
|
|
219
234
|
constructor(message) {
|
|
235
|
+
// Added id parameter
|
|
220
236
|
super(message);
|
|
221
237
|
this.name = 'PipelineExecutionError';
|
|
238
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
239
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
222
240
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
223
241
|
}
|
|
224
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* TODO: !!!!!! Add id to all errors
|
|
245
|
+
*/
|
|
225
246
|
|
|
226
247
|
/**
|
|
227
248
|
* This error indicates problems parsing the format value
|
|
@@ -551,19 +572,21 @@ const ALL_ERRORS = {
|
|
|
551
572
|
*/
|
|
552
573
|
function serializeError(error) {
|
|
553
574
|
const { name, message, stack } = error;
|
|
575
|
+
const { id } = error;
|
|
554
576
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
555
577
|
console.error(spaceTrim$1((block) => `
|
|
556
|
-
|
|
578
|
+
|
|
557
579
|
Cannot serialize error with name "${name}"
|
|
558
580
|
|
|
559
581
|
${block(stack || message)}
|
|
560
|
-
|
|
582
|
+
|
|
561
583
|
`));
|
|
562
584
|
}
|
|
563
585
|
return {
|
|
564
586
|
name: name,
|
|
565
587
|
message,
|
|
566
588
|
stack,
|
|
589
|
+
id, // Include id in the serialized object
|
|
567
590
|
};
|
|
568
591
|
}
|
|
569
592
|
|
|
@@ -1707,18 +1730,54 @@ function isPipelinePrepared(pipeline) {
|
|
|
1707
1730
|
*/
|
|
1708
1731
|
|
|
1709
1732
|
/**
|
|
1710
|
-
*
|
|
1711
|
-
*
|
|
1712
|
-
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
1733
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1713
1734
|
*
|
|
1714
|
-
* @
|
|
1715
|
-
* @returns secure random token
|
|
1735
|
+
* @public exported from `@promptbook/utils`
|
|
1716
1736
|
*/
|
|
1717
|
-
function
|
|
1718
|
-
|
|
1737
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1738
|
+
try {
|
|
1739
|
+
JSON.parse(value);
|
|
1740
|
+
return true;
|
|
1741
|
+
}
|
|
1742
|
+
catch (error) {
|
|
1743
|
+
if (!(error instanceof Error)) {
|
|
1744
|
+
throw error;
|
|
1745
|
+
}
|
|
1746
|
+
if (error.message.includes('Unexpected token')) {
|
|
1747
|
+
return false;
|
|
1748
|
+
}
|
|
1749
|
+
return false;
|
|
1750
|
+
}
|
|
1719
1751
|
}
|
|
1752
|
+
|
|
1720
1753
|
/**
|
|
1721
|
-
*
|
|
1754
|
+
* Recursively converts JSON strings to JSON objects
|
|
1755
|
+
|
|
1756
|
+
* @public exported from `@promptbook/utils`
|
|
1757
|
+
*/
|
|
1758
|
+
function jsonStringsToJsons(object) {
|
|
1759
|
+
if (object === null) {
|
|
1760
|
+
return object;
|
|
1761
|
+
}
|
|
1762
|
+
if (Array.isArray(object)) {
|
|
1763
|
+
return object.map(jsonStringsToJsons);
|
|
1764
|
+
}
|
|
1765
|
+
if (typeof object !== 'object') {
|
|
1766
|
+
return object;
|
|
1767
|
+
}
|
|
1768
|
+
const newObject = { ...object };
|
|
1769
|
+
for (const [key, value] of Object.entries(object)) {
|
|
1770
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
1771
|
+
newObject[key] = JSON.parse(value);
|
|
1772
|
+
}
|
|
1773
|
+
else {
|
|
1774
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
return newObject;
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* TODO: Type the return type correctly
|
|
1722
1781
|
*/
|
|
1723
1782
|
|
|
1724
1783
|
/**
|
|
@@ -1727,7 +1786,7 @@ function $randomToken(randomness) {
|
|
|
1727
1786
|
* @public exported from `@promptbook/utils`
|
|
1728
1787
|
*/
|
|
1729
1788
|
function deserializeError(error) {
|
|
1730
|
-
const { name, stack } = error;
|
|
1789
|
+
const { name, stack, id } = error; // Added id
|
|
1731
1790
|
let { message } = error;
|
|
1732
1791
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
1733
1792
|
if (ErrorClass === undefined) {
|
|
@@ -1742,7 +1801,9 @@ function deserializeError(error) {
|
|
|
1742
1801
|
${block(stack || '')}
|
|
1743
1802
|
`);
|
|
1744
1803
|
}
|
|
1745
|
-
|
|
1804
|
+
const deserializedError = new ErrorClass(message);
|
|
1805
|
+
deserializedError.id = id; // Assign id to the error object
|
|
1806
|
+
return deserializedError;
|
|
1746
1807
|
}
|
|
1747
1808
|
|
|
1748
1809
|
/**
|
|
@@ -1792,17 +1853,19 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
1792
1853
|
*/
|
|
1793
1854
|
function createTask(options) {
|
|
1794
1855
|
const { taskType, taskProcessCallback } = options;
|
|
1856
|
+
// TODO: [🐙] DRY
|
|
1795
1857
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1796
1858
|
let status = 'RUNNING';
|
|
1797
1859
|
const createdAt = new Date();
|
|
1798
1860
|
let updatedAt = createdAt;
|
|
1799
1861
|
const errors = [];
|
|
1800
1862
|
const warnings = [];
|
|
1801
|
-
|
|
1863
|
+
let currentValue = {};
|
|
1802
1864
|
const partialResultSubject = new Subject();
|
|
1803
1865
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
1804
1866
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
1805
1867
|
Object.assign(currentValue, newOngoingResult);
|
|
1868
|
+
// <- TODO: assign deep
|
|
1806
1869
|
partialResultSubject.next(newOngoingResult);
|
|
1807
1870
|
});
|
|
1808
1871
|
finalResultPromise
|
|
@@ -1822,7 +1885,8 @@ function createTask(options) {
|
|
|
1822
1885
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1823
1886
|
assertsTaskSuccessful(executionResult);
|
|
1824
1887
|
status = 'FINISHED';
|
|
1825
|
-
|
|
1888
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
1889
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
1826
1890
|
partialResultSubject.next(executionResult);
|
|
1827
1891
|
}
|
|
1828
1892
|
catch (error) {
|
|
@@ -1945,27 +2009,6 @@ function isValidFilePath(filename) {
|
|
|
1945
2009
|
* TODO: [🍏] Implement for MacOs
|
|
1946
2010
|
*/
|
|
1947
2011
|
|
|
1948
|
-
/**
|
|
1949
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1950
|
-
*
|
|
1951
|
-
* @public exported from `@promptbook/utils`
|
|
1952
|
-
*/
|
|
1953
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1954
|
-
try {
|
|
1955
|
-
JSON.parse(value);
|
|
1956
|
-
return true;
|
|
1957
|
-
}
|
|
1958
|
-
catch (error) {
|
|
1959
|
-
if (!(error instanceof Error)) {
|
|
1960
|
-
throw error;
|
|
1961
|
-
}
|
|
1962
|
-
if (error.message.includes('Unexpected token')) {
|
|
1963
|
-
return false;
|
|
1964
|
-
}
|
|
1965
|
-
return false;
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
2012
|
/**
|
|
1970
2013
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1971
2014
|
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
@@ -4659,6 +4702,9 @@ function countCharacters(text) {
|
|
|
4659
4702
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4660
4703
|
return text.length;
|
|
4661
4704
|
}
|
|
4705
|
+
/**
|
|
4706
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4707
|
+
*/
|
|
4662
4708
|
|
|
4663
4709
|
/**
|
|
4664
4710
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4690,6 +4736,9 @@ function countLines(text) {
|
|
|
4690
4736
|
const lines = text.split('\n');
|
|
4691
4737
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4692
4738
|
}
|
|
4739
|
+
/**
|
|
4740
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4741
|
+
*/
|
|
4693
4742
|
|
|
4694
4743
|
/**
|
|
4695
4744
|
* Counts number of pages in the text
|
|
@@ -4701,6 +4750,9 @@ function countLines(text) {
|
|
|
4701
4750
|
function countPages(text) {
|
|
4702
4751
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4703
4752
|
}
|
|
4753
|
+
/**
|
|
4754
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4755
|
+
*/
|
|
4704
4756
|
|
|
4705
4757
|
/**
|
|
4706
4758
|
* Counts number of paragraphs in the text
|
|
@@ -4710,6 +4762,9 @@ function countPages(text) {
|
|
|
4710
4762
|
function countParagraphs(text) {
|
|
4711
4763
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4712
4764
|
}
|
|
4765
|
+
/**
|
|
4766
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4767
|
+
*/
|
|
4713
4768
|
|
|
4714
4769
|
/**
|
|
4715
4770
|
* Split text into sentences
|
|
@@ -4727,6 +4782,9 @@ function splitIntoSentences(text) {
|
|
|
4727
4782
|
function countSentences(text) {
|
|
4728
4783
|
return splitIntoSentences(text).length;
|
|
4729
4784
|
}
|
|
4785
|
+
/**
|
|
4786
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4787
|
+
*/
|
|
4730
4788
|
|
|
4731
4789
|
/**
|
|
4732
4790
|
* Counts number of words in the text
|
|
@@ -4740,6 +4798,9 @@ function countWords(text) {
|
|
|
4740
4798
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4741
4799
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4742
4800
|
}
|
|
4801
|
+
/**
|
|
4802
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4803
|
+
*/
|
|
4743
4804
|
|
|
4744
4805
|
/**
|
|
4745
4806
|
* Index of all counter functions
|