@promptbook/core 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 +71 -10
- 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 +1 -1
- package/umd/index.umd.js +71 -10
- 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/core`
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
- Anonymous mode
|
|
348
|
-
- Application mode
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
## 🔌 Usage in Typescript / Javascript
|
|
347
|
+
## 🚂 Promptbook Engine
|
|
353
348
|
|
|
354
|
-
|
|
355
|
-
- [Usage with client and remote server](./examples/usage/remote)
|
|
349
|
+

|
|
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="
|
|
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="
|
|
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
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.88.0
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -453,7 +453,7 @@ const CLAIM = `It's time for a paradigm shift. The future of software in plain E
|
|
|
453
453
|
*
|
|
454
454
|
* @public exported from `@promptbook/core`
|
|
455
455
|
*/
|
|
456
|
-
const LOGO_LIGHT_SRC = `https://promptbook.studio/_next/static/media/promptbook-logo.b21f0c70.png`;
|
|
456
|
+
const LOGO_LIGHT_SRC = `https://promptbook.studio/_next/static/media/promptbook-logo.b21f0c70.png`; // <- TODO: !!! Auto-update or remove
|
|
457
457
|
/**
|
|
458
458
|
* Logo for the dark theme
|
|
459
459
|
*
|
|
@@ -461,7 +461,7 @@ const LOGO_LIGHT_SRC = `https://promptbook.studio/_next/static/media/promptbook-
|
|
|
461
461
|
*
|
|
462
462
|
* @public exported from `@promptbook/core`
|
|
463
463
|
*/
|
|
464
|
-
const LOGO_DARK_SRC = `https://promptbook.studio/_next/static/media/promptbook-logo-white.09887cbc.png`;
|
|
464
|
+
const LOGO_DARK_SRC = `https://promptbook.studio/_next/static/media/promptbook-logo-white.09887cbc.png`; // <- TODO: !!! Auto-update or remove
|
|
465
465
|
/**
|
|
466
466
|
* When the title is not provided, the default title is used
|
|
467
467
|
*
|
|
@@ -549,7 +549,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
549
549
|
*
|
|
550
550
|
* @public exported from `@promptbook/core`
|
|
551
551
|
*/
|
|
552
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
552
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
553
553
|
/**
|
|
554
554
|
* @@@
|
|
555
555
|
* TODO: [🐝][main] !!3 Use
|
|
@@ -1814,6 +1814,36 @@ function $randomToken(randomness) {
|
|
|
1814
1814
|
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
1815
1815
|
*/
|
|
1816
1816
|
|
|
1817
|
+
/**
|
|
1818
|
+
* Recursively converts JSON strings to JSON objects
|
|
1819
|
+
|
|
1820
|
+
* @public exported from `@promptbook/utils`
|
|
1821
|
+
*/
|
|
1822
|
+
function jsonStringsToJsons(object) {
|
|
1823
|
+
if (object === null) {
|
|
1824
|
+
return object;
|
|
1825
|
+
}
|
|
1826
|
+
if (Array.isArray(object)) {
|
|
1827
|
+
return object.map(jsonStringsToJsons);
|
|
1828
|
+
}
|
|
1829
|
+
if (typeof object !== 'object') {
|
|
1830
|
+
return object;
|
|
1831
|
+
}
|
|
1832
|
+
const newObject = { ...object };
|
|
1833
|
+
for (const [key, value] of Object.entries(object)) {
|
|
1834
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
1835
|
+
newObject[key] = JSON.parse(value);
|
|
1836
|
+
}
|
|
1837
|
+
else {
|
|
1838
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
return newObject;
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* TODO: Type the return type correctly
|
|
1845
|
+
*/
|
|
1846
|
+
|
|
1817
1847
|
/**
|
|
1818
1848
|
* This error indicates errors during the execution of the pipeline
|
|
1819
1849
|
*
|
|
@@ -1821,11 +1851,17 @@ function $randomToken(randomness) {
|
|
|
1821
1851
|
*/
|
|
1822
1852
|
class PipelineExecutionError extends Error {
|
|
1823
1853
|
constructor(message) {
|
|
1854
|
+
// Added id parameter
|
|
1824
1855
|
super(message);
|
|
1825
1856
|
this.name = 'PipelineExecutionError';
|
|
1857
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
1858
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1826
1859
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
1827
1860
|
}
|
|
1828
1861
|
}
|
|
1862
|
+
/**
|
|
1863
|
+
* TODO: !!!!!! Add id to all errors
|
|
1864
|
+
*/
|
|
1829
1865
|
|
|
1830
1866
|
/**
|
|
1831
1867
|
* This error indicates problems parsing the format value
|
|
@@ -2013,7 +2049,7 @@ const ALL_ERRORS = {
|
|
|
2013
2049
|
* @public exported from `@promptbook/utils`
|
|
2014
2050
|
*/
|
|
2015
2051
|
function deserializeError(error) {
|
|
2016
|
-
const { name, stack } = error;
|
|
2052
|
+
const { name, stack, id } = error; // Added id
|
|
2017
2053
|
let { message } = error;
|
|
2018
2054
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2019
2055
|
if (ErrorClass === undefined) {
|
|
@@ -2028,7 +2064,9 @@ function deserializeError(error) {
|
|
|
2028
2064
|
${block(stack || '')}
|
|
2029
2065
|
`);
|
|
2030
2066
|
}
|
|
2031
|
-
|
|
2067
|
+
const deserializedError = new ErrorClass(message);
|
|
2068
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2069
|
+
return deserializedError;
|
|
2032
2070
|
}
|
|
2033
2071
|
|
|
2034
2072
|
/**
|
|
@@ -2078,17 +2116,19 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2078
2116
|
*/
|
|
2079
2117
|
function createTask(options) {
|
|
2080
2118
|
const { taskType, taskProcessCallback } = options;
|
|
2119
|
+
// TODO: [🐙] DRY
|
|
2081
2120
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2082
2121
|
let status = 'RUNNING';
|
|
2083
2122
|
const createdAt = new Date();
|
|
2084
2123
|
let updatedAt = createdAt;
|
|
2085
2124
|
const errors = [];
|
|
2086
2125
|
const warnings = [];
|
|
2087
|
-
|
|
2126
|
+
let currentValue = {};
|
|
2088
2127
|
const partialResultSubject = new Subject();
|
|
2089
2128
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2090
2129
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
2091
2130
|
Object.assign(currentValue, newOngoingResult);
|
|
2131
|
+
// <- TODO: assign deep
|
|
2092
2132
|
partialResultSubject.next(newOngoingResult);
|
|
2093
2133
|
});
|
|
2094
2134
|
finalResultPromise
|
|
@@ -2108,7 +2148,8 @@ function createTask(options) {
|
|
|
2108
2148
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2109
2149
|
assertsTaskSuccessful(executionResult);
|
|
2110
2150
|
status = 'FINISHED';
|
|
2111
|
-
|
|
2151
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
2152
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2112
2153
|
partialResultSubject.next(executionResult);
|
|
2113
2154
|
}
|
|
2114
2155
|
catch (error) {
|
|
@@ -2172,19 +2213,21 @@ function createTask(options) {
|
|
|
2172
2213
|
*/
|
|
2173
2214
|
function serializeError(error) {
|
|
2174
2215
|
const { name, message, stack } = error;
|
|
2216
|
+
const { id } = error;
|
|
2175
2217
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2176
2218
|
console.error(spaceTrim((block) => `
|
|
2177
|
-
|
|
2219
|
+
|
|
2178
2220
|
Cannot serialize error with name "${name}"
|
|
2179
2221
|
|
|
2180
2222
|
${block(stack || message)}
|
|
2181
|
-
|
|
2223
|
+
|
|
2182
2224
|
`));
|
|
2183
2225
|
}
|
|
2184
2226
|
return {
|
|
2185
2227
|
name: name,
|
|
2186
2228
|
message,
|
|
2187
2229
|
stack,
|
|
2230
|
+
id, // Include id in the serialized object
|
|
2188
2231
|
};
|
|
2189
2232
|
}
|
|
2190
2233
|
|
|
@@ -3227,6 +3270,9 @@ function countCharacters(text) {
|
|
|
3227
3270
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
3228
3271
|
return text.length;
|
|
3229
3272
|
}
|
|
3273
|
+
/**
|
|
3274
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3275
|
+
*/
|
|
3230
3276
|
|
|
3231
3277
|
/**
|
|
3232
3278
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -3258,6 +3304,9 @@ function countLines(text) {
|
|
|
3258
3304
|
const lines = text.split('\n');
|
|
3259
3305
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
3260
3306
|
}
|
|
3307
|
+
/**
|
|
3308
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3309
|
+
*/
|
|
3261
3310
|
|
|
3262
3311
|
/**
|
|
3263
3312
|
* Counts number of pages in the text
|
|
@@ -3269,6 +3318,9 @@ function countLines(text) {
|
|
|
3269
3318
|
function countPages(text) {
|
|
3270
3319
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
3271
3320
|
}
|
|
3321
|
+
/**
|
|
3322
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3323
|
+
*/
|
|
3272
3324
|
|
|
3273
3325
|
/**
|
|
3274
3326
|
* Counts number of paragraphs in the text
|
|
@@ -3278,6 +3330,9 @@ function countPages(text) {
|
|
|
3278
3330
|
function countParagraphs(text) {
|
|
3279
3331
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
3280
3332
|
}
|
|
3333
|
+
/**
|
|
3334
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3335
|
+
*/
|
|
3281
3336
|
|
|
3282
3337
|
/**
|
|
3283
3338
|
* Split text into sentences
|
|
@@ -3295,6 +3350,9 @@ function splitIntoSentences(text) {
|
|
|
3295
3350
|
function countSentences(text) {
|
|
3296
3351
|
return splitIntoSentences(text).length;
|
|
3297
3352
|
}
|
|
3353
|
+
/**
|
|
3354
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3355
|
+
*/
|
|
3298
3356
|
|
|
3299
3357
|
const defaultDiacriticsRemovalMap = [
|
|
3300
3358
|
{
|
|
@@ -3569,6 +3627,9 @@ function countWords(text) {
|
|
|
3569
3627
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
3570
3628
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
3571
3629
|
}
|
|
3630
|
+
/**
|
|
3631
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3632
|
+
*/
|
|
3572
3633
|
|
|
3573
3634
|
/**
|
|
3574
3635
|
* Index of all counter functions
|