@promptbook/core 0.86.31 → 0.88.0-10
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 -43
- package/esm/index.es.js +83 -10
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/cli/cli-commands/common/handleActionErrors.d.ts +11 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +24 -0
- package/esm/typings/src/scrapers/_common/register/$provideScriptingForNode.d.ts +11 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.d.ts +1 -1
- 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 +82 -9
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/_packages/{execute-javascript.index.d.ts → javascript.index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
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
|
+
|
|
26
30
|
## 📦 Package `@promptbook/core`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -58,8 +62,6 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
|
|
|
58
62
|
|
|
59
63
|
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**!
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
65
|
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
66
|
|
|
65
67
|
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.
|
|
@@ -116,27 +118,28 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
|
|
|
116
118
|
</tbody>
|
|
117
119
|
</table>
|
|
118
120
|
|
|
121
|
+
Hello world examples:
|
|
122
|
+
|
|
123
|
+
- [Hello world](https://github.com/webgptorg/hello-world)
|
|
124
|
+
- [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
|
|
125
|
+
- [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
|
|
126
|
+
|
|
119
127
|
We also have a community of developers and users of **Promptbook**:
|
|
120
128
|
|
|
121
129
|
- [Discord community](https://discord.gg/x3QWNaa89N)
|
|
122
130
|
- [Landing page `ptbk.io`](https://ptbk.io)
|
|
123
131
|
- [Github discussions](https://github.com/webgptorg/promptbook/discussions)
|
|
124
132
|
- [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
|
|
125
|
-
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
133
|
+
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
126
134
|
|
|
127
135
|
And **Promptbook.studio** branded socials:
|
|
128
136
|
|
|
129
|
-
|
|
130
|
-
|
|
131
137
|
- [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
|
|
132
138
|
|
|
133
139
|
And **Promptujeme** sub-brand:
|
|
134
140
|
|
|
135
141
|
_/Subbrand for Czech clients/_
|
|
136
142
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
143
|
- [Promptujeme.cz](https://www.promptujeme.cz/)
|
|
141
144
|
- [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
|
|
142
145
|
|
|
@@ -154,8 +157,6 @@ _/Sub-brand for images and graphics generated via Promptbook prompting/_
|
|
|
154
157
|
|
|
155
158
|
## 💙 The Book language
|
|
156
159
|
|
|
157
|
-
|
|
158
|
-
|
|
159
160
|
Following is the documentation and blueprint of the [Book language](https://github.com/webgptorg/book).
|
|
160
161
|
|
|
161
162
|
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.
|
|
@@ -205,8 +206,6 @@ Personas can have access to different knowledge, tools and actions. They can als
|
|
|
205
206
|
|
|
206
207
|
- [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
|
|
207
208
|
|
|
208
|
-
|
|
209
|
-
|
|
210
209
|
### **How:** Knowledge, Instruments and Actions
|
|
211
210
|
|
|
212
211
|
The resources used by the personas are used to do the work.
|
|
@@ -253,7 +252,7 @@ Or you can install them separately:
|
|
|
253
252
|
- ⭐ **[@promptbook/utils](https://www.npmjs.com/package/@promptbook/utils)** - Utility functions used in the library but also useful for individual use in preprocessing and postprocessing LLM inputs and outputs
|
|
254
253
|
- **[@promptbook/markdown-utils](https://www.npmjs.com/package/@promptbook/markdown-utils)** - Utility functions used for processing markdown
|
|
255
254
|
- _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
|
|
256
|
-
- **[@promptbook/
|
|
255
|
+
- **[@promptbook/javascript](https://www.npmjs.com/package/@promptbook/javascript)** - Execution tools for javascript inside promptbooks
|
|
257
256
|
- **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
|
|
258
257
|
- **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
|
|
259
258
|
- **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
|
|
@@ -282,16 +281,9 @@ Or you can install them separately:
|
|
|
282
281
|
|
|
283
282
|
## 📚 Dictionary
|
|
284
283
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
### 📚 Dictionary
|
|
291
|
-
|
|
292
284
|
The following glossary is used to clarify certain concepts:
|
|
293
285
|
|
|
294
|
-
|
|
286
|
+
### General LLM / AI terms
|
|
295
287
|
|
|
296
288
|
- **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
289
|
- **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.
|
|
@@ -302,13 +294,9 @@ The following glossary is used to clarify certain concepts:
|
|
|
302
294
|
- **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.
|
|
303
295
|
- **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.
|
|
304
296
|
|
|
297
|
+
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
305
298
|
|
|
306
|
-
|
|
307
|
-
_Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
#### 💯 Core concepts
|
|
299
|
+
### 💯 Core concepts
|
|
312
300
|
|
|
313
301
|
- [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
|
|
314
302
|
- [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
|
|
@@ -321,7 +309,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
321
309
|
- [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
|
|
322
310
|
- [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
|
|
323
311
|
|
|
324
|
-
|
|
312
|
+
#### Advanced concepts
|
|
325
313
|
|
|
326
314
|
- [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
|
|
327
315
|
- [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
|
|
@@ -338,17 +326,9 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
338
326
|
|
|
339
327
|
|
|
340
328
|
|
|
341
|
-
|
|
329
|
+
## 🚂 Promptbook Engine
|
|
342
330
|
|
|
343
|
-
-
|
|
344
|
-
- Application mode
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
## 🔌 Usage in Typescript / Javascript
|
|
349
|
-
|
|
350
|
-
- [Simple usage](./examples/usage/simple-script)
|
|
351
|
-
- [Usage with client and remote server](./examples/usage/remote)
|
|
331
|
+

|
|
352
332
|
|
|
353
333
|
## ➕➖ When to use Promptbook?
|
|
354
334
|
|
|
@@ -409,20 +389,18 @@ Promptbook project is under [BUSL 1.1 is an SPDX license](https://spdx.org/licen
|
|
|
409
389
|
|
|
410
390
|
See [TODO.md](./TODO.md)
|
|
411
391
|
|
|
412
|
-
|
|
413
|
-
|
|
414
392
|
## 🤝 Partners
|
|
415
393
|
|
|
416
394
|
<div style="display: flex; align-items: center; gap: 20px;">
|
|
417
395
|
|
|
418
396
|
<a href="https://promptbook.studio/">
|
|
419
|
-
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="
|
|
397
|
+
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
|
|
420
398
|
</a>
|
|
421
399
|
|
|
422
400
|
<a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
|
|
423
|
-
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="
|
|
401
|
+
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
|
|
424
402
|
</a>
|
|
425
|
-
|
|
403
|
+
|
|
426
404
|
</div>
|
|
427
405
|
|
|
428
406
|
## 🖋️ Contributing
|
package/esm/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
2
|
import { format } from 'prettier';
|
|
3
3
|
import parserHtml from 'prettier/parser-html';
|
|
4
|
-
import {
|
|
4
|
+
import { Subject } from 'rxjs';
|
|
5
5
|
import { randomBytes } from 'crypto';
|
|
6
6
|
import { forTime } from 'waitasecond';
|
|
7
7
|
import { parse, unparse } from 'papaparse';
|
|
@@ -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.
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-10';
|
|
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
|
|
@@ -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
|
*
|
|
@@ -2079,21 +2109,43 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2079
2109
|
function createTask(options) {
|
|
2080
2110
|
const { taskType, taskProcessCallback } = options;
|
|
2081
2111
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2082
|
-
|
|
2112
|
+
let status = 'RUNNING';
|
|
2113
|
+
const createdAt = new Date();
|
|
2114
|
+
let updatedAt = createdAt;
|
|
2115
|
+
const errors = [];
|
|
2116
|
+
const warnings = [];
|
|
2117
|
+
let currentValue = {};
|
|
2118
|
+
const partialResultSubject = new Subject();
|
|
2119
|
+
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2083
2120
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
2121
|
+
Object.assign(currentValue, newOngoingResult);
|
|
2122
|
+
// <- TODO: assign deep
|
|
2084
2123
|
partialResultSubject.next(newOngoingResult);
|
|
2085
2124
|
});
|
|
2086
2125
|
finalResultPromise
|
|
2087
2126
|
.catch((error) => {
|
|
2127
|
+
errors.push(error);
|
|
2088
2128
|
partialResultSubject.error(error);
|
|
2089
2129
|
})
|
|
2090
|
-
.then((
|
|
2091
|
-
if (
|
|
2130
|
+
.then((executionResult) => {
|
|
2131
|
+
if (executionResult) {
|
|
2092
2132
|
try {
|
|
2093
|
-
|
|
2094
|
-
|
|
2133
|
+
updatedAt = new Date();
|
|
2134
|
+
errors.push(...executionResult.errors);
|
|
2135
|
+
warnings.push(...executionResult.warnings);
|
|
2136
|
+
// <- TODO: !!! Only unique errors and warnings should be added (or filtered)
|
|
2137
|
+
// TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2138
|
+
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2139
|
+
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2140
|
+
assertsTaskSuccessful(executionResult);
|
|
2141
|
+
status = 'FINISHED';
|
|
2142
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
2143
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2144
|
+
partialResultSubject.next(executionResult);
|
|
2095
2145
|
}
|
|
2096
2146
|
catch (error) {
|
|
2147
|
+
status = 'ERROR';
|
|
2148
|
+
errors.push(error);
|
|
2097
2149
|
partialResultSubject.error(error);
|
|
2098
2150
|
}
|
|
2099
2151
|
}
|
|
@@ -2110,12 +2162,33 @@ function createTask(options) {
|
|
|
2110
2162
|
return {
|
|
2111
2163
|
taskType,
|
|
2112
2164
|
taskId,
|
|
2165
|
+
get status() {
|
|
2166
|
+
return status;
|
|
2167
|
+
// <- Note: [1] Theese must be getters to allow changing the value in the future
|
|
2168
|
+
},
|
|
2169
|
+
get createdAt() {
|
|
2170
|
+
return createdAt;
|
|
2171
|
+
// <- Note: [1]
|
|
2172
|
+
},
|
|
2173
|
+
get updatedAt() {
|
|
2174
|
+
return updatedAt;
|
|
2175
|
+
// <- Note: [1]
|
|
2176
|
+
},
|
|
2113
2177
|
asPromise,
|
|
2114
2178
|
asObservable() {
|
|
2115
2179
|
return partialResultSubject.asObservable();
|
|
2116
2180
|
},
|
|
2181
|
+
get errors() {
|
|
2182
|
+
return errors;
|
|
2183
|
+
// <- Note: [1]
|
|
2184
|
+
},
|
|
2185
|
+
get warnings() {
|
|
2186
|
+
return warnings;
|
|
2187
|
+
// <- Note: [1]
|
|
2188
|
+
},
|
|
2117
2189
|
get currentValue() {
|
|
2118
|
-
return
|
|
2190
|
+
return currentValue;
|
|
2191
|
+
// <- Note: [1]
|
|
2119
2192
|
},
|
|
2120
2193
|
};
|
|
2121
2194
|
}
|
|
@@ -2331,7 +2404,7 @@ function addUsage(...usageItems) {
|
|
|
2331
2404
|
* @param script from which to extract the variables
|
|
2332
2405
|
* @returns the list of variable names
|
|
2333
2406
|
* @throws {ParseError} if the script is invalid
|
|
2334
|
-
* @public exported from `@promptbook/
|
|
2407
|
+
* @public exported from `@promptbook/javascript`
|
|
2335
2408
|
*/
|
|
2336
2409
|
function extractVariablesFromJavascript(script) {
|
|
2337
2410
|
const variables = new Set();
|
|
@@ -3904,7 +3977,7 @@ async function executeAttempts(options) {
|
|
|
3904
3977
|
Last result:
|
|
3905
3978
|
${block($ongoingTaskResult.$resultString === null
|
|
3906
3979
|
? 'null'
|
|
3907
|
-
: $ongoingTaskResult.$resultString
|
|
3980
|
+
: spaceTrim$1($ongoingTaskResult.$resultString)
|
|
3908
3981
|
.split('\n')
|
|
3909
3982
|
.map((line) => `> ${line}`)
|
|
3910
3983
|
.join('\n'))}
|