@promptbook/cli 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 +476 -315
- 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 +1 -1
- package/umd/index.umd.js +396 -235
- 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,5 +1,5 @@
|
|
|
1
1
|
import commander from 'commander';
|
|
2
|
-
import spaceTrim, { spaceTrim
|
|
2
|
+
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
3
3
|
import colors from 'colors';
|
|
4
4
|
import { forTime } from 'waitasecond';
|
|
5
5
|
import { stat, access, constants, readdir, readFile, writeFile, mkdir, unlink } from 'fs/promises';
|
|
@@ -20,7 +20,7 @@ import OpenAI from 'openai';
|
|
|
20
20
|
/**
|
|
21
21
|
* The version of the Promptbook library
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_VERSION = '0.66.0
|
|
23
|
+
var PROMPTBOOK_VERSION = '0.66.0';
|
|
24
24
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
25
25
|
|
|
26
26
|
/*! *****************************************************************************
|
|
@@ -167,6 +167,26 @@ var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
|
167
167
|
*/
|
|
168
168
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Returns the same value that is passed as argument.
|
|
172
|
+
* No side effects.
|
|
173
|
+
*
|
|
174
|
+
* Note: It can be usefull for:
|
|
175
|
+
*
|
|
176
|
+
* 1) Leveling indentation
|
|
177
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
178
|
+
*
|
|
179
|
+
* @param value any values
|
|
180
|
+
* @returns the same values
|
|
181
|
+
* @private within the repository
|
|
182
|
+
*/
|
|
183
|
+
function just(value) {
|
|
184
|
+
if (value === undefined) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
|
|
170
190
|
/**
|
|
171
191
|
* @@@
|
|
172
192
|
*
|
|
@@ -197,42 +217,169 @@ function $deepFreeze(objectValue) {
|
|
|
197
217
|
}
|
|
198
218
|
return Object.freeze(objectValue);
|
|
199
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
226
|
+
*
|
|
227
|
+
* @public exported from `@promptbook/core`
|
|
228
|
+
*/
|
|
229
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
230
|
+
__extends(UnexpectedError, _super);
|
|
231
|
+
function UnexpectedError(message) {
|
|
232
|
+
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;
|
|
233
|
+
_this.name = 'UnexpectedError';
|
|
234
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
235
|
+
return _this;
|
|
236
|
+
}
|
|
237
|
+
return UnexpectedError;
|
|
238
|
+
}(Error));
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
242
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
243
|
+
*
|
|
244
|
+
* - Almost all primitives are serializable BUT:
|
|
245
|
+
* - `undefined` is not serializable
|
|
246
|
+
* - `NaN` is not serializable
|
|
247
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
248
|
+
* - Functions are not serializable
|
|
249
|
+
* - Circular references are not serializable
|
|
250
|
+
* - `Date` objects are not serializable
|
|
251
|
+
* - `Map` and `Set` objects are not serializable
|
|
252
|
+
* - `RegExp` objects are not serializable
|
|
253
|
+
* - `Error` objects are not serializable
|
|
254
|
+
* - `Symbol` objects are not serializable
|
|
255
|
+
* - And much more...
|
|
256
|
+
*
|
|
257
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
258
|
+
* @public exported from `@promptbook/utils`
|
|
259
|
+
*/
|
|
260
|
+
function checkSerializableAsJson(name, value) {
|
|
261
|
+
var e_1, _a;
|
|
262
|
+
if (value === undefined) {
|
|
263
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
264
|
+
}
|
|
265
|
+
else if (value === null) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
else if (typeof value === 'boolean') {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
else if (typeof value === 'string') {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
else if (typeof value === 'symbol') {
|
|
278
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
279
|
+
}
|
|
280
|
+
else if (typeof value === 'function') {
|
|
281
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
282
|
+
}
|
|
283
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
284
|
+
for (var i = 0; i < value.length; i++) {
|
|
285
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else if (typeof value === 'object') {
|
|
289
|
+
if (value instanceof Date) {
|
|
290
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
291
|
+
}
|
|
292
|
+
else if (value instanceof Map) {
|
|
293
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
294
|
+
}
|
|
295
|
+
else if (value instanceof Set) {
|
|
296
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
297
|
+
}
|
|
298
|
+
else if (value instanceof RegExp) {
|
|
299
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
300
|
+
}
|
|
301
|
+
else if (value instanceof Error) {
|
|
302
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
try {
|
|
306
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
307
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
308
|
+
if (subValue === undefined) {
|
|
309
|
+
// Note: undefined in object is serializable - it is just omited
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
316
|
+
finally {
|
|
317
|
+
try {
|
|
318
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
319
|
+
}
|
|
320
|
+
finally { if (e_1) throw e_1.error; }
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
if (!(error instanceof Error)) {
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
330
|
+
}
|
|
331
|
+
/*
|
|
332
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
333
|
+
const seen = new Set();
|
|
334
|
+
const stack = [{ value }];
|
|
335
|
+
while (stack.length > 0) {
|
|
336
|
+
const { value } = stack.pop()!;
|
|
337
|
+
if (typeof value === 'object' && value !== null) {
|
|
338
|
+
if (seen.has(value)) {
|
|
339
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
340
|
+
}
|
|
341
|
+
seen.add(value);
|
|
342
|
+
if (Array.isArray(value)) {
|
|
343
|
+
stack.push(...value.map((value) => ({ value })));
|
|
344
|
+
} else {
|
|
345
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
*/
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
359
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
360
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
361
|
+
*/
|
|
362
|
+
|
|
200
363
|
/**
|
|
201
364
|
* @@@
|
|
202
365
|
* @@@
|
|
203
366
|
*
|
|
204
367
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
205
368
|
*
|
|
369
|
+
* @param name - Name of the object for debugging purposes
|
|
370
|
+
* @param objectValue - Object to be deeply frozen
|
|
206
371
|
* @returns The same object as the input, but deeply frozen
|
|
207
372
|
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
208
373
|
*/
|
|
209
|
-
function
|
|
374
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
375
|
+
checkSerializableAsJson(name, objectValue);
|
|
210
376
|
return $deepFreeze(objectValue);
|
|
211
377
|
}
|
|
212
378
|
/**
|
|
379
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
213
380
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
214
381
|
*/
|
|
215
382
|
|
|
216
|
-
/**
|
|
217
|
-
* Returns the same value that is passed as argument.
|
|
218
|
-
* No side effects.
|
|
219
|
-
*
|
|
220
|
-
* Note: It can be usefull for:
|
|
221
|
-
*
|
|
222
|
-
* 1) Leveling indentation
|
|
223
|
-
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
224
|
-
*
|
|
225
|
-
* @param value any values
|
|
226
|
-
* @returns the same values
|
|
227
|
-
* @private within the repository
|
|
228
|
-
*/
|
|
229
|
-
function just(value) {
|
|
230
|
-
if (value === undefined) {
|
|
231
|
-
return undefined;
|
|
232
|
-
}
|
|
233
|
-
return value;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
383
|
/**
|
|
237
384
|
* Warning message for the generated sections and files files
|
|
238
385
|
*
|
|
@@ -301,7 +448,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
301
448
|
*
|
|
302
449
|
* @public exported from `@promptbook/core`
|
|
303
450
|
*/
|
|
304
|
-
var RESERVED_PARAMETER_NAMES = $
|
|
451
|
+
var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
305
452
|
'content',
|
|
306
453
|
'context',
|
|
307
454
|
'knowledge',
|
|
@@ -335,6 +482,13 @@ var DEFAULT_REMOTE_URL = 'https://api.pavolhejny.com/';
|
|
|
335
482
|
* @public exported from `@promptbook/core`
|
|
336
483
|
*/
|
|
337
484
|
var DEFAULT_REMOTE_URL_PATH = '/promptbook/socket.io';
|
|
485
|
+
// <- TODO: [🧜♂️]
|
|
486
|
+
/**
|
|
487
|
+
* @@@
|
|
488
|
+
*
|
|
489
|
+
* @public exported from `@promptbook/core`
|
|
490
|
+
*/
|
|
491
|
+
var IS_VERBOSE = false;
|
|
338
492
|
/**
|
|
339
493
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
340
494
|
*/
|
|
@@ -347,7 +501,7 @@ var DEFAULT_REMOTE_URL_PATH = '/promptbook/socket.io';
|
|
|
347
501
|
function initializeAboutCommand(program) {
|
|
348
502
|
var _this = this;
|
|
349
503
|
var makeCommand = program.command('about');
|
|
350
|
-
makeCommand.description(spaceTrim("\n Tells about Promptbook CLI and its abilities\n "));
|
|
504
|
+
makeCommand.description(spaceTrim$1("\n Tells about Promptbook CLI and its abilities\n "));
|
|
351
505
|
makeCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
352
506
|
return __generator(this, function (_a) {
|
|
353
507
|
console.info(colors.cyan("Promptbook"));
|
|
@@ -372,7 +526,7 @@ function initializeAboutCommand(program) {
|
|
|
372
526
|
function initializeHelloCommand(program) {
|
|
373
527
|
var _this = this;
|
|
374
528
|
var helloCommand = program.command('hello');
|
|
375
|
-
helloCommand.description(spaceTrim("\n Just command for testing\n "));
|
|
529
|
+
helloCommand.description(spaceTrim$1("\n Just command for testing\n "));
|
|
376
530
|
helloCommand.argument('[name]', 'Your name', 'Paul');
|
|
377
531
|
helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
|
|
378
532
|
helloCommand.action(function (name, _a) {
|
|
@@ -634,7 +788,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
634
788
|
pipelineString += '\n\n';
|
|
635
789
|
pipelineString += '```' + contentLanguage;
|
|
636
790
|
pipelineString += '\n';
|
|
637
|
-
pipelineString += spaceTrim(content);
|
|
791
|
+
pipelineString += spaceTrim$1(content);
|
|
638
792
|
// <- TODO: !!! Escape
|
|
639
793
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
640
794
|
pipelineString += '\n';
|
|
@@ -867,7 +1021,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
867
1021
|
});
|
|
868
1022
|
}
|
|
869
1023
|
|
|
870
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0
|
|
1024
|
+
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"}];
|
|
871
1025
|
|
|
872
1026
|
/**
|
|
873
1027
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -901,22 +1055,6 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
901
1055
|
return PipelineLogicError;
|
|
902
1056
|
}(Error));
|
|
903
1057
|
|
|
904
|
-
/**
|
|
905
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
906
|
-
*
|
|
907
|
-
* @public exported from `@promptbook/core`
|
|
908
|
-
*/
|
|
909
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
910
|
-
__extends(UnexpectedError, _super);
|
|
911
|
-
function UnexpectedError(message) {
|
|
912
|
-
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;
|
|
913
|
-
_this.name = 'UnexpectedError';
|
|
914
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
915
|
-
return _this;
|
|
916
|
-
}
|
|
917
|
-
return UnexpectedError;
|
|
918
|
-
}(Error));
|
|
919
|
-
|
|
920
1058
|
/**
|
|
921
1059
|
* Tests if given string is valid semantic version
|
|
922
1060
|
*
|
|
@@ -1102,36 +1240,36 @@ function validatePipeline(pipeline) {
|
|
|
1102
1240
|
})();
|
|
1103
1241
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
1104
1242
|
// <- Note: [🚲]
|
|
1105
|
-
throw new PipelineLogicError(spaceTrim
|
|
1243
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1106
1244
|
}
|
|
1107
1245
|
if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
|
|
1108
1246
|
// <- Note: [🚲]
|
|
1109
|
-
throw new PipelineLogicError(spaceTrim
|
|
1247
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1110
1248
|
}
|
|
1111
1249
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1112
1250
|
if (!Array.isArray(pipeline.parameters)) {
|
|
1113
1251
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1114
|
-
throw new ParsingError(spaceTrim
|
|
1252
|
+
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 "); }));
|
|
1115
1253
|
}
|
|
1116
1254
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1117
1255
|
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
1118
1256
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1119
|
-
throw new ParsingError(spaceTrim
|
|
1257
|
+
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 "); }));
|
|
1120
1258
|
}
|
|
1121
1259
|
var _loop_1 = function (parameter) {
|
|
1122
1260
|
if (parameter.isInput && parameter.isOutput) {
|
|
1123
|
-
throw new PipelineLogicError(spaceTrim
|
|
1261
|
+
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 "); }));
|
|
1124
1262
|
}
|
|
1125
1263
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
1126
1264
|
if (!parameter.isInput &&
|
|
1127
1265
|
!parameter.isOutput &&
|
|
1128
1266
|
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
1129
|
-
throw new PipelineLogicError(spaceTrim
|
|
1267
|
+
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 "); }));
|
|
1130
1268
|
}
|
|
1131
1269
|
// Note: Testing that parameter is either input or result of some template
|
|
1132
1270
|
if (!parameter.isInput &&
|
|
1133
1271
|
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
1134
|
-
throw new PipelineLogicError(spaceTrim
|
|
1272
|
+
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 "); }));
|
|
1135
1273
|
}
|
|
1136
1274
|
};
|
|
1137
1275
|
try {
|
|
@@ -1159,20 +1297,20 @@ function validatePipeline(pipeline) {
|
|
|
1159
1297
|
var _loop_2 = function (template) {
|
|
1160
1298
|
var e_4, _h, e_5, _j;
|
|
1161
1299
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
1162
|
-
throw new PipelineLogicError(spaceTrim
|
|
1300
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1163
1301
|
}
|
|
1164
1302
|
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
1165
|
-
throw new PipelineLogicError(spaceTrim
|
|
1303
|
+
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 "); }));
|
|
1166
1304
|
}
|
|
1167
1305
|
definedParameters.add(template.resultingParameterName);
|
|
1168
1306
|
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
1169
1307
|
if (!template.expectFormat &&
|
|
1170
1308
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1171
|
-
throw new PipelineLogicError(spaceTrim
|
|
1309
|
+
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 "); }));
|
|
1172
1310
|
}
|
|
1173
1311
|
var _loop_4 = function (joker) {
|
|
1174
1312
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
1175
|
-
throw new PipelineLogicError(spaceTrim
|
|
1313
|
+
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 "); }));
|
|
1176
1314
|
}
|
|
1177
1315
|
};
|
|
1178
1316
|
try {
|
|
@@ -1192,13 +1330,13 @@ function validatePipeline(pipeline) {
|
|
|
1192
1330
|
if (template.expectations) {
|
|
1193
1331
|
var _loop_5 = function (unit, min, max) {
|
|
1194
1332
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1195
|
-
throw new PipelineLogicError(spaceTrim
|
|
1333
|
+
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 "); }));
|
|
1196
1334
|
}
|
|
1197
1335
|
if (min !== undefined && min < 0) {
|
|
1198
|
-
throw new PipelineLogicError(spaceTrim
|
|
1336
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1199
1337
|
}
|
|
1200
1338
|
if (max !== undefined && max <= 0) {
|
|
1201
|
-
throw new PipelineLogicError(spaceTrim
|
|
1339
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1202
1340
|
}
|
|
1203
1341
|
};
|
|
1204
1342
|
try {
|
|
@@ -1260,7 +1398,7 @@ function validatePipeline(pipeline) {
|
|
|
1260
1398
|
var _loop_3 = function () {
|
|
1261
1399
|
if (loopLimit-- < 0) {
|
|
1262
1400
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
1263
|
-
throw new UnexpectedError(spaceTrim
|
|
1401
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
1264
1402
|
}
|
|
1265
1403
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
1266
1404
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
@@ -1268,7 +1406,7 @@ function validatePipeline(pipeline) {
|
|
|
1268
1406
|
if (currentlyResovedTemplates.length === 0) {
|
|
1269
1407
|
throw new PipelineLogicError(
|
|
1270
1408
|
// TODO: [🐎] DRY
|
|
1271
|
-
spaceTrim
|
|
1409
|
+
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
|
|
1272
1410
|
.map(function (_a) {
|
|
1273
1411
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1274
1412
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -1330,15 +1468,15 @@ var NotFoundError = /** @class */ (function (_super) {
|
|
|
1330
1468
|
*
|
|
1331
1469
|
* @public exported from `@promptbook/core`
|
|
1332
1470
|
*/
|
|
1333
|
-
var
|
|
1334
|
-
__extends(
|
|
1335
|
-
function
|
|
1471
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1472
|
+
__extends(PipelineUrlError, _super);
|
|
1473
|
+
function PipelineUrlError(message) {
|
|
1336
1474
|
var _this = _super.call(this, message) || this;
|
|
1337
|
-
_this.name = '
|
|
1338
|
-
Object.setPrototypeOf(_this,
|
|
1475
|
+
_this.name = 'PipelineUrlError';
|
|
1476
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1339
1477
|
return _this;
|
|
1340
1478
|
}
|
|
1341
|
-
return
|
|
1479
|
+
return PipelineUrlError;
|
|
1342
1480
|
}(Error));
|
|
1343
1481
|
|
|
1344
1482
|
/**
|
|
@@ -1386,7 +1524,7 @@ function unpreparePipeline(pipeline) {
|
|
|
1386
1524
|
delete promptTemplateUnprepared.preparedContent;
|
|
1387
1525
|
return promptTemplateUnprepared;
|
|
1388
1526
|
});
|
|
1389
|
-
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
1527
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1390
1528
|
}
|
|
1391
1529
|
/**
|
|
1392
1530
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1422,7 +1560,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1422
1560
|
var pipeline = pipelines_1_1.value;
|
|
1423
1561
|
// TODO: [👠] DRY
|
|
1424
1562
|
if (pipeline.pipelineUrl === undefined) {
|
|
1425
|
-
throw new
|
|
1563
|
+
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 ")));
|
|
1426
1564
|
}
|
|
1427
1565
|
// Note: [🐨]
|
|
1428
1566
|
validatePipeline(pipeline);
|
|
@@ -1434,7 +1572,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1434
1572
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1435
1573
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1436
1574
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1437
|
-
throw new
|
|
1575
|
+
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 ")));
|
|
1438
1576
|
}
|
|
1439
1577
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1440
1578
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1464,9 +1602,9 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1464
1602
|
var pipeline = this.collection.get(url);
|
|
1465
1603
|
if (!pipeline) {
|
|
1466
1604
|
if (this.listPipelines().length === 0) {
|
|
1467
|
-
throw new NotFoundError(spaceTrim
|
|
1605
|
+
throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
|
|
1468
1606
|
}
|
|
1469
|
-
throw new NotFoundError(spaceTrim
|
|
1607
|
+
throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
|
|
1470
1608
|
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
1471
1609
|
.join('\n')), "\n\n "); }));
|
|
1472
1610
|
}
|
|
@@ -1879,9 +2017,89 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
1879
2017
|
}(Error));
|
|
1880
2018
|
|
|
1881
2019
|
/**
|
|
1882
|
-
*
|
|
2020
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2021
|
+
*
|
|
2022
|
+
* @public exported from `@promptbook/core`
|
|
2023
|
+
*/
|
|
2024
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
2025
|
+
__extends(CollectionError, _super);
|
|
2026
|
+
function CollectionError(message) {
|
|
2027
|
+
var _this = _super.call(this, message) || this;
|
|
2028
|
+
_this.name = 'CollectionError';
|
|
2029
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
2030
|
+
return _this;
|
|
2031
|
+
}
|
|
2032
|
+
return CollectionError;
|
|
2033
|
+
}(Error));
|
|
2034
|
+
|
|
2035
|
+
/**
|
|
2036
|
+
* This error type indicates that some limit was reached
|
|
2037
|
+
*
|
|
2038
|
+
* @public exported from `@promptbook/core`
|
|
2039
|
+
*/
|
|
2040
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2041
|
+
__extends(LimitReachedError, _super);
|
|
2042
|
+
function LimitReachedError(message) {
|
|
2043
|
+
var _this = _super.call(this, message) || this;
|
|
2044
|
+
_this.name = 'LimitReachedError';
|
|
2045
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2046
|
+
return _this;
|
|
2047
|
+
}
|
|
2048
|
+
return LimitReachedError;
|
|
2049
|
+
}(Error));
|
|
2050
|
+
|
|
2051
|
+
/**
|
|
2052
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
2053
|
+
*
|
|
2054
|
+
* @public exported from `@promptbook/core`
|
|
2055
|
+
*/
|
|
2056
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
2057
|
+
__extends(NotYetImplementedError, _super);
|
|
2058
|
+
function NotYetImplementedError(message) {
|
|
2059
|
+
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;
|
|
2060
|
+
_this.name = 'NotYetImplementedError';
|
|
2061
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
2062
|
+
return _this;
|
|
2063
|
+
}
|
|
2064
|
+
return NotYetImplementedError;
|
|
2065
|
+
}(Error));
|
|
2066
|
+
|
|
2067
|
+
/**
|
|
2068
|
+
* Index of all custom errors
|
|
2069
|
+
*
|
|
2070
|
+
* @public exported from `@promptbook/core`
|
|
2071
|
+
*/
|
|
2072
|
+
var ERRORS = {
|
|
2073
|
+
CollectionError: CollectionError,
|
|
2074
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2075
|
+
LimitReachedError: LimitReachedError,
|
|
2076
|
+
NotFoundError: NotFoundError,
|
|
2077
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
2078
|
+
ParsingError: ParsingError,
|
|
2079
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
2080
|
+
PipelineLogicError: PipelineLogicError,
|
|
2081
|
+
PipelineUrlError: PipelineUrlError,
|
|
2082
|
+
UnexpectedError: UnexpectedError,
|
|
2083
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
2084
|
+
};
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* Deserializes the error object
|
|
1883
2088
|
*
|
|
1884
|
-
* @
|
|
2089
|
+
* @public exported from `@promptbook/utils`
|
|
2090
|
+
*/
|
|
2091
|
+
function deserializeError(error) {
|
|
2092
|
+
if (error.name === 'Error') {
|
|
2093
|
+
return new Error(error.message);
|
|
2094
|
+
}
|
|
2095
|
+
var CustomError = ERRORS[error.name];
|
|
2096
|
+
return new CustomError(error.message);
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
/**
|
|
2100
|
+
* Asserts that the execution of a Promptbook is successful
|
|
2101
|
+
*
|
|
2102
|
+
* @param executionResult - The partial result of the Promptbook execution
|
|
1885
2103
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1886
2104
|
* @public exported from `@promptbook/core`
|
|
1887
2105
|
*/
|
|
@@ -1891,15 +2109,16 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1891
2109
|
return;
|
|
1892
2110
|
}
|
|
1893
2111
|
if (errors.length === 0) {
|
|
1894
|
-
throw new PipelineExecutionError("
|
|
2112
|
+
throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
|
|
1895
2113
|
}
|
|
1896
2114
|
else if (errors.length === 1) {
|
|
1897
|
-
throw errors[0];
|
|
2115
|
+
throw deserializeError(errors[0]);
|
|
1898
2116
|
}
|
|
1899
2117
|
else {
|
|
1900
|
-
throw new PipelineExecutionError(spaceTrim
|
|
1901
|
-
.map(function (
|
|
1902
|
-
|
|
2118
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
2119
|
+
.map(function (_a, index) {
|
|
2120
|
+
var name = _a.name, stack = _a.stack, message = _a.message;
|
|
2121
|
+
return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
1903
2122
|
})
|
|
1904
2123
|
.join('\n')), "\n "); }));
|
|
1905
2124
|
}
|
|
@@ -1931,7 +2150,7 @@ function extractVariables(script) {
|
|
|
1931
2150
|
var undefinedName = error.message.split(' ')[0];
|
|
1932
2151
|
/*
|
|
1933
2152
|
Note: Parsing the error
|
|
1934
|
-
[
|
|
2153
|
+
[PipelineUrlError: thing is not defined]
|
|
1935
2154
|
*/
|
|
1936
2155
|
if (!undefinedName) {
|
|
1937
2156
|
throw error;
|
|
@@ -1949,7 +2168,7 @@ function extractVariables(script) {
|
|
|
1949
2168
|
if (!(error instanceof Error)) {
|
|
1950
2169
|
throw error;
|
|
1951
2170
|
}
|
|
1952
|
-
throw new ParsingError(spaceTrim
|
|
2171
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
1953
2172
|
}
|
|
1954
2173
|
return variables;
|
|
1955
2174
|
}
|
|
@@ -2036,6 +2255,23 @@ var ExpectError = /** @class */ (function (_super) {
|
|
|
2036
2255
|
return ExpectError;
|
|
2037
2256
|
}(Error));
|
|
2038
2257
|
|
|
2258
|
+
/**
|
|
2259
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2260
|
+
*
|
|
2261
|
+
* @public exported from `@promptbook/utils`
|
|
2262
|
+
*/
|
|
2263
|
+
function serializeError(error) {
|
|
2264
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2265
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2266
|
+
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 "); }));
|
|
2267
|
+
}
|
|
2268
|
+
return {
|
|
2269
|
+
name: name,
|
|
2270
|
+
message: message,
|
|
2271
|
+
stack: stack,
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2039
2275
|
/**
|
|
2040
2276
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2041
2277
|
*
|
|
@@ -2275,7 +2511,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2275
2511
|
// 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2276
2512
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2277
2513
|
// 3) ...
|
|
2278
|
-
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2514
|
+
spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2279
2515
|
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2280
2516
|
.join('\n')), "\n\n "); }));
|
|
2281
2517
|
}
|
|
@@ -2283,7 +2519,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2283
2519
|
throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
|
|
2284
2520
|
}
|
|
2285
2521
|
else {
|
|
2286
|
-
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
|
|
2522
|
+
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
|
|
2287
2523
|
.map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
|
|
2288
2524
|
.join('\n')), "\n\n "); }));
|
|
2289
2525
|
}
|
|
@@ -2320,7 +2556,7 @@ function joinLlmExecutionTools() {
|
|
|
2320
2556
|
llmExecutionTools[_i] = arguments[_i];
|
|
2321
2557
|
}
|
|
2322
2558
|
if (llmExecutionTools.length === 0) {
|
|
2323
|
-
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 ");
|
|
2559
|
+
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 ");
|
|
2324
2560
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2325
2561
|
console.warn(warningMessage);
|
|
2326
2562
|
/*
|
|
@@ -2417,22 +2653,6 @@ function TODO_USE() {
|
|
|
2417
2653
|
}
|
|
2418
2654
|
}
|
|
2419
2655
|
|
|
2420
|
-
/**
|
|
2421
|
-
* This error type indicates that some limit was reached
|
|
2422
|
-
*
|
|
2423
|
-
* @public exported from `@promptbook/core`
|
|
2424
|
-
*/
|
|
2425
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2426
|
-
__extends(LimitReachedError, _super);
|
|
2427
|
-
function LimitReachedError(message) {
|
|
2428
|
-
var _this = _super.call(this, message) || this;
|
|
2429
|
-
_this.name = 'LimitReachedError';
|
|
2430
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2431
|
-
return _this;
|
|
2432
|
-
}
|
|
2433
|
-
return LimitReachedError;
|
|
2434
|
-
}(Error));
|
|
2435
|
-
|
|
2436
2656
|
/**
|
|
2437
2657
|
* Replaces parameters in template with values from parameters object
|
|
2438
2658
|
*
|
|
@@ -2724,7 +2944,7 @@ function checkExpectations(expectations, value) {
|
|
|
2724
2944
|
function createPipelineExecutor(options) {
|
|
2725
2945
|
var _this = this;
|
|
2726
2946
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2727
|
-
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 ?
|
|
2947
|
+
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;
|
|
2728
2948
|
validatePipeline(pipeline);
|
|
2729
2949
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2730
2950
|
var preparedPipeline;
|
|
@@ -2732,7 +2952,7 @@ function createPipelineExecutor(options) {
|
|
|
2732
2952
|
preparedPipeline = pipeline;
|
|
2733
2953
|
}
|
|
2734
2954
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
2735
|
-
console.warn(spaceTrim
|
|
2955
|
+
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 ")));
|
|
2736
2956
|
}
|
|
2737
2957
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2738
2958
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -2818,7 +3038,6 @@ function createPipelineExecutor(options) {
|
|
|
2818
3038
|
return __awaiter(this, void 0, void 0, function () {
|
|
2819
3039
|
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;
|
|
2820
3040
|
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2821
|
-
var _this = this;
|
|
2822
3041
|
return __generator(this, function (_u) {
|
|
2823
3042
|
switch (_u.label) {
|
|
2824
3043
|
case 0:
|
|
@@ -2843,7 +3062,7 @@ function createPipelineExecutor(options) {
|
|
|
2843
3062
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2844
3063
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2845
3064
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2846
|
-
throw new UnexpectedError(spaceTrim
|
|
3065
|
+
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 ")));
|
|
2847
3066
|
}
|
|
2848
3067
|
_b = (_a = Object).freeze;
|
|
2849
3068
|
_c = [{}];
|
|
@@ -2868,7 +3087,7 @@ function createPipelineExecutor(options) {
|
|
|
2868
3087
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2869
3088
|
// Houston, we have a problem
|
|
2870
3089
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2871
|
-
throw new UnexpectedError(spaceTrim
|
|
3090
|
+
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 ")));
|
|
2872
3091
|
}
|
|
2873
3092
|
}
|
|
2874
3093
|
}
|
|
@@ -2939,71 +3158,8 @@ function createPipelineExecutor(options) {
|
|
|
2939
3158
|
return name === currentTemplate.personaName;
|
|
2940
3159
|
}) || {})), currentTemplate.expectations),
|
|
2941
3160
|
expectFormat: currentTemplate.expectFormat,
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
var e_8, _c;
|
|
2945
|
-
return __generator(this, function (_d) {
|
|
2946
|
-
switch (_d.label) {
|
|
2947
|
-
case 0:
|
|
2948
|
-
errors = [];
|
|
2949
|
-
_d.label = 1;
|
|
2950
|
-
case 1:
|
|
2951
|
-
_d.trys.push([1, 8, 9, 10]);
|
|
2952
|
-
_a = __values(arrayableToArray(tools.script)), _b = _a.next();
|
|
2953
|
-
_d.label = 2;
|
|
2954
|
-
case 2:
|
|
2955
|
-
if (!!_b.done) return [3 /*break*/, 7];
|
|
2956
|
-
scriptTools = _b.value;
|
|
2957
|
-
_d.label = 3;
|
|
2958
|
-
case 3:
|
|
2959
|
-
_d.trys.push([3, 5, , 6]);
|
|
2960
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
2961
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2962
|
-
script: "".concat(functionName, "(result)"),
|
|
2963
|
-
parameters: {
|
|
2964
|
-
result: result || '',
|
|
2965
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
2966
|
-
},
|
|
2967
|
-
})];
|
|
2968
|
-
case 4: return [2 /*return*/, _d.sent()];
|
|
2969
|
-
case 5:
|
|
2970
|
-
error_5 = _d.sent();
|
|
2971
|
-
if (!(error_5 instanceof Error)) {
|
|
2972
|
-
throw error_5;
|
|
2973
|
-
}
|
|
2974
|
-
if (error_5 instanceof UnexpectedError) {
|
|
2975
|
-
throw error_5;
|
|
2976
|
-
}
|
|
2977
|
-
errors.push(error_5);
|
|
2978
|
-
return [3 /*break*/, 6];
|
|
2979
|
-
case 6:
|
|
2980
|
-
_b = _a.next();
|
|
2981
|
-
return [3 /*break*/, 2];
|
|
2982
|
-
case 7: return [3 /*break*/, 10];
|
|
2983
|
-
case 8:
|
|
2984
|
-
e_8_1 = _d.sent();
|
|
2985
|
-
e_8 = { error: e_8_1 };
|
|
2986
|
-
return [3 /*break*/, 10];
|
|
2987
|
-
case 9:
|
|
2988
|
-
try {
|
|
2989
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2990
|
-
}
|
|
2991
|
-
finally { if (e_8) throw e_8.error; }
|
|
2992
|
-
return [7 /*endfinally*/];
|
|
2993
|
-
case 10:
|
|
2994
|
-
if (errors.length === 0) {
|
|
2995
|
-
throw new PipelineExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
2996
|
-
}
|
|
2997
|
-
else if (errors.length === 1) {
|
|
2998
|
-
throw errors[0];
|
|
2999
|
-
}
|
|
3000
|
-
else {
|
|
3001
|
-
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 "); }));
|
|
3002
|
-
}
|
|
3003
|
-
}
|
|
3004
|
-
});
|
|
3005
|
-
}); }; }),
|
|
3006
|
-
};
|
|
3161
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3162
|
+
}; // <- TODO: Not very good type guard
|
|
3007
3163
|
_g = currentTemplate.modelRequirements.modelVariant;
|
|
3008
3164
|
switch (_g) {
|
|
3009
3165
|
case 'CHAT': return [3 /*break*/, 8];
|
|
@@ -3092,7 +3248,7 @@ function createPipelineExecutor(options) {
|
|
|
3092
3248
|
throw scriptPipelineExecutionErrors[0];
|
|
3093
3249
|
}
|
|
3094
3250
|
else {
|
|
3095
|
-
throw new PipelineExecutionError(spaceTrim
|
|
3251
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3096
3252
|
.map(function (error) { return '- ' + error.message; })
|
|
3097
3253
|
.join('\n\n')), "\n "); }));
|
|
3098
3254
|
}
|
|
@@ -3228,13 +3384,13 @@ function createPipelineExecutor(options) {
|
|
|
3228
3384
|
executionReport.promptExecutions.push({
|
|
3229
3385
|
prompt: __assign({}, prompt),
|
|
3230
3386
|
result: result || undefined,
|
|
3231
|
-
error: expectError
|
|
3387
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3232
3388
|
});
|
|
3233
3389
|
}
|
|
3234
3390
|
return [7 /*endfinally*/];
|
|
3235
3391
|
case 50:
|
|
3236
3392
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3237
|
-
throw new PipelineExecutionError(spaceTrim
|
|
3393
|
+
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 "); }));
|
|
3238
3394
|
}
|
|
3239
3395
|
_u.label = 51;
|
|
3240
3396
|
case 51:
|
|
@@ -3263,7 +3419,7 @@ function createPipelineExecutor(options) {
|
|
|
3263
3419
|
});
|
|
3264
3420
|
}
|
|
3265
3421
|
function filterJustOutputParameters() {
|
|
3266
|
-
var
|
|
3422
|
+
var e_8, _a;
|
|
3267
3423
|
var outputParameters = {};
|
|
3268
3424
|
try {
|
|
3269
3425
|
// Note: Filter ONLY output parameters
|
|
@@ -3280,12 +3436,12 @@ function createPipelineExecutor(options) {
|
|
|
3280
3436
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3281
3437
|
}
|
|
3282
3438
|
}
|
|
3283
|
-
catch (
|
|
3439
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3284
3440
|
finally {
|
|
3285
3441
|
try {
|
|
3286
3442
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3287
3443
|
}
|
|
3288
|
-
finally { if (
|
|
3444
|
+
finally { if (e_8) throw e_8.error; }
|
|
3289
3445
|
}
|
|
3290
3446
|
return outputParameters;
|
|
3291
3447
|
}
|
|
@@ -3322,11 +3478,11 @@ function createPipelineExecutor(options) {
|
|
|
3322
3478
|
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3323
3479
|
parameter = _b.value;
|
|
3324
3480
|
if (inputParameters[parameter.name] === undefined) {
|
|
3325
|
-
return [2 /*return*/,
|
|
3481
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3326
3482
|
isSuccessful: false,
|
|
3327
3483
|
errors: __spreadArray([
|
|
3328
3484
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3329
|
-
], __read(errors), false),
|
|
3485
|
+
], __read(errors), false).map(serializeError),
|
|
3330
3486
|
warnings: [],
|
|
3331
3487
|
executionReport: executionReport,
|
|
3332
3488
|
outputParameters: {},
|
|
@@ -3352,12 +3508,12 @@ function createPipelineExecutor(options) {
|
|
|
3352
3508
|
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3353
3509
|
}
|
|
3354
3510
|
else if (parameter.isInput === false) {
|
|
3355
|
-
return { value:
|
|
3511
|
+
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3356
3512
|
isSuccessful: false,
|
|
3357
3513
|
errors: __spreadArray([
|
|
3358
3514
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3359
|
-
], __read(errors), false),
|
|
3360
|
-
warnings: warnings,
|
|
3515
|
+
], __read(errors), false).map(serializeError),
|
|
3516
|
+
warnings: warnings.map(serializeError),
|
|
3361
3517
|
executionReport: executionReport,
|
|
3362
3518
|
outputParameters: {},
|
|
3363
3519
|
usage: ZERO_USAGE,
|
|
@@ -3414,7 +3570,7 @@ function createPipelineExecutor(options) {
|
|
|
3414
3570
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3415
3571
|
throw new UnexpectedError(
|
|
3416
3572
|
// TODO: [🐎] DRY
|
|
3417
|
-
spaceTrim
|
|
3573
|
+
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3418
3574
|
.map(function (_a) {
|
|
3419
3575
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3420
3576
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3464,10 +3620,10 @@ function createPipelineExecutor(options) {
|
|
|
3464
3620
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3465
3621
|
})), false));
|
|
3466
3622
|
outputParameters_1 = filterJustOutputParameters();
|
|
3467
|
-
return [2 /*return*/,
|
|
3623
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
|
|
3468
3624
|
isSuccessful: false,
|
|
3469
|
-
errors: __spreadArray([error_1], __read(errors), false),
|
|
3470
|
-
warnings: warnings,
|
|
3625
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
3626
|
+
warnings: warnings.map(serializeError),
|
|
3471
3627
|
usage: usage_1,
|
|
3472
3628
|
executionReport: executionReport,
|
|
3473
3629
|
outputParameters: outputParameters_1,
|
|
@@ -3479,10 +3635,10 @@ function createPipelineExecutor(options) {
|
|
|
3479
3635
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3480
3636
|
})), false));
|
|
3481
3637
|
outputParameters = filterJustOutputParameters();
|
|
3482
|
-
return [2 /*return*/,
|
|
3638
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
|
|
3483
3639
|
isSuccessful: true,
|
|
3484
|
-
errors: errors,
|
|
3485
|
-
warnings: warnings,
|
|
3640
|
+
errors: errors.map(serializeError),
|
|
3641
|
+
warnings: warnings.map(serializeError),
|
|
3486
3642
|
usage: usage,
|
|
3487
3643
|
executionReport: executionReport,
|
|
3488
3644
|
outputParameters: outputParameters,
|
|
@@ -3519,7 +3675,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3519
3675
|
return __generator(this, function (_j) {
|
|
3520
3676
|
switch (_j.label) {
|
|
3521
3677
|
case 0:
|
|
3522
|
-
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ?
|
|
3678
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
|
|
3523
3679
|
TODO_USE(maxParallelCount); // <- [🪂]
|
|
3524
3680
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3525
3681
|
_c = createPipelineExecutor;
|
|
@@ -3568,8 +3724,8 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3568
3724
|
switch (_c.label) {
|
|
3569
3725
|
case 0:
|
|
3570
3726
|
name = "piece-".concat(i);
|
|
3571
|
-
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
3572
|
-
knowledgePieceContent = spaceTrim(knowledgeTextPiece);
|
|
3727
|
+
title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
|
|
3728
|
+
knowledgePieceContent = spaceTrim$1(knowledgeTextPiece);
|
|
3573
3729
|
keywords = [];
|
|
3574
3730
|
index = [];
|
|
3575
3731
|
_c.label = 1;
|
|
@@ -3579,7 +3735,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3579
3735
|
case 2:
|
|
3580
3736
|
titleResult = _c.sent();
|
|
3581
3737
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
3582
|
-
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3738
|
+
title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3583
3739
|
name = titleToName(title);
|
|
3584
3740
|
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
3585
3741
|
case 3:
|
|
@@ -3806,7 +3962,7 @@ function preparePersona(personaDescription, options) {
|
|
|
3806
3962
|
return __generator(this, function (_d) {
|
|
3807
3963
|
switch (_d.label) {
|
|
3808
3964
|
case 0:
|
|
3809
|
-
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ?
|
|
3965
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
3810
3966
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3811
3967
|
_b = createPipelineExecutor;
|
|
3812
3968
|
_c = {};
|
|
@@ -3911,7 +4067,7 @@ function prepareTemplates(pipeline, options) {
|
|
|
3911
4067
|
dependentParameterNames = template.dependentParameterNames;
|
|
3912
4068
|
preparedContent = undefined;
|
|
3913
4069
|
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
3914
|
-
preparedContent = spaceTrim
|
|
4070
|
+
preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
3915
4071
|
// <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
|
|
3916
4072
|
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
3917
4073
|
'knowledge',
|
|
@@ -3952,7 +4108,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3952
4108
|
return __awaiter(this, void 0, void 0, function () {
|
|
3953
4109
|
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
|
|
3954
4110
|
/*
|
|
3955
|
-
<- TODO: [🧠][
|
|
4111
|
+
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3956
4112
|
knowledgeSources /*
|
|
3957
4113
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3958
4114
|
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
@@ -3963,7 +4119,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3963
4119
|
if (isPipelinePrepared(pipeline)) {
|
|
3964
4120
|
return [2 /*return*/, pipeline];
|
|
3965
4121
|
}
|
|
3966
|
-
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ?
|
|
4122
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
|
|
3967
4123
|
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3968
4124
|
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
3969
4125
|
currentPreparation = {
|
|
@@ -4022,7 +4178,7 @@ function preparePipeline(pipeline, options) {
|
|
|
4022
4178
|
// ----- /Templates preparation -----
|
|
4023
4179
|
// Note: Count total usage
|
|
4024
4180
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
4025
|
-
return [2 /*return*/, __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
4181
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
|
|
4026
4182
|
}
|
|
4027
4183
|
});
|
|
4028
4184
|
});
|
|
@@ -4098,7 +4254,7 @@ var knowledgeCommandParser = {
|
|
|
4098
4254
|
*/
|
|
4099
4255
|
parse: function (input) {
|
|
4100
4256
|
var args = input.args;
|
|
4101
|
-
var sourceContent = spaceTrim(args[0] || '');
|
|
4257
|
+
var sourceContent = spaceTrim$1(args[0] || '');
|
|
4102
4258
|
if (sourceContent === '') {
|
|
4103
4259
|
throw new ParsingError("Source is not defined");
|
|
4104
4260
|
}
|
|
@@ -4214,8 +4370,8 @@ var personaCommandParser = {
|
|
|
4214
4370
|
persona.description = personaDescription;
|
|
4215
4371
|
return;
|
|
4216
4372
|
}
|
|
4217
|
-
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 ")));
|
|
4218
|
-
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
4373
|
+
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 ")));
|
|
4374
|
+
persona.description += spaceTrim$1('\n\n' + personaDescription);
|
|
4219
4375
|
},
|
|
4220
4376
|
};
|
|
4221
4377
|
|
|
@@ -4402,7 +4558,7 @@ var blockCommandParser = {
|
|
|
4402
4558
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
4403
4559
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
4404
4560
|
if (blockTypes.length !== 1) {
|
|
4405
|
-
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 "); }));
|
|
4561
|
+
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 "); }));
|
|
4406
4562
|
}
|
|
4407
4563
|
var blockType = blockTypes[0];
|
|
4408
4564
|
return {
|
|
@@ -4509,7 +4665,7 @@ var expectCommandParser = {
|
|
|
4509
4665
|
/**
|
|
4510
4666
|
* Description of the EXPECT command
|
|
4511
4667
|
*/
|
|
4512
|
-
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 "),
|
|
4668
|
+
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 "),
|
|
4513
4669
|
/**
|
|
4514
4670
|
* Link to discussion
|
|
4515
4671
|
*/
|
|
@@ -4602,7 +4758,7 @@ var expectCommandParser = {
|
|
|
4602
4758
|
if (!(error instanceof Error)) {
|
|
4603
4759
|
throw error;
|
|
4604
4760
|
}
|
|
4605
|
-
throw new ParsingError(spaceTrim(function (block) {
|
|
4761
|
+
throw new ParsingError(spaceTrim$1(function (block) {
|
|
4606
4762
|
return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
|
|
4607
4763
|
}));
|
|
4608
4764
|
}
|
|
@@ -4721,7 +4877,7 @@ var modelCommandParser = {
|
|
|
4721
4877
|
// <- Note: [🤖]
|
|
4722
4878
|
}
|
|
4723
4879
|
else {
|
|
4724
|
-
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 "); }));
|
|
4880
|
+
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 "); }));
|
|
4725
4881
|
}
|
|
4726
4882
|
}
|
|
4727
4883
|
if (normalized.startsWith('MODEL_NAME')) {
|
|
@@ -4732,7 +4888,7 @@ var modelCommandParser = {
|
|
|
4732
4888
|
};
|
|
4733
4889
|
}
|
|
4734
4890
|
else {
|
|
4735
|
-
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 "); }));
|
|
4891
|
+
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 "); }));
|
|
4736
4892
|
}
|
|
4737
4893
|
},
|
|
4738
4894
|
};
|
|
@@ -5191,7 +5347,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
5191
5347
|
.map(removeMarkdownFormatting)
|
|
5192
5348
|
.map(function (item) { return item.trim(); });
|
|
5193
5349
|
if (items.length === 0 || items[0] === '') {
|
|
5194
|
-
throw new ParsingError(spaceTrim
|
|
5350
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5195
5351
|
return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5196
5352
|
}));
|
|
5197
5353
|
}
|
|
@@ -5218,7 +5374,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
5218
5374
|
return command;
|
|
5219
5375
|
}
|
|
5220
5376
|
}
|
|
5221
|
-
throw new ParsingError(spaceTrim
|
|
5377
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5222
5378
|
return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5223
5379
|
}));
|
|
5224
5380
|
}
|
|
@@ -5251,7 +5407,7 @@ function parseCommandVariant(input) {
|
|
|
5251
5407
|
if (!(error instanceof ParsingError)) {
|
|
5252
5408
|
throw error;
|
|
5253
5409
|
}
|
|
5254
|
-
throw new ParsingError(spaceTrim
|
|
5410
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5255
5411
|
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 ");
|
|
5256
5412
|
}));
|
|
5257
5413
|
}
|
|
@@ -5278,22 +5434,6 @@ function parseCommandVariant(input) {
|
|
|
5278
5434
|
return null;
|
|
5279
5435
|
}
|
|
5280
5436
|
|
|
5281
|
-
/**
|
|
5282
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
5283
|
-
*
|
|
5284
|
-
* @public exported from `@promptbook/core`
|
|
5285
|
-
*/
|
|
5286
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
5287
|
-
__extends(NotYetImplementedError, _super);
|
|
5288
|
-
function NotYetImplementedError(message) {
|
|
5289
|
-
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;
|
|
5290
|
-
_this.name = 'NotYetImplementedError';
|
|
5291
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
5292
|
-
return _this;
|
|
5293
|
-
}
|
|
5294
|
-
return NotYetImplementedError;
|
|
5295
|
-
}(Error));
|
|
5296
|
-
|
|
5297
5437
|
/**
|
|
5298
5438
|
* Supported script languages
|
|
5299
5439
|
*
|
|
@@ -5433,7 +5573,7 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
5433
5573
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5434
5574
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
5435
5575
|
if (codeBlocks.length !== 1) {
|
|
5436
|
-
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 "); }));
|
|
5576
|
+
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 "); }));
|
|
5437
5577
|
}
|
|
5438
5578
|
return codeBlocks[0];
|
|
5439
5579
|
}
|
|
@@ -5454,7 +5594,7 @@ function parseMarkdownSection(value) {
|
|
|
5454
5594
|
}
|
|
5455
5595
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
5456
5596
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
5457
|
-
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
5597
|
+
var content = spaceTrim$1(lines.slice(1).join('\n'));
|
|
5458
5598
|
if (level < 1 || level > 6) {
|
|
5459
5599
|
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
5460
5600
|
}
|
|
@@ -5482,7 +5622,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
5482
5622
|
if (buffer.length === 0) {
|
|
5483
5623
|
return;
|
|
5484
5624
|
}
|
|
5485
|
-
var section = spaceTrim(buffer.join('\n'));
|
|
5625
|
+
var section = spaceTrim$1(buffer.join('\n'));
|
|
5486
5626
|
if (section === '') {
|
|
5487
5627
|
return;
|
|
5488
5628
|
}
|
|
@@ -5578,7 +5718,7 @@ function flattenMarkdown(markdown) {
|
|
|
5578
5718
|
}
|
|
5579
5719
|
finally { if (e_1) throw e_1.error; }
|
|
5580
5720
|
}
|
|
5581
|
-
return spaceTrim(flattenedMarkdown);
|
|
5721
|
+
return spaceTrim$1(flattenedMarkdown);
|
|
5582
5722
|
}
|
|
5583
5723
|
/**
|
|
5584
5724
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -5596,7 +5736,7 @@ function flattenMarkdown(markdown) {
|
|
|
5596
5736
|
* @public exported from `@promptbook/markdown-utils`
|
|
5597
5737
|
*/
|
|
5598
5738
|
function removeContentComments(content) {
|
|
5599
|
-
return spaceTrim
|
|
5739
|
+
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
5600
5740
|
}
|
|
5601
5741
|
|
|
5602
5742
|
/**
|
|
@@ -5637,13 +5777,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5637
5777
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5638
5778
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5639
5779
|
if (pipelineHead === undefined) {
|
|
5640
|
-
throw new UnexpectedError(spaceTrim
|
|
5780
|
+
throw new UnexpectedError(spaceTrim("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5641
5781
|
}
|
|
5642
5782
|
if (pipelineHead.level !== 1) {
|
|
5643
|
-
throw new UnexpectedError(spaceTrim
|
|
5783
|
+
throw new UnexpectedError(spaceTrim("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5644
5784
|
}
|
|
5645
5785
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5646
|
-
throw new UnexpectedError(spaceTrim
|
|
5786
|
+
throw new UnexpectedError(spaceTrim("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5647
5787
|
}
|
|
5648
5788
|
// =============================================================
|
|
5649
5789
|
///Note: 2️⃣ Function for defining parameters
|
|
@@ -5657,7 +5797,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5657
5797
|
existingParameter.description &&
|
|
5658
5798
|
existingParameter.description !== parameterDescription &&
|
|
5659
5799
|
parameterDescription) {
|
|
5660
|
-
throw new ParsingError(spaceTrim
|
|
5800
|
+
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 "); }));
|
|
5661
5801
|
}
|
|
5662
5802
|
if (existingParameter) {
|
|
5663
5803
|
if (parameterDescription) {
|
|
@@ -5683,7 +5823,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5683
5823
|
description = description.split(/^>.*$/gm).join('');
|
|
5684
5824
|
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
5685
5825
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5686
|
-
description = spaceTrim
|
|
5826
|
+
description = spaceTrim(description);
|
|
5687
5827
|
if (description === '') {
|
|
5688
5828
|
description = undefined;
|
|
5689
5829
|
}
|
|
@@ -5754,7 +5894,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5754
5894
|
if (resultingParameterName !== null) {
|
|
5755
5895
|
return resultingParameterName;
|
|
5756
5896
|
}
|
|
5757
|
-
throw new ParsingError(spaceTrim
|
|
5897
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5758
5898
|
// TODO: Show code of invalid sections each time + DRY
|
|
5759
5899
|
section.content
|
|
5760
5900
|
.split('\n')
|
|
@@ -5769,7 +5909,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5769
5909
|
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5770
5910
|
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5771
5911
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5772
|
-
description_1 = spaceTrim
|
|
5912
|
+
description_1 = spaceTrim(description_1);
|
|
5773
5913
|
if (description_1 === '') {
|
|
5774
5914
|
description_1 = undefined;
|
|
5775
5915
|
}
|
|
@@ -5853,7 +5993,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5853
5993
|
break;
|
|
5854
5994
|
case 'EXPECT_FORMAT':
|
|
5855
5995
|
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5856
|
-
throw new ParsingError(spaceTrim
|
|
5996
|
+
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 ")));
|
|
5857
5997
|
}
|
|
5858
5998
|
templateJson.expectFormat = command.format;
|
|
5859
5999
|
break;
|
|
@@ -5910,7 +6050,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5910
6050
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
5911
6051
|
}
|
|
5912
6052
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
5913
|
-
throw new ParsingError(spaceTrim
|
|
6053
|
+
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 "); }));
|
|
5914
6054
|
}
|
|
5915
6055
|
templateJson.contentLanguage = language;
|
|
5916
6056
|
}
|
|
@@ -5985,7 +6125,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5985
6125
|
}
|
|
5986
6126
|
});
|
|
5987
6127
|
// =============================================================
|
|
5988
|
-
return pipelineJson;
|
|
6128
|
+
return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
|
|
5989
6129
|
}
|
|
5990
6130
|
/**
|
|
5991
6131
|
* TODO: !!!! Warn if used only sync version
|
|
@@ -6029,7 +6169,9 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
6029
6169
|
case 1:
|
|
6030
6170
|
pipelineJson = _a.sent();
|
|
6031
6171
|
_a.label = 2;
|
|
6032
|
-
case 2:
|
|
6172
|
+
case 2:
|
|
6173
|
+
// Note: No need to use `$asDeeplyFrozenSerializableJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
|
|
6174
|
+
return [2 /*return*/, pipelineJson];
|
|
6033
6175
|
}
|
|
6034
6176
|
});
|
|
6035
6177
|
});
|
|
@@ -6040,22 +6182,6 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
6040
6182
|
* TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
|
|
6041
6183
|
*/
|
|
6042
6184
|
|
|
6043
|
-
/**
|
|
6044
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
6045
|
-
*
|
|
6046
|
-
* @public exported from `@promptbook/core`
|
|
6047
|
-
*/
|
|
6048
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
6049
|
-
__extends(CollectionError, _super);
|
|
6050
|
-
function CollectionError(message) {
|
|
6051
|
-
var _this = _super.call(this, message) || this;
|
|
6052
|
-
_this.name = 'CollectionError';
|
|
6053
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
6054
|
-
return _this;
|
|
6055
|
-
}
|
|
6056
|
-
return CollectionError;
|
|
6057
|
-
}(Error));
|
|
6058
|
-
|
|
6059
6185
|
/**
|
|
6060
6186
|
* Checks if the file exists
|
|
6061
6187
|
*
|
|
@@ -6319,7 +6445,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6319
6445
|
// TODO: !! Implement;
|
|
6320
6446
|
// TODO: [🌗]
|
|
6321
6447
|
}
|
|
6322
|
-
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ?
|
|
6448
|
+
_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;
|
|
6323
6449
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
6324
6450
|
var fileNames, collection, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
6325
6451
|
var e_1, _a;
|
|
@@ -6412,7 +6538,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6412
6538
|
}
|
|
6413
6539
|
else {
|
|
6414
6540
|
existing = collection.get(pipeline.pipelineUrl);
|
|
6415
|
-
throw new
|
|
6541
|
+
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 ")));
|
|
6416
6542
|
}
|
|
6417
6543
|
}
|
|
6418
6544
|
}
|
|
@@ -6422,7 +6548,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6422
6548
|
if (!(error_1 instanceof Error)) {
|
|
6423
6549
|
throw error_1;
|
|
6424
6550
|
}
|
|
6425
|
-
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 "); });
|
|
6551
|
+
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 "); });
|
|
6426
6552
|
if (isCrashedOnError) {
|
|
6427
6553
|
throw new CollectionError(wrappedErrorMessage);
|
|
6428
6554
|
}
|
|
@@ -6478,6 +6604,39 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6478
6604
|
* TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
|
|
6479
6605
|
*/
|
|
6480
6606
|
|
|
6607
|
+
/**
|
|
6608
|
+
* Tests if the value is [🚉] serializable as JSON
|
|
6609
|
+
*
|
|
6610
|
+
* - Almost all primitives are serializable BUT:
|
|
6611
|
+
* - `undefined` is not serializable
|
|
6612
|
+
* - `NaN` is not serializable
|
|
6613
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
6614
|
+
* - Functions are not serializable
|
|
6615
|
+
* - Circular references are not serializable
|
|
6616
|
+
* - `Date` objects are not serializable
|
|
6617
|
+
* - `Map` and `Set` objects are not serializable
|
|
6618
|
+
* - `RegExp` objects are not serializable
|
|
6619
|
+
* - `Error` objects are not serializable
|
|
6620
|
+
* - `Symbol` objects are not serializable
|
|
6621
|
+
* - And much more...
|
|
6622
|
+
*
|
|
6623
|
+
*
|
|
6624
|
+
* @public exported from `@promptbook/utils`
|
|
6625
|
+
*/
|
|
6626
|
+
function isSerializableAsJson(value) {
|
|
6627
|
+
try {
|
|
6628
|
+
checkSerializableAsJson('', value);
|
|
6629
|
+
return true;
|
|
6630
|
+
}
|
|
6631
|
+
catch (error) {
|
|
6632
|
+
return false;
|
|
6633
|
+
}
|
|
6634
|
+
}
|
|
6635
|
+
/**
|
|
6636
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
6637
|
+
* TODO: [🧠][💺] Can be done this on type-level?
|
|
6638
|
+
*/
|
|
6639
|
+
|
|
6481
6640
|
/**
|
|
6482
6641
|
* Stringify the PipelineJson with proper formatting
|
|
6483
6642
|
*
|
|
@@ -6487,6 +6646,9 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6487
6646
|
* @public exported from `@promptbook/core`
|
|
6488
6647
|
*/
|
|
6489
6648
|
function stringifyPipelineJson(pipeline) {
|
|
6649
|
+
if (!isSerializableAsJson(pipeline)) {
|
|
6650
|
+
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 "));
|
|
6651
|
+
}
|
|
6490
6652
|
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
6491
6653
|
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
6492
6654
|
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
@@ -6535,7 +6697,7 @@ function usageToHuman(usage) {
|
|
|
6535
6697
|
};
|
|
6536
6698
|
report += '\n' + "- Cost ".concat(uncertainNumberToHuman(usage.price), " USD");
|
|
6537
6699
|
report += '\n' + "- Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time");
|
|
6538
|
-
return spaceTrim(report);
|
|
6700
|
+
return spaceTrim$1(report);
|
|
6539
6701
|
}
|
|
6540
6702
|
/**
|
|
6541
6703
|
* TODO: Use "$1" not "1 USD"
|
|
@@ -6612,6 +6774,9 @@ var FilesStorage = /** @class */ (function () {
|
|
|
6612
6774
|
switch (_a.label) {
|
|
6613
6775
|
case 0:
|
|
6614
6776
|
filename = this.getFilenameForKey(key);
|
|
6777
|
+
if (!isSerializableAsJson(value)) {
|
|
6778
|
+
throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
|
|
6779
|
+
}
|
|
6615
6780
|
fileContent = stringifyPipelineJson(value);
|
|
6616
6781
|
return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
|
|
6617
6782
|
case 1:
|
|
@@ -6656,14 +6821,11 @@ var FilesStorage = /** @class */ (function () {
|
|
|
6656
6821
|
*
|
|
6657
6822
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
6658
6823
|
*
|
|
6659
|
-
*
|
|
6824
|
+
* @private internal function of `$Register`
|
|
6660
6825
|
*/
|
|
6661
6826
|
function $getGlobalScope() {
|
|
6662
6827
|
return Function('return this')();
|
|
6663
6828
|
}
|
|
6664
|
-
/***
|
|
6665
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
6666
|
-
*/
|
|
6667
6829
|
|
|
6668
6830
|
/**
|
|
6669
6831
|
* Register is @@@
|
|
@@ -6694,13 +6856,10 @@ var $Register = /** @class */ (function () {
|
|
|
6694
6856
|
var packageName = registered.packageName, className = registered.className;
|
|
6695
6857
|
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
6696
6858
|
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
6697
|
-
// TODO: !!!!!! Global IS_VERBOSE mode
|
|
6698
6859
|
if (!existingRegistration) {
|
|
6699
|
-
console.warn("[\uD83D\uDCE6] Registering `".concat(packageName, ".").concat(className, "` to `").concat(this.storageName, "`"));
|
|
6700
6860
|
this.storage.push(registered);
|
|
6701
6861
|
}
|
|
6702
6862
|
else {
|
|
6703
|
-
console.warn("[\uD83D\uDCE6] Re-registering `".concat(packageName, ".").concat(className, "` to `").concat(this.storageName, "`"));
|
|
6704
6863
|
this.storage[existingRegistrationIndex] = registered;
|
|
6705
6864
|
}
|
|
6706
6865
|
};
|
|
@@ -6791,7 +6950,7 @@ function $registeredLlmToolsMessage() {
|
|
|
6791
6950
|
});
|
|
6792
6951
|
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
|
|
6793
6952
|
});
|
|
6794
|
-
return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
6953
|
+
return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
6795
6954
|
.map(function (_a, i) {
|
|
6796
6955
|
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
|
|
6797
6956
|
var more;
|
|
@@ -6830,7 +6989,7 @@ function $registeredLlmToolsMessage() {
|
|
|
6830
6989
|
*/
|
|
6831
6990
|
function createLlmToolsFromConfiguration(configuration, options) {
|
|
6832
6991
|
if (options === void 0) { options = {}; }
|
|
6833
|
-
var _a = options.isVerbose, isVerbose = _a === void 0 ?
|
|
6992
|
+
var _a = options.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
6834
6993
|
var llmTools = configuration.map(function (llmConfiguration) {
|
|
6835
6994
|
var registeredItem = $llmToolsRegister
|
|
6836
6995
|
.list()
|
|
@@ -6839,7 +6998,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
6839
6998
|
return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
|
|
6840
6999
|
});
|
|
6841
7000
|
if (registeredItem === undefined) {
|
|
6842
|
-
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 "); }));
|
|
7001
|
+
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 "); }));
|
|
6843
7002
|
}
|
|
6844
7003
|
return registeredItem(__assign({ isVerbose: isVerbose }, llmConfiguration.options));
|
|
6845
7004
|
});
|
|
@@ -6910,7 +7069,7 @@ function createLlmToolsFromEnv(options) {
|
|
|
6910
7069
|
var configuration = createLlmToolsFromConfigurationFromEnv();
|
|
6911
7070
|
if (configuration.length === 0) {
|
|
6912
7071
|
// TODO: [🥃]
|
|
6913
|
-
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 "); }));
|
|
7072
|
+
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 "); }));
|
|
6914
7073
|
}
|
|
6915
7074
|
return createLlmToolsFromConfiguration(configuration, options);
|
|
6916
7075
|
}
|
|
@@ -7136,17 +7295,17 @@ function getLlmToolsForCli(options) {
|
|
|
7136
7295
|
function initializeMakeCommand(program) {
|
|
7137
7296
|
var _this = this;
|
|
7138
7297
|
var makeCommand = program.command('make');
|
|
7139
|
-
makeCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
|
|
7298
|
+
makeCommand.description(spaceTrim$1("\n Makes a new pipeline collection in given folder\n "));
|
|
7140
7299
|
makeCommand.argument('[path]',
|
|
7141
7300
|
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
7142
7301
|
'Path to promptbook directory', './promptbook-collection');
|
|
7143
7302
|
makeCommand.option('--project-name', "Name of the project for whom collection is", 'Untitled Promptbook project');
|
|
7144
|
-
makeCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳🌈] */);
|
|
7303
|
+
makeCommand.option('-f, --format <format>', spaceTrim$1("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳🌈] */);
|
|
7145
7304
|
makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
|
|
7146
7305
|
makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
|
|
7147
7306
|
makeCommand.option('--reload-cache', "Use LLM models even if cached ", false);
|
|
7148
7307
|
makeCommand.option('--verbose', "Is verbose", false);
|
|
7149
|
-
makeCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), PIPELINE_COLLECTION_BASE_FILENAME);
|
|
7308
|
+
makeCommand.option('-o, --out-file <path>', spaceTrim$1("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), PIPELINE_COLLECTION_BASE_FILENAME);
|
|
7150
7309
|
makeCommand.action(function (path, _a) {
|
|
7151
7310
|
var projectName = _a.projectName, format = _a.format, validation = _a.validation, reloadCache = _a.reloadCache, verbose = _a.verbose, outFile = _a.outFile;
|
|
7152
7311
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -7251,7 +7410,7 @@ function initializeMakeCommand(program) {
|
|
|
7251
7410
|
if (lastChar !== ']') {
|
|
7252
7411
|
throw new UnexpectedError("Last character of serialized collection should be \"]\" not \"".concat(lastChar, "\""));
|
|
7253
7412
|
}
|
|
7254
|
-
return spaceTrim(collectionJsonString.substring(1, collectionJsonString.length - 1));
|
|
7413
|
+
return spaceTrim$1(collectionJsonString.substring(1, collectionJsonString.length - 1));
|
|
7255
7414
|
})();
|
|
7256
7415
|
saveFile = function (extension, content) { return __awaiter(_this, void 0, void 0, function () {
|
|
7257
7416
|
var filePath;
|
|
@@ -7285,14 +7444,14 @@ function initializeMakeCommand(program) {
|
|
|
7285
7444
|
case 19:
|
|
7286
7445
|
if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 21];
|
|
7287
7446
|
formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
|
|
7288
|
-
return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
|
|
7447
|
+
return [4 /*yield*/, saveFile('js', spaceTrim$1(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
|
|
7289
7448
|
case 20:
|
|
7290
7449
|
(_f.sent()) + '\n';
|
|
7291
7450
|
_f.label = 21;
|
|
7292
7451
|
case 21:
|
|
7293
7452
|
if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 23];
|
|
7294
7453
|
formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
|
|
7295
|
-
return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
|
|
7454
|
+
return [4 /*yield*/, saveFile('ts', spaceTrim$1(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
|
|
7296
7455
|
case 22:
|
|
7297
7456
|
_f.sent();
|
|
7298
7457
|
_f.label = 23;
|
|
@@ -7330,7 +7489,7 @@ function addAutoGeneratedSection(content, options) {
|
|
|
7330
7489
|
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
7331
7490
|
var sectionMatch = content.match(sectionRegex);
|
|
7332
7491
|
if (sectionMatch) {
|
|
7333
|
-
return content.replace(sectionRegex, spaceTrim
|
|
7492
|
+
return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
7334
7493
|
}
|
|
7335
7494
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
7336
7495
|
if (!placeForSection) {
|
|
@@ -7433,7 +7592,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
7433
7592
|
}
|
|
7434
7593
|
return normalizeTo_camelCase('template-' + titleToName(template.title));
|
|
7435
7594
|
};
|
|
7436
|
-
var promptbookMermaid = spaceTrim
|
|
7595
|
+
var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.promptTemplates
|
|
7437
7596
|
.flatMap(function (_a) {
|
|
7438
7597
|
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
7439
7598
|
return __spreadArray([
|
|
@@ -7491,7 +7650,7 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
7491
7650
|
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
7492
7651
|
},
|
|
7493
7652
|
});
|
|
7494
|
-
promptbookMermaidBlock = spaceTrim
|
|
7653
|
+
promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
7495
7654
|
pipelineString = addAutoGeneratedSection(pipelineString, {
|
|
7496
7655
|
sectionName: 'Graph',
|
|
7497
7656
|
sectionContent: promptbookMermaidBlock,
|
|
@@ -7519,7 +7678,7 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
7519
7678
|
function initializePrettifyCommand(program) {
|
|
7520
7679
|
var _this = this;
|
|
7521
7680
|
var prettifyCommand = program.command('prettify');
|
|
7522
|
-
prettifyCommand.description(spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
|
|
7681
|
+
prettifyCommand.description(spaceTrim$1("\n Iterates over promptbooks and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
|
|
7523
7682
|
prettifyCommand.argument('<filesGlob>',
|
|
7524
7683
|
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
7525
7684
|
'Promptbooks to prettify as glob pattern');
|
|
@@ -7611,13 +7770,13 @@ function promptbookCli() {
|
|
|
7611
7770
|
var program;
|
|
7612
7771
|
return __generator(this, function (_a) {
|
|
7613
7772
|
if (!$isRunningInNode()) {
|
|
7614
|
-
throw new EnvironmentMismatchError(spaceTrim
|
|
7773
|
+
throw new EnvironmentMismatchError(spaceTrim("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
|
|
7615
7774
|
}
|
|
7616
7775
|
program = new commander.Command();
|
|
7617
7776
|
program.name('promptbook');
|
|
7618
7777
|
program.alias('ptbk');
|
|
7619
7778
|
program.version(PROMPTBOOK_VERSION);
|
|
7620
|
-
program.description(spaceTrim
|
|
7779
|
+
program.description(spaceTrim("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
|
|
7621
7780
|
initializeAboutCommand(program);
|
|
7622
7781
|
initializeHelloCommand(program);
|
|
7623
7782
|
initializeMakeCommand(program);
|
|
@@ -7747,13 +7906,13 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
7747
7906
|
socket.emit('listModels-request', {
|
|
7748
7907
|
isAnonymous: true,
|
|
7749
7908
|
llmToolsConfiguration: this.options.llmToolsConfiguration,
|
|
7750
|
-
});
|
|
7909
|
+
} /* <- TODO: [🤛] */);
|
|
7751
7910
|
}
|
|
7752
7911
|
else {
|
|
7753
7912
|
socket.emit('listModels-request', {
|
|
7754
7913
|
isAnonymous: false,
|
|
7755
7914
|
clientId: this.options.clientId,
|
|
7756
|
-
});
|
|
7915
|
+
} /* <- TODO: [🤛] */);
|
|
7757
7916
|
}
|
|
7758
7917
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7759
7918
|
socket.on('listModels-response', function (response) {
|
|
@@ -7761,7 +7920,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
7761
7920
|
socket.disconnect();
|
|
7762
7921
|
});
|
|
7763
7922
|
socket.on('error', function (error) {
|
|
7764
|
-
reject(
|
|
7923
|
+
reject(deserializeError(error));
|
|
7765
7924
|
socket.disconnect();
|
|
7766
7925
|
});
|
|
7767
7926
|
})];
|
|
@@ -7840,16 +7999,14 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
7840
7999
|
isAnonymous: true,
|
|
7841
8000
|
llmToolsConfiguration: this.options.llmToolsConfiguration,
|
|
7842
8001
|
prompt: prompt,
|
|
7843
|
-
|
|
7844
|
-
});
|
|
8002
|
+
} /* <- TODO: [🤛] */);
|
|
7845
8003
|
}
|
|
7846
8004
|
else {
|
|
7847
8005
|
socket.emit('prompt-request', {
|
|
7848
8006
|
isAnonymous: false,
|
|
7849
8007
|
clientId: this.options.clientId,
|
|
7850
8008
|
prompt: prompt,
|
|
7851
|
-
|
|
7852
|
-
});
|
|
8009
|
+
} /* <- TODO: [🤛] */);
|
|
7853
8010
|
}
|
|
7854
8011
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7855
8012
|
socket.on('prompt-response', function (response) {
|
|
@@ -7857,7 +8014,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
7857
8014
|
socket.disconnect();
|
|
7858
8015
|
});
|
|
7859
8016
|
socket.on('error', function (error) {
|
|
7860
|
-
reject(
|
|
8017
|
+
reject(deserializeError(error));
|
|
7861
8018
|
socket.disconnect();
|
|
7862
8019
|
});
|
|
7863
8020
|
})];
|
|
@@ -7872,6 +8029,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
7872
8029
|
return RemoteLlmExecutionTools;
|
|
7873
8030
|
}());
|
|
7874
8031
|
/**
|
|
8032
|
+
* TODO: Maybe use `$asDeeplyFrozenSerializableJson`
|
|
7875
8033
|
* TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
|
|
7876
8034
|
* TODO: [🍓] Allow to list compatible models with each variant
|
|
7877
8035
|
* TODO: [🗯] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
|
|
@@ -7906,7 +8064,7 @@ function computeUsage(value) {
|
|
|
7906
8064
|
* @see https://docs.anthropic.com/en/docs/models-overview
|
|
7907
8065
|
* @public exported from `@promptbook/anthropic-claude`
|
|
7908
8066
|
*/
|
|
7909
|
-
var ANTHROPIC_CLAUDE_MODELS = [
|
|
8067
|
+
var ANTHROPIC_CLAUDE_MODELS = $asDeeplyFrozenSerializableJson('ANTHROPIC_CLAUDE_MODELS', [
|
|
7910
8068
|
{
|
|
7911
8069
|
modelVariant: 'CHAT',
|
|
7912
8070
|
modelTitle: 'Claude 3.5 Sonnet',
|
|
@@ -7971,7 +8129,7 @@ var ANTHROPIC_CLAUDE_MODELS = [
|
|
|
7971
8129
|
},
|
|
7972
8130
|
},
|
|
7973
8131
|
// TODO: !!! Claude 1 and 2 has also completion versions - ask Hoagy
|
|
7974
|
-
];
|
|
8132
|
+
]);
|
|
7975
8133
|
/**
|
|
7976
8134
|
* Note: [🤖] Add models of new variant
|
|
7977
8135
|
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
@@ -8182,7 +8340,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8182
8340
|
// eslint-disable-next-line prefer-const
|
|
8183
8341
|
complete = getCurrentIsoDate();
|
|
8184
8342
|
usage = computeAnthropicClaudeUsage(content, '', rawResponse);
|
|
8185
|
-
return [2 /*return*/, {
|
|
8343
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('AnthropicClaudeExecutionTools ChatPromptResult', {
|
|
8186
8344
|
content: resultContent,
|
|
8187
8345
|
modelName: rawResponse.model,
|
|
8188
8346
|
timing: {
|
|
@@ -8194,7 +8352,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8194
8352
|
rawRequest: rawRequest,
|
|
8195
8353
|
rawResponse: rawResponse,
|
|
8196
8354
|
// <- [🗯]
|
|
8197
|
-
}];
|
|
8355
|
+
})];
|
|
8198
8356
|
}
|
|
8199
8357
|
});
|
|
8200
8358
|
});
|
|
@@ -8203,7 +8361,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8203
8361
|
TODO: [👏]
|
|
8204
8362
|
public async callCompletionModel(
|
|
8205
8363
|
prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>,
|
|
8206
|
-
): Promise<
|
|
8364
|
+
): Promise<CompletionPromptResult> {
|
|
8207
8365
|
|
|
8208
8366
|
if (this.options.isVerbose) {
|
|
8209
8367
|
console.info('🖋 Anthropic Claude callCompletionModel call');
|
|
@@ -8256,7 +8414,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8256
8414
|
|
|
8257
8415
|
|
|
8258
8416
|
|
|
8259
|
-
return {
|
|
8417
|
+
return $asDeeplyFrozenSerializableJson('AnthropicClaudeExecutionTools CompletionPromptResult',{
|
|
8260
8418
|
content: resultContent,
|
|
8261
8419
|
modelName: rawResponse.model || model,
|
|
8262
8420
|
timing: {
|
|
@@ -8266,7 +8424,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8266
8424
|
usage,
|
|
8267
8425
|
rawResponse,
|
|
8268
8426
|
// <- [🗯]
|
|
8269
|
-
};
|
|
8427
|
+
});
|
|
8270
8428
|
}
|
|
8271
8429
|
*/
|
|
8272
8430
|
// <- Note: [🤖] callXxxModel
|
|
@@ -8279,7 +8437,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8279
8437
|
return modelName.startsWith(defaultModelName);
|
|
8280
8438
|
});
|
|
8281
8439
|
if (model === undefined) {
|
|
8282
|
-
throw new UnexpectedError(spaceTrim(function (block) {
|
|
8440
|
+
throw new UnexpectedError(spaceTrim$1(function (block) {
|
|
8283
8441
|
return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(ANTHROPIC_CLAUDE_MODELS.map(function (_a) {
|
|
8284
8442
|
var modelName = _a.modelName;
|
|
8285
8443
|
return "- \"".concat(modelName, "\"");
|
|
@@ -8388,7 +8546,7 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
8388
8546
|
else if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ||
|
|
8389
8547
|
typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ||
|
|
8390
8548
|
typeof env.AZUREOPENAI_API_KEY === 'string') {
|
|
8391
|
-
throw new Error(spaceTrim("\n You must provide all of the following environment variables:\n \n - AZUREOPENAI_RESOURCE_NAME (".concat(typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_DEPLOYMENT_NAME (").concat(typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_API_KEY (").concat(typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined', ") \n ")));
|
|
8549
|
+
throw new Error(spaceTrim$1("\n You must provide all of the following environment variables:\n \n - AZUREOPENAI_RESOURCE_NAME (".concat(typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_DEPLOYMENT_NAME (").concat(typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_API_KEY (").concat(typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined', ") \n ")));
|
|
8392
8550
|
}
|
|
8393
8551
|
return null;
|
|
8394
8552
|
},
|
|
@@ -8403,7 +8561,7 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
8403
8561
|
* @see https://openai.com/api/pricing/
|
|
8404
8562
|
* @public exported from `@promptbook/openai`
|
|
8405
8563
|
*/
|
|
8406
|
-
var OPENAI_MODELS = [
|
|
8564
|
+
var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
|
|
8407
8565
|
/*/
|
|
8408
8566
|
{
|
|
8409
8567
|
modelTitle: 'dall-e-3',
|
|
@@ -8731,7 +8889,7 @@ var OPENAI_MODELS = [
|
|
|
8731
8889
|
},
|
|
8732
8890
|
},
|
|
8733
8891
|
/**/
|
|
8734
|
-
];
|
|
8892
|
+
]);
|
|
8735
8893
|
/**
|
|
8736
8894
|
* Note: [🤖] Add models of new variant
|
|
8737
8895
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
@@ -8899,7 +9057,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
8899
9057
|
input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
|
|
8900
9058
|
output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
|
|
8901
9059
|
};
|
|
8902
|
-
return [2 /*return*/, {
|
|
9060
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('AzureOpenAiExecutionTools ChatPromptResult', {
|
|
8903
9061
|
content: resultContent,
|
|
8904
9062
|
modelName: modelName,
|
|
8905
9063
|
timing: {
|
|
@@ -8909,9 +9067,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
8909
9067
|
usage: usage,
|
|
8910
9068
|
rawPromptContent: rawPromptContent,
|
|
8911
9069
|
rawRequest: rawRequest,
|
|
8912
|
-
rawResponse: rawResponse,
|
|
9070
|
+
rawResponse: __assign(__assign({}, rawResponse), { created: rawResponse.created.toISOString() }),
|
|
8913
9071
|
// <- [🗯]
|
|
8914
|
-
}];
|
|
9072
|
+
})];
|
|
8915
9073
|
case 4:
|
|
8916
9074
|
error_1 = _c.sent();
|
|
8917
9075
|
throw this.transformAzureError(error_1);
|
|
@@ -8986,7 +9144,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
8986
9144
|
input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
|
|
8987
9145
|
output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
|
|
8988
9146
|
};
|
|
8989
|
-
return [2 /*return*/, {
|
|
9147
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('AzureOpenAiExecutionTools CompletionPromptResult', {
|
|
8990
9148
|
content: resultContent,
|
|
8991
9149
|
modelName: modelName,
|
|
8992
9150
|
timing: {
|
|
@@ -8996,9 +9154,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
8996
9154
|
usage: usage,
|
|
8997
9155
|
rawPromptContent: rawPromptContent,
|
|
8998
9156
|
rawRequest: rawRequest,
|
|
8999
|
-
rawResponse: rawResponse,
|
|
9157
|
+
rawResponse: __assign(__assign({}, rawResponse), { created: rawResponse.created.toISOString() }),
|
|
9000
9158
|
// <- [🗯]
|
|
9001
|
-
}];
|
|
9159
|
+
})];
|
|
9002
9160
|
case 4:
|
|
9003
9161
|
error_2 = _c.sent();
|
|
9004
9162
|
throw this.transformAzureError(error_2);
|
|
@@ -9012,11 +9170,14 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
9012
9170
|
* Changes Azure error (which is not propper Error but object) to propper Error
|
|
9013
9171
|
*/
|
|
9014
9172
|
AzureOpenAiExecutionTools.prototype.transformAzureError = function (azureError) {
|
|
9173
|
+
if (azureError instanceof UnexpectedError) {
|
|
9174
|
+
return azureError;
|
|
9175
|
+
}
|
|
9015
9176
|
if (typeof azureError !== 'object' || azureError === null) {
|
|
9016
9177
|
return new PipelineExecutionError("Unknown Azure OpenAI error");
|
|
9017
9178
|
}
|
|
9018
9179
|
var code = azureError.code, message = azureError.message;
|
|
9019
|
-
return new PipelineExecutionError("".concat(code, ": ").concat(message));
|
|
9180
|
+
return new PipelineExecutionError("".concat(code || '(No Azure error code)', ": ").concat(message));
|
|
9020
9181
|
};
|
|
9021
9182
|
return AzureOpenAiExecutionTools;
|
|
9022
9183
|
}());
|
|
@@ -9278,7 +9439,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
9278
9439
|
if (resultContent === null) {
|
|
9279
9440
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
9280
9441
|
}
|
|
9281
|
-
return [2 /*return*/, {
|
|
9442
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools ChatPromptResult', {
|
|
9282
9443
|
content: resultContent,
|
|
9283
9444
|
modelName: rawResponse.model || modelName,
|
|
9284
9445
|
timing: {
|
|
@@ -9290,7 +9451,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
9290
9451
|
rawRequest: rawRequest,
|
|
9291
9452
|
rawResponse: rawResponse,
|
|
9292
9453
|
// <- [🗯]
|
|
9293
|
-
}];
|
|
9454
|
+
})];
|
|
9294
9455
|
}
|
|
9295
9456
|
});
|
|
9296
9457
|
});
|
|
@@ -9347,7 +9508,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
9347
9508
|
// eslint-disable-next-line prefer-const
|
|
9348
9509
|
complete = getCurrentIsoDate();
|
|
9349
9510
|
usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
|
|
9350
|
-
return [2 /*return*/, {
|
|
9511
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools CompletionPromptResult', {
|
|
9351
9512
|
content: resultContent,
|
|
9352
9513
|
modelName: rawResponse.model || modelName,
|
|
9353
9514
|
timing: {
|
|
@@ -9359,7 +9520,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
9359
9520
|
rawRequest: rawRequest,
|
|
9360
9521
|
rawResponse: rawResponse,
|
|
9361
9522
|
// <- [🗯]
|
|
9362
|
-
}];
|
|
9523
|
+
})];
|
|
9363
9524
|
}
|
|
9364
9525
|
});
|
|
9365
9526
|
});
|
|
@@ -9407,7 +9568,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
9407
9568
|
// eslint-disable-next-line prefer-const
|
|
9408
9569
|
complete = getCurrentIsoDate();
|
|
9409
9570
|
usage = computeOpenAiUsage(content, '', rawResponse);
|
|
9410
|
-
return [2 /*return*/, {
|
|
9571
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools EmbeddingPromptResult', {
|
|
9411
9572
|
content: resultContent,
|
|
9412
9573
|
modelName: rawResponse.model || modelName,
|
|
9413
9574
|
timing: {
|
|
@@ -9419,7 +9580,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
9419
9580
|
rawRequest: rawRequest,
|
|
9420
9581
|
rawResponse: rawResponse,
|
|
9421
9582
|
// <- [🗯]
|
|
9422
|
-
}];
|
|
9583
|
+
})];
|
|
9423
9584
|
}
|
|
9424
9585
|
});
|
|
9425
9586
|
});
|
|
@@ -9434,7 +9595,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
9434
9595
|
return modelName === defaultModelName;
|
|
9435
9596
|
});
|
|
9436
9597
|
if (model === undefined) {
|
|
9437
|
-
throw new UnexpectedError(spaceTrim(function (block) {
|
|
9598
|
+
throw new UnexpectedError(spaceTrim$1(function (block) {
|
|
9438
9599
|
return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(OPENAI_MODELS.map(function (_a) {
|
|
9439
9600
|
var modelName = _a.modelName;
|
|
9440
9601
|
return "- \"".concat(modelName, "\"");
|