@promptbook/remote-server 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 +17 -24
- package/esm/index.es.js +136 -36
- package/esm/index.es.js.map +1 -1
- 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/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 +135 -35
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -116,6 +116,14 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
|
|
|
116
116
|
</tbody>
|
|
117
117
|
</table>
|
|
118
118
|
|
|
119
|
+
Hello world examples:
|
|
120
|
+
|
|
121
|
+
- [Hello world](https://github.com/webgptorg/hello-world)
|
|
122
|
+
- [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
|
|
123
|
+
- [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
119
127
|
We also have a community of developers and users of **Promptbook**:
|
|
120
128
|
|
|
121
129
|
- [Discord community](https://discord.gg/x3QWNaa89N)
|
|
@@ -282,16 +290,9 @@ Or you can install them separately:
|
|
|
282
290
|
|
|
283
291
|
## 📚 Dictionary
|
|
284
292
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
### 📚 Dictionary
|
|
291
|
-
|
|
292
293
|
The following glossary is used to clarify certain concepts:
|
|
293
294
|
|
|
294
|
-
|
|
295
|
+
### General LLM / AI terms
|
|
295
296
|
|
|
296
297
|
- **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
298
|
- **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 +305,11 @@ The following glossary is used to clarify certain concepts:
|
|
|
304
305
|
|
|
305
306
|
|
|
306
307
|
|
|
307
|
-
_Note:
|
|
308
|
+
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
308
309
|
|
|
309
310
|
|
|
310
311
|
|
|
311
|
-
|
|
312
|
+
### 💯 Core concepts
|
|
312
313
|
|
|
313
314
|
- [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
|
|
314
315
|
- [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
|
|
@@ -321,7 +322,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
321
322
|
- [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
|
|
322
323
|
- [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
|
|
323
324
|
|
|
324
|
-
|
|
325
|
+
#### Advanced concepts
|
|
325
326
|
|
|
326
327
|
- [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
|
|
327
328
|
- [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
|
|
@@ -338,17 +339,9 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
338
339
|
|
|
339
340
|
|
|
340
341
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
- Anonymous mode
|
|
344
|
-
- Application mode
|
|
345
|
-
|
|
342
|
+
## 🚂 Promptbook Engine
|
|
346
343
|
|
|
347
|
-
|
|
348
|
-
## 🔌 Usage in Typescript / Javascript
|
|
349
|
-
|
|
350
|
-
- [Simple usage](./examples/usage/simple-script)
|
|
351
|
-
- [Usage with client and remote server](./examples/usage/remote)
|
|
344
|
+

|
|
352
345
|
|
|
353
346
|
## ➕➖ When to use Promptbook?
|
|
354
347
|
|
|
@@ -414,13 +407,13 @@ See [TODO.md](./TODO.md)
|
|
|
414
407
|
<div style="display: flex; align-items: center; gap: 20px;">
|
|
415
408
|
|
|
416
409
|
<a href="https://promptbook.studio/">
|
|
417
|
-
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="
|
|
410
|
+
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
|
|
418
411
|
</a>
|
|
419
412
|
|
|
420
413
|
<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="
|
|
414
|
+
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
|
|
422
415
|
</a>
|
|
423
|
-
|
|
416
|
+
|
|
424
417
|
</div>
|
|
425
418
|
|
|
426
419
|
## 🖋️ Contributing
|
package/esm/index.es.js
CHANGED
|
@@ -7,7 +7,7 @@ import { forTime } from 'waitasecond';
|
|
|
7
7
|
import { spawn } from 'child_process';
|
|
8
8
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
|
|
9
9
|
import { join, basename, dirname } from 'path';
|
|
10
|
-
import {
|
|
10
|
+
import { Subject } from 'rxjs';
|
|
11
11
|
import { randomBytes } from 'crypto';
|
|
12
12
|
import { format } from 'prettier';
|
|
13
13
|
import parserHtml from 'prettier/parser-html';
|
|
@@ -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-11';
|
|
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
|
|
@@ -1721,6 +1721,57 @@ function $randomToken(randomness) {
|
|
|
1721
1721
|
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
1722
1722
|
*/
|
|
1723
1723
|
|
|
1724
|
+
/**
|
|
1725
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1726
|
+
*
|
|
1727
|
+
* @public exported from `@promptbook/utils`
|
|
1728
|
+
*/
|
|
1729
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1730
|
+
try {
|
|
1731
|
+
JSON.parse(value);
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
catch (error) {
|
|
1735
|
+
if (!(error instanceof Error)) {
|
|
1736
|
+
throw error;
|
|
1737
|
+
}
|
|
1738
|
+
if (error.message.includes('Unexpected token')) {
|
|
1739
|
+
return false;
|
|
1740
|
+
}
|
|
1741
|
+
return false;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
/**
|
|
1746
|
+
* Recursively converts JSON strings to JSON objects
|
|
1747
|
+
|
|
1748
|
+
* @public exported from `@promptbook/utils`
|
|
1749
|
+
*/
|
|
1750
|
+
function jsonStringsToJsons(object) {
|
|
1751
|
+
if (object === null) {
|
|
1752
|
+
return object;
|
|
1753
|
+
}
|
|
1754
|
+
if (Array.isArray(object)) {
|
|
1755
|
+
return object.map(jsonStringsToJsons);
|
|
1756
|
+
}
|
|
1757
|
+
if (typeof object !== 'object') {
|
|
1758
|
+
return object;
|
|
1759
|
+
}
|
|
1760
|
+
const newObject = { ...object };
|
|
1761
|
+
for (const [key, value] of Object.entries(object)) {
|
|
1762
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
1763
|
+
newObject[key] = JSON.parse(value);
|
|
1764
|
+
}
|
|
1765
|
+
else {
|
|
1766
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
return newObject;
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* TODO: Type the return type correctly
|
|
1773
|
+
*/
|
|
1774
|
+
|
|
1724
1775
|
/**
|
|
1725
1776
|
* Deserializes the error object
|
|
1726
1777
|
*
|
|
@@ -1793,21 +1844,43 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
1793
1844
|
function createTask(options) {
|
|
1794
1845
|
const { taskType, taskProcessCallback } = options;
|
|
1795
1846
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1796
|
-
|
|
1847
|
+
let status = 'RUNNING';
|
|
1848
|
+
const createdAt = new Date();
|
|
1849
|
+
let updatedAt = createdAt;
|
|
1850
|
+
const errors = [];
|
|
1851
|
+
const warnings = [];
|
|
1852
|
+
let currentValue = {};
|
|
1853
|
+
const partialResultSubject = new Subject();
|
|
1854
|
+
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
1797
1855
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
1856
|
+
Object.assign(currentValue, newOngoingResult);
|
|
1857
|
+
// <- TODO: assign deep
|
|
1798
1858
|
partialResultSubject.next(newOngoingResult);
|
|
1799
1859
|
});
|
|
1800
1860
|
finalResultPromise
|
|
1801
1861
|
.catch((error) => {
|
|
1862
|
+
errors.push(error);
|
|
1802
1863
|
partialResultSubject.error(error);
|
|
1803
1864
|
})
|
|
1804
|
-
.then((
|
|
1805
|
-
if (
|
|
1865
|
+
.then((executionResult) => {
|
|
1866
|
+
if (executionResult) {
|
|
1806
1867
|
try {
|
|
1807
|
-
|
|
1808
|
-
|
|
1868
|
+
updatedAt = new Date();
|
|
1869
|
+
errors.push(...executionResult.errors);
|
|
1870
|
+
warnings.push(...executionResult.warnings);
|
|
1871
|
+
// <- TODO: !!! Only unique errors and warnings should be added (or filtered)
|
|
1872
|
+
// TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
1873
|
+
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
1874
|
+
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1875
|
+
assertsTaskSuccessful(executionResult);
|
|
1876
|
+
status = 'FINISHED';
|
|
1877
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
1878
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
1879
|
+
partialResultSubject.next(executionResult);
|
|
1809
1880
|
}
|
|
1810
1881
|
catch (error) {
|
|
1882
|
+
status = 'ERROR';
|
|
1883
|
+
errors.push(error);
|
|
1811
1884
|
partialResultSubject.error(error);
|
|
1812
1885
|
}
|
|
1813
1886
|
}
|
|
@@ -1824,12 +1897,33 @@ function createTask(options) {
|
|
|
1824
1897
|
return {
|
|
1825
1898
|
taskType,
|
|
1826
1899
|
taskId,
|
|
1900
|
+
get status() {
|
|
1901
|
+
return status;
|
|
1902
|
+
// <- Note: [1] Theese must be getters to allow changing the value in the future
|
|
1903
|
+
},
|
|
1904
|
+
get createdAt() {
|
|
1905
|
+
return createdAt;
|
|
1906
|
+
// <- Note: [1]
|
|
1907
|
+
},
|
|
1908
|
+
get updatedAt() {
|
|
1909
|
+
return updatedAt;
|
|
1910
|
+
// <- Note: [1]
|
|
1911
|
+
},
|
|
1827
1912
|
asPromise,
|
|
1828
1913
|
asObservable() {
|
|
1829
1914
|
return partialResultSubject.asObservable();
|
|
1830
1915
|
},
|
|
1916
|
+
get errors() {
|
|
1917
|
+
return errors;
|
|
1918
|
+
// <- Note: [1]
|
|
1919
|
+
},
|
|
1920
|
+
get warnings() {
|
|
1921
|
+
return warnings;
|
|
1922
|
+
// <- Note: [1]
|
|
1923
|
+
},
|
|
1831
1924
|
get currentValue() {
|
|
1832
|
-
return
|
|
1925
|
+
return currentValue;
|
|
1926
|
+
// <- Note: [1]
|
|
1833
1927
|
},
|
|
1834
1928
|
};
|
|
1835
1929
|
}
|
|
@@ -1904,27 +1998,6 @@ function isValidFilePath(filename) {
|
|
|
1904
1998
|
* TODO: [🍏] Implement for MacOs
|
|
1905
1999
|
*/
|
|
1906
2000
|
|
|
1907
|
-
/**
|
|
1908
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1909
|
-
*
|
|
1910
|
-
* @public exported from `@promptbook/utils`
|
|
1911
|
-
*/
|
|
1912
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1913
|
-
try {
|
|
1914
|
-
JSON.parse(value);
|
|
1915
|
-
return true;
|
|
1916
|
-
}
|
|
1917
|
-
catch (error) {
|
|
1918
|
-
if (!(error instanceof Error)) {
|
|
1919
|
-
throw error;
|
|
1920
|
-
}
|
|
1921
|
-
if (error.message.includes('Unexpected token')) {
|
|
1922
|
-
return false;
|
|
1923
|
-
}
|
|
1924
|
-
return false;
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
2001
|
/**
|
|
1929
2002
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1930
2003
|
* 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.
|
|
@@ -5053,7 +5126,7 @@ async function executeAttempts(options) {
|
|
|
5053
5126
|
Last result:
|
|
5054
5127
|
${block($ongoingTaskResult.$resultString === null
|
|
5055
5128
|
? 'null'
|
|
5056
|
-
: $ongoingTaskResult.$resultString
|
|
5129
|
+
: spaceTrim($ongoingTaskResult.$resultString)
|
|
5057
5130
|
.split('\n')
|
|
5058
5131
|
.map((line) => `> ${line}`)
|
|
5059
5132
|
.join('\n'))}
|
|
@@ -6740,8 +6813,35 @@ function startRemoteServer(options) {
|
|
|
6740
6813
|
.send({ error: serializeError(error) });
|
|
6741
6814
|
}
|
|
6742
6815
|
});
|
|
6816
|
+
function exportExecutionTask(executionTask, isFull) {
|
|
6817
|
+
// <- TODO: [🧠] This should be maybe method of `ExecutionTask` itself
|
|
6818
|
+
const { taskType, taskId, status, errors, warnings, createdAt, updatedAt, currentValue } = executionTask;
|
|
6819
|
+
if (isFull) {
|
|
6820
|
+
return {
|
|
6821
|
+
nonce: '✨',
|
|
6822
|
+
taskId,
|
|
6823
|
+
taskType,
|
|
6824
|
+
status,
|
|
6825
|
+
errors: errors.map(serializeError),
|
|
6826
|
+
warnings: warnings.map(serializeError),
|
|
6827
|
+
createdAt,
|
|
6828
|
+
updatedAt,
|
|
6829
|
+
currentValue,
|
|
6830
|
+
};
|
|
6831
|
+
}
|
|
6832
|
+
else {
|
|
6833
|
+
return {
|
|
6834
|
+
nonce: '✨',
|
|
6835
|
+
taskId,
|
|
6836
|
+
taskType,
|
|
6837
|
+
status,
|
|
6838
|
+
createdAt,
|
|
6839
|
+
updatedAt,
|
|
6840
|
+
};
|
|
6841
|
+
}
|
|
6842
|
+
}
|
|
6743
6843
|
app.get(`${rootPath}/executions`, async (request, response) => {
|
|
6744
|
-
response.send(runningExecutionTasks);
|
|
6844
|
+
response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
|
|
6745
6845
|
});
|
|
6746
6846
|
app.get(`${rootPath}/executions/last`, async (request, response) => {
|
|
6747
6847
|
// TODO: [🤬] Filter only for user
|
|
@@ -6749,20 +6849,20 @@ function startRemoteServer(options) {
|
|
|
6749
6849
|
response.status(404).send('No execution tasks found');
|
|
6750
6850
|
return;
|
|
6751
6851
|
}
|
|
6752
|
-
const
|
|
6753
|
-
response.send(
|
|
6852
|
+
const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
|
|
6853
|
+
response.send(exportExecutionTask(lastExecutionTask, true));
|
|
6754
6854
|
});
|
|
6755
6855
|
app.get(`${rootPath}/executions/:taskId`, async (request, response) => {
|
|
6756
6856
|
const { taskId } = request.params;
|
|
6757
6857
|
// TODO: [🤬] Filter only for user
|
|
6758
|
-
const
|
|
6759
|
-
if (
|
|
6858
|
+
const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
|
|
6859
|
+
if (executionTask === undefined) {
|
|
6760
6860
|
response
|
|
6761
6861
|
.status(404)
|
|
6762
6862
|
.send(`Execution "${taskId}" not found`);
|
|
6763
6863
|
return;
|
|
6764
6864
|
}
|
|
6765
|
-
response.send(
|
|
6865
|
+
response.send(exportExecutionTask(executionTask, true));
|
|
6766
6866
|
});
|
|
6767
6867
|
app.post(`${rootPath}/executions/new`, async (request, response) => {
|
|
6768
6868
|
try {
|