@promptbook/node 0.66.0-9 → 0.67.0-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/esm/index.es.js +442 -283
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -4
- package/esm/typings/src/_packages/types.index.d.ts +7 -1
- package/esm/typings/src/_packages/utils.index.d.ts +14 -8
- package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +2 -0
- package/esm/typings/src/config.d.ts +6 -0
- package/esm/typings/src/errors/{ReferenceError.d.ts → PipelineUrlError.d.ts} +2 -2
- package/esm/typings/src/errors/index.d.ts +27 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
- package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
- package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +4 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -47
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +49 -0
- package/esm/typings/src/execution/PromptResult.d.ts +5 -4
- package/esm/typings/src/execution/PromptResultUsage.d.ts +4 -0
- package/esm/typings/src/execution/UncertainNumber.d.ts +1 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +0 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Error.d.ts +2 -6
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +5 -5
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +3 -1
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +7 -7
- package/esm/typings/src/types/ScriptLanguage.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionPromptReportJson.d.ts +24 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -20
- package/esm/typings/src/types/typeAliases.d.ts +7 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +1 -4
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +17 -0
- package/esm/typings/src/utils/{deepFreeze.d.ts → serialization/$deepFreeze.d.ts} +0 -10
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +27 -0
- package/esm/typings/src/utils/{clonePipeline.d.ts → serialization/clonePipeline.d.ts} +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +24 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +380 -221
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/errors/VersionMismatchError.d.ts +0 -10
- /package/esm/typings/src/utils/{deepClone.d.ts → serialization/deepClone.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import { stat, access, constants, readdir, readFile, writeFile, mkdir, unlink } from 'fs/promises';
|
|
3
3
|
import { join as join$1, dirname } from 'path';
|
|
4
|
-
import spaceTrim, { spaceTrim
|
|
4
|
+
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
5
5
|
import { format } from 'prettier';
|
|
6
6
|
import parserHtml from 'prettier/parser-html';
|
|
7
7
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
@@ -13,7 +13,7 @@ import * as dotenv from 'dotenv';
|
|
|
13
13
|
/**
|
|
14
14
|
* The version of the Promptbook library
|
|
15
15
|
*/
|
|
16
|
-
var PROMPTBOOK_VERSION = '0.66.0
|
|
16
|
+
var PROMPTBOOK_VERSION = '0.66.0';
|
|
17
17
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
18
18
|
|
|
19
19
|
/*! *****************************************************************************
|
|
@@ -135,6 +135,26 @@ function __spreadArray(to, from, pack) {
|
|
|
135
135
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Returns the same value that is passed as argument.
|
|
140
|
+
* No side effects.
|
|
141
|
+
*
|
|
142
|
+
* Note: It can be usefull for:
|
|
143
|
+
*
|
|
144
|
+
* 1) Leveling indentation
|
|
145
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
146
|
+
*
|
|
147
|
+
* @param value any values
|
|
148
|
+
* @returns the same values
|
|
149
|
+
* @private within the repository
|
|
150
|
+
*/
|
|
151
|
+
function just(value) {
|
|
152
|
+
if (value === undefined) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
|
|
138
158
|
/**
|
|
139
159
|
* @@@
|
|
140
160
|
*
|
|
@@ -165,42 +185,169 @@ function $deepFreeze(objectValue) {
|
|
|
165
185
|
}
|
|
166
186
|
return Object.freeze(objectValue);
|
|
167
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
194
|
+
*
|
|
195
|
+
* @public exported from `@promptbook/core`
|
|
196
|
+
*/
|
|
197
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
198
|
+
__extends(UnexpectedError, _super);
|
|
199
|
+
function UnexpectedError(message) {
|
|
200
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
201
|
+
_this.name = 'UnexpectedError';
|
|
202
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
203
|
+
return _this;
|
|
204
|
+
}
|
|
205
|
+
return UnexpectedError;
|
|
206
|
+
}(Error));
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
210
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
211
|
+
*
|
|
212
|
+
* - Almost all primitives are serializable BUT:
|
|
213
|
+
* - `undefined` is not serializable
|
|
214
|
+
* - `NaN` is not serializable
|
|
215
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
216
|
+
* - Functions are not serializable
|
|
217
|
+
* - Circular references are not serializable
|
|
218
|
+
* - `Date` objects are not serializable
|
|
219
|
+
* - `Map` and `Set` objects are not serializable
|
|
220
|
+
* - `RegExp` objects are not serializable
|
|
221
|
+
* - `Error` objects are not serializable
|
|
222
|
+
* - `Symbol` objects are not serializable
|
|
223
|
+
* - And much more...
|
|
224
|
+
*
|
|
225
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
226
|
+
* @public exported from `@promptbook/utils`
|
|
227
|
+
*/
|
|
228
|
+
function checkSerializableAsJson(name, value) {
|
|
229
|
+
var e_1, _a;
|
|
230
|
+
if (value === undefined) {
|
|
231
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
232
|
+
}
|
|
233
|
+
else if (value === null) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
else if (typeof value === 'boolean') {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
else if (typeof value === 'string') {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
else if (typeof value === 'symbol') {
|
|
246
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
247
|
+
}
|
|
248
|
+
else if (typeof value === 'function') {
|
|
249
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
250
|
+
}
|
|
251
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
252
|
+
for (var i = 0; i < value.length; i++) {
|
|
253
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (typeof value === 'object') {
|
|
257
|
+
if (value instanceof Date) {
|
|
258
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
259
|
+
}
|
|
260
|
+
else if (value instanceof Map) {
|
|
261
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
262
|
+
}
|
|
263
|
+
else if (value instanceof Set) {
|
|
264
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
265
|
+
}
|
|
266
|
+
else if (value instanceof RegExp) {
|
|
267
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
268
|
+
}
|
|
269
|
+
else if (value instanceof Error) {
|
|
270
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
try {
|
|
274
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
275
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
276
|
+
if (subValue === undefined) {
|
|
277
|
+
// Note: undefined in object is serializable - it is just omited
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
284
|
+
finally {
|
|
285
|
+
try {
|
|
286
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
287
|
+
}
|
|
288
|
+
finally { if (e_1) throw e_1.error; }
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
if (!(error instanceof Error)) {
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
298
|
+
}
|
|
299
|
+
/*
|
|
300
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
301
|
+
const seen = new Set();
|
|
302
|
+
const stack = [{ value }];
|
|
303
|
+
while (stack.length > 0) {
|
|
304
|
+
const { value } = stack.pop()!;
|
|
305
|
+
if (typeof value === 'object' && value !== null) {
|
|
306
|
+
if (seen.has(value)) {
|
|
307
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
308
|
+
}
|
|
309
|
+
seen.add(value);
|
|
310
|
+
if (Array.isArray(value)) {
|
|
311
|
+
stack.push(...value.map((value) => ({ value })));
|
|
312
|
+
} else {
|
|
313
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
*/
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
327
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
328
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
329
|
+
*/
|
|
330
|
+
|
|
168
331
|
/**
|
|
169
332
|
* @@@
|
|
170
333
|
* @@@
|
|
171
334
|
*
|
|
172
335
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
173
336
|
*
|
|
337
|
+
* @param name - Name of the object for debugging purposes
|
|
338
|
+
* @param objectValue - Object to be deeply frozen
|
|
174
339
|
* @returns The same object as the input, but deeply frozen
|
|
175
340
|
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
176
341
|
*/
|
|
177
|
-
function
|
|
342
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
343
|
+
checkSerializableAsJson(name, objectValue);
|
|
178
344
|
return $deepFreeze(objectValue);
|
|
179
345
|
}
|
|
180
346
|
/**
|
|
347
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
181
348
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
182
349
|
*/
|
|
183
350
|
|
|
184
|
-
/**
|
|
185
|
-
* Returns the same value that is passed as argument.
|
|
186
|
-
* No side effects.
|
|
187
|
-
*
|
|
188
|
-
* Note: It can be usefull for:
|
|
189
|
-
*
|
|
190
|
-
* 1) Leveling indentation
|
|
191
|
-
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
192
|
-
*
|
|
193
|
-
* @param value any values
|
|
194
|
-
* @returns the same values
|
|
195
|
-
* @private within the repository
|
|
196
|
-
*/
|
|
197
|
-
function just(value) {
|
|
198
|
-
if (value === undefined) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
return value;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
351
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
205
352
|
/**
|
|
206
353
|
* The maximum number of iterations for a loops
|
|
@@ -243,7 +390,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
243
390
|
*
|
|
244
391
|
* @public exported from `@promptbook/core`
|
|
245
392
|
*/
|
|
246
|
-
var RESERVED_PARAMETER_NAMES = $
|
|
393
|
+
var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
247
394
|
'content',
|
|
248
395
|
'context',
|
|
249
396
|
'knowledge',
|
|
@@ -265,6 +412,13 @@ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
|
265
412
|
* @private within the repository
|
|
266
413
|
*/
|
|
267
414
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
415
|
+
// <- TODO: [🧜♂️]
|
|
416
|
+
/**
|
|
417
|
+
* @@@
|
|
418
|
+
*
|
|
419
|
+
* @public exported from `@promptbook/core`
|
|
420
|
+
*/
|
|
421
|
+
var IS_VERBOSE = false;
|
|
268
422
|
/**
|
|
269
423
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
270
424
|
*/
|
|
@@ -479,7 +633,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
479
633
|
pipelineString += '\n\n';
|
|
480
634
|
pipelineString += '```' + contentLanguage;
|
|
481
635
|
pipelineString += '\n';
|
|
482
|
-
pipelineString += spaceTrim(content);
|
|
636
|
+
pipelineString += spaceTrim$1(content);
|
|
483
637
|
// <- TODO: !!! Escape
|
|
484
638
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
485
639
|
pipelineString += '\n';
|
|
@@ -712,7 +866,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
712
866
|
});
|
|
713
867
|
}
|
|
714
868
|
|
|
715
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0
|
|
869
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
716
870
|
|
|
717
871
|
/**
|
|
718
872
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -746,22 +900,6 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
746
900
|
return PipelineLogicError;
|
|
747
901
|
}(Error));
|
|
748
902
|
|
|
749
|
-
/**
|
|
750
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
751
|
-
*
|
|
752
|
-
* @public exported from `@promptbook/core`
|
|
753
|
-
*/
|
|
754
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
755
|
-
__extends(UnexpectedError, _super);
|
|
756
|
-
function UnexpectedError(message) {
|
|
757
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
758
|
-
_this.name = 'UnexpectedError';
|
|
759
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
760
|
-
return _this;
|
|
761
|
-
}
|
|
762
|
-
return UnexpectedError;
|
|
763
|
-
}(Error));
|
|
764
|
-
|
|
765
903
|
/**
|
|
766
904
|
* Tests if given string is valid semantic version
|
|
767
905
|
*
|
|
@@ -947,36 +1085,36 @@ function validatePipeline(pipeline) {
|
|
|
947
1085
|
})();
|
|
948
1086
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
949
1087
|
// <- Note: [🚲]
|
|
950
|
-
throw new PipelineLogicError(spaceTrim
|
|
1088
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
951
1089
|
}
|
|
952
1090
|
if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
|
|
953
1091
|
// <- Note: [🚲]
|
|
954
|
-
throw new PipelineLogicError(spaceTrim
|
|
1092
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
955
1093
|
}
|
|
956
1094
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
957
1095
|
if (!Array.isArray(pipeline.parameters)) {
|
|
958
1096
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
959
|
-
throw new ParsingError(spaceTrim
|
|
1097
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
960
1098
|
}
|
|
961
1099
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
962
1100
|
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
963
1101
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
964
|
-
throw new ParsingError(spaceTrim
|
|
1102
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
965
1103
|
}
|
|
966
1104
|
var _loop_1 = function (parameter) {
|
|
967
1105
|
if (parameter.isInput && parameter.isOutput) {
|
|
968
|
-
throw new PipelineLogicError(spaceTrim
|
|
1106
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
969
1107
|
}
|
|
970
1108
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
971
1109
|
if (!parameter.isInput &&
|
|
972
1110
|
!parameter.isOutput &&
|
|
973
1111
|
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
974
|
-
throw new PipelineLogicError(spaceTrim
|
|
1112
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
975
1113
|
}
|
|
976
1114
|
// Note: Testing that parameter is either input or result of some template
|
|
977
1115
|
if (!parameter.isInput &&
|
|
978
1116
|
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
979
|
-
throw new PipelineLogicError(spaceTrim
|
|
1117
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
980
1118
|
}
|
|
981
1119
|
};
|
|
982
1120
|
try {
|
|
@@ -1004,20 +1142,20 @@ function validatePipeline(pipeline) {
|
|
|
1004
1142
|
var _loop_2 = function (template) {
|
|
1005
1143
|
var e_4, _h, e_5, _j;
|
|
1006
1144
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
1007
|
-
throw new PipelineLogicError(spaceTrim
|
|
1145
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1008
1146
|
}
|
|
1009
1147
|
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
1010
|
-
throw new PipelineLogicError(spaceTrim
|
|
1148
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1011
1149
|
}
|
|
1012
1150
|
definedParameters.add(template.resultingParameterName);
|
|
1013
1151
|
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
1014
1152
|
if (!template.expectFormat &&
|
|
1015
1153
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1016
|
-
throw new PipelineLogicError(spaceTrim
|
|
1154
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1017
1155
|
}
|
|
1018
1156
|
var _loop_4 = function (joker) {
|
|
1019
1157
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
1020
|
-
throw new PipelineLogicError(spaceTrim
|
|
1158
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1021
1159
|
}
|
|
1022
1160
|
};
|
|
1023
1161
|
try {
|
|
@@ -1037,13 +1175,13 @@ function validatePipeline(pipeline) {
|
|
|
1037
1175
|
if (template.expectations) {
|
|
1038
1176
|
var _loop_5 = function (unit, min, max) {
|
|
1039
1177
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1040
|
-
throw new PipelineLogicError(spaceTrim
|
|
1178
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1041
1179
|
}
|
|
1042
1180
|
if (min !== undefined && min < 0) {
|
|
1043
|
-
throw new PipelineLogicError(spaceTrim
|
|
1181
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1044
1182
|
}
|
|
1045
1183
|
if (max !== undefined && max <= 0) {
|
|
1046
|
-
throw new PipelineLogicError(spaceTrim
|
|
1184
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1047
1185
|
}
|
|
1048
1186
|
};
|
|
1049
1187
|
try {
|
|
@@ -1105,7 +1243,7 @@ function validatePipeline(pipeline) {
|
|
|
1105
1243
|
var _loop_3 = function () {
|
|
1106
1244
|
if (loopLimit-- < 0) {
|
|
1107
1245
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
1108
|
-
throw new UnexpectedError(spaceTrim
|
|
1246
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
1109
1247
|
}
|
|
1110
1248
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
1111
1249
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
@@ -1113,7 +1251,7 @@ function validatePipeline(pipeline) {
|
|
|
1113
1251
|
if (currentlyResovedTemplates.length === 0) {
|
|
1114
1252
|
throw new PipelineLogicError(
|
|
1115
1253
|
// TODO: [🐎] DRY
|
|
1116
|
-
spaceTrim
|
|
1254
|
+
spaceTrim(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
1117
1255
|
.map(function (_a) {
|
|
1118
1256
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1119
1257
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -1175,15 +1313,15 @@ var NotFoundError = /** @class */ (function (_super) {
|
|
|
1175
1313
|
*
|
|
1176
1314
|
* @public exported from `@promptbook/core`
|
|
1177
1315
|
*/
|
|
1178
|
-
var
|
|
1179
|
-
__extends(
|
|
1180
|
-
function
|
|
1316
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1317
|
+
__extends(PipelineUrlError, _super);
|
|
1318
|
+
function PipelineUrlError(message) {
|
|
1181
1319
|
var _this = _super.call(this, message) || this;
|
|
1182
|
-
_this.name = '
|
|
1183
|
-
Object.setPrototypeOf(_this,
|
|
1320
|
+
_this.name = 'PipelineUrlError';
|
|
1321
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1184
1322
|
return _this;
|
|
1185
1323
|
}
|
|
1186
|
-
return
|
|
1324
|
+
return PipelineUrlError;
|
|
1187
1325
|
}(Error));
|
|
1188
1326
|
|
|
1189
1327
|
/**
|
|
@@ -1231,7 +1369,7 @@ function unpreparePipeline(pipeline) {
|
|
|
1231
1369
|
delete promptTemplateUnprepared.preparedContent;
|
|
1232
1370
|
return promptTemplateUnprepared;
|
|
1233
1371
|
});
|
|
1234
|
-
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
1372
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1235
1373
|
}
|
|
1236
1374
|
/**
|
|
1237
1375
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1267,7 +1405,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1267
1405
|
var pipeline = pipelines_1_1.value;
|
|
1268
1406
|
// TODO: [👠] DRY
|
|
1269
1407
|
if (pipeline.pipelineUrl === undefined) {
|
|
1270
|
-
throw new
|
|
1408
|
+
throw new PipelineUrlError(spaceTrim("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
1271
1409
|
}
|
|
1272
1410
|
// Note: [🐨]
|
|
1273
1411
|
validatePipeline(pipeline);
|
|
@@ -1279,7 +1417,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1279
1417
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1280
1418
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1281
1419
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1282
|
-
throw new
|
|
1420
|
+
throw new PipelineUrlError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
1283
1421
|
}
|
|
1284
1422
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1285
1423
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1309,9 +1447,9 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1309
1447
|
var pipeline = this.collection.get(url);
|
|
1310
1448
|
if (!pipeline) {
|
|
1311
1449
|
if (this.listPipelines().length === 0) {
|
|
1312
|
-
throw new NotFoundError(spaceTrim
|
|
1450
|
+
throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
|
|
1313
1451
|
}
|
|
1314
|
-
throw new NotFoundError(spaceTrim
|
|
1452
|
+
throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
|
|
1315
1453
|
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
1316
1454
|
.join('\n')), "\n\n "); }));
|
|
1317
1455
|
}
|
|
@@ -1724,9 +1862,105 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
1724
1862
|
}(Error));
|
|
1725
1863
|
|
|
1726
1864
|
/**
|
|
1727
|
-
*
|
|
1865
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1866
|
+
*
|
|
1867
|
+
* @public exported from `@promptbook/core`
|
|
1868
|
+
*/
|
|
1869
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
1870
|
+
__extends(CollectionError, _super);
|
|
1871
|
+
function CollectionError(message) {
|
|
1872
|
+
var _this = _super.call(this, message) || this;
|
|
1873
|
+
_this.name = 'CollectionError';
|
|
1874
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
1875
|
+
return _this;
|
|
1876
|
+
}
|
|
1877
|
+
return CollectionError;
|
|
1878
|
+
}(Error));
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
1882
|
+
*
|
|
1883
|
+
* @public exported from `@promptbook/core`
|
|
1884
|
+
*/
|
|
1885
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
1886
|
+
__extends(EnvironmentMismatchError, _super);
|
|
1887
|
+
function EnvironmentMismatchError(message) {
|
|
1888
|
+
var _this = _super.call(this, message) || this;
|
|
1889
|
+
_this.name = 'EnvironmentMismatchError';
|
|
1890
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
1891
|
+
return _this;
|
|
1892
|
+
}
|
|
1893
|
+
return EnvironmentMismatchError;
|
|
1894
|
+
}(Error));
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* This error type indicates that some limit was reached
|
|
1728
1898
|
*
|
|
1729
|
-
* @
|
|
1899
|
+
* @public exported from `@promptbook/core`
|
|
1900
|
+
*/
|
|
1901
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
1902
|
+
__extends(LimitReachedError, _super);
|
|
1903
|
+
function LimitReachedError(message) {
|
|
1904
|
+
var _this = _super.call(this, message) || this;
|
|
1905
|
+
_this.name = 'LimitReachedError';
|
|
1906
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
1907
|
+
return _this;
|
|
1908
|
+
}
|
|
1909
|
+
return LimitReachedError;
|
|
1910
|
+
}(Error));
|
|
1911
|
+
|
|
1912
|
+
/**
|
|
1913
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
1914
|
+
*
|
|
1915
|
+
* @public exported from `@promptbook/core`
|
|
1916
|
+
*/
|
|
1917
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1918
|
+
__extends(NotYetImplementedError, _super);
|
|
1919
|
+
function NotYetImplementedError(message) {
|
|
1920
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
1921
|
+
_this.name = 'NotYetImplementedError';
|
|
1922
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1923
|
+
return _this;
|
|
1924
|
+
}
|
|
1925
|
+
return NotYetImplementedError;
|
|
1926
|
+
}(Error));
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Index of all custom errors
|
|
1930
|
+
*
|
|
1931
|
+
* @public exported from `@promptbook/core`
|
|
1932
|
+
*/
|
|
1933
|
+
var ERRORS = {
|
|
1934
|
+
CollectionError: CollectionError,
|
|
1935
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
1936
|
+
LimitReachedError: LimitReachedError,
|
|
1937
|
+
NotFoundError: NotFoundError,
|
|
1938
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
1939
|
+
ParsingError: ParsingError,
|
|
1940
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
1941
|
+
PipelineLogicError: PipelineLogicError,
|
|
1942
|
+
PipelineUrlError: PipelineUrlError,
|
|
1943
|
+
UnexpectedError: UnexpectedError,
|
|
1944
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
1945
|
+
};
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* Deserializes the error object
|
|
1949
|
+
*
|
|
1950
|
+
* @public exported from `@promptbook/utils`
|
|
1951
|
+
*/
|
|
1952
|
+
function deserializeError(error) {
|
|
1953
|
+
if (error.name === 'Error') {
|
|
1954
|
+
return new Error(error.message);
|
|
1955
|
+
}
|
|
1956
|
+
var CustomError = ERRORS[error.name];
|
|
1957
|
+
return new CustomError(error.message);
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
/**
|
|
1961
|
+
* Asserts that the execution of a Promptbook is successful
|
|
1962
|
+
*
|
|
1963
|
+
* @param executionResult - The partial result of the Promptbook execution
|
|
1730
1964
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1731
1965
|
* @public exported from `@promptbook/core`
|
|
1732
1966
|
*/
|
|
@@ -1736,15 +1970,16 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1736
1970
|
return;
|
|
1737
1971
|
}
|
|
1738
1972
|
if (errors.length === 0) {
|
|
1739
|
-
throw new PipelineExecutionError("
|
|
1973
|
+
throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
|
|
1740
1974
|
}
|
|
1741
1975
|
else if (errors.length === 1) {
|
|
1742
|
-
throw errors[0];
|
|
1976
|
+
throw deserializeError(errors[0]);
|
|
1743
1977
|
}
|
|
1744
1978
|
else {
|
|
1745
|
-
throw new PipelineExecutionError(spaceTrim
|
|
1746
|
-
.map(function (
|
|
1747
|
-
|
|
1979
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
1980
|
+
.map(function (_a, index) {
|
|
1981
|
+
var name = _a.name, stack = _a.stack, message = _a.message;
|
|
1982
|
+
return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
1748
1983
|
})
|
|
1749
1984
|
.join('\n')), "\n "); }));
|
|
1750
1985
|
}
|
|
@@ -1776,7 +2011,7 @@ function extractVariables(script) {
|
|
|
1776
2011
|
var undefinedName = error.message.split(' ')[0];
|
|
1777
2012
|
/*
|
|
1778
2013
|
Note: Parsing the error
|
|
1779
|
-
[
|
|
2014
|
+
[PipelineUrlError: thing is not defined]
|
|
1780
2015
|
*/
|
|
1781
2016
|
if (!undefinedName) {
|
|
1782
2017
|
throw error;
|
|
@@ -1794,7 +2029,7 @@ function extractVariables(script) {
|
|
|
1794
2029
|
if (!(error instanceof Error)) {
|
|
1795
2030
|
throw error;
|
|
1796
2031
|
}
|
|
1797
|
-
throw new ParsingError(spaceTrim
|
|
2032
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
1798
2033
|
}
|
|
1799
2034
|
return variables;
|
|
1800
2035
|
}
|
|
@@ -1881,6 +2116,23 @@ var ExpectError = /** @class */ (function (_super) {
|
|
|
1881
2116
|
return ExpectError;
|
|
1882
2117
|
}(Error));
|
|
1883
2118
|
|
|
2119
|
+
/**
|
|
2120
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2121
|
+
*
|
|
2122
|
+
* @public exported from `@promptbook/utils`
|
|
2123
|
+
*/
|
|
2124
|
+
function serializeError(error) {
|
|
2125
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2126
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2127
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2128
|
+
}
|
|
2129
|
+
return {
|
|
2130
|
+
name: name,
|
|
2131
|
+
message: message,
|
|
2132
|
+
stack: stack,
|
|
2133
|
+
};
|
|
2134
|
+
}
|
|
2135
|
+
|
|
1884
2136
|
/**
|
|
1885
2137
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1886
2138
|
*
|
|
@@ -2120,7 +2372,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2120
2372
|
// 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2121
2373
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2122
2374
|
// 3) ...
|
|
2123
|
-
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2375
|
+
spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2124
2376
|
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2125
2377
|
.join('\n')), "\n\n "); }));
|
|
2126
2378
|
}
|
|
@@ -2128,7 +2380,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2128
2380
|
throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
|
|
2129
2381
|
}
|
|
2130
2382
|
else {
|
|
2131
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
|
|
2383
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
|
|
2132
2384
|
.map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
|
|
2133
2385
|
.join('\n')), "\n\n "); }));
|
|
2134
2386
|
}
|
|
@@ -2165,7 +2417,7 @@ function joinLlmExecutionTools() {
|
|
|
2165
2417
|
llmExecutionTools[_i] = arguments[_i];
|
|
2166
2418
|
}
|
|
2167
2419
|
if (llmExecutionTools.length === 0) {
|
|
2168
|
-
var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
2420
|
+
var warningMessage = spaceTrim$1("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
2169
2421
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2170
2422
|
console.warn(warningMessage);
|
|
2171
2423
|
/*
|
|
@@ -2262,22 +2514,6 @@ function TODO_USE() {
|
|
|
2262
2514
|
}
|
|
2263
2515
|
}
|
|
2264
2516
|
|
|
2265
|
-
/**
|
|
2266
|
-
* This error type indicates that some limit was reached
|
|
2267
|
-
*
|
|
2268
|
-
* @public exported from `@promptbook/core`
|
|
2269
|
-
*/
|
|
2270
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2271
|
-
__extends(LimitReachedError, _super);
|
|
2272
|
-
function LimitReachedError(message) {
|
|
2273
|
-
var _this = _super.call(this, message) || this;
|
|
2274
|
-
_this.name = 'LimitReachedError';
|
|
2275
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2276
|
-
return _this;
|
|
2277
|
-
}
|
|
2278
|
-
return LimitReachedError;
|
|
2279
|
-
}(Error));
|
|
2280
|
-
|
|
2281
2517
|
/**
|
|
2282
2518
|
* Replaces parameters in template with values from parameters object
|
|
2283
2519
|
*
|
|
@@ -2569,7 +2805,7 @@ function checkExpectations(expectations, value) {
|
|
|
2569
2805
|
function createPipelineExecutor(options) {
|
|
2570
2806
|
var _this = this;
|
|
2571
2807
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2572
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ?
|
|
2808
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
|
|
2573
2809
|
validatePipeline(pipeline);
|
|
2574
2810
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2575
2811
|
var preparedPipeline;
|
|
@@ -2577,7 +2813,7 @@ function createPipelineExecutor(options) {
|
|
|
2577
2813
|
preparedPipeline = pipeline;
|
|
2578
2814
|
}
|
|
2579
2815
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
2580
|
-
console.warn(spaceTrim
|
|
2816
|
+
console.warn(spaceTrim("\n Pipeline ".concat(pipeline.pipelineUrl || pipeline.sourceFile || pipeline.title, " is not prepared\n\n ").concat(pipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
|
|
2581
2817
|
}
|
|
2582
2818
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2583
2819
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -2663,7 +2899,6 @@ function createPipelineExecutor(options) {
|
|
|
2663
2899
|
return __awaiter(this, void 0, void 0, function () {
|
|
2664
2900
|
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
|
|
2665
2901
|
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2666
|
-
var _this = this;
|
|
2667
2902
|
return __generator(this, function (_u) {
|
|
2668
2903
|
switch (_u.label) {
|
|
2669
2904
|
case 0:
|
|
@@ -2688,7 +2923,7 @@ function createPipelineExecutor(options) {
|
|
|
2688
2923
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2689
2924
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2690
2925
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2691
|
-
throw new UnexpectedError(spaceTrim
|
|
2926
|
+
throw new UnexpectedError(spaceTrim("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
|
|
2692
2927
|
}
|
|
2693
2928
|
_b = (_a = Object).freeze;
|
|
2694
2929
|
_c = [{}];
|
|
@@ -2713,7 +2948,7 @@ function createPipelineExecutor(options) {
|
|
|
2713
2948
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2714
2949
|
// Houston, we have a problem
|
|
2715
2950
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2716
|
-
throw new UnexpectedError(spaceTrim
|
|
2951
|
+
throw new UnexpectedError(spaceTrim("\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ")));
|
|
2717
2952
|
}
|
|
2718
2953
|
}
|
|
2719
2954
|
}
|
|
@@ -2784,71 +3019,8 @@ function createPipelineExecutor(options) {
|
|
|
2784
3019
|
return name === currentTemplate.personaName;
|
|
2785
3020
|
}) || {})), currentTemplate.expectations),
|
|
2786
3021
|
expectFormat: currentTemplate.expectFormat,
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
var e_8, _c;
|
|
2790
|
-
return __generator(this, function (_d) {
|
|
2791
|
-
switch (_d.label) {
|
|
2792
|
-
case 0:
|
|
2793
|
-
errors = [];
|
|
2794
|
-
_d.label = 1;
|
|
2795
|
-
case 1:
|
|
2796
|
-
_d.trys.push([1, 8, 9, 10]);
|
|
2797
|
-
_a = __values(arrayableToArray(tools.script)), _b = _a.next();
|
|
2798
|
-
_d.label = 2;
|
|
2799
|
-
case 2:
|
|
2800
|
-
if (!!_b.done) return [3 /*break*/, 7];
|
|
2801
|
-
scriptTools = _b.value;
|
|
2802
|
-
_d.label = 3;
|
|
2803
|
-
case 3:
|
|
2804
|
-
_d.trys.push([3, 5, , 6]);
|
|
2805
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
2806
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2807
|
-
script: "".concat(functionName, "(result)"),
|
|
2808
|
-
parameters: {
|
|
2809
|
-
result: result || '',
|
|
2810
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
2811
|
-
},
|
|
2812
|
-
})];
|
|
2813
|
-
case 4: return [2 /*return*/, _d.sent()];
|
|
2814
|
-
case 5:
|
|
2815
|
-
error_5 = _d.sent();
|
|
2816
|
-
if (!(error_5 instanceof Error)) {
|
|
2817
|
-
throw error_5;
|
|
2818
|
-
}
|
|
2819
|
-
if (error_5 instanceof UnexpectedError) {
|
|
2820
|
-
throw error_5;
|
|
2821
|
-
}
|
|
2822
|
-
errors.push(error_5);
|
|
2823
|
-
return [3 /*break*/, 6];
|
|
2824
|
-
case 6:
|
|
2825
|
-
_b = _a.next();
|
|
2826
|
-
return [3 /*break*/, 2];
|
|
2827
|
-
case 7: return [3 /*break*/, 10];
|
|
2828
|
-
case 8:
|
|
2829
|
-
e_8_1 = _d.sent();
|
|
2830
|
-
e_8 = { error: e_8_1 };
|
|
2831
|
-
return [3 /*break*/, 10];
|
|
2832
|
-
case 9:
|
|
2833
|
-
try {
|
|
2834
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2835
|
-
}
|
|
2836
|
-
finally { if (e_8) throw e_8.error; }
|
|
2837
|
-
return [7 /*endfinally*/];
|
|
2838
|
-
case 10:
|
|
2839
|
-
if (errors.length === 0) {
|
|
2840
|
-
throw new PipelineExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
2841
|
-
}
|
|
2842
|
-
else if (errors.length === 1) {
|
|
2843
|
-
throw errors[0];
|
|
2844
|
-
}
|
|
2845
|
-
else {
|
|
2846
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
});
|
|
2850
|
-
}); }; }),
|
|
2851
|
-
};
|
|
3022
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3023
|
+
}; // <- TODO: Not very good type guard
|
|
2852
3024
|
_g = currentTemplate.modelRequirements.modelVariant;
|
|
2853
3025
|
switch (_g) {
|
|
2854
3026
|
case 'CHAT': return [3 /*break*/, 8];
|
|
@@ -2937,7 +3109,7 @@ function createPipelineExecutor(options) {
|
|
|
2937
3109
|
throw scriptPipelineExecutionErrors[0];
|
|
2938
3110
|
}
|
|
2939
3111
|
else {
|
|
2940
|
-
throw new PipelineExecutionError(spaceTrim
|
|
3112
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
2941
3113
|
.map(function (error) { return '- ' + error.message; })
|
|
2942
3114
|
.join('\n\n')), "\n "); }));
|
|
2943
3115
|
}
|
|
@@ -3073,13 +3245,13 @@ function createPipelineExecutor(options) {
|
|
|
3073
3245
|
executionReport.promptExecutions.push({
|
|
3074
3246
|
prompt: __assign({}, prompt),
|
|
3075
3247
|
result: result || undefined,
|
|
3076
|
-
error: expectError
|
|
3248
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3077
3249
|
});
|
|
3078
3250
|
}
|
|
3079
3251
|
return [7 /*endfinally*/];
|
|
3080
3252
|
case 50:
|
|
3081
3253
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3082
|
-
throw new PipelineExecutionError(spaceTrim
|
|
3254
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
3083
3255
|
}
|
|
3084
3256
|
_u.label = 51;
|
|
3085
3257
|
case 51:
|
|
@@ -3108,7 +3280,7 @@ function createPipelineExecutor(options) {
|
|
|
3108
3280
|
});
|
|
3109
3281
|
}
|
|
3110
3282
|
function filterJustOutputParameters() {
|
|
3111
|
-
var
|
|
3283
|
+
var e_8, _a;
|
|
3112
3284
|
var outputParameters = {};
|
|
3113
3285
|
try {
|
|
3114
3286
|
// Note: Filter ONLY output parameters
|
|
@@ -3125,12 +3297,12 @@ function createPipelineExecutor(options) {
|
|
|
3125
3297
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3126
3298
|
}
|
|
3127
3299
|
}
|
|
3128
|
-
catch (
|
|
3300
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3129
3301
|
finally {
|
|
3130
3302
|
try {
|
|
3131
3303
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3132
3304
|
}
|
|
3133
|
-
finally { if (
|
|
3305
|
+
finally { if (e_8) throw e_8.error; }
|
|
3134
3306
|
}
|
|
3135
3307
|
return outputParameters;
|
|
3136
3308
|
}
|
|
@@ -3167,11 +3339,11 @@ function createPipelineExecutor(options) {
|
|
|
3167
3339
|
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3168
3340
|
parameter = _b.value;
|
|
3169
3341
|
if (inputParameters[parameter.name] === undefined) {
|
|
3170
|
-
return [2 /*return*/,
|
|
3342
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3171
3343
|
isSuccessful: false,
|
|
3172
3344
|
errors: __spreadArray([
|
|
3173
3345
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3174
|
-
], __read(errors), false),
|
|
3346
|
+
], __read(errors), false).map(serializeError),
|
|
3175
3347
|
warnings: [],
|
|
3176
3348
|
executionReport: executionReport,
|
|
3177
3349
|
outputParameters: {},
|
|
@@ -3197,12 +3369,12 @@ function createPipelineExecutor(options) {
|
|
|
3197
3369
|
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3198
3370
|
}
|
|
3199
3371
|
else if (parameter.isInput === false) {
|
|
3200
|
-
return { value:
|
|
3372
|
+
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3201
3373
|
isSuccessful: false,
|
|
3202
3374
|
errors: __spreadArray([
|
|
3203
3375
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3204
|
-
], __read(errors), false),
|
|
3205
|
-
warnings: warnings,
|
|
3376
|
+
], __read(errors), false).map(serializeError),
|
|
3377
|
+
warnings: warnings.map(serializeError),
|
|
3206
3378
|
executionReport: executionReport,
|
|
3207
3379
|
outputParameters: {},
|
|
3208
3380
|
usage: ZERO_USAGE,
|
|
@@ -3259,7 +3431,7 @@ function createPipelineExecutor(options) {
|
|
|
3259
3431
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3260
3432
|
throw new UnexpectedError(
|
|
3261
3433
|
// TODO: [🐎] DRY
|
|
3262
|
-
spaceTrim
|
|
3434
|
+
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3263
3435
|
.map(function (_a) {
|
|
3264
3436
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3265
3437
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3309,10 +3481,10 @@ function createPipelineExecutor(options) {
|
|
|
3309
3481
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3310
3482
|
})), false));
|
|
3311
3483
|
outputParameters_1 = filterJustOutputParameters();
|
|
3312
|
-
return [2 /*return*/,
|
|
3484
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
|
|
3313
3485
|
isSuccessful: false,
|
|
3314
|
-
errors: __spreadArray([error_1], __read(errors), false),
|
|
3315
|
-
warnings: warnings,
|
|
3486
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
3487
|
+
warnings: warnings.map(serializeError),
|
|
3316
3488
|
usage: usage_1,
|
|
3317
3489
|
executionReport: executionReport,
|
|
3318
3490
|
outputParameters: outputParameters_1,
|
|
@@ -3324,10 +3496,10 @@ function createPipelineExecutor(options) {
|
|
|
3324
3496
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3325
3497
|
})), false));
|
|
3326
3498
|
outputParameters = filterJustOutputParameters();
|
|
3327
|
-
return [2 /*return*/,
|
|
3499
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
|
|
3328
3500
|
isSuccessful: true,
|
|
3329
|
-
errors: errors,
|
|
3330
|
-
warnings: warnings,
|
|
3501
|
+
errors: errors.map(serializeError),
|
|
3502
|
+
warnings: warnings.map(serializeError),
|
|
3331
3503
|
usage: usage,
|
|
3332
3504
|
executionReport: executionReport,
|
|
3333
3505
|
outputParameters: outputParameters,
|
|
@@ -3364,7 +3536,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3364
3536
|
return __generator(this, function (_j) {
|
|
3365
3537
|
switch (_j.label) {
|
|
3366
3538
|
case 0:
|
|
3367
|
-
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ?
|
|
3539
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
|
|
3368
3540
|
TODO_USE(maxParallelCount); // <- [🪂]
|
|
3369
3541
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3370
3542
|
_c = createPipelineExecutor;
|
|
@@ -3413,8 +3585,8 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3413
3585
|
switch (_c.label) {
|
|
3414
3586
|
case 0:
|
|
3415
3587
|
name = "piece-".concat(i);
|
|
3416
|
-
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
3417
|
-
knowledgePieceContent = spaceTrim(knowledgeTextPiece);
|
|
3588
|
+
title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
|
|
3589
|
+
knowledgePieceContent = spaceTrim$1(knowledgeTextPiece);
|
|
3418
3590
|
keywords = [];
|
|
3419
3591
|
index = [];
|
|
3420
3592
|
_c.label = 1;
|
|
@@ -3424,7 +3596,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3424
3596
|
case 2:
|
|
3425
3597
|
titleResult = _c.sent();
|
|
3426
3598
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
3427
|
-
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3599
|
+
title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3428
3600
|
name = titleToName(title);
|
|
3429
3601
|
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
3430
3602
|
case 3:
|
|
@@ -3651,7 +3823,7 @@ function preparePersona(personaDescription, options) {
|
|
|
3651
3823
|
return __generator(this, function (_d) {
|
|
3652
3824
|
switch (_d.label) {
|
|
3653
3825
|
case 0:
|
|
3654
|
-
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ?
|
|
3826
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
3655
3827
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3656
3828
|
_b = createPipelineExecutor;
|
|
3657
3829
|
_c = {};
|
|
@@ -3756,7 +3928,7 @@ function prepareTemplates(pipeline, options) {
|
|
|
3756
3928
|
dependentParameterNames = template.dependentParameterNames;
|
|
3757
3929
|
preparedContent = undefined;
|
|
3758
3930
|
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
3759
|
-
preparedContent = spaceTrim
|
|
3931
|
+
preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
3760
3932
|
// <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
|
|
3761
3933
|
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
3762
3934
|
'knowledge',
|
|
@@ -3797,7 +3969,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3797
3969
|
return __awaiter(this, void 0, void 0, function () {
|
|
3798
3970
|
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
|
|
3799
3971
|
/*
|
|
3800
|
-
<- TODO: [🧠][
|
|
3972
|
+
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3801
3973
|
knowledgeSources /*
|
|
3802
3974
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3803
3975
|
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
@@ -3808,7 +3980,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3808
3980
|
if (isPipelinePrepared(pipeline)) {
|
|
3809
3981
|
return [2 /*return*/, pipeline];
|
|
3810
3982
|
}
|
|
3811
|
-
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ?
|
|
3983
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
|
|
3812
3984
|
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3813
3985
|
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
3814
3986
|
currentPreparation = {
|
|
@@ -3867,7 +4039,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3867
4039
|
// ----- /Templates preparation -----
|
|
3868
4040
|
// Note: Count total usage
|
|
3869
4041
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3870
|
-
return [2 /*return*/, __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
4042
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
|
|
3871
4043
|
}
|
|
3872
4044
|
});
|
|
3873
4045
|
});
|
|
@@ -3943,7 +4115,7 @@ var knowledgeCommandParser = {
|
|
|
3943
4115
|
*/
|
|
3944
4116
|
parse: function (input) {
|
|
3945
4117
|
var args = input.args;
|
|
3946
|
-
var sourceContent = spaceTrim(args[0] || '');
|
|
4118
|
+
var sourceContent = spaceTrim$1(args[0] || '');
|
|
3947
4119
|
if (sourceContent === '') {
|
|
3948
4120
|
throw new ParsingError("Source is not defined");
|
|
3949
4121
|
}
|
|
@@ -4059,8 +4231,8 @@ var personaCommandParser = {
|
|
|
4059
4231
|
persona.description = personaDescription;
|
|
4060
4232
|
return;
|
|
4061
4233
|
}
|
|
4062
|
-
console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
4063
|
-
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
4234
|
+
console.warn(spaceTrim$1("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
4235
|
+
persona.description += spaceTrim$1('\n\n' + personaDescription);
|
|
4064
4236
|
},
|
|
4065
4237
|
};
|
|
4066
4238
|
|
|
@@ -4247,7 +4419,7 @@ var blockCommandParser = {
|
|
|
4247
4419
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
4248
4420
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
4249
4421
|
if (blockTypes.length !== 1) {
|
|
4250
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
4422
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
4251
4423
|
}
|
|
4252
4424
|
var blockType = blockTypes[0];
|
|
4253
4425
|
return {
|
|
@@ -4354,7 +4526,7 @@ var expectCommandParser = {
|
|
|
4354
4526
|
/**
|
|
4355
4527
|
* Description of the EXPECT command
|
|
4356
4528
|
*/
|
|
4357
|
-
description: spaceTrim("\n Expect command describes the desired output of the prompt template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
4529
|
+
description: spaceTrim$1("\n Expect command describes the desired output of the prompt template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
4358
4530
|
/**
|
|
4359
4531
|
* Link to discussion
|
|
4360
4532
|
*/
|
|
@@ -4447,7 +4619,7 @@ var expectCommandParser = {
|
|
|
4447
4619
|
if (!(error instanceof Error)) {
|
|
4448
4620
|
throw error;
|
|
4449
4621
|
}
|
|
4450
|
-
throw new ParsingError(spaceTrim(function (block) {
|
|
4622
|
+
throw new ParsingError(spaceTrim$1(function (block) {
|
|
4451
4623
|
return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
|
|
4452
4624
|
}));
|
|
4453
4625
|
}
|
|
@@ -4566,7 +4738,7 @@ var modelCommandParser = {
|
|
|
4566
4738
|
// <- Note: [🤖]
|
|
4567
4739
|
}
|
|
4568
4740
|
else {
|
|
4569
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n Supported variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) { return "- ".concat(variantName); }).join('\n')), "\n "); }));
|
|
4741
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Unknown model variant in command:\n\n Supported variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) { return "- ".concat(variantName); }).join('\n')), "\n "); }));
|
|
4570
4742
|
}
|
|
4571
4743
|
}
|
|
4572
4744
|
if (normalized.startsWith('MODEL_NAME')) {
|
|
@@ -4577,7 +4749,7 @@ var modelCommandParser = {
|
|
|
4577
4749
|
};
|
|
4578
4750
|
}
|
|
4579
4751
|
else {
|
|
4580
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Unknown model key in command.\n\n Supported model keys are:\n ".concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
4752
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Unknown model key in command.\n\n Supported model keys are:\n ".concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
4581
4753
|
}
|
|
4582
4754
|
},
|
|
4583
4755
|
};
|
|
@@ -5036,7 +5208,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
5036
5208
|
.map(removeMarkdownFormatting)
|
|
5037
5209
|
.map(function (item) { return item.trim(); });
|
|
5038
5210
|
if (items.length === 0 || items[0] === '') {
|
|
5039
|
-
throw new ParsingError(spaceTrim
|
|
5211
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5040
5212
|
return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5041
5213
|
}));
|
|
5042
5214
|
}
|
|
@@ -5063,7 +5235,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
5063
5235
|
return command;
|
|
5064
5236
|
}
|
|
5065
5237
|
}
|
|
5066
|
-
throw new ParsingError(spaceTrim
|
|
5238
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5067
5239
|
return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5068
5240
|
}));
|
|
5069
5241
|
}
|
|
@@ -5096,7 +5268,7 @@ function parseCommandVariant(input) {
|
|
|
5096
5268
|
if (!(error instanceof ParsingError)) {
|
|
5097
5269
|
throw error;
|
|
5098
5270
|
}
|
|
5099
|
-
throw new ParsingError(spaceTrim
|
|
5271
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5100
5272
|
return "\n Invalid ".concat(commandName, " command:\n ").concat(block(error.message), "\n\n - ").concat(raw, "\n\n Usage of ").concat(commandName, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n All supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5101
5273
|
}));
|
|
5102
5274
|
}
|
|
@@ -5123,22 +5295,6 @@ function parseCommandVariant(input) {
|
|
|
5123
5295
|
return null;
|
|
5124
5296
|
}
|
|
5125
5297
|
|
|
5126
|
-
/**
|
|
5127
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
5128
|
-
*
|
|
5129
|
-
* @public exported from `@promptbook/core`
|
|
5130
|
-
*/
|
|
5131
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
5132
|
-
__extends(NotYetImplementedError, _super);
|
|
5133
|
-
function NotYetImplementedError(message) {
|
|
5134
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
5135
|
-
_this.name = 'NotYetImplementedError';
|
|
5136
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
5137
|
-
return _this;
|
|
5138
|
-
}
|
|
5139
|
-
return NotYetImplementedError;
|
|
5140
|
-
}(Error));
|
|
5141
|
-
|
|
5142
5298
|
/**
|
|
5143
5299
|
* Supported script languages
|
|
5144
5300
|
*
|
|
@@ -5278,7 +5434,7 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
5278
5434
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5279
5435
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
5280
5436
|
if (codeBlocks.length !== 1) {
|
|
5281
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
5437
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
5282
5438
|
}
|
|
5283
5439
|
return codeBlocks[0];
|
|
5284
5440
|
}
|
|
@@ -5299,7 +5455,7 @@ function parseMarkdownSection(value) {
|
|
|
5299
5455
|
}
|
|
5300
5456
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
5301
5457
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
5302
|
-
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
5458
|
+
var content = spaceTrim$1(lines.slice(1).join('\n'));
|
|
5303
5459
|
if (level < 1 || level > 6) {
|
|
5304
5460
|
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
5305
5461
|
}
|
|
@@ -5327,7 +5483,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
5327
5483
|
if (buffer.length === 0) {
|
|
5328
5484
|
return;
|
|
5329
5485
|
}
|
|
5330
|
-
var section = spaceTrim(buffer.join('\n'));
|
|
5486
|
+
var section = spaceTrim$1(buffer.join('\n'));
|
|
5331
5487
|
if (section === '') {
|
|
5332
5488
|
return;
|
|
5333
5489
|
}
|
|
@@ -5423,7 +5579,7 @@ function flattenMarkdown(markdown) {
|
|
|
5423
5579
|
}
|
|
5424
5580
|
finally { if (e_1) throw e_1.error; }
|
|
5425
5581
|
}
|
|
5426
|
-
return spaceTrim(flattenedMarkdown);
|
|
5582
|
+
return spaceTrim$1(flattenedMarkdown);
|
|
5427
5583
|
}
|
|
5428
5584
|
/**
|
|
5429
5585
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -5441,7 +5597,7 @@ function flattenMarkdown(markdown) {
|
|
|
5441
5597
|
* @public exported from `@promptbook/markdown-utils`
|
|
5442
5598
|
*/
|
|
5443
5599
|
function removeContentComments(content) {
|
|
5444
|
-
return spaceTrim
|
|
5600
|
+
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
5445
5601
|
}
|
|
5446
5602
|
|
|
5447
5603
|
/**
|
|
@@ -5482,13 +5638,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5482
5638
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5483
5639
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5484
5640
|
if (pipelineHead === undefined) {
|
|
5485
|
-
throw new UnexpectedError(spaceTrim
|
|
5641
|
+
throw new UnexpectedError(spaceTrim("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5486
5642
|
}
|
|
5487
5643
|
if (pipelineHead.level !== 1) {
|
|
5488
|
-
throw new UnexpectedError(spaceTrim
|
|
5644
|
+
throw new UnexpectedError(spaceTrim("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5489
5645
|
}
|
|
5490
5646
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5491
|
-
throw new UnexpectedError(spaceTrim
|
|
5647
|
+
throw new UnexpectedError(spaceTrim("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5492
5648
|
}
|
|
5493
5649
|
// =============================================================
|
|
5494
5650
|
///Note: 2️⃣ Function for defining parameters
|
|
@@ -5502,7 +5658,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5502
5658
|
existingParameter.description &&
|
|
5503
5659
|
existingParameter.description !== parameterDescription &&
|
|
5504
5660
|
parameterDescription) {
|
|
5505
|
-
throw new ParsingError(spaceTrim
|
|
5661
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
5506
5662
|
}
|
|
5507
5663
|
if (existingParameter) {
|
|
5508
5664
|
if (parameterDescription) {
|
|
@@ -5528,7 +5684,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5528
5684
|
description = description.split(/^>.*$/gm).join('');
|
|
5529
5685
|
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
5530
5686
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5531
|
-
description = spaceTrim
|
|
5687
|
+
description = spaceTrim(description);
|
|
5532
5688
|
if (description === '') {
|
|
5533
5689
|
description = undefined;
|
|
5534
5690
|
}
|
|
@@ -5599,7 +5755,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5599
5755
|
if (resultingParameterName !== null) {
|
|
5600
5756
|
return resultingParameterName;
|
|
5601
5757
|
}
|
|
5602
|
-
throw new ParsingError(spaceTrim
|
|
5758
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5603
5759
|
// TODO: Show code of invalid sections each time + DRY
|
|
5604
5760
|
section.content
|
|
5605
5761
|
.split('\n')
|
|
@@ -5614,7 +5770,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5614
5770
|
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5615
5771
|
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5616
5772
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5617
|
-
description_1 = spaceTrim
|
|
5773
|
+
description_1 = spaceTrim(description_1);
|
|
5618
5774
|
if (description_1 === '') {
|
|
5619
5775
|
description_1 = undefined;
|
|
5620
5776
|
}
|
|
@@ -5698,7 +5854,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5698
5854
|
break;
|
|
5699
5855
|
case 'EXPECT_FORMAT':
|
|
5700
5856
|
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5701
|
-
throw new ParsingError(spaceTrim
|
|
5857
|
+
throw new ParsingError(spaceTrim("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
|
|
5702
5858
|
}
|
|
5703
5859
|
templateJson.expectFormat = command.format;
|
|
5704
5860
|
break;
|
|
@@ -5755,7 +5911,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5755
5911
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
5756
5912
|
}
|
|
5757
5913
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
5758
|
-
throw new ParsingError(spaceTrim
|
|
5914
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
5759
5915
|
}
|
|
5760
5916
|
templateJson.contentLanguage = language;
|
|
5761
5917
|
}
|
|
@@ -5830,7 +5986,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5830
5986
|
}
|
|
5831
5987
|
});
|
|
5832
5988
|
// =============================================================
|
|
5833
|
-
return pipelineJson;
|
|
5989
|
+
return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
|
|
5834
5990
|
}
|
|
5835
5991
|
/**
|
|
5836
5992
|
* TODO: !!!! Warn if used only sync version
|
|
@@ -5874,7 +6030,9 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
5874
6030
|
case 1:
|
|
5875
6031
|
pipelineJson = _a.sent();
|
|
5876
6032
|
_a.label = 2;
|
|
5877
|
-
case 2:
|
|
6033
|
+
case 2:
|
|
6034
|
+
// Note: No need to use `$asDeeplyFrozenSerializableJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
|
|
6035
|
+
return [2 /*return*/, pipelineJson];
|
|
5878
6036
|
}
|
|
5879
6037
|
});
|
|
5880
6038
|
});
|
|
@@ -5885,22 +6043,6 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
5885
6043
|
* TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
|
|
5886
6044
|
*/
|
|
5887
6045
|
|
|
5888
|
-
/**
|
|
5889
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
5890
|
-
*
|
|
5891
|
-
* @public exported from `@promptbook/core`
|
|
5892
|
-
*/
|
|
5893
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
5894
|
-
__extends(CollectionError, _super);
|
|
5895
|
-
function CollectionError(message) {
|
|
5896
|
-
var _this = _super.call(this, message) || this;
|
|
5897
|
-
_this.name = 'CollectionError';
|
|
5898
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
5899
|
-
return _this;
|
|
5900
|
-
}
|
|
5901
|
-
return CollectionError;
|
|
5902
|
-
}(Error));
|
|
5903
|
-
|
|
5904
6046
|
/**
|
|
5905
6047
|
* Detects if the code is running in a Node.js environment
|
|
5906
6048
|
*
|
|
@@ -6173,7 +6315,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6173
6315
|
// TODO: !! Implement;
|
|
6174
6316
|
// TODO: [🌗]
|
|
6175
6317
|
}
|
|
6176
|
-
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ?
|
|
6318
|
+
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? IS_VERBOSE : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
|
|
6177
6319
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
6178
6320
|
var fileNames, collection, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
6179
6321
|
var e_1, _a;
|
|
@@ -6266,7 +6408,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6266
6408
|
}
|
|
6267
6409
|
else {
|
|
6268
6410
|
existing = collection.get(pipeline.pipelineUrl);
|
|
6269
|
-
throw new
|
|
6411
|
+
throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4F\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
6270
6412
|
}
|
|
6271
6413
|
}
|
|
6272
6414
|
}
|
|
@@ -6276,7 +6418,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6276
6418
|
if (!(error_1 instanceof Error)) {
|
|
6277
6419
|
throw error_1;
|
|
6278
6420
|
}
|
|
6279
|
-
wrappedErrorMessage = spaceTrim(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
6421
|
+
wrappedErrorMessage = spaceTrim$1(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
6280
6422
|
if (isCrashedOnError) {
|
|
6281
6423
|
throw new CollectionError(wrappedErrorMessage);
|
|
6282
6424
|
}
|
|
@@ -6332,35 +6474,16 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6332
6474
|
* TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
|
|
6333
6475
|
*/
|
|
6334
6476
|
|
|
6335
|
-
/**
|
|
6336
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
6337
|
-
*
|
|
6338
|
-
* @public exported from `@promptbook/core`
|
|
6339
|
-
*/
|
|
6340
|
-
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
6341
|
-
__extends(EnvironmentMismatchError, _super);
|
|
6342
|
-
function EnvironmentMismatchError(message) {
|
|
6343
|
-
var _this = _super.call(this, message) || this;
|
|
6344
|
-
_this.name = 'EnvironmentMismatchError';
|
|
6345
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
6346
|
-
return _this;
|
|
6347
|
-
}
|
|
6348
|
-
return EnvironmentMismatchError;
|
|
6349
|
-
}(Error));
|
|
6350
|
-
|
|
6351
6477
|
/**
|
|
6352
6478
|
* @@@
|
|
6353
6479
|
*
|
|
6354
6480
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
6355
6481
|
*
|
|
6356
|
-
*
|
|
6482
|
+
* @private internal function of `$Register`
|
|
6357
6483
|
*/
|
|
6358
6484
|
function $getGlobalScope() {
|
|
6359
6485
|
return Function('return this')();
|
|
6360
6486
|
}
|
|
6361
|
-
/***
|
|
6362
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
6363
|
-
*/
|
|
6364
6487
|
|
|
6365
6488
|
/**
|
|
6366
6489
|
* Register is @@@
|
|
@@ -6391,13 +6514,10 @@ var $Register = /** @class */ (function () {
|
|
|
6391
6514
|
var packageName = registered.packageName, className = registered.className;
|
|
6392
6515
|
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
6393
6516
|
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
6394
|
-
// TODO: !!!!!! Global IS_VERBOSE mode
|
|
6395
6517
|
if (!existingRegistration) {
|
|
6396
|
-
console.warn("[\uD83D\uDCE6] Registering `".concat(packageName, ".").concat(className, "` to `").concat(this.storageName, "`"));
|
|
6397
6518
|
this.storage.push(registered);
|
|
6398
6519
|
}
|
|
6399
6520
|
else {
|
|
6400
|
-
console.warn("[\uD83D\uDCE6] Re-registering `".concat(packageName, ".").concat(className, "` to `").concat(this.storageName, "`"));
|
|
6401
6521
|
this.storage[existingRegistrationIndex] = registered;
|
|
6402
6522
|
}
|
|
6403
6523
|
};
|
|
@@ -6522,7 +6642,7 @@ function $registeredLlmToolsMessage() {
|
|
|
6522
6642
|
});
|
|
6523
6643
|
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
|
|
6524
6644
|
});
|
|
6525
|
-
return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
6645
|
+
return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
6526
6646
|
.map(function (_a, i) {
|
|
6527
6647
|
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
|
|
6528
6648
|
var more;
|
|
@@ -6561,7 +6681,7 @@ function $registeredLlmToolsMessage() {
|
|
|
6561
6681
|
*/
|
|
6562
6682
|
function createLlmToolsFromConfiguration(configuration, options) {
|
|
6563
6683
|
if (options === void 0) { options = {}; }
|
|
6564
|
-
var _a = options.isVerbose, isVerbose = _a === void 0 ?
|
|
6684
|
+
var _a = options.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
6565
6685
|
var llmTools = configuration.map(function (llmConfiguration) {
|
|
6566
6686
|
var registeredItem = $llmToolsRegister
|
|
6567
6687
|
.list()
|
|
@@ -6570,7 +6690,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
6570
6690
|
return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
|
|
6571
6691
|
});
|
|
6572
6692
|
if (registeredItem === undefined) {
|
|
6573
|
-
throw new Error(spaceTrim(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
|
|
6693
|
+
throw new Error(spaceTrim$1(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
|
|
6574
6694
|
}
|
|
6575
6695
|
return registeredItem(__assign({ isVerbose: isVerbose }, llmConfiguration.options));
|
|
6576
6696
|
});
|
|
@@ -6607,7 +6727,7 @@ function createLlmToolsFromEnv(options) {
|
|
|
6607
6727
|
var configuration = createLlmToolsFromConfigurationFromEnv();
|
|
6608
6728
|
if (configuration.length === 0) {
|
|
6609
6729
|
// TODO: [🥃]
|
|
6610
|
-
throw new Error(spaceTrim(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
|
|
6730
|
+
throw new Error(spaceTrim$1(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
|
|
6611
6731
|
}
|
|
6612
6732
|
return createLlmToolsFromConfiguration(configuration, options);
|
|
6613
6733
|
}
|
|
@@ -6620,6 +6740,39 @@ function createLlmToolsFromEnv(options) {
|
|
|
6620
6740
|
* TODO: This should be maybe not under `_common` but under `utils`
|
|
6621
6741
|
*/
|
|
6622
6742
|
|
|
6743
|
+
/**
|
|
6744
|
+
* Tests if the value is [🚉] serializable as JSON
|
|
6745
|
+
*
|
|
6746
|
+
* - Almost all primitives are serializable BUT:
|
|
6747
|
+
* - `undefined` is not serializable
|
|
6748
|
+
* - `NaN` is not serializable
|
|
6749
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
6750
|
+
* - Functions are not serializable
|
|
6751
|
+
* - Circular references are not serializable
|
|
6752
|
+
* - `Date` objects are not serializable
|
|
6753
|
+
* - `Map` and `Set` objects are not serializable
|
|
6754
|
+
* - `RegExp` objects are not serializable
|
|
6755
|
+
* - `Error` objects are not serializable
|
|
6756
|
+
* - `Symbol` objects are not serializable
|
|
6757
|
+
* - And much more...
|
|
6758
|
+
*
|
|
6759
|
+
*
|
|
6760
|
+
* @public exported from `@promptbook/utils`
|
|
6761
|
+
*/
|
|
6762
|
+
function isSerializableAsJson(value) {
|
|
6763
|
+
try {
|
|
6764
|
+
checkSerializableAsJson('', value);
|
|
6765
|
+
return true;
|
|
6766
|
+
}
|
|
6767
|
+
catch (error) {
|
|
6768
|
+
return false;
|
|
6769
|
+
}
|
|
6770
|
+
}
|
|
6771
|
+
/**
|
|
6772
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
6773
|
+
* TODO: [🧠][💺] Can be done this on type-level?
|
|
6774
|
+
*/
|
|
6775
|
+
|
|
6623
6776
|
/**
|
|
6624
6777
|
* Stringify the PipelineJson with proper formatting
|
|
6625
6778
|
*
|
|
@@ -6629,6 +6782,9 @@ function createLlmToolsFromEnv(options) {
|
|
|
6629
6782
|
* @public exported from `@promptbook/core`
|
|
6630
6783
|
*/
|
|
6631
6784
|
function stringifyPipelineJson(pipeline) {
|
|
6785
|
+
if (!isSerializableAsJson(pipeline)) {
|
|
6786
|
+
throw new UnexpectedError(spaceTrim$1("\n Cannot stringify the pipeline, because it is not serializable as JSON\n\n There can be multiple reasons:\n 1) The pipeline contains circular references\n 2) It is not a valid PipelineJson\n "));
|
|
6787
|
+
}
|
|
6632
6788
|
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
6633
6789
|
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
6634
6790
|
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
@@ -6709,6 +6865,9 @@ var FilesStorage = /** @class */ (function () {
|
|
|
6709
6865
|
switch (_a.label) {
|
|
6710
6866
|
case 0:
|
|
6711
6867
|
filename = this.getFilenameForKey(key);
|
|
6868
|
+
if (!isSerializableAsJson(value)) {
|
|
6869
|
+
throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
|
|
6870
|
+
}
|
|
6712
6871
|
fileContent = stringifyPipelineJson(value);
|
|
6713
6872
|
return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
|
|
6714
6873
|
case 1:
|