@promptbook/pdf 0.88.0-9 → 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 +35 -18
- package/esm/index.es.js +52 -23
- package/esm/index.es.js.map +1 -1
- 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/package.json +2 -2
- package/umd/index.umd.js +55 -26
- 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/pdf`
|
|
31
27
|
|
|
32
28
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -60,6 +56,8 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
|
|
|
60
56
|
|
|
61
57
|
During the computer revolution, we have seen [multiple generations of computer languages](https://github.com/webgptorg/promptbook/discussions/180), from the physical rewiring of the vacuum tubes through low-level machine code to the high-level languages like Python or JavaScript. And now, we're on the edge of the **next revolution**!
|
|
62
58
|
|
|
59
|
+
|
|
60
|
+
|
|
63
61
|
It's a revolution of writing software in **plain human language** that is understandable and executable by both humans and machines – and it's going to change everything!
|
|
64
62
|
|
|
65
63
|
The incredible growth in power of microprocessors and the Moore's Law have been the driving force behind the ever-more powerful languages, and it's been an amazing journey! Similarly, the large language models (like GPT or Claude) are the next big thing in language technology, and they're set to transform the way we interact with computers.
|
|
@@ -70,6 +68,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
|
|
|
70
68
|
|
|
71
69
|
|
|
72
70
|
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
73
74
|
## 🚀 Get started
|
|
74
75
|
|
|
75
76
|
Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
|
|
@@ -81,6 +82,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
|
|
|
81
82
|
|
|
82
83
|
|
|
83
84
|
|
|
85
|
+
|
|
86
|
+
|
|
84
87
|
## 💜 The Promptbook Project
|
|
85
88
|
|
|
86
89
|
Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
|
|
@@ -116,22 +119,35 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
|
|
|
116
119
|
</tbody>
|
|
117
120
|
</table>
|
|
118
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
|
+
|
|
119
130
|
We also have a community of developers and users of **Promptbook**:
|
|
120
131
|
|
|
121
132
|
- [Discord community](https://discord.gg/x3QWNaa89N)
|
|
122
133
|
- [Landing page `ptbk.io`](https://ptbk.io)
|
|
123
134
|
- [Github discussions](https://github.com/webgptorg/promptbook/discussions)
|
|
124
135
|
- [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
|
|
125
|
-
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
136
|
+
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
126
137
|
|
|
127
138
|
And **Promptbook.studio** branded socials:
|
|
128
139
|
|
|
140
|
+
|
|
141
|
+
|
|
129
142
|
- [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
|
|
130
143
|
|
|
131
144
|
And **Promptujeme** sub-brand:
|
|
132
145
|
|
|
133
146
|
_/Subbrand for Czech clients/_
|
|
134
147
|
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
135
151
|
- [Promptujeme.cz](https://www.promptujeme.cz/)
|
|
136
152
|
- [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
|
|
137
153
|
|
|
@@ -149,6 +165,8 @@ _/Sub-brand for images and graphics generated via Promptbook prompting/_
|
|
|
149
165
|
|
|
150
166
|
## 💙 The Book language
|
|
151
167
|
|
|
168
|
+
|
|
169
|
+
|
|
152
170
|
Following is the documentation and blueprint of the [Book language](https://github.com/webgptorg/book).
|
|
153
171
|
|
|
154
172
|
Book is a language that can be used to write AI applications, agents, workflows, automations, knowledgebases, translators, sheet processors, email automations and more. It allows you to harness the power of AI models in human-like terms, without the need to know the specifics and technicalities of the models.
|
|
@@ -198,6 +216,8 @@ Personas can have access to different knowledge, tools and actions. They can als
|
|
|
198
216
|
|
|
199
217
|
- [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
|
|
200
218
|
|
|
219
|
+
|
|
220
|
+
|
|
201
221
|
### **How:** Knowledge, Instruments and Actions
|
|
202
222
|
|
|
203
223
|
The resources used by the personas are used to do the work.
|
|
@@ -273,11 +293,9 @@ Or you can install them separately:
|
|
|
273
293
|
|
|
274
294
|
## 📚 Dictionary
|
|
275
295
|
|
|
276
|
-
### 📚 Dictionary
|
|
277
|
-
|
|
278
296
|
The following glossary is used to clarify certain concepts:
|
|
279
297
|
|
|
280
|
-
|
|
298
|
+
### General LLM / AI terms
|
|
281
299
|
|
|
282
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.
|
|
283
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.
|
|
@@ -288,9 +306,13 @@ The following glossary is used to clarify certain concepts:
|
|
|
288
306
|
- **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
|
|
289
307
|
- **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
|
|
290
308
|
|
|
291
|
-
_Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
292
309
|
|
|
293
|
-
|
|
310
|
+
|
|
311
|
+
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
### 💯 Core concepts
|
|
294
316
|
|
|
295
317
|
- [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
|
|
296
318
|
- [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
|
|
@@ -303,7 +325,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
303
325
|
- [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
|
|
304
326
|
- [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
|
|
305
327
|
|
|
306
|
-
|
|
328
|
+
#### Advanced concepts
|
|
307
329
|
|
|
308
330
|
- [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
|
|
309
331
|
- [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
|
|
@@ -318,11 +340,6 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
318
340
|
- [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
|
|
319
341
|
- [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
|
|
320
342
|
|
|
321
|
-
### Terms specific to Promptbook TypeScript implementation
|
|
322
|
-
|
|
323
|
-
- Anonymous mode
|
|
324
|
-
- Application mode
|
|
325
|
-
|
|
326
343
|
|
|
327
344
|
|
|
328
345
|
## 🚂 Promptbook Engine
|
|
@@ -393,11 +410,11 @@ See [TODO.md](./TODO.md)
|
|
|
393
410
|
<div style="display: flex; align-items: center; gap: 20px;">
|
|
394
411
|
|
|
395
412
|
<a href="https://promptbook.studio/">
|
|
396
|
-
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="
|
|
413
|
+
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
|
|
397
414
|
</a>
|
|
398
415
|
|
|
399
416
|
<a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
|
|
400
|
-
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="
|
|
417
|
+
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
|
|
401
418
|
</a>
|
|
402
419
|
|
|
403
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
|
|
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 =
|
|
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
|
|
@@ -2066,21 +2087,6 @@ function isPipelinePrepared(pipeline) {
|
|
|
2066
2087
|
* - [♨] Are tasks prepared
|
|
2067
2088
|
*/
|
|
2068
2089
|
|
|
2069
|
-
/**
|
|
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
|
|
2076
|
-
*/
|
|
2077
|
-
function $randomToken(randomness) {
|
|
2078
|
-
return randomBytes(randomness).toString('hex');
|
|
2079
|
-
}
|
|
2080
|
-
/**
|
|
2081
|
-
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2082
|
-
*/
|
|
2083
|
-
|
|
2084
2090
|
/**
|
|
2085
2091
|
* Recursively converts JSON strings to JSON objects
|
|
2086
2092
|
|
|
@@ -2271,7 +2277,7 @@ const ALL_ERRORS = {
|
|
|
2271
2277
|
* @public exported from `@promptbook/utils`
|
|
2272
2278
|
*/
|
|
2273
2279
|
function deserializeError(error) {
|
|
2274
|
-
const { name, stack } = error;
|
|
2280
|
+
const { name, stack, id } = error; // Added id
|
|
2275
2281
|
let { message } = error;
|
|
2276
2282
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2277
2283
|
if (ErrorClass === undefined) {
|
|
@@ -2286,7 +2292,9 @@ function deserializeError(error) {
|
|
|
2286
2292
|
${block(stack || '')}
|
|
2287
2293
|
`);
|
|
2288
2294
|
}
|
|
2289
|
-
|
|
2295
|
+
const deserializedError = new ErrorClass(message);
|
|
2296
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2297
|
+
return deserializedError;
|
|
2290
2298
|
}
|
|
2291
2299
|
|
|
2292
2300
|
/**
|
|
@@ -2336,6 +2344,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2336
2344
|
*/
|
|
2337
2345
|
function createTask(options) {
|
|
2338
2346
|
const { taskType, taskProcessCallback } = options;
|
|
2347
|
+
// TODO: [🐙] DRY
|
|
2339
2348
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2340
2349
|
let status = 'RUNNING';
|
|
2341
2350
|
const createdAt = new Date();
|
|
@@ -2368,7 +2377,7 @@ function createTask(options) {
|
|
|
2368
2377
|
assertsTaskSuccessful(executionResult);
|
|
2369
2378
|
status = 'FINISHED';
|
|
2370
2379
|
currentValue = jsonStringsToJsons(executionResult);
|
|
2371
|
-
// <- TODO:
|
|
2380
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2372
2381
|
partialResultSubject.next(executionResult);
|
|
2373
2382
|
}
|
|
2374
2383
|
catch (error) {
|
|
@@ -2432,19 +2441,21 @@ function createTask(options) {
|
|
|
2432
2441
|
*/
|
|
2433
2442
|
function serializeError(error) {
|
|
2434
2443
|
const { name, message, stack } = error;
|
|
2444
|
+
const { id } = error;
|
|
2435
2445
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2436
2446
|
console.error(spaceTrim((block) => `
|
|
2437
|
-
|
|
2447
|
+
|
|
2438
2448
|
Cannot serialize error with name "${name}"
|
|
2439
2449
|
|
|
2440
2450
|
${block(stack || message)}
|
|
2441
|
-
|
|
2451
|
+
|
|
2442
2452
|
`));
|
|
2443
2453
|
}
|
|
2444
2454
|
return {
|
|
2445
2455
|
name: name,
|
|
2446
2456
|
message,
|
|
2447
2457
|
stack,
|
|
2458
|
+
id, // Include id in the serialized object
|
|
2448
2459
|
};
|
|
2449
2460
|
}
|
|
2450
2461
|
|
|
@@ -4356,6 +4367,9 @@ function countCharacters(text) {
|
|
|
4356
4367
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4357
4368
|
return text.length;
|
|
4358
4369
|
}
|
|
4370
|
+
/**
|
|
4371
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4372
|
+
*/
|
|
4359
4373
|
|
|
4360
4374
|
/**
|
|
4361
4375
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4387,6 +4401,9 @@ function countLines(text) {
|
|
|
4387
4401
|
const lines = text.split('\n');
|
|
4388
4402
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4389
4403
|
}
|
|
4404
|
+
/**
|
|
4405
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4406
|
+
*/
|
|
4390
4407
|
|
|
4391
4408
|
/**
|
|
4392
4409
|
* Counts number of pages in the text
|
|
@@ -4398,6 +4415,9 @@ function countLines(text) {
|
|
|
4398
4415
|
function countPages(text) {
|
|
4399
4416
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4400
4417
|
}
|
|
4418
|
+
/**
|
|
4419
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4420
|
+
*/
|
|
4401
4421
|
|
|
4402
4422
|
/**
|
|
4403
4423
|
* Counts number of paragraphs in the text
|
|
@@ -4407,6 +4427,9 @@ function countPages(text) {
|
|
|
4407
4427
|
function countParagraphs(text) {
|
|
4408
4428
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4409
4429
|
}
|
|
4430
|
+
/**
|
|
4431
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4432
|
+
*/
|
|
4410
4433
|
|
|
4411
4434
|
/**
|
|
4412
4435
|
* Split text into sentences
|
|
@@ -4424,6 +4447,9 @@ function splitIntoSentences(text) {
|
|
|
4424
4447
|
function countSentences(text) {
|
|
4425
4448
|
return splitIntoSentences(text).length;
|
|
4426
4449
|
}
|
|
4450
|
+
/**
|
|
4451
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4452
|
+
*/
|
|
4427
4453
|
|
|
4428
4454
|
/**
|
|
4429
4455
|
* Counts number of words in the text
|
|
@@ -4437,6 +4463,9 @@ function countWords(text) {
|
|
|
4437
4463
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4438
4464
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4439
4465
|
}
|
|
4466
|
+
/**
|
|
4467
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4468
|
+
*/
|
|
4440
4469
|
|
|
4441
4470
|
/**
|
|
4442
4471
|
* Index of all counter functions
|