@promptbook/core 0.88.0-9 → 0.89.0-1
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 -14
- package/esm/index.es.js +50 -14
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -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/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +7 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
- package/esm/typings/src/playground/BrjappConnector.d.ts +64 -0
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
- package/esm/typings/src/playground/playground.d.ts +5 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- 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 +1 -1
- package/umd/index.umd.js +50 -14
- package/umd/index.umd.js.map +1 -1
package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts
CHANGED
|
@@ -37,7 +37,8 @@ export type PromptbookServer_AnonymousIdentification = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Identifier of the end user
|
|
39
39
|
*
|
|
40
|
-
* Note:
|
|
40
|
+
* Note: This can be either some id or email or any other identifier
|
|
41
|
+
* Note: In anonymous mode, this is passed to the certain model providers to identify misuse
|
|
41
42
|
* Note: In anonymous mode, there is no need to identify yourself, nor does it change the actual configuration of LLM Tools (unlike in application mode)
|
|
42
43
|
*/
|
|
43
44
|
readonly userId?: string_user_id;
|
|
@@ -58,15 +58,27 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
|
|
|
58
58
|
};
|
|
59
59
|
export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Identifier of the application
|
|
62
|
+
*
|
|
63
|
+
* Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
|
|
64
|
+
* Note: This can be some id or some semantic name like "email-agent"
|
|
62
65
|
*/
|
|
63
66
|
readonly appId: string_app_id | null;
|
|
64
67
|
/**
|
|
65
|
-
*
|
|
68
|
+
* Identifier of the end user
|
|
69
|
+
*
|
|
70
|
+
* Note: This can be either some id or email or any other identifier
|
|
71
|
+
* Note: This is also passed to the certain model providers to identify misuse
|
|
66
72
|
*/
|
|
67
73
|
readonly userId?: string_user_id;
|
|
68
74
|
/**
|
|
69
|
-
*
|
|
75
|
+
* Token of the user to verify its identity
|
|
76
|
+
*
|
|
77
|
+
* Note: This is passed for example to `createLlmExecutionTools`
|
|
78
|
+
*/
|
|
79
|
+
readonly userToken?: string_user_id;
|
|
80
|
+
/**
|
|
81
|
+
* Additional arbitrary options to identify the client or to pass custom metadata
|
|
70
82
|
*/
|
|
71
83
|
readonly customOptions?: TCustomOptions;
|
|
72
84
|
};
|
|
@@ -433,13 +433,13 @@ export type string_uuid = string & {
|
|
|
433
433
|
*
|
|
434
434
|
* @@@
|
|
435
435
|
*/
|
|
436
|
-
export type string_app_id = id;
|
|
436
|
+
export type string_app_id = id | 'app';
|
|
437
437
|
/**
|
|
438
438
|
* End user identifier
|
|
439
439
|
*
|
|
440
440
|
* @@@
|
|
441
441
|
*/
|
|
442
|
-
export type string_user_id = id;
|
|
442
|
+
export type string_user_id = id | string_email;
|
|
443
443
|
/**
|
|
444
444
|
* Semantic helper
|
|
445
445
|
*
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countCharacters(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countLines(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countPages(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countParagraphs(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -11,3 +11,6 @@ export declare function splitIntoSentences(text: string): ReadonlyArray<string>;
|
|
|
11
11
|
* @public exported from `@promptbook/utils`
|
|
12
12
|
*/
|
|
13
13
|
export declare function countSentences(text: string): ExpectationAmount;
|
|
14
|
+
/**
|
|
15
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
16
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countWords(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
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.89.0-1';
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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
|
|
@@ -1851,11 +1851,17 @@
|
|
|
1851
1851
|
*/
|
|
1852
1852
|
class PipelineExecutionError extends Error {
|
|
1853
1853
|
constructor(message) {
|
|
1854
|
+
// Added id parameter
|
|
1854
1855
|
super(message);
|
|
1855
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 */)}`;
|
|
1856
1859
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
1857
1860
|
}
|
|
1858
1861
|
}
|
|
1862
|
+
/**
|
|
1863
|
+
* TODO: !!!!!! Add id to all errors
|
|
1864
|
+
*/
|
|
1859
1865
|
|
|
1860
1866
|
/**
|
|
1861
1867
|
* This error indicates problems parsing the format value
|
|
@@ -2043,7 +2049,7 @@
|
|
|
2043
2049
|
* @public exported from `@promptbook/utils`
|
|
2044
2050
|
*/
|
|
2045
2051
|
function deserializeError(error) {
|
|
2046
|
-
const { name, stack } = error;
|
|
2052
|
+
const { name, stack, id } = error; // Added id
|
|
2047
2053
|
let { message } = error;
|
|
2048
2054
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2049
2055
|
if (ErrorClass === undefined) {
|
|
@@ -2058,7 +2064,9 @@
|
|
|
2058
2064
|
${block(stack || '')}
|
|
2059
2065
|
`);
|
|
2060
2066
|
}
|
|
2061
|
-
|
|
2067
|
+
const deserializedError = new ErrorClass(message);
|
|
2068
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2069
|
+
return deserializedError;
|
|
2062
2070
|
}
|
|
2063
2071
|
|
|
2064
2072
|
/**
|
|
@@ -2108,6 +2116,7 @@
|
|
|
2108
2116
|
*/
|
|
2109
2117
|
function createTask(options) {
|
|
2110
2118
|
const { taskType, taskProcessCallback } = options;
|
|
2119
|
+
// TODO: [🐙] DRY
|
|
2111
2120
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2112
2121
|
let status = 'RUNNING';
|
|
2113
2122
|
const createdAt = new Date();
|
|
@@ -2140,7 +2149,7 @@
|
|
|
2140
2149
|
assertsTaskSuccessful(executionResult);
|
|
2141
2150
|
status = 'FINISHED';
|
|
2142
2151
|
currentValue = jsonStringsToJsons(executionResult);
|
|
2143
|
-
// <- TODO:
|
|
2152
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2144
2153
|
partialResultSubject.next(executionResult);
|
|
2145
2154
|
}
|
|
2146
2155
|
catch (error) {
|
|
@@ -2204,19 +2213,21 @@
|
|
|
2204
2213
|
*/
|
|
2205
2214
|
function serializeError(error) {
|
|
2206
2215
|
const { name, message, stack } = error;
|
|
2216
|
+
const { id } = error;
|
|
2207
2217
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2208
2218
|
console.error(spaceTrim__default["default"]((block) => `
|
|
2209
|
-
|
|
2219
|
+
|
|
2210
2220
|
Cannot serialize error with name "${name}"
|
|
2211
2221
|
|
|
2212
2222
|
${block(stack || message)}
|
|
2213
|
-
|
|
2223
|
+
|
|
2214
2224
|
`));
|
|
2215
2225
|
}
|
|
2216
2226
|
return {
|
|
2217
2227
|
name: name,
|
|
2218
2228
|
message,
|
|
2219
2229
|
stack,
|
|
2230
|
+
id, // Include id in the serialized object
|
|
2220
2231
|
};
|
|
2221
2232
|
}
|
|
2222
2233
|
|
|
@@ -3259,6 +3270,9 @@
|
|
|
3259
3270
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
3260
3271
|
return text.length;
|
|
3261
3272
|
}
|
|
3273
|
+
/**
|
|
3274
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3275
|
+
*/
|
|
3262
3276
|
|
|
3263
3277
|
/**
|
|
3264
3278
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -3290,6 +3304,9 @@
|
|
|
3290
3304
|
const lines = text.split('\n');
|
|
3291
3305
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
3292
3306
|
}
|
|
3307
|
+
/**
|
|
3308
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3309
|
+
*/
|
|
3293
3310
|
|
|
3294
3311
|
/**
|
|
3295
3312
|
* Counts number of pages in the text
|
|
@@ -3301,6 +3318,9 @@
|
|
|
3301
3318
|
function countPages(text) {
|
|
3302
3319
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
3303
3320
|
}
|
|
3321
|
+
/**
|
|
3322
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3323
|
+
*/
|
|
3304
3324
|
|
|
3305
3325
|
/**
|
|
3306
3326
|
* Counts number of paragraphs in the text
|
|
@@ -3310,6 +3330,9 @@
|
|
|
3310
3330
|
function countParagraphs(text) {
|
|
3311
3331
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
3312
3332
|
}
|
|
3333
|
+
/**
|
|
3334
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3335
|
+
*/
|
|
3313
3336
|
|
|
3314
3337
|
/**
|
|
3315
3338
|
* Split text into sentences
|
|
@@ -3327,6 +3350,9 @@
|
|
|
3327
3350
|
function countSentences(text) {
|
|
3328
3351
|
return splitIntoSentences(text).length;
|
|
3329
3352
|
}
|
|
3353
|
+
/**
|
|
3354
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3355
|
+
*/
|
|
3330
3356
|
|
|
3331
3357
|
const defaultDiacriticsRemovalMap = [
|
|
3332
3358
|
{
|
|
@@ -3601,6 +3627,9 @@
|
|
|
3601
3627
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
3602
3628
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
3603
3629
|
}
|
|
3630
|
+
/**
|
|
3631
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3632
|
+
*/
|
|
3604
3633
|
|
|
3605
3634
|
/**
|
|
3606
3635
|
* Index of all counter functions
|
|
@@ -4678,8 +4707,9 @@
|
|
|
4678
4707
|
* @returns LLM tools with same functionality with added total cost counting
|
|
4679
4708
|
* @public exported from `@promptbook/core`
|
|
4680
4709
|
*/
|
|
4681
|
-
function
|
|
4710
|
+
function countUsage(llmTools) {
|
|
4682
4711
|
let totalUsage = ZERO_USAGE;
|
|
4712
|
+
const spending = new rxjs.Subject();
|
|
4683
4713
|
const proxyTools = {
|
|
4684
4714
|
get title() {
|
|
4685
4715
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -4689,12 +4719,15 @@
|
|
|
4689
4719
|
// TODO: [🧠] Maybe put here some suffix
|
|
4690
4720
|
return llmTools.description;
|
|
4691
4721
|
},
|
|
4692
|
-
|
|
4722
|
+
checkConfiguration() {
|
|
4693
4723
|
return /* not await */ llmTools.checkConfiguration();
|
|
4694
4724
|
},
|
|
4695
4725
|
listModels() {
|
|
4696
4726
|
return /* not await */ llmTools.listModels();
|
|
4697
4727
|
},
|
|
4728
|
+
spending() {
|
|
4729
|
+
return spending.asObservable();
|
|
4730
|
+
},
|
|
4698
4731
|
getTotalUsage() {
|
|
4699
4732
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
4700
4733
|
return totalUsage;
|
|
@@ -4705,6 +4738,7 @@
|
|
|
4705
4738
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
4706
4739
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
4707
4740
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4741
|
+
spending.next(promptResult.usage);
|
|
4708
4742
|
return promptResult;
|
|
4709
4743
|
};
|
|
4710
4744
|
}
|
|
@@ -4713,6 +4747,7 @@
|
|
|
4713
4747
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
4714
4748
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
4715
4749
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4750
|
+
spending.next(promptResult.usage);
|
|
4716
4751
|
return promptResult;
|
|
4717
4752
|
};
|
|
4718
4753
|
}
|
|
@@ -4721,6 +4756,7 @@
|
|
|
4721
4756
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
4722
4757
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
4723
4758
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4759
|
+
spending.next(promptResult.usage);
|
|
4724
4760
|
return promptResult;
|
|
4725
4761
|
};
|
|
4726
4762
|
}
|
|
@@ -5539,7 +5575,7 @@
|
|
|
5539
5575
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
5540
5576
|
const _llms = arrayableToArray(tools.llm);
|
|
5541
5577
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
5542
|
-
const llmToolsWithUsage =
|
|
5578
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
5543
5579
|
// <- TODO: [🌯]
|
|
5544
5580
|
/*
|
|
5545
5581
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -10050,7 +10086,7 @@
|
|
|
10050
10086
|
*/
|
|
10051
10087
|
function limitTotalUsage(llmTools, options = {}) {
|
|
10052
10088
|
const { maxTotalUsage = ZERO_USAGE, storage = new MemoryStorage() } = options;
|
|
10053
|
-
const proxyTools =
|
|
10089
|
+
const proxyTools = countUsage(llmTools);
|
|
10054
10090
|
if (maxTotalUsage.price.value !== 0) {
|
|
10055
10091
|
throw new NotYetImplementedError('`limitTotalUsage` is not yet implemented for non-zero price');
|
|
10056
10092
|
// TODO: "Cannot call `callChatModel` because the total cost limit is reached"
|
|
@@ -10896,7 +10932,7 @@
|
|
|
10896
10932
|
exports.cacheLlmTools = cacheLlmTools;
|
|
10897
10933
|
exports.collectionToJson = collectionToJson;
|
|
10898
10934
|
exports.compilePipeline = compilePipeline;
|
|
10899
|
-
exports.
|
|
10935
|
+
exports.countUsage = countUsage;
|
|
10900
10936
|
exports.createCollectionFromJson = createCollectionFromJson;
|
|
10901
10937
|
exports.createCollectionFromPromise = createCollectionFromPromise;
|
|
10902
10938
|
exports.createCollectionFromUrl = createCollectionFromUrl;
|