@promptbook/node 0.66.0 → 0.67.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +431 -274
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -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/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 +4 -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/personas/preparePersona.d.ts +1 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +5 -5
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +3 -1
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +7 -7
- package/esm/typings/src/types/ScriptLanguage.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionPromptReportJson.d.ts +24 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -20
- package/esm/typings/src/types/typeAliases.d.ts +7 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +1 -4
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +17 -0
- package/esm/typings/src/utils/{deepFreeze.d.ts → serialization/$deepFreeze.d.ts} +0 -10
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +27 -0
- package/esm/typings/src/utils/{clonePipeline.d.ts → serialization/clonePipeline.d.ts} +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +24 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +369 -212
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/errors/VersionMismatchError.d.ts +0 -10
- /package/esm/typings/src/utils/{deepClone.d.ts → serialization/deepClone.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import { stat, access, constants, readdir, readFile, writeFile, mkdir, unlink } from 'fs/promises';
|
|
3
3
|
import { join as join$1, dirname } from 'path';
|
|
4
|
-
import spaceTrim, { spaceTrim
|
|
4
|
+
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
5
5
|
import { format } from 'prettier';
|
|
6
6
|
import parserHtml from 'prettier/parser-html';
|
|
7
7
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
@@ -13,7 +13,7 @@ import * as dotenv from 'dotenv';
|
|
|
13
13
|
/**
|
|
14
14
|
* The version of the Promptbook library
|
|
15
15
|
*/
|
|
16
|
-
var PROMPTBOOK_VERSION = '0.
|
|
16
|
+
var PROMPTBOOK_VERSION = '0.67.0-0';
|
|
17
17
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
18
18
|
|
|
19
19
|
/*! *****************************************************************************
|
|
@@ -135,6 +135,26 @@ function __spreadArray(to, from, pack) {
|
|
|
135
135
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Returns the same value that is passed as argument.
|
|
140
|
+
* No side effects.
|
|
141
|
+
*
|
|
142
|
+
* Note: It can be usefull for:
|
|
143
|
+
*
|
|
144
|
+
* 1) Leveling indentation
|
|
145
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
146
|
+
*
|
|
147
|
+
* @param value any values
|
|
148
|
+
* @returns the same values
|
|
149
|
+
* @private within the repository
|
|
150
|
+
*/
|
|
151
|
+
function just(value) {
|
|
152
|
+
if (value === undefined) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
|
|
138
158
|
/**
|
|
139
159
|
* @@@
|
|
140
160
|
*
|
|
@@ -165,42 +185,169 @@ function $deepFreeze(objectValue) {
|
|
|
165
185
|
}
|
|
166
186
|
return Object.freeze(objectValue);
|
|
167
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
194
|
+
*
|
|
195
|
+
* @public exported from `@promptbook/core`
|
|
196
|
+
*/
|
|
197
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
198
|
+
__extends(UnexpectedError, _super);
|
|
199
|
+
function UnexpectedError(message) {
|
|
200
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
201
|
+
_this.name = 'UnexpectedError';
|
|
202
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
203
|
+
return _this;
|
|
204
|
+
}
|
|
205
|
+
return UnexpectedError;
|
|
206
|
+
}(Error));
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
210
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
211
|
+
*
|
|
212
|
+
* - Almost all primitives are serializable BUT:
|
|
213
|
+
* - `undefined` is not serializable
|
|
214
|
+
* - `NaN` is not serializable
|
|
215
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
216
|
+
* - Functions are not serializable
|
|
217
|
+
* - Circular references are not serializable
|
|
218
|
+
* - `Date` objects are not serializable
|
|
219
|
+
* - `Map` and `Set` objects are not serializable
|
|
220
|
+
* - `RegExp` objects are not serializable
|
|
221
|
+
* - `Error` objects are not serializable
|
|
222
|
+
* - `Symbol` objects are not serializable
|
|
223
|
+
* - And much more...
|
|
224
|
+
*
|
|
225
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
226
|
+
* @public exported from `@promptbook/utils`
|
|
227
|
+
*/
|
|
228
|
+
function checkSerializableAsJson(name, value) {
|
|
229
|
+
var e_1, _a;
|
|
230
|
+
if (value === undefined) {
|
|
231
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
232
|
+
}
|
|
233
|
+
else if (value === null) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
else if (typeof value === 'boolean') {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
else if (typeof value === 'string') {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
else if (typeof value === 'symbol') {
|
|
246
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
247
|
+
}
|
|
248
|
+
else if (typeof value === 'function') {
|
|
249
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
250
|
+
}
|
|
251
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
252
|
+
for (var i = 0; i < value.length; i++) {
|
|
253
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (typeof value === 'object') {
|
|
257
|
+
if (value instanceof Date) {
|
|
258
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
259
|
+
}
|
|
260
|
+
else if (value instanceof Map) {
|
|
261
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
262
|
+
}
|
|
263
|
+
else if (value instanceof Set) {
|
|
264
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
265
|
+
}
|
|
266
|
+
else if (value instanceof RegExp) {
|
|
267
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
268
|
+
}
|
|
269
|
+
else if (value instanceof Error) {
|
|
270
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
try {
|
|
274
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
275
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
276
|
+
if (subValue === undefined) {
|
|
277
|
+
// Note: undefined in object is serializable - it is just omited
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
284
|
+
finally {
|
|
285
|
+
try {
|
|
286
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
287
|
+
}
|
|
288
|
+
finally { if (e_1) throw e_1.error; }
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
if (!(error instanceof Error)) {
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
298
|
+
}
|
|
299
|
+
/*
|
|
300
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
301
|
+
const seen = new Set();
|
|
302
|
+
const stack = [{ value }];
|
|
303
|
+
while (stack.length > 0) {
|
|
304
|
+
const { value } = stack.pop()!;
|
|
305
|
+
if (typeof value === 'object' && value !== null) {
|
|
306
|
+
if (seen.has(value)) {
|
|
307
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
308
|
+
}
|
|
309
|
+
seen.add(value);
|
|
310
|
+
if (Array.isArray(value)) {
|
|
311
|
+
stack.push(...value.map((value) => ({ value })));
|
|
312
|
+
} else {
|
|
313
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
*/
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
327
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
328
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
329
|
+
*/
|
|
330
|
+
|
|
168
331
|
/**
|
|
169
332
|
* @@@
|
|
170
333
|
* @@@
|
|
171
334
|
*
|
|
172
335
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
173
336
|
*
|
|
337
|
+
* @param name - Name of the object for debugging purposes
|
|
338
|
+
* @param objectValue - Object to be deeply frozen
|
|
174
339
|
* @returns The same object as the input, but deeply frozen
|
|
175
340
|
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
176
341
|
*/
|
|
177
|
-
function
|
|
342
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
343
|
+
checkSerializableAsJson(name, objectValue);
|
|
178
344
|
return $deepFreeze(objectValue);
|
|
179
345
|
}
|
|
180
346
|
/**
|
|
347
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
181
348
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
182
349
|
*/
|
|
183
350
|
|
|
184
|
-
/**
|
|
185
|
-
* Returns the same value that is passed as argument.
|
|
186
|
-
* No side effects.
|
|
187
|
-
*
|
|
188
|
-
* Note: It can be usefull for:
|
|
189
|
-
*
|
|
190
|
-
* 1) Leveling indentation
|
|
191
|
-
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
192
|
-
*
|
|
193
|
-
* @param value any values
|
|
194
|
-
* @returns the same values
|
|
195
|
-
* @private within the repository
|
|
196
|
-
*/
|
|
197
|
-
function just(value) {
|
|
198
|
-
if (value === undefined) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
return value;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
351
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
205
352
|
/**
|
|
206
353
|
* The maximum number of iterations for a loops
|
|
@@ -243,7 +390,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
243
390
|
*
|
|
244
391
|
* @public exported from `@promptbook/core`
|
|
245
392
|
*/
|
|
246
|
-
var RESERVED_PARAMETER_NAMES = $
|
|
393
|
+
var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
247
394
|
'content',
|
|
248
395
|
'context',
|
|
249
396
|
'knowledge',
|
|
@@ -486,7 +633,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
486
633
|
pipelineString += '\n\n';
|
|
487
634
|
pipelineString += '```' + contentLanguage;
|
|
488
635
|
pipelineString += '\n';
|
|
489
|
-
pipelineString += spaceTrim(content);
|
|
636
|
+
pipelineString += spaceTrim$1(content);
|
|
490
637
|
// <- TODO: !!! Escape
|
|
491
638
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
492
639
|
pipelineString += '\n';
|
|
@@ -719,7 +866,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
719
866
|
});
|
|
720
867
|
}
|
|
721
868
|
|
|
722
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.
|
|
869
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.0-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.67.0-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.67.0-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.67.0-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"}];
|
|
723
870
|
|
|
724
871
|
/**
|
|
725
872
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -753,22 +900,6 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
753
900
|
return PipelineLogicError;
|
|
754
901
|
}(Error));
|
|
755
902
|
|
|
756
|
-
/**
|
|
757
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
758
|
-
*
|
|
759
|
-
* @public exported from `@promptbook/core`
|
|
760
|
-
*/
|
|
761
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
762
|
-
__extends(UnexpectedError, _super);
|
|
763
|
-
function UnexpectedError(message) {
|
|
764
|
-
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;
|
|
765
|
-
_this.name = 'UnexpectedError';
|
|
766
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
767
|
-
return _this;
|
|
768
|
-
}
|
|
769
|
-
return UnexpectedError;
|
|
770
|
-
}(Error));
|
|
771
|
-
|
|
772
903
|
/**
|
|
773
904
|
* Tests if given string is valid semantic version
|
|
774
905
|
*
|
|
@@ -954,36 +1085,36 @@ function validatePipeline(pipeline) {
|
|
|
954
1085
|
})();
|
|
955
1086
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
956
1087
|
// <- Note: [🚲]
|
|
957
|
-
throw new PipelineLogicError(spaceTrim
|
|
1088
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
958
1089
|
}
|
|
959
1090
|
if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
|
|
960
1091
|
// <- Note: [🚲]
|
|
961
|
-
throw new PipelineLogicError(spaceTrim
|
|
1092
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
962
1093
|
}
|
|
963
1094
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
964
1095
|
if (!Array.isArray(pipeline.parameters)) {
|
|
965
1096
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
966
|
-
throw new ParsingError(spaceTrim
|
|
1097
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
967
1098
|
}
|
|
968
1099
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
969
1100
|
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
970
1101
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
971
|
-
throw new ParsingError(spaceTrim
|
|
1102
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
972
1103
|
}
|
|
973
1104
|
var _loop_1 = function (parameter) {
|
|
974
1105
|
if (parameter.isInput && parameter.isOutput) {
|
|
975
|
-
throw new PipelineLogicError(spaceTrim
|
|
1106
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
976
1107
|
}
|
|
977
1108
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
978
1109
|
if (!parameter.isInput &&
|
|
979
1110
|
!parameter.isOutput &&
|
|
980
1111
|
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
981
|
-
throw new PipelineLogicError(spaceTrim
|
|
1112
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
982
1113
|
}
|
|
983
1114
|
// Note: Testing that parameter is either input or result of some template
|
|
984
1115
|
if (!parameter.isInput &&
|
|
985
1116
|
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
986
|
-
throw new PipelineLogicError(spaceTrim
|
|
1117
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
987
1118
|
}
|
|
988
1119
|
};
|
|
989
1120
|
try {
|
|
@@ -1011,20 +1142,20 @@ function validatePipeline(pipeline) {
|
|
|
1011
1142
|
var _loop_2 = function (template) {
|
|
1012
1143
|
var e_4, _h, e_5, _j;
|
|
1013
1144
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
1014
|
-
throw new PipelineLogicError(spaceTrim
|
|
1145
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1015
1146
|
}
|
|
1016
1147
|
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
1017
|
-
throw new PipelineLogicError(spaceTrim
|
|
1148
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1018
1149
|
}
|
|
1019
1150
|
definedParameters.add(template.resultingParameterName);
|
|
1020
1151
|
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
1021
1152
|
if (!template.expectFormat &&
|
|
1022
1153
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1023
|
-
throw new PipelineLogicError(spaceTrim
|
|
1154
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1024
1155
|
}
|
|
1025
1156
|
var _loop_4 = function (joker) {
|
|
1026
1157
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
1027
|
-
throw new PipelineLogicError(spaceTrim
|
|
1158
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1028
1159
|
}
|
|
1029
1160
|
};
|
|
1030
1161
|
try {
|
|
@@ -1044,13 +1175,13 @@ function validatePipeline(pipeline) {
|
|
|
1044
1175
|
if (template.expectations) {
|
|
1045
1176
|
var _loop_5 = function (unit, min, max) {
|
|
1046
1177
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1047
|
-
throw new PipelineLogicError(spaceTrim
|
|
1178
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1048
1179
|
}
|
|
1049
1180
|
if (min !== undefined && min < 0) {
|
|
1050
|
-
throw new PipelineLogicError(spaceTrim
|
|
1181
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1051
1182
|
}
|
|
1052
1183
|
if (max !== undefined && max <= 0) {
|
|
1053
|
-
throw new PipelineLogicError(spaceTrim
|
|
1184
|
+
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1054
1185
|
}
|
|
1055
1186
|
};
|
|
1056
1187
|
try {
|
|
@@ -1112,7 +1243,7 @@ function validatePipeline(pipeline) {
|
|
|
1112
1243
|
var _loop_3 = function () {
|
|
1113
1244
|
if (loopLimit-- < 0) {
|
|
1114
1245
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
1115
|
-
throw new UnexpectedError(spaceTrim
|
|
1246
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
1116
1247
|
}
|
|
1117
1248
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
1118
1249
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
@@ -1120,7 +1251,7 @@ function validatePipeline(pipeline) {
|
|
|
1120
1251
|
if (currentlyResovedTemplates.length === 0) {
|
|
1121
1252
|
throw new PipelineLogicError(
|
|
1122
1253
|
// TODO: [🐎] DRY
|
|
1123
|
-
spaceTrim
|
|
1254
|
+
spaceTrim(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
1124
1255
|
.map(function (_a) {
|
|
1125
1256
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1126
1257
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -1182,15 +1313,15 @@ var NotFoundError = /** @class */ (function (_super) {
|
|
|
1182
1313
|
*
|
|
1183
1314
|
* @public exported from `@promptbook/core`
|
|
1184
1315
|
*/
|
|
1185
|
-
var
|
|
1186
|
-
__extends(
|
|
1187
|
-
function
|
|
1316
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1317
|
+
__extends(PipelineUrlError, _super);
|
|
1318
|
+
function PipelineUrlError(message) {
|
|
1188
1319
|
var _this = _super.call(this, message) || this;
|
|
1189
|
-
_this.name = '
|
|
1190
|
-
Object.setPrototypeOf(_this,
|
|
1320
|
+
_this.name = 'PipelineUrlError';
|
|
1321
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1191
1322
|
return _this;
|
|
1192
1323
|
}
|
|
1193
|
-
return
|
|
1324
|
+
return PipelineUrlError;
|
|
1194
1325
|
}(Error));
|
|
1195
1326
|
|
|
1196
1327
|
/**
|
|
@@ -1238,7 +1369,7 @@ function unpreparePipeline(pipeline) {
|
|
|
1238
1369
|
delete promptTemplateUnprepared.preparedContent;
|
|
1239
1370
|
return promptTemplateUnprepared;
|
|
1240
1371
|
});
|
|
1241
|
-
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
1372
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1242
1373
|
}
|
|
1243
1374
|
/**
|
|
1244
1375
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1274,7 +1405,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1274
1405
|
var pipeline = pipelines_1_1.value;
|
|
1275
1406
|
// TODO: [👠] DRY
|
|
1276
1407
|
if (pipeline.pipelineUrl === undefined) {
|
|
1277
|
-
throw new
|
|
1408
|
+
throw new PipelineUrlError(spaceTrim("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
1278
1409
|
}
|
|
1279
1410
|
// Note: [🐨]
|
|
1280
1411
|
validatePipeline(pipeline);
|
|
@@ -1286,7 +1417,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1286
1417
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1287
1418
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1288
1419
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1289
|
-
throw new
|
|
1420
|
+
throw new PipelineUrlError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
1290
1421
|
}
|
|
1291
1422
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1292
1423
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1316,9 +1447,9 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1316
1447
|
var pipeline = this.collection.get(url);
|
|
1317
1448
|
if (!pipeline) {
|
|
1318
1449
|
if (this.listPipelines().length === 0) {
|
|
1319
|
-
throw new NotFoundError(spaceTrim
|
|
1450
|
+
throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
|
|
1320
1451
|
}
|
|
1321
|
-
throw new NotFoundError(spaceTrim
|
|
1452
|
+
throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
|
|
1322
1453
|
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
1323
1454
|
.join('\n')), "\n\n "); }));
|
|
1324
1455
|
}
|
|
@@ -1731,9 +1862,105 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
1731
1862
|
}(Error));
|
|
1732
1863
|
|
|
1733
1864
|
/**
|
|
1734
|
-
*
|
|
1865
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1735
1866
|
*
|
|
1736
|
-
* @
|
|
1867
|
+
* @public exported from `@promptbook/core`
|
|
1868
|
+
*/
|
|
1869
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
1870
|
+
__extends(CollectionError, _super);
|
|
1871
|
+
function CollectionError(message) {
|
|
1872
|
+
var _this = _super.call(this, message) || this;
|
|
1873
|
+
_this.name = 'CollectionError';
|
|
1874
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
1875
|
+
return _this;
|
|
1876
|
+
}
|
|
1877
|
+
return CollectionError;
|
|
1878
|
+
}(Error));
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
1882
|
+
*
|
|
1883
|
+
* @public exported from `@promptbook/core`
|
|
1884
|
+
*/
|
|
1885
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
1886
|
+
__extends(EnvironmentMismatchError, _super);
|
|
1887
|
+
function EnvironmentMismatchError(message) {
|
|
1888
|
+
var _this = _super.call(this, message) || this;
|
|
1889
|
+
_this.name = 'EnvironmentMismatchError';
|
|
1890
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
1891
|
+
return _this;
|
|
1892
|
+
}
|
|
1893
|
+
return EnvironmentMismatchError;
|
|
1894
|
+
}(Error));
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* This error type indicates that some limit was reached
|
|
1898
|
+
*
|
|
1899
|
+
* @public exported from `@promptbook/core`
|
|
1900
|
+
*/
|
|
1901
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
1902
|
+
__extends(LimitReachedError, _super);
|
|
1903
|
+
function LimitReachedError(message) {
|
|
1904
|
+
var _this = _super.call(this, message) || this;
|
|
1905
|
+
_this.name = 'LimitReachedError';
|
|
1906
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
1907
|
+
return _this;
|
|
1908
|
+
}
|
|
1909
|
+
return LimitReachedError;
|
|
1910
|
+
}(Error));
|
|
1911
|
+
|
|
1912
|
+
/**
|
|
1913
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
1914
|
+
*
|
|
1915
|
+
* @public exported from `@promptbook/core`
|
|
1916
|
+
*/
|
|
1917
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1918
|
+
__extends(NotYetImplementedError, _super);
|
|
1919
|
+
function NotYetImplementedError(message) {
|
|
1920
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
1921
|
+
_this.name = 'NotYetImplementedError';
|
|
1922
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1923
|
+
return _this;
|
|
1924
|
+
}
|
|
1925
|
+
return NotYetImplementedError;
|
|
1926
|
+
}(Error));
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Index of all custom errors
|
|
1930
|
+
*
|
|
1931
|
+
* @public exported from `@promptbook/core`
|
|
1932
|
+
*/
|
|
1933
|
+
var ERRORS = {
|
|
1934
|
+
CollectionError: CollectionError,
|
|
1935
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
1936
|
+
LimitReachedError: LimitReachedError,
|
|
1937
|
+
NotFoundError: NotFoundError,
|
|
1938
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
1939
|
+
ParsingError: ParsingError,
|
|
1940
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
1941
|
+
PipelineLogicError: PipelineLogicError,
|
|
1942
|
+
PipelineUrlError: PipelineUrlError,
|
|
1943
|
+
UnexpectedError: UnexpectedError,
|
|
1944
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
1945
|
+
};
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* Deserializes the error object
|
|
1949
|
+
*
|
|
1950
|
+
* @public exported from `@promptbook/utils`
|
|
1951
|
+
*/
|
|
1952
|
+
function deserializeError(error) {
|
|
1953
|
+
if (error.name === 'Error') {
|
|
1954
|
+
return new Error(error.message);
|
|
1955
|
+
}
|
|
1956
|
+
var CustomError = ERRORS[error.name];
|
|
1957
|
+
return new CustomError(error.message);
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
/**
|
|
1961
|
+
* Asserts that the execution of a Promptbook is successful
|
|
1962
|
+
*
|
|
1963
|
+
* @param executionResult - The partial result of the Promptbook execution
|
|
1737
1964
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1738
1965
|
* @public exported from `@promptbook/core`
|
|
1739
1966
|
*/
|
|
@@ -1743,15 +1970,16 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1743
1970
|
return;
|
|
1744
1971
|
}
|
|
1745
1972
|
if (errors.length === 0) {
|
|
1746
|
-
throw new PipelineExecutionError("
|
|
1973
|
+
throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
|
|
1747
1974
|
}
|
|
1748
1975
|
else if (errors.length === 1) {
|
|
1749
|
-
throw errors[0];
|
|
1976
|
+
throw deserializeError(errors[0]);
|
|
1750
1977
|
}
|
|
1751
1978
|
else {
|
|
1752
|
-
throw new PipelineExecutionError(spaceTrim
|
|
1753
|
-
.map(function (
|
|
1754
|
-
|
|
1979
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
1980
|
+
.map(function (_a, index) {
|
|
1981
|
+
var name = _a.name, stack = _a.stack, message = _a.message;
|
|
1982
|
+
return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
1755
1983
|
})
|
|
1756
1984
|
.join('\n')), "\n "); }));
|
|
1757
1985
|
}
|
|
@@ -1783,7 +2011,7 @@ function extractVariables(script) {
|
|
|
1783
2011
|
var undefinedName = error.message.split(' ')[0];
|
|
1784
2012
|
/*
|
|
1785
2013
|
Note: Parsing the error
|
|
1786
|
-
[
|
|
2014
|
+
[PipelineUrlError: thing is not defined]
|
|
1787
2015
|
*/
|
|
1788
2016
|
if (!undefinedName) {
|
|
1789
2017
|
throw error;
|
|
@@ -1801,7 +2029,7 @@ function extractVariables(script) {
|
|
|
1801
2029
|
if (!(error instanceof Error)) {
|
|
1802
2030
|
throw error;
|
|
1803
2031
|
}
|
|
1804
|
-
throw new ParsingError(spaceTrim
|
|
2032
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
1805
2033
|
}
|
|
1806
2034
|
return variables;
|
|
1807
2035
|
}
|
|
@@ -1888,6 +2116,23 @@ var ExpectError = /** @class */ (function (_super) {
|
|
|
1888
2116
|
return ExpectError;
|
|
1889
2117
|
}(Error));
|
|
1890
2118
|
|
|
2119
|
+
/**
|
|
2120
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2121
|
+
*
|
|
2122
|
+
* @public exported from `@promptbook/utils`
|
|
2123
|
+
*/
|
|
2124
|
+
function serializeError(error) {
|
|
2125
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2126
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2127
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2128
|
+
}
|
|
2129
|
+
return {
|
|
2130
|
+
name: name,
|
|
2131
|
+
message: message,
|
|
2132
|
+
stack: stack,
|
|
2133
|
+
};
|
|
2134
|
+
}
|
|
2135
|
+
|
|
1891
2136
|
/**
|
|
1892
2137
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1893
2138
|
*
|
|
@@ -2127,7 +2372,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2127
2372
|
// 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2128
2373
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2129
2374
|
// 3) ...
|
|
2130
|
-
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2375
|
+
spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2131
2376
|
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2132
2377
|
.join('\n')), "\n\n "); }));
|
|
2133
2378
|
}
|
|
@@ -2135,7 +2380,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2135
2380
|
throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
|
|
2136
2381
|
}
|
|
2137
2382
|
else {
|
|
2138
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
|
|
2383
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
|
|
2139
2384
|
.map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
|
|
2140
2385
|
.join('\n')), "\n\n "); }));
|
|
2141
2386
|
}
|
|
@@ -2172,7 +2417,7 @@ function joinLlmExecutionTools() {
|
|
|
2172
2417
|
llmExecutionTools[_i] = arguments[_i];
|
|
2173
2418
|
}
|
|
2174
2419
|
if (llmExecutionTools.length === 0) {
|
|
2175
|
-
var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
2420
|
+
var warningMessage = spaceTrim$1("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
2176
2421
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2177
2422
|
console.warn(warningMessage);
|
|
2178
2423
|
/*
|
|
@@ -2225,6 +2470,7 @@ function isPipelinePrepared(pipeline) {
|
|
|
2225
2470
|
return true;
|
|
2226
2471
|
}
|
|
2227
2472
|
/**
|
|
2473
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2228
2474
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2229
2475
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2230
2476
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -2269,22 +2515,6 @@ function TODO_USE() {
|
|
|
2269
2515
|
}
|
|
2270
2516
|
}
|
|
2271
2517
|
|
|
2272
|
-
/**
|
|
2273
|
-
* This error type indicates that some limit was reached
|
|
2274
|
-
*
|
|
2275
|
-
* @public exported from `@promptbook/core`
|
|
2276
|
-
*/
|
|
2277
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2278
|
-
__extends(LimitReachedError, _super);
|
|
2279
|
-
function LimitReachedError(message) {
|
|
2280
|
-
var _this = _super.call(this, message) || this;
|
|
2281
|
-
_this.name = 'LimitReachedError';
|
|
2282
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2283
|
-
return _this;
|
|
2284
|
-
}
|
|
2285
|
-
return LimitReachedError;
|
|
2286
|
-
}(Error));
|
|
2287
|
-
|
|
2288
2518
|
/**
|
|
2289
2519
|
* Replaces parameters in template with values from parameters object
|
|
2290
2520
|
*
|
|
@@ -2584,7 +2814,7 @@ function createPipelineExecutor(options) {
|
|
|
2584
2814
|
preparedPipeline = pipeline;
|
|
2585
2815
|
}
|
|
2586
2816
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
2587
|
-
console.warn(spaceTrim
|
|
2817
|
+
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 ")));
|
|
2588
2818
|
}
|
|
2589
2819
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2590
2820
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -2670,7 +2900,6 @@ function createPipelineExecutor(options) {
|
|
|
2670
2900
|
return __awaiter(this, void 0, void 0, function () {
|
|
2671
2901
|
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;
|
|
2672
2902
|
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2673
|
-
var _this = this;
|
|
2674
2903
|
return __generator(this, function (_u) {
|
|
2675
2904
|
switch (_u.label) {
|
|
2676
2905
|
case 0:
|
|
@@ -2695,7 +2924,7 @@ function createPipelineExecutor(options) {
|
|
|
2695
2924
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2696
2925
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2697
2926
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2698
|
-
throw new UnexpectedError(spaceTrim
|
|
2927
|
+
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 ")));
|
|
2699
2928
|
}
|
|
2700
2929
|
_b = (_a = Object).freeze;
|
|
2701
2930
|
_c = [{}];
|
|
@@ -2720,7 +2949,7 @@ function createPipelineExecutor(options) {
|
|
|
2720
2949
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2721
2950
|
// Houston, we have a problem
|
|
2722
2951
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2723
|
-
throw new UnexpectedError(spaceTrim
|
|
2952
|
+
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 ")));
|
|
2724
2953
|
}
|
|
2725
2954
|
}
|
|
2726
2955
|
}
|
|
@@ -2791,71 +3020,8 @@ function createPipelineExecutor(options) {
|
|
|
2791
3020
|
return name === currentTemplate.personaName;
|
|
2792
3021
|
}) || {})), currentTemplate.expectations),
|
|
2793
3022
|
expectFormat: currentTemplate.expectFormat,
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
var e_8, _c;
|
|
2797
|
-
return __generator(this, function (_d) {
|
|
2798
|
-
switch (_d.label) {
|
|
2799
|
-
case 0:
|
|
2800
|
-
errors = [];
|
|
2801
|
-
_d.label = 1;
|
|
2802
|
-
case 1:
|
|
2803
|
-
_d.trys.push([1, 8, 9, 10]);
|
|
2804
|
-
_a = __values(arrayableToArray(tools.script)), _b = _a.next();
|
|
2805
|
-
_d.label = 2;
|
|
2806
|
-
case 2:
|
|
2807
|
-
if (!!_b.done) return [3 /*break*/, 7];
|
|
2808
|
-
scriptTools = _b.value;
|
|
2809
|
-
_d.label = 3;
|
|
2810
|
-
case 3:
|
|
2811
|
-
_d.trys.push([3, 5, , 6]);
|
|
2812
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
2813
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2814
|
-
script: "".concat(functionName, "(result)"),
|
|
2815
|
-
parameters: {
|
|
2816
|
-
result: result || '',
|
|
2817
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
2818
|
-
},
|
|
2819
|
-
})];
|
|
2820
|
-
case 4: return [2 /*return*/, _d.sent()];
|
|
2821
|
-
case 5:
|
|
2822
|
-
error_5 = _d.sent();
|
|
2823
|
-
if (!(error_5 instanceof Error)) {
|
|
2824
|
-
throw error_5;
|
|
2825
|
-
}
|
|
2826
|
-
if (error_5 instanceof UnexpectedError) {
|
|
2827
|
-
throw error_5;
|
|
2828
|
-
}
|
|
2829
|
-
errors.push(error_5);
|
|
2830
|
-
return [3 /*break*/, 6];
|
|
2831
|
-
case 6:
|
|
2832
|
-
_b = _a.next();
|
|
2833
|
-
return [3 /*break*/, 2];
|
|
2834
|
-
case 7: return [3 /*break*/, 10];
|
|
2835
|
-
case 8:
|
|
2836
|
-
e_8_1 = _d.sent();
|
|
2837
|
-
e_8 = { error: e_8_1 };
|
|
2838
|
-
return [3 /*break*/, 10];
|
|
2839
|
-
case 9:
|
|
2840
|
-
try {
|
|
2841
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2842
|
-
}
|
|
2843
|
-
finally { if (e_8) throw e_8.error; }
|
|
2844
|
-
return [7 /*endfinally*/];
|
|
2845
|
-
case 10:
|
|
2846
|
-
if (errors.length === 0) {
|
|
2847
|
-
throw new PipelineExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
2848
|
-
}
|
|
2849
|
-
else if (errors.length === 1) {
|
|
2850
|
-
throw errors[0];
|
|
2851
|
-
}
|
|
2852
|
-
else {
|
|
2853
|
-
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 "); }));
|
|
2854
|
-
}
|
|
2855
|
-
}
|
|
2856
|
-
});
|
|
2857
|
-
}); }; }),
|
|
2858
|
-
};
|
|
3023
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3024
|
+
}; // <- TODO: Not very good type guard
|
|
2859
3025
|
_g = currentTemplate.modelRequirements.modelVariant;
|
|
2860
3026
|
switch (_g) {
|
|
2861
3027
|
case 'CHAT': return [3 /*break*/, 8];
|
|
@@ -2944,7 +3110,7 @@ function createPipelineExecutor(options) {
|
|
|
2944
3110
|
throw scriptPipelineExecutionErrors[0];
|
|
2945
3111
|
}
|
|
2946
3112
|
else {
|
|
2947
|
-
throw new PipelineExecutionError(spaceTrim
|
|
3113
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
2948
3114
|
.map(function (error) { return '- ' + error.message; })
|
|
2949
3115
|
.join('\n\n')), "\n "); }));
|
|
2950
3116
|
}
|
|
@@ -3080,13 +3246,13 @@ function createPipelineExecutor(options) {
|
|
|
3080
3246
|
executionReport.promptExecutions.push({
|
|
3081
3247
|
prompt: __assign({}, prompt),
|
|
3082
3248
|
result: result || undefined,
|
|
3083
|
-
error: expectError
|
|
3249
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3084
3250
|
});
|
|
3085
3251
|
}
|
|
3086
3252
|
return [7 /*endfinally*/];
|
|
3087
3253
|
case 50:
|
|
3088
3254
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3089
|
-
throw new PipelineExecutionError(spaceTrim
|
|
3255
|
+
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 "); }));
|
|
3090
3256
|
}
|
|
3091
3257
|
_u.label = 51;
|
|
3092
3258
|
case 51:
|
|
@@ -3115,7 +3281,7 @@ function createPipelineExecutor(options) {
|
|
|
3115
3281
|
});
|
|
3116
3282
|
}
|
|
3117
3283
|
function filterJustOutputParameters() {
|
|
3118
|
-
var
|
|
3284
|
+
var e_8, _a;
|
|
3119
3285
|
var outputParameters = {};
|
|
3120
3286
|
try {
|
|
3121
3287
|
// Note: Filter ONLY output parameters
|
|
@@ -3132,12 +3298,12 @@ function createPipelineExecutor(options) {
|
|
|
3132
3298
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3133
3299
|
}
|
|
3134
3300
|
}
|
|
3135
|
-
catch (
|
|
3301
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3136
3302
|
finally {
|
|
3137
3303
|
try {
|
|
3138
3304
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3139
3305
|
}
|
|
3140
|
-
finally { if (
|
|
3306
|
+
finally { if (e_8) throw e_8.error; }
|
|
3141
3307
|
}
|
|
3142
3308
|
return outputParameters;
|
|
3143
3309
|
}
|
|
@@ -3174,11 +3340,11 @@ function createPipelineExecutor(options) {
|
|
|
3174
3340
|
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3175
3341
|
parameter = _b.value;
|
|
3176
3342
|
if (inputParameters[parameter.name] === undefined) {
|
|
3177
|
-
return [2 /*return*/,
|
|
3343
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3178
3344
|
isSuccessful: false,
|
|
3179
3345
|
errors: __spreadArray([
|
|
3180
3346
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3181
|
-
], __read(errors), false),
|
|
3347
|
+
], __read(errors), false).map(serializeError),
|
|
3182
3348
|
warnings: [],
|
|
3183
3349
|
executionReport: executionReport,
|
|
3184
3350
|
outputParameters: {},
|
|
@@ -3204,12 +3370,12 @@ function createPipelineExecutor(options) {
|
|
|
3204
3370
|
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3205
3371
|
}
|
|
3206
3372
|
else if (parameter.isInput === false) {
|
|
3207
|
-
return { value:
|
|
3373
|
+
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3208
3374
|
isSuccessful: false,
|
|
3209
3375
|
errors: __spreadArray([
|
|
3210
3376
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3211
|
-
], __read(errors), false),
|
|
3212
|
-
warnings: warnings,
|
|
3377
|
+
], __read(errors), false).map(serializeError),
|
|
3378
|
+
warnings: warnings.map(serializeError),
|
|
3213
3379
|
executionReport: executionReport,
|
|
3214
3380
|
outputParameters: {},
|
|
3215
3381
|
usage: ZERO_USAGE,
|
|
@@ -3266,7 +3432,7 @@ function createPipelineExecutor(options) {
|
|
|
3266
3432
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3267
3433
|
throw new UnexpectedError(
|
|
3268
3434
|
// TODO: [🐎] DRY
|
|
3269
|
-
spaceTrim
|
|
3435
|
+
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3270
3436
|
.map(function (_a) {
|
|
3271
3437
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3272
3438
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3316,10 +3482,10 @@ function createPipelineExecutor(options) {
|
|
|
3316
3482
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3317
3483
|
})), false));
|
|
3318
3484
|
outputParameters_1 = filterJustOutputParameters();
|
|
3319
|
-
return [2 /*return*/,
|
|
3485
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
|
|
3320
3486
|
isSuccessful: false,
|
|
3321
|
-
errors: __spreadArray([error_1], __read(errors), false),
|
|
3322
|
-
warnings: warnings,
|
|
3487
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
3488
|
+
warnings: warnings.map(serializeError),
|
|
3323
3489
|
usage: usage_1,
|
|
3324
3490
|
executionReport: executionReport,
|
|
3325
3491
|
outputParameters: outputParameters_1,
|
|
@@ -3331,10 +3497,10 @@ function createPipelineExecutor(options) {
|
|
|
3331
3497
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3332
3498
|
})), false));
|
|
3333
3499
|
outputParameters = filterJustOutputParameters();
|
|
3334
|
-
return [2 /*return*/,
|
|
3500
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
|
|
3335
3501
|
isSuccessful: true,
|
|
3336
|
-
errors: errors,
|
|
3337
|
-
warnings: warnings,
|
|
3502
|
+
errors: errors.map(serializeError),
|
|
3503
|
+
warnings: warnings.map(serializeError),
|
|
3338
3504
|
usage: usage,
|
|
3339
3505
|
executionReport: executionReport,
|
|
3340
3506
|
outputParameters: outputParameters,
|
|
@@ -3420,8 +3586,8 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3420
3586
|
switch (_c.label) {
|
|
3421
3587
|
case 0:
|
|
3422
3588
|
name = "piece-".concat(i);
|
|
3423
|
-
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
3424
|
-
knowledgePieceContent = spaceTrim(knowledgeTextPiece);
|
|
3589
|
+
title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
|
|
3590
|
+
knowledgePieceContent = spaceTrim$1(knowledgeTextPiece);
|
|
3425
3591
|
keywords = [];
|
|
3426
3592
|
index = [];
|
|
3427
3593
|
_c.label = 1;
|
|
@@ -3431,7 +3597,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3431
3597
|
case 2:
|
|
3432
3598
|
titleResult = _c.sent();
|
|
3433
3599
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
3434
|
-
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3600
|
+
title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3435
3601
|
name = titleToName(title);
|
|
3436
3602
|
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
3437
3603
|
case 3:
|
|
@@ -3704,6 +3870,7 @@ function preparePersona(personaDescription, options) {
|
|
|
3704
3870
|
});
|
|
3705
3871
|
}
|
|
3706
3872
|
/**
|
|
3873
|
+
* TODO: [🔃] !!!!! If the persona was prepared with different version or different set of models, prepare it once again
|
|
3707
3874
|
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
3708
3875
|
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
3709
3876
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
@@ -3763,7 +3930,7 @@ function prepareTemplates(pipeline, options) {
|
|
|
3763
3930
|
dependentParameterNames = template.dependentParameterNames;
|
|
3764
3931
|
preparedContent = undefined;
|
|
3765
3932
|
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
3766
|
-
preparedContent = spaceTrim
|
|
3933
|
+
preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
3767
3934
|
// <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
|
|
3768
3935
|
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
3769
3936
|
'knowledge',
|
|
@@ -3804,7 +3971,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3804
3971
|
return __awaiter(this, void 0, void 0, function () {
|
|
3805
3972
|
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
|
|
3806
3973
|
/*
|
|
3807
|
-
<- TODO: [🧠][
|
|
3974
|
+
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3808
3975
|
knowledgeSources /*
|
|
3809
3976
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3810
3977
|
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
@@ -3874,7 +4041,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3874
4041
|
// ----- /Templates preparation -----
|
|
3875
4042
|
// Note: Count total usage
|
|
3876
4043
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3877
|
-
return [2 /*return*/, __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
4044
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
|
|
3878
4045
|
}
|
|
3879
4046
|
});
|
|
3880
4047
|
});
|
|
@@ -3950,7 +4117,7 @@ var knowledgeCommandParser = {
|
|
|
3950
4117
|
*/
|
|
3951
4118
|
parse: function (input) {
|
|
3952
4119
|
var args = input.args;
|
|
3953
|
-
var sourceContent = spaceTrim(args[0] || '');
|
|
4120
|
+
var sourceContent = spaceTrim$1(args[0] || '');
|
|
3954
4121
|
if (sourceContent === '') {
|
|
3955
4122
|
throw new ParsingError("Source is not defined");
|
|
3956
4123
|
}
|
|
@@ -4066,8 +4233,8 @@ var personaCommandParser = {
|
|
|
4066
4233
|
persona.description = personaDescription;
|
|
4067
4234
|
return;
|
|
4068
4235
|
}
|
|
4069
|
-
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 ")));
|
|
4070
|
-
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
4236
|
+
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 ")));
|
|
4237
|
+
persona.description += spaceTrim$1('\n\n' + personaDescription);
|
|
4071
4238
|
},
|
|
4072
4239
|
};
|
|
4073
4240
|
|
|
@@ -4254,7 +4421,7 @@ var blockCommandParser = {
|
|
|
4254
4421
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
4255
4422
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
4256
4423
|
if (blockTypes.length !== 1) {
|
|
4257
|
-
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 "); }));
|
|
4424
|
+
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 "); }));
|
|
4258
4425
|
}
|
|
4259
4426
|
var blockType = blockTypes[0];
|
|
4260
4427
|
return {
|
|
@@ -4361,7 +4528,7 @@ var expectCommandParser = {
|
|
|
4361
4528
|
/**
|
|
4362
4529
|
* Description of the EXPECT command
|
|
4363
4530
|
*/
|
|
4364
|
-
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 "),
|
|
4531
|
+
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 "),
|
|
4365
4532
|
/**
|
|
4366
4533
|
* Link to discussion
|
|
4367
4534
|
*/
|
|
@@ -4454,7 +4621,7 @@ var expectCommandParser = {
|
|
|
4454
4621
|
if (!(error instanceof Error)) {
|
|
4455
4622
|
throw error;
|
|
4456
4623
|
}
|
|
4457
|
-
throw new ParsingError(spaceTrim(function (block) {
|
|
4624
|
+
throw new ParsingError(spaceTrim$1(function (block) {
|
|
4458
4625
|
return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
|
|
4459
4626
|
}));
|
|
4460
4627
|
}
|
|
@@ -4573,7 +4740,7 @@ var modelCommandParser = {
|
|
|
4573
4740
|
// <- Note: [🤖]
|
|
4574
4741
|
}
|
|
4575
4742
|
else {
|
|
4576
|
-
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 "); }));
|
|
4743
|
+
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 "); }));
|
|
4577
4744
|
}
|
|
4578
4745
|
}
|
|
4579
4746
|
if (normalized.startsWith('MODEL_NAME')) {
|
|
@@ -4584,7 +4751,7 @@ var modelCommandParser = {
|
|
|
4584
4751
|
};
|
|
4585
4752
|
}
|
|
4586
4753
|
else {
|
|
4587
|
-
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 "); }));
|
|
4754
|
+
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 "); }));
|
|
4588
4755
|
}
|
|
4589
4756
|
},
|
|
4590
4757
|
};
|
|
@@ -5043,7 +5210,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
5043
5210
|
.map(removeMarkdownFormatting)
|
|
5044
5211
|
.map(function (item) { return item.trim(); });
|
|
5045
5212
|
if (items.length === 0 || items[0] === '') {
|
|
5046
|
-
throw new ParsingError(spaceTrim
|
|
5213
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5047
5214
|
return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5048
5215
|
}));
|
|
5049
5216
|
}
|
|
@@ -5070,7 +5237,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
5070
5237
|
return command;
|
|
5071
5238
|
}
|
|
5072
5239
|
}
|
|
5073
|
-
throw new ParsingError(spaceTrim
|
|
5240
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5074
5241
|
return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5075
5242
|
}));
|
|
5076
5243
|
}
|
|
@@ -5103,7 +5270,7 @@ function parseCommandVariant(input) {
|
|
|
5103
5270
|
if (!(error instanceof ParsingError)) {
|
|
5104
5271
|
throw error;
|
|
5105
5272
|
}
|
|
5106
|
-
throw new ParsingError(spaceTrim
|
|
5273
|
+
throw new ParsingError(spaceTrim(function (block) {
|
|
5107
5274
|
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 ");
|
|
5108
5275
|
}));
|
|
5109
5276
|
}
|
|
@@ -5130,22 +5297,6 @@ function parseCommandVariant(input) {
|
|
|
5130
5297
|
return null;
|
|
5131
5298
|
}
|
|
5132
5299
|
|
|
5133
|
-
/**
|
|
5134
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
5135
|
-
*
|
|
5136
|
-
* @public exported from `@promptbook/core`
|
|
5137
|
-
*/
|
|
5138
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
5139
|
-
__extends(NotYetImplementedError, _super);
|
|
5140
|
-
function NotYetImplementedError(message) {
|
|
5141
|
-
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;
|
|
5142
|
-
_this.name = 'NotYetImplementedError';
|
|
5143
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
5144
|
-
return _this;
|
|
5145
|
-
}
|
|
5146
|
-
return NotYetImplementedError;
|
|
5147
|
-
}(Error));
|
|
5148
|
-
|
|
5149
5300
|
/**
|
|
5150
5301
|
* Supported script languages
|
|
5151
5302
|
*
|
|
@@ -5285,7 +5436,7 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
5285
5436
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5286
5437
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
5287
5438
|
if (codeBlocks.length !== 1) {
|
|
5288
|
-
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 "); }));
|
|
5439
|
+
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 "); }));
|
|
5289
5440
|
}
|
|
5290
5441
|
return codeBlocks[0];
|
|
5291
5442
|
}
|
|
@@ -5306,7 +5457,7 @@ function parseMarkdownSection(value) {
|
|
|
5306
5457
|
}
|
|
5307
5458
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
5308
5459
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
5309
|
-
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
5460
|
+
var content = spaceTrim$1(lines.slice(1).join('\n'));
|
|
5310
5461
|
if (level < 1 || level > 6) {
|
|
5311
5462
|
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
5312
5463
|
}
|
|
@@ -5334,7 +5485,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
5334
5485
|
if (buffer.length === 0) {
|
|
5335
5486
|
return;
|
|
5336
5487
|
}
|
|
5337
|
-
var section = spaceTrim(buffer.join('\n'));
|
|
5488
|
+
var section = spaceTrim$1(buffer.join('\n'));
|
|
5338
5489
|
if (section === '') {
|
|
5339
5490
|
return;
|
|
5340
5491
|
}
|
|
@@ -5430,7 +5581,7 @@ function flattenMarkdown(markdown) {
|
|
|
5430
5581
|
}
|
|
5431
5582
|
finally { if (e_1) throw e_1.error; }
|
|
5432
5583
|
}
|
|
5433
|
-
return spaceTrim(flattenedMarkdown);
|
|
5584
|
+
return spaceTrim$1(flattenedMarkdown);
|
|
5434
5585
|
}
|
|
5435
5586
|
/**
|
|
5436
5587
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -5448,7 +5599,7 @@ function flattenMarkdown(markdown) {
|
|
|
5448
5599
|
* @public exported from `@promptbook/markdown-utils`
|
|
5449
5600
|
*/
|
|
5450
5601
|
function removeContentComments(content) {
|
|
5451
|
-
return spaceTrim
|
|
5602
|
+
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
5452
5603
|
}
|
|
5453
5604
|
|
|
5454
5605
|
/**
|
|
@@ -5489,13 +5640,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5489
5640
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5490
5641
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5491
5642
|
if (pipelineHead === undefined) {
|
|
5492
|
-
throw new UnexpectedError(spaceTrim
|
|
5643
|
+
throw new UnexpectedError(spaceTrim("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5493
5644
|
}
|
|
5494
5645
|
if (pipelineHead.level !== 1) {
|
|
5495
|
-
throw new UnexpectedError(spaceTrim
|
|
5646
|
+
throw new UnexpectedError(spaceTrim("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5496
5647
|
}
|
|
5497
5648
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5498
|
-
throw new UnexpectedError(spaceTrim
|
|
5649
|
+
throw new UnexpectedError(spaceTrim("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
|
|
5499
5650
|
}
|
|
5500
5651
|
// =============================================================
|
|
5501
5652
|
///Note: 2️⃣ Function for defining parameters
|
|
@@ -5509,7 +5660,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5509
5660
|
existingParameter.description &&
|
|
5510
5661
|
existingParameter.description !== parameterDescription &&
|
|
5511
5662
|
parameterDescription) {
|
|
5512
|
-
throw new ParsingError(spaceTrim
|
|
5663
|
+
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 "); }));
|
|
5513
5664
|
}
|
|
5514
5665
|
if (existingParameter) {
|
|
5515
5666
|
if (parameterDescription) {
|
|
@@ -5535,7 +5686,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5535
5686
|
description = description.split(/^>.*$/gm).join('');
|
|
5536
5687
|
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
5537
5688
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5538
|
-
description = spaceTrim
|
|
5689
|
+
description = spaceTrim(description);
|
|
5539
5690
|
if (description === '') {
|
|
5540
5691
|
description = undefined;
|
|
5541
5692
|
}
|
|
@@ -5606,7 +5757,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5606
5757
|
if (resultingParameterName !== null) {
|
|
5607
5758
|
return resultingParameterName;
|
|
5608
5759
|
}
|
|
5609
|
-
throw new ParsingError(spaceTrim
|
|
5760
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5610
5761
|
// TODO: Show code of invalid sections each time + DRY
|
|
5611
5762
|
section.content
|
|
5612
5763
|
.split('\n')
|
|
@@ -5621,7 +5772,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5621
5772
|
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5622
5773
|
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5623
5774
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5624
|
-
description_1 = spaceTrim
|
|
5775
|
+
description_1 = spaceTrim(description_1);
|
|
5625
5776
|
if (description_1 === '') {
|
|
5626
5777
|
description_1 = undefined;
|
|
5627
5778
|
}
|
|
@@ -5705,7 +5856,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5705
5856
|
break;
|
|
5706
5857
|
case 'EXPECT_FORMAT':
|
|
5707
5858
|
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5708
|
-
throw new ParsingError(spaceTrim
|
|
5859
|
+
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 ")));
|
|
5709
5860
|
}
|
|
5710
5861
|
templateJson.expectFormat = command.format;
|
|
5711
5862
|
break;
|
|
@@ -5762,7 +5913,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5762
5913
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
5763
5914
|
}
|
|
5764
5915
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
5765
|
-
throw new ParsingError(spaceTrim
|
|
5916
|
+
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 "); }));
|
|
5766
5917
|
}
|
|
5767
5918
|
templateJson.contentLanguage = language;
|
|
5768
5919
|
}
|
|
@@ -5837,7 +5988,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5837
5988
|
}
|
|
5838
5989
|
});
|
|
5839
5990
|
// =============================================================
|
|
5840
|
-
return pipelineJson;
|
|
5991
|
+
return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
|
|
5841
5992
|
}
|
|
5842
5993
|
/**
|
|
5843
5994
|
* TODO: !!!! Warn if used only sync version
|
|
@@ -5881,7 +6032,9 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
5881
6032
|
case 1:
|
|
5882
6033
|
pipelineJson = _a.sent();
|
|
5883
6034
|
_a.label = 2;
|
|
5884
|
-
case 2:
|
|
6035
|
+
case 2:
|
|
6036
|
+
// Note: No need to use `$asDeeplyFrozenSerializableJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
|
|
6037
|
+
return [2 /*return*/, pipelineJson];
|
|
5885
6038
|
}
|
|
5886
6039
|
});
|
|
5887
6040
|
});
|
|
@@ -5892,22 +6045,6 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
5892
6045
|
* TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
|
|
5893
6046
|
*/
|
|
5894
6047
|
|
|
5895
|
-
/**
|
|
5896
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
5897
|
-
*
|
|
5898
|
-
* @public exported from `@promptbook/core`
|
|
5899
|
-
*/
|
|
5900
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
5901
|
-
__extends(CollectionError, _super);
|
|
5902
|
-
function CollectionError(message) {
|
|
5903
|
-
var _this = _super.call(this, message) || this;
|
|
5904
|
-
_this.name = 'CollectionError';
|
|
5905
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
5906
|
-
return _this;
|
|
5907
|
-
}
|
|
5908
|
-
return CollectionError;
|
|
5909
|
-
}(Error));
|
|
5910
|
-
|
|
5911
6048
|
/**
|
|
5912
6049
|
* Detects if the code is running in a Node.js environment
|
|
5913
6050
|
*
|
|
@@ -6273,7 +6410,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6273
6410
|
}
|
|
6274
6411
|
else {
|
|
6275
6412
|
existing = collection.get(pipeline.pipelineUrl);
|
|
6276
|
-
throw new
|
|
6413
|
+
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 ")));
|
|
6277
6414
|
}
|
|
6278
6415
|
}
|
|
6279
6416
|
}
|
|
@@ -6283,7 +6420,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6283
6420
|
if (!(error_1 instanceof Error)) {
|
|
6284
6421
|
throw error_1;
|
|
6285
6422
|
}
|
|
6286
|
-
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 "); });
|
|
6423
|
+
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 "); });
|
|
6287
6424
|
if (isCrashedOnError) {
|
|
6288
6425
|
throw new CollectionError(wrappedErrorMessage);
|
|
6289
6426
|
}
|
|
@@ -6339,35 +6476,16 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6339
6476
|
* TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
|
|
6340
6477
|
*/
|
|
6341
6478
|
|
|
6342
|
-
/**
|
|
6343
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
6344
|
-
*
|
|
6345
|
-
* @public exported from `@promptbook/core`
|
|
6346
|
-
*/
|
|
6347
|
-
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
6348
|
-
__extends(EnvironmentMismatchError, _super);
|
|
6349
|
-
function EnvironmentMismatchError(message) {
|
|
6350
|
-
var _this = _super.call(this, message) || this;
|
|
6351
|
-
_this.name = 'EnvironmentMismatchError';
|
|
6352
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
6353
|
-
return _this;
|
|
6354
|
-
}
|
|
6355
|
-
return EnvironmentMismatchError;
|
|
6356
|
-
}(Error));
|
|
6357
|
-
|
|
6358
6479
|
/**
|
|
6359
6480
|
* @@@
|
|
6360
6481
|
*
|
|
6361
6482
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
6362
6483
|
*
|
|
6363
|
-
*
|
|
6484
|
+
* @private internal function of `$Register`
|
|
6364
6485
|
*/
|
|
6365
6486
|
function $getGlobalScope() {
|
|
6366
6487
|
return Function('return this')();
|
|
6367
6488
|
}
|
|
6368
|
-
/***
|
|
6369
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
6370
|
-
*/
|
|
6371
6489
|
|
|
6372
6490
|
/**
|
|
6373
6491
|
* Register is @@@
|
|
@@ -6526,7 +6644,7 @@ function $registeredLlmToolsMessage() {
|
|
|
6526
6644
|
});
|
|
6527
6645
|
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
|
|
6528
6646
|
});
|
|
6529
|
-
return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
6647
|
+
return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
6530
6648
|
.map(function (_a, i) {
|
|
6531
6649
|
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
|
|
6532
6650
|
var more;
|
|
@@ -6574,7 +6692,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
6574
6692
|
return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
|
|
6575
6693
|
});
|
|
6576
6694
|
if (registeredItem === undefined) {
|
|
6577
|
-
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 "); }));
|
|
6695
|
+
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 "); }));
|
|
6578
6696
|
}
|
|
6579
6697
|
return registeredItem(__assign({ isVerbose: isVerbose }, llmConfiguration.options));
|
|
6580
6698
|
});
|
|
@@ -6611,7 +6729,7 @@ function createLlmToolsFromEnv(options) {
|
|
|
6611
6729
|
var configuration = createLlmToolsFromConfigurationFromEnv();
|
|
6612
6730
|
if (configuration.length === 0) {
|
|
6613
6731
|
// TODO: [🥃]
|
|
6614
|
-
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 "); }));
|
|
6732
|
+
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 "); }));
|
|
6615
6733
|
}
|
|
6616
6734
|
return createLlmToolsFromConfiguration(configuration, options);
|
|
6617
6735
|
}
|
|
@@ -6624,6 +6742,39 @@ function createLlmToolsFromEnv(options) {
|
|
|
6624
6742
|
* TODO: This should be maybe not under `_common` but under `utils`
|
|
6625
6743
|
*/
|
|
6626
6744
|
|
|
6745
|
+
/**
|
|
6746
|
+
* Tests if the value is [🚉] serializable as JSON
|
|
6747
|
+
*
|
|
6748
|
+
* - Almost all primitives are serializable BUT:
|
|
6749
|
+
* - `undefined` is not serializable
|
|
6750
|
+
* - `NaN` is not serializable
|
|
6751
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
6752
|
+
* - Functions are not serializable
|
|
6753
|
+
* - Circular references are not serializable
|
|
6754
|
+
* - `Date` objects are not serializable
|
|
6755
|
+
* - `Map` and `Set` objects are not serializable
|
|
6756
|
+
* - `RegExp` objects are not serializable
|
|
6757
|
+
* - `Error` objects are not serializable
|
|
6758
|
+
* - `Symbol` objects are not serializable
|
|
6759
|
+
* - And much more...
|
|
6760
|
+
*
|
|
6761
|
+
*
|
|
6762
|
+
* @public exported from `@promptbook/utils`
|
|
6763
|
+
*/
|
|
6764
|
+
function isSerializableAsJson(value) {
|
|
6765
|
+
try {
|
|
6766
|
+
checkSerializableAsJson('', value);
|
|
6767
|
+
return true;
|
|
6768
|
+
}
|
|
6769
|
+
catch (error) {
|
|
6770
|
+
return false;
|
|
6771
|
+
}
|
|
6772
|
+
}
|
|
6773
|
+
/**
|
|
6774
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
6775
|
+
* TODO: [🧠][💺] Can be done this on type-level?
|
|
6776
|
+
*/
|
|
6777
|
+
|
|
6627
6778
|
/**
|
|
6628
6779
|
* Stringify the PipelineJson with proper formatting
|
|
6629
6780
|
*
|
|
@@ -6633,6 +6784,9 @@ function createLlmToolsFromEnv(options) {
|
|
|
6633
6784
|
* @public exported from `@promptbook/core`
|
|
6634
6785
|
*/
|
|
6635
6786
|
function stringifyPipelineJson(pipeline) {
|
|
6787
|
+
if (!isSerializableAsJson(pipeline)) {
|
|
6788
|
+
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 "));
|
|
6789
|
+
}
|
|
6636
6790
|
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
6637
6791
|
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
6638
6792
|
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
@@ -6713,6 +6867,9 @@ var FilesStorage = /** @class */ (function () {
|
|
|
6713
6867
|
switch (_a.label) {
|
|
6714
6868
|
case 0:
|
|
6715
6869
|
filename = this.getFilenameForKey(key);
|
|
6870
|
+
if (!isSerializableAsJson(value)) {
|
|
6871
|
+
throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
|
|
6872
|
+
}
|
|
6716
6873
|
fileContent = stringifyPipelineJson(value);
|
|
6717
6874
|
return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
|
|
6718
6875
|
case 1:
|