@promptbook/markdown-utils 0.89.0-9 โ 0.92.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/esm/index.es.js +594 -359
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +40 -0
- package/esm/typings/src/_packages/core.index.d.ts +14 -4
- package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
- package/esm/typings/src/_packages/google.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +18 -0
- package/esm/typings/src/_packages/utils.index.d.ts +6 -0
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
- package/esm/typings/src/config.d.ts +10 -19
- package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
- package/esm/typings/src/errors/0-index.d.ts +7 -4
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +11 -0
- package/esm/typings/src/execution/CommonToolsOptions.d.ts +4 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +5 -0
- package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
- package/esm/typings/src/formats/json/utils/jsonParse.d.ts +11 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/filterModels.d.ts +15 -0
- package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts โ $provideEnvFilename.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +43 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
- package/esm/typings/src/remote-server/openapi-types.d.ts +626 -0
- package/esm/typings/src/remote-server/openapi.d.ts +581 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
- package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +26 -0
- package/package.json +7 -3
- package/umd/index.umd.js +595 -360
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-10';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -172,9 +172,302 @@
|
|
|
172
172
|
return content;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Returns the same value that is passed as argument.
|
|
177
|
+
* No side effects.
|
|
178
|
+
*
|
|
179
|
+
* Note: It can be usefull for:
|
|
180
|
+
*
|
|
181
|
+
* 1) Leveling indentation
|
|
182
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
183
|
+
*
|
|
184
|
+
* @param value any values
|
|
185
|
+
* @returns the same values
|
|
186
|
+
* @private within the repository
|
|
187
|
+
*/
|
|
188
|
+
function just(value) {
|
|
189
|
+
if (value === undefined) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Warning message for the generated sections and files files
|
|
197
|
+
*
|
|
198
|
+
* @private within the repository
|
|
199
|
+
*/
|
|
200
|
+
const GENERATOR_WARNING = `โ ๏ธ WARNING: This code has been generated so that any manual changes will be overwritten`;
|
|
201
|
+
/**
|
|
202
|
+
* Name for the Promptbook
|
|
203
|
+
*
|
|
204
|
+
* TODO: [๐ฝ] Unite branding and make single place for it
|
|
205
|
+
*
|
|
206
|
+
* @public exported from `@promptbook/core`
|
|
207
|
+
*/
|
|
208
|
+
const NAME = `Promptbook`;
|
|
209
|
+
/**
|
|
210
|
+
* Email of the responsible person
|
|
211
|
+
*
|
|
212
|
+
* @public exported from `@promptbook/core`
|
|
213
|
+
*/
|
|
214
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
215
|
+
/**
|
|
216
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
217
|
+
*
|
|
218
|
+
* @public exported from `@promptbook/core`
|
|
219
|
+
*/
|
|
220
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
221
|
+
// <- TODO: [๐] Pick the best claim
|
|
222
|
+
/**
|
|
223
|
+
* When the title is not provided, the default title is used
|
|
224
|
+
*
|
|
225
|
+
* @public exported from `@promptbook/core`
|
|
226
|
+
*/
|
|
227
|
+
const DEFAULT_BOOK_TITLE = `โจ Untitled Book`;
|
|
228
|
+
/**
|
|
229
|
+
* Maximum file size limit
|
|
230
|
+
*
|
|
231
|
+
* @public exported from `@promptbook/core`
|
|
232
|
+
*/
|
|
233
|
+
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
234
|
+
// <- TODO: [๐ง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
235
|
+
/**
|
|
236
|
+
* The maximum number of iterations for a loops
|
|
237
|
+
*
|
|
238
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
239
|
+
*/
|
|
240
|
+
const LOOP_LIMIT = 1000;
|
|
241
|
+
/**
|
|
242
|
+
* Strings to represent various values in the context of parameter values
|
|
243
|
+
*
|
|
244
|
+
* @public exported from `@promptbook/utils`
|
|
245
|
+
*/
|
|
246
|
+
const VALUE_STRINGS = {
|
|
247
|
+
empty: '(nothing; empty string)',
|
|
248
|
+
null: '(no value; null)',
|
|
249
|
+
undefined: '(unknown value; undefined)',
|
|
250
|
+
nan: '(not a number; NaN)',
|
|
251
|
+
infinity: '(infinity; โ)',
|
|
252
|
+
negativeInfinity: '(negative infinity; -โ)',
|
|
253
|
+
unserializable: '(unserializable value)',
|
|
254
|
+
circular: '(circular JSON)',
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Small number limit
|
|
258
|
+
*
|
|
259
|
+
* @public exported from `@promptbook/utils`
|
|
260
|
+
*/
|
|
261
|
+
const SMALL_NUMBER = 0.001;
|
|
262
|
+
/**
|
|
263
|
+
* Short time interval to prevent race conditions in milliseconds
|
|
264
|
+
*
|
|
265
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
266
|
+
*/
|
|
267
|
+
const IMMEDIATE_TIME = 10;
|
|
268
|
+
/**
|
|
269
|
+
* The maximum length of the (generated) filename
|
|
270
|
+
*
|
|
271
|
+
* @public exported from `@promptbook/core`
|
|
272
|
+
*/
|
|
273
|
+
const MAX_FILENAME_LENGTH = 30;
|
|
274
|
+
/**
|
|
275
|
+
* Strategy for caching the intermediate results for knowledge sources
|
|
276
|
+
*
|
|
277
|
+
* @public exported from `@promptbook/core`
|
|
278
|
+
*/
|
|
279
|
+
const DEFAULT_INTERMEDIATE_FILES_STRATEGY = 'HIDE_AND_KEEP';
|
|
280
|
+
// <- TODO: [๐ก] Change to 'VISIBLE'
|
|
281
|
+
/**
|
|
282
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
283
|
+
*
|
|
284
|
+
* @public exported from `@promptbook/core`
|
|
285
|
+
*/
|
|
286
|
+
const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐คนโโ๏ธ]
|
|
287
|
+
/**
|
|
288
|
+
* The maximum number of attempts to execute LLM task before giving up
|
|
289
|
+
*
|
|
290
|
+
* @public exported from `@promptbook/core`
|
|
291
|
+
*/
|
|
292
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐คนโโ๏ธ]
|
|
293
|
+
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
294
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
295
|
+
/**
|
|
296
|
+
* Where to store the temporary downloads
|
|
297
|
+
*
|
|
298
|
+
* Note: When the folder does not exist, it is created recursively
|
|
299
|
+
*
|
|
300
|
+
* @public exported from `@promptbook/core`
|
|
301
|
+
*/
|
|
302
|
+
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
303
|
+
/**
|
|
304
|
+
* Where to store the scrape cache
|
|
305
|
+
*
|
|
306
|
+
* Note: When the folder does not exist, it is created recursively
|
|
307
|
+
*
|
|
308
|
+
* @public exported from `@promptbook/core`
|
|
309
|
+
*/
|
|
310
|
+
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
311
|
+
// <- TODO: [๐งโโ๏ธ]
|
|
312
|
+
/**
|
|
313
|
+
* @@@
|
|
314
|
+
*
|
|
315
|
+
* @public exported from `@promptbook/core`
|
|
316
|
+
*/
|
|
317
|
+
const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
318
|
+
delimiter: ',',
|
|
319
|
+
quoteChar: '"',
|
|
320
|
+
newline: '\n',
|
|
321
|
+
skipEmptyLines: true,
|
|
322
|
+
});
|
|
323
|
+
/**
|
|
324
|
+
* @@@
|
|
325
|
+
*
|
|
326
|
+
* @public exported from `@promptbook/core`
|
|
327
|
+
*/
|
|
328
|
+
let DEFAULT_IS_VERBOSE = false;
|
|
329
|
+
/**
|
|
330
|
+
* @@@
|
|
331
|
+
*
|
|
332
|
+
* @public exported from `@promptbook/core`
|
|
333
|
+
*/
|
|
334
|
+
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
335
|
+
/**
|
|
336
|
+
* @@@
|
|
337
|
+
*
|
|
338
|
+
* @private within the repository
|
|
339
|
+
*/
|
|
340
|
+
const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
341
|
+
/**/
|
|
342
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
343
|
+
true);
|
|
344
|
+
/**
|
|
345
|
+
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
346
|
+
* TODO: [๐ง ][๐งโโ๏ธ] Maybe join remoteServerUrl and path into single value
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Make error report URL for the given error
|
|
351
|
+
*
|
|
352
|
+
* @private private within the repository
|
|
353
|
+
*/
|
|
354
|
+
function getErrorReportUrl(error) {
|
|
355
|
+
const report = {
|
|
356
|
+
title: `๐ Error report from ${NAME}`,
|
|
357
|
+
body: spaceTrim__default["default"]((block) => `
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
361
|
+
|
|
362
|
+
\`\`\`
|
|
363
|
+
${block(error.message || '(no error message)')}
|
|
364
|
+
\`\`\`
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
## More info:
|
|
368
|
+
|
|
369
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
370
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
371
|
+
- **Time:** ${new Date().toISOString()}
|
|
372
|
+
|
|
373
|
+
<details>
|
|
374
|
+
<summary>Stack trace:</summary>
|
|
375
|
+
|
|
376
|
+
## Stack trace:
|
|
377
|
+
|
|
378
|
+
\`\`\`stacktrace
|
|
379
|
+
${block(error.stack || '(empty)')}
|
|
380
|
+
\`\`\`
|
|
381
|
+
</details>
|
|
382
|
+
|
|
383
|
+
`),
|
|
384
|
+
};
|
|
385
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
386
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
387
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
388
|
+
reportUrl.searchParams.set('title', report.title);
|
|
389
|
+
reportUrl.searchParams.set('body', report.body);
|
|
390
|
+
return reportUrl;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
395
|
+
*
|
|
396
|
+
* @public exported from `@promptbook/core`
|
|
397
|
+
*/
|
|
398
|
+
class UnexpectedError extends Error {
|
|
399
|
+
constructor(message) {
|
|
400
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
401
|
+
${block(message)}
|
|
402
|
+
|
|
403
|
+
Note: This error should not happen.
|
|
404
|
+
It's probbably a bug in the pipeline collection
|
|
405
|
+
|
|
406
|
+
Please report issue:
|
|
407
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
408
|
+
|
|
409
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
410
|
+
|
|
411
|
+
`));
|
|
412
|
+
this.name = 'UnexpectedError';
|
|
413
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
419
|
+
*
|
|
420
|
+
* @public exported from `@promptbook/core`
|
|
421
|
+
*/
|
|
422
|
+
class WrappedError extends Error {
|
|
423
|
+
constructor(whatWasThrown) {
|
|
424
|
+
const tag = `[๐คฎ]`;
|
|
425
|
+
console.error(tag, whatWasThrown);
|
|
426
|
+
super(spaceTrim.spaceTrim(`
|
|
427
|
+
Non-Error object was thrown
|
|
428
|
+
|
|
429
|
+
Note: Look for ${tag} in the console for more details
|
|
430
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
431
|
+
`));
|
|
432
|
+
this.name = 'WrappedError';
|
|
433
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
439
|
+
*
|
|
440
|
+
* @param whatWasThrown Any object that was thrown
|
|
441
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
442
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
443
|
+
*
|
|
444
|
+
* @private within the repository
|
|
445
|
+
*/
|
|
446
|
+
function assertsError(whatWasThrown) {
|
|
447
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
448
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
449
|
+
const wrappedError = whatWasThrown;
|
|
450
|
+
throw wrappedError;
|
|
451
|
+
}
|
|
452
|
+
// Case 2: Handle unexpected errors
|
|
453
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
454
|
+
const unexpectedError = whatWasThrown;
|
|
455
|
+
throw unexpectedError;
|
|
456
|
+
}
|
|
457
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
458
|
+
if (whatWasThrown instanceof Error) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
462
|
+
throw new WrappedError(whatWasThrown);
|
|
463
|
+
}
|
|
464
|
+
|
|
175
465
|
/**
|
|
176
466
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
177
467
|
*
|
|
468
|
+
* @param value The string to check
|
|
469
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
470
|
+
*
|
|
178
471
|
* @public exported from `@promptbook/utils`
|
|
179
472
|
*/
|
|
180
473
|
function isValidJsonString(value /* <- [๐จโโ๏ธ] */) {
|
|
@@ -183,9 +476,7 @@
|
|
|
183
476
|
return true;
|
|
184
477
|
}
|
|
185
478
|
catch (error) {
|
|
186
|
-
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
479
|
+
assertsError(error);
|
|
189
480
|
if (error.message.includes('Unexpected token')) {
|
|
190
481
|
return false;
|
|
191
482
|
}
|
|
@@ -246,7 +537,7 @@
|
|
|
246
537
|
function keepUnused(...valuesToKeep) {
|
|
247
538
|
}
|
|
248
539
|
|
|
249
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",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}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
|
|
540
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",parameters:[{name:"availableModels",description:"List of available model names together with their descriptions as JSON",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelsRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n```json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n```\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n```json\n{availableModels}\n```\n\n### Key `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### Key `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}",resultingParameterName:"modelsRequirements",format:"JSON",dependentParameterNames:["availableModels","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModels}` List of available model names together with their descriptions as JSON\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelsRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n\\`\\`\\`json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n\\`\\`\\`json\n{availableModels}\n\\`\\`\\`\n\n### Key `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### Key `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}\n```\n\n`-> {modelsRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
|
|
250
541
|
|
|
251
542
|
/**
|
|
252
543
|
* Checks if value is valid email
|
|
@@ -486,234 +777,62 @@
|
|
|
486
777
|
} /* not else */
|
|
487
778
|
if (postprocessing) {
|
|
488
779
|
for (const postprocessingFunctionName of postprocessing) {
|
|
489
|
-
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
490
|
-
}
|
|
491
|
-
} /* not else */
|
|
492
|
-
if (expectations) {
|
|
493
|
-
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
494
|
-
if (min === max) {
|
|
495
|
-
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
if (min !== undefined) {
|
|
499
|
-
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
500
|
-
} /* not else */
|
|
501
|
-
if (max !== undefined) {
|
|
502
|
-
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
} /* not else */
|
|
507
|
-
if (format) {
|
|
508
|
-
if (format === 'JSON') {
|
|
509
|
-
// TODO: @deprecated remove
|
|
510
|
-
commands.push(`FORMAT JSON`);
|
|
511
|
-
}
|
|
512
|
-
} /* not else */
|
|
513
|
-
pipelineString += '\n\n';
|
|
514
|
-
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
515
|
-
pipelineString += '\n\n';
|
|
516
|
-
pipelineString += '```' + contentLanguage;
|
|
517
|
-
pipelineString += '\n';
|
|
518
|
-
pipelineString += spaceTrim__default["default"](content);
|
|
519
|
-
// <- TODO: [main] !!3 Escape
|
|
520
|
-
// <- TODO: [๐ง ] Some clear strategy how to spaceTrim the blocks
|
|
521
|
-
pipelineString += '\n';
|
|
522
|
-
pipelineString += '```';
|
|
523
|
-
pipelineString += '\n\n';
|
|
524
|
-
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
525
|
-
}
|
|
526
|
-
return validatePipelineString(pipelineString);
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* @private internal utility of `pipelineJsonToString`
|
|
530
|
-
*/
|
|
531
|
-
function taskParameterJsonToString(taskParameterJson) {
|
|
532
|
-
const { name, description } = taskParameterJson;
|
|
533
|
-
let parameterString = `{${name}}`;
|
|
534
|
-
if (description) {
|
|
535
|
-
parameterString = `${parameterString} ${description}`;
|
|
536
|
-
}
|
|
537
|
-
return parameterString;
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* TODO: [๐] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
541
|
-
* TODO: [๐ง ] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
542
|
-
* TODO: [๐] Maybe make some markdown builder
|
|
543
|
-
* TODO: [๐] Escape all
|
|
544
|
-
* TODO: [๐ง ] Should be in generated .book.md file GENERATOR_WARNING
|
|
545
|
-
*/
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Returns the same value that is passed as argument.
|
|
549
|
-
* No side effects.
|
|
550
|
-
*
|
|
551
|
-
* Note: It can be usefull for:
|
|
552
|
-
*
|
|
553
|
-
* 1) Leveling indentation
|
|
554
|
-
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
555
|
-
*
|
|
556
|
-
* @param value any values
|
|
557
|
-
* @returns the same values
|
|
558
|
-
* @private within the repository
|
|
559
|
-
*/
|
|
560
|
-
function just(value) {
|
|
561
|
-
if (value === undefined) {
|
|
562
|
-
return undefined;
|
|
563
|
-
}
|
|
564
|
-
return value;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* Warning message for the generated sections and files files
|
|
569
|
-
*
|
|
570
|
-
* @private within the repository
|
|
571
|
-
*/
|
|
572
|
-
const GENERATOR_WARNING = `โ ๏ธ WARNING: This code has been generated so that any manual changes will be overwritten`;
|
|
573
|
-
/**
|
|
574
|
-
* Name for the Promptbook
|
|
575
|
-
*
|
|
576
|
-
* TODO: [๐ฝ] Unite branding and make single place for it
|
|
577
|
-
*
|
|
578
|
-
* @public exported from `@promptbook/core`
|
|
579
|
-
*/
|
|
580
|
-
const NAME = `Promptbook`;
|
|
581
|
-
/**
|
|
582
|
-
* Email of the responsible person
|
|
583
|
-
*
|
|
584
|
-
* @public exported from `@promptbook/core`
|
|
585
|
-
*/
|
|
586
|
-
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
587
|
-
/**
|
|
588
|
-
* Name of the responsible person for the Promptbook on GitHub
|
|
589
|
-
*
|
|
590
|
-
* @public exported from `@promptbook/core`
|
|
591
|
-
*/
|
|
592
|
-
const ADMIN_GITHUB_NAME = 'hejny';
|
|
593
|
-
/**
|
|
594
|
-
* When the title is not provided, the default title is used
|
|
595
|
-
*
|
|
596
|
-
* @public exported from `@promptbook/core`
|
|
597
|
-
*/
|
|
598
|
-
const DEFAULT_BOOK_TITLE = `โจ Untitled Book`;
|
|
599
|
-
/**
|
|
600
|
-
* Maximum file size limit
|
|
601
|
-
*
|
|
602
|
-
* @public exported from `@promptbook/core`
|
|
603
|
-
*/
|
|
604
|
-
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
605
|
-
// <- TODO: [๐ง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
606
|
-
/**
|
|
607
|
-
* The maximum number of iterations for a loops
|
|
608
|
-
*
|
|
609
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
610
|
-
*/
|
|
611
|
-
const LOOP_LIMIT = 1000;
|
|
612
|
-
/**
|
|
613
|
-
* Strings to represent various values in the context of parameter values
|
|
614
|
-
*
|
|
615
|
-
* @public exported from `@promptbook/utils`
|
|
616
|
-
*/
|
|
617
|
-
const VALUE_STRINGS = {
|
|
618
|
-
empty: '(nothing; empty string)',
|
|
619
|
-
null: '(no value; null)',
|
|
620
|
-
undefined: '(unknown value; undefined)',
|
|
621
|
-
nan: '(not a number; NaN)',
|
|
622
|
-
infinity: '(infinity; โ)',
|
|
623
|
-
negativeInfinity: '(negative infinity; -โ)',
|
|
624
|
-
unserializable: '(unserializable value)',
|
|
625
|
-
};
|
|
626
|
-
/**
|
|
627
|
-
* Small number limit
|
|
628
|
-
*
|
|
629
|
-
* @public exported from `@promptbook/utils`
|
|
630
|
-
*/
|
|
631
|
-
const SMALL_NUMBER = 0.001;
|
|
632
|
-
/**
|
|
633
|
-
* Short time interval to prevent race conditions in milliseconds
|
|
634
|
-
*
|
|
635
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
636
|
-
*/
|
|
637
|
-
const IMMEDIATE_TIME = 10;
|
|
638
|
-
/**
|
|
639
|
-
* The maximum length of the (generated) filename
|
|
640
|
-
*
|
|
641
|
-
* @public exported from `@promptbook/core`
|
|
642
|
-
*/
|
|
643
|
-
const MAX_FILENAME_LENGTH = 30;
|
|
644
|
-
/**
|
|
645
|
-
* Strategy for caching the intermediate results for knowledge sources
|
|
646
|
-
*
|
|
647
|
-
* @public exported from `@promptbook/core`
|
|
648
|
-
*/
|
|
649
|
-
const DEFAULT_INTERMEDIATE_FILES_STRATEGY = 'HIDE_AND_KEEP';
|
|
650
|
-
// <- TODO: [๐ก] Change to 'VISIBLE'
|
|
651
|
-
/**
|
|
652
|
-
* The maximum number of (LLM) tasks running in parallel
|
|
653
|
-
*
|
|
654
|
-
* @public exported from `@promptbook/core`
|
|
655
|
-
*/
|
|
656
|
-
const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐คนโโ๏ธ]
|
|
657
|
-
/**
|
|
658
|
-
* The maximum number of attempts to execute LLM task before giving up
|
|
659
|
-
*
|
|
660
|
-
* @public exported from `@promptbook/core`
|
|
661
|
-
*/
|
|
662
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐คนโโ๏ธ]
|
|
663
|
-
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
664
|
-
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
665
|
-
/**
|
|
666
|
-
* Where to store the temporary downloads
|
|
667
|
-
*
|
|
668
|
-
* Note: When the folder does not exist, it is created recursively
|
|
669
|
-
*
|
|
670
|
-
* @public exported from `@promptbook/core`
|
|
671
|
-
*/
|
|
672
|
-
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
673
|
-
/**
|
|
674
|
-
* Where to store the scrape cache
|
|
675
|
-
*
|
|
676
|
-
* Note: When the folder does not exist, it is created recursively
|
|
677
|
-
*
|
|
678
|
-
* @public exported from `@promptbook/core`
|
|
679
|
-
*/
|
|
680
|
-
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
681
|
-
// <- TODO: [๐งโโ๏ธ]
|
|
682
|
-
/**
|
|
683
|
-
* @@@
|
|
684
|
-
*
|
|
685
|
-
* @public exported from `@promptbook/core`
|
|
686
|
-
*/
|
|
687
|
-
const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
688
|
-
delimiter: ',',
|
|
689
|
-
quoteChar: '"',
|
|
690
|
-
newline: '\n',
|
|
691
|
-
skipEmptyLines: true,
|
|
692
|
-
});
|
|
693
|
-
/**
|
|
694
|
-
* @@@
|
|
695
|
-
*
|
|
696
|
-
* @public exported from `@promptbook/core`
|
|
697
|
-
*/
|
|
698
|
-
let DEFAULT_IS_VERBOSE = false;
|
|
699
|
-
/**
|
|
700
|
-
* @@@
|
|
701
|
-
*
|
|
702
|
-
* @public exported from `@promptbook/core`
|
|
703
|
-
*/
|
|
704
|
-
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
780
|
+
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
781
|
+
}
|
|
782
|
+
} /* not else */
|
|
783
|
+
if (expectations) {
|
|
784
|
+
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
785
|
+
if (min === max) {
|
|
786
|
+
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
if (min !== undefined) {
|
|
790
|
+
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
791
|
+
} /* not else */
|
|
792
|
+
if (max !== undefined) {
|
|
793
|
+
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
} /* not else */
|
|
798
|
+
if (format) {
|
|
799
|
+
if (format === 'JSON') {
|
|
800
|
+
// TODO: @deprecated remove
|
|
801
|
+
commands.push(`FORMAT JSON`);
|
|
802
|
+
}
|
|
803
|
+
} /* not else */
|
|
804
|
+
pipelineString += '\n\n';
|
|
805
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
806
|
+
pipelineString += '\n\n';
|
|
807
|
+
pipelineString += '```' + contentLanguage;
|
|
808
|
+
pipelineString += '\n';
|
|
809
|
+
pipelineString += spaceTrim__default["default"](content);
|
|
810
|
+
// <- TODO: [main] !!3 Escape
|
|
811
|
+
// <- TODO: [๐ง ] Some clear strategy how to spaceTrim the blocks
|
|
812
|
+
pipelineString += '\n';
|
|
813
|
+
pipelineString += '```';
|
|
814
|
+
pipelineString += '\n\n';
|
|
815
|
+
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
816
|
+
}
|
|
817
|
+
return validatePipelineString(pipelineString);
|
|
818
|
+
}
|
|
705
819
|
/**
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* @private within the repository
|
|
820
|
+
* @private internal utility of `pipelineJsonToString`
|
|
709
821
|
*/
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
822
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
823
|
+
const { name, description } = taskParameterJson;
|
|
824
|
+
let parameterString = `{${name}}`;
|
|
825
|
+
if (description) {
|
|
826
|
+
parameterString = `${parameterString} ${description}`;
|
|
827
|
+
}
|
|
828
|
+
return parameterString;
|
|
829
|
+
}
|
|
714
830
|
/**
|
|
715
|
-
*
|
|
716
|
-
* TODO: [๐ง ]
|
|
831
|
+
* TODO: [๐] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
832
|
+
* TODO: [๐ง ] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
833
|
+
* TODO: [๐] Maybe make some markdown builder
|
|
834
|
+
* TODO: [๐] Escape all
|
|
835
|
+
* TODO: [๐ง ] Should be in generated .book.md file GENERATOR_WARNING
|
|
717
836
|
*/
|
|
718
837
|
|
|
719
838
|
/**
|
|
@@ -758,74 +877,6 @@
|
|
|
758
877
|
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
759
878
|
*/
|
|
760
879
|
|
|
761
|
-
/**
|
|
762
|
-
* Make error report URL for the given error
|
|
763
|
-
*
|
|
764
|
-
* @private private within the repository
|
|
765
|
-
*/
|
|
766
|
-
function getErrorReportUrl(error) {
|
|
767
|
-
const report = {
|
|
768
|
-
title: `๐ Error report from ${NAME}`,
|
|
769
|
-
body: spaceTrim__default["default"]((block) => `
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
773
|
-
|
|
774
|
-
\`\`\`
|
|
775
|
-
${block(error.message || '(no error message)')}
|
|
776
|
-
\`\`\`
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
## More info:
|
|
780
|
-
|
|
781
|
-
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
782
|
-
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
783
|
-
- **Time:** ${new Date().toISOString()}
|
|
784
|
-
|
|
785
|
-
<details>
|
|
786
|
-
<summary>Stack trace:</summary>
|
|
787
|
-
|
|
788
|
-
## Stack trace:
|
|
789
|
-
|
|
790
|
-
\`\`\`stacktrace
|
|
791
|
-
${block(error.stack || '(empty)')}
|
|
792
|
-
\`\`\`
|
|
793
|
-
</details>
|
|
794
|
-
|
|
795
|
-
`),
|
|
796
|
-
};
|
|
797
|
-
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
798
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
799
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
800
|
-
reportUrl.searchParams.set('title', report.title);
|
|
801
|
-
reportUrl.searchParams.set('body', report.body);
|
|
802
|
-
return reportUrl;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
/**
|
|
806
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
807
|
-
*
|
|
808
|
-
* @public exported from `@promptbook/core`
|
|
809
|
-
*/
|
|
810
|
-
class UnexpectedError extends Error {
|
|
811
|
-
constructor(message) {
|
|
812
|
-
super(spaceTrim.spaceTrim((block) => `
|
|
813
|
-
${block(message)}
|
|
814
|
-
|
|
815
|
-
Note: This error should not happen.
|
|
816
|
-
It's probbably a bug in the pipeline collection
|
|
817
|
-
|
|
818
|
-
Please report issue:
|
|
819
|
-
${block(getErrorReportUrl(new Error(message)).href)}
|
|
820
|
-
|
|
821
|
-
Or contact us on ${ADMIN_EMAIL}
|
|
822
|
-
|
|
823
|
-
`));
|
|
824
|
-
this.name = 'UnexpectedError';
|
|
825
|
-
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
|
|
829
880
|
/**
|
|
830
881
|
* Checks if the value is [๐] serializable as JSON
|
|
831
882
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -917,9 +968,7 @@
|
|
|
917
968
|
JSON.stringify(value); // <- TODO: [0]
|
|
918
969
|
}
|
|
919
970
|
catch (error) {
|
|
920
|
-
|
|
921
|
-
throw error;
|
|
922
|
-
}
|
|
971
|
+
assertsError(error);
|
|
923
972
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
924
973
|
\`${name}\` is not serializable
|
|
925
974
|
|
|
@@ -1514,7 +1563,7 @@
|
|
|
1514
1563
|
*/
|
|
1515
1564
|
function unpreparePipeline(pipeline) {
|
|
1516
1565
|
let { personas, knowledgeSources, tasks } = pipeline;
|
|
1517
|
-
personas = personas.map((persona) => ({ ...persona,
|
|
1566
|
+
personas = personas.map((persona) => ({ ...persona, modelsRequirements: undefined, preparationIds: undefined }));
|
|
1518
1567
|
knowledgeSources = knowledgeSources.map((knowledgeSource) => ({ ...knowledgeSource, preparationIds: undefined }));
|
|
1519
1568
|
tasks = tasks.map((task) => {
|
|
1520
1569
|
let { dependentParameterNames } = task;
|
|
@@ -1708,7 +1757,7 @@
|
|
|
1708
1757
|
}
|
|
1709
1758
|
}
|
|
1710
1759
|
/**
|
|
1711
|
-
* TODO:
|
|
1760
|
+
* TODO: [๐ง ][๐] Add id to all errors
|
|
1712
1761
|
*/
|
|
1713
1762
|
|
|
1714
1763
|
/**
|
|
@@ -1724,7 +1773,7 @@
|
|
|
1724
1773
|
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
1725
1774
|
return false;
|
|
1726
1775
|
}
|
|
1727
|
-
if (!pipeline.personas.every((persona) => persona.
|
|
1776
|
+
if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
|
|
1728
1777
|
return false;
|
|
1729
1778
|
}
|
|
1730
1779
|
if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
|
|
@@ -1748,6 +1797,45 @@
|
|
|
1748
1797
|
* - [โจ] Are tasks prepared
|
|
1749
1798
|
*/
|
|
1750
1799
|
|
|
1800
|
+
/**
|
|
1801
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
1802
|
+
*
|
|
1803
|
+
* Note: This is wrapper around `JSON.parse()` with better error and type handling
|
|
1804
|
+
*
|
|
1805
|
+
* @public exported from `@promptbook/utils`
|
|
1806
|
+
*/
|
|
1807
|
+
function jsonParse(value) {
|
|
1808
|
+
if (value === undefined) {
|
|
1809
|
+
throw new Error(`Can not parse JSON from undefined value.`);
|
|
1810
|
+
}
|
|
1811
|
+
else if (typeof value !== 'string') {
|
|
1812
|
+
console.error('Can not parse JSON from non-string value.', { text: value });
|
|
1813
|
+
throw new Error(spaceTrim__default["default"](`
|
|
1814
|
+
Can not parse JSON from non-string value.
|
|
1815
|
+
|
|
1816
|
+
The value type: ${typeof value}
|
|
1817
|
+
See more in console.
|
|
1818
|
+
`));
|
|
1819
|
+
}
|
|
1820
|
+
try {
|
|
1821
|
+
return JSON.parse(value);
|
|
1822
|
+
}
|
|
1823
|
+
catch (error) {
|
|
1824
|
+
if (!(error instanceof Error)) {
|
|
1825
|
+
throw error;
|
|
1826
|
+
}
|
|
1827
|
+
throw new Error(spaceTrim__default["default"]((block) => `
|
|
1828
|
+
${block(error.message)}
|
|
1829
|
+
|
|
1830
|
+
The JSON text:
|
|
1831
|
+
${block(value)}
|
|
1832
|
+
`));
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* TODO: !!!! Use in Promptbook.studio
|
|
1837
|
+
*/
|
|
1838
|
+
|
|
1751
1839
|
/**
|
|
1752
1840
|
* Recursively converts JSON strings to JSON objects
|
|
1753
1841
|
|
|
@@ -1766,7 +1854,7 @@
|
|
|
1766
1854
|
const newObject = { ...object };
|
|
1767
1855
|
for (const [key, value] of Object.entries(object)) {
|
|
1768
1856
|
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
1769
|
-
newObject[key] =
|
|
1857
|
+
newObject[key] = jsonParse(value);
|
|
1770
1858
|
}
|
|
1771
1859
|
else {
|
|
1772
1860
|
newObject[key] = jsonStringsToJsons(value);
|
|
@@ -1945,7 +2033,10 @@
|
|
|
1945
2033
|
PipelineExecutionError,
|
|
1946
2034
|
PipelineLogicError,
|
|
1947
2035
|
PipelineUrlError,
|
|
2036
|
+
AuthenticationError,
|
|
2037
|
+
PromptbookFetchError,
|
|
1948
2038
|
UnexpectedError,
|
|
2039
|
+
WrappedError,
|
|
1949
2040
|
// TODO: [๐ช]> VersionMismatchError,
|
|
1950
2041
|
};
|
|
1951
2042
|
/**
|
|
@@ -1962,8 +2053,6 @@
|
|
|
1962
2053
|
TypeError,
|
|
1963
2054
|
URIError,
|
|
1964
2055
|
AggregateError,
|
|
1965
|
-
AuthenticationError,
|
|
1966
|
-
PromptbookFetchError,
|
|
1967
2056
|
/*
|
|
1968
2057
|
Note: Not widely supported
|
|
1969
2058
|
> InternalError,
|
|
@@ -2086,8 +2175,8 @@
|
|
|
2086
2175
|
updatedAt = new Date();
|
|
2087
2176
|
errors.push(...executionResult.errors);
|
|
2088
2177
|
warnings.push(...executionResult.warnings);
|
|
2089
|
-
// <- TODO:
|
|
2090
|
-
// TODO: [๐ง ]
|
|
2178
|
+
// <- TODO: [๐] Only unique errors and warnings should be added (or filtered)
|
|
2179
|
+
// TODO: [๐ง ] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2091
2180
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2092
2181
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2093
2182
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2097,6 +2186,7 @@
|
|
|
2097
2186
|
partialResultSubject.next(executionResult);
|
|
2098
2187
|
}
|
|
2099
2188
|
catch (error) {
|
|
2189
|
+
assertsError(error);
|
|
2100
2190
|
status = 'ERROR';
|
|
2101
2191
|
errors.push(error);
|
|
2102
2192
|
partialResultSubject.error(error);
|
|
@@ -2488,14 +2578,15 @@
|
|
|
2488
2578
|
}
|
|
2489
2579
|
}
|
|
2490
2580
|
catch (error) {
|
|
2491
|
-
|
|
2581
|
+
assertsError(error);
|
|
2582
|
+
if (error instanceof UnexpectedError) {
|
|
2492
2583
|
throw error;
|
|
2493
2584
|
}
|
|
2494
2585
|
errors.push({ llmExecutionTools, error });
|
|
2495
2586
|
}
|
|
2496
2587
|
}
|
|
2497
2588
|
if (errors.length === 1) {
|
|
2498
|
-
throw errors[0];
|
|
2589
|
+
throw errors[0].error;
|
|
2499
2590
|
}
|
|
2500
2591
|
else if (errors.length > 1) {
|
|
2501
2592
|
throw new PipelineExecutionError(
|
|
@@ -2621,27 +2712,48 @@
|
|
|
2621
2712
|
pipeline: await collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book'),
|
|
2622
2713
|
tools,
|
|
2623
2714
|
});
|
|
2624
|
-
// TODO: [๐] Make arrayable LLMs -> single LLM DRY
|
|
2625
2715
|
const _llms = arrayableToArray(tools.llm);
|
|
2626
2716
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
2627
|
-
const availableModels = await llmTools.listModels()
|
|
2628
|
-
const availableModelNames = availableModels
|
|
2717
|
+
const availableModels = (await llmTools.listModels())
|
|
2629
2718
|
.filter(({ modelVariant }) => modelVariant === 'CHAT')
|
|
2630
|
-
.map(({ modelName }) =>
|
|
2631
|
-
|
|
2632
|
-
|
|
2719
|
+
.map(({ modelName, modelDescription }) => ({
|
|
2720
|
+
modelName,
|
|
2721
|
+
modelDescription,
|
|
2722
|
+
// <- Note: `modelTitle` and `modelVariant` is not relevant for this task
|
|
2723
|
+
}));
|
|
2724
|
+
const result = await preparePersonaExecutor({
|
|
2725
|
+
availableModels /* <- Note: Passing as JSON */,
|
|
2726
|
+
personaDescription,
|
|
2727
|
+
}).asPromise();
|
|
2633
2728
|
const { outputParameters } = result;
|
|
2634
|
-
const {
|
|
2635
|
-
|
|
2729
|
+
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
2730
|
+
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
2636
2731
|
if (isVerbose) {
|
|
2637
|
-
console.info(`PERSONA ${personaDescription}`,
|
|
2732
|
+
console.info(`PERSONA ${personaDescription}`, modelsRequirementsUnchecked);
|
|
2638
2733
|
}
|
|
2639
|
-
|
|
2640
|
-
|
|
2734
|
+
if (!Array.isArray(modelsRequirementsUnchecked)) {
|
|
2735
|
+
// <- TODO: Book should have syntax and system to enforce shape of JSON
|
|
2736
|
+
modelsRequirementsUnchecked = [modelsRequirementsUnchecked];
|
|
2737
|
+
/*
|
|
2738
|
+
throw new UnexpectedError(
|
|
2739
|
+
spaceTrim(
|
|
2740
|
+
(block) => `
|
|
2741
|
+
Invalid \`modelsRequirements\`:
|
|
2742
|
+
|
|
2743
|
+
\`\`\`json
|
|
2744
|
+
${block(JSON.stringify(modelsRequirementsUnchecked, null, 4))}
|
|
2745
|
+
\`\`\`
|
|
2746
|
+
`,
|
|
2747
|
+
),
|
|
2748
|
+
);
|
|
2749
|
+
*/
|
|
2750
|
+
}
|
|
2751
|
+
const modelsRequirements = modelsRequirementsUnchecked.map((modelRequirements) => ({
|
|
2641
2752
|
modelVariant: 'CHAT',
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2753
|
+
...modelRequirements,
|
|
2754
|
+
}));
|
|
2755
|
+
return {
|
|
2756
|
+
modelsRequirements,
|
|
2645
2757
|
};
|
|
2646
2758
|
}
|
|
2647
2759
|
/**
|
|
@@ -3336,9 +3448,7 @@
|
|
|
3336
3448
|
return await fetch(urlOrRequest, init);
|
|
3337
3449
|
}
|
|
3338
3450
|
catch (error) {
|
|
3339
|
-
|
|
3340
|
-
throw error;
|
|
3341
|
-
}
|
|
3451
|
+
assertsError(error);
|
|
3342
3452
|
let url;
|
|
3343
3453
|
if (typeof urlOrRequest === 'string') {
|
|
3344
3454
|
url = urlOrRequest;
|
|
@@ -3467,7 +3577,7 @@
|
|
|
3467
3577
|
> },
|
|
3468
3578
|
*/
|
|
3469
3579
|
async asJson() {
|
|
3470
|
-
return
|
|
3580
|
+
return jsonParse(await tools.fs.readFile(filename, 'utf-8'));
|
|
3471
3581
|
},
|
|
3472
3582
|
async asText() {
|
|
3473
3583
|
return await tools.fs.readFile(filename, 'utf-8');
|
|
@@ -3569,9 +3679,7 @@
|
|
|
3569
3679
|
knowledgePreparedUnflatten[index] = pieces;
|
|
3570
3680
|
}
|
|
3571
3681
|
catch (error) {
|
|
3572
|
-
|
|
3573
|
-
throw error;
|
|
3574
|
-
}
|
|
3682
|
+
assertsError(error);
|
|
3575
3683
|
console.warn(error);
|
|
3576
3684
|
// <- TODO: [๐ฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3577
3685
|
}
|
|
@@ -3727,14 +3835,14 @@
|
|
|
3727
3835
|
// TODO: [๐][๐ง ] Implement some `mapAsync` function
|
|
3728
3836
|
const preparedPersonas = new Array(personas.length);
|
|
3729
3837
|
await forEachAsync(personas, { maxParallelCount /* <- TODO: [๐ช] When there are subtasks, this maximul limit can be broken */ }, async (persona, index) => {
|
|
3730
|
-
const
|
|
3838
|
+
const { modelsRequirements } = await preparePersona(persona.description, { ...tools, llm: llmToolsWithUsage }, {
|
|
3731
3839
|
rootDirname,
|
|
3732
3840
|
maxParallelCount /* <- TODO: [๐ช] */,
|
|
3733
3841
|
isVerbose,
|
|
3734
3842
|
});
|
|
3735
3843
|
const preparedPersona = {
|
|
3736
3844
|
...persona,
|
|
3737
|
-
|
|
3845
|
+
modelsRequirements,
|
|
3738
3846
|
preparationIds: [/* TODO: [๐ง] -> */ currentPreparation.id],
|
|
3739
3847
|
// <- TODO: [๐] Make some standard order of json properties
|
|
3740
3848
|
};
|
|
@@ -3863,13 +3971,19 @@
|
|
|
3863
3971
|
return value.toISOString();
|
|
3864
3972
|
}
|
|
3865
3973
|
else {
|
|
3866
|
-
|
|
3974
|
+
try {
|
|
3975
|
+
return JSON.stringify(value);
|
|
3976
|
+
}
|
|
3977
|
+
catch (error) {
|
|
3978
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3979
|
+
return VALUE_STRINGS.circular;
|
|
3980
|
+
}
|
|
3981
|
+
throw error;
|
|
3982
|
+
}
|
|
3867
3983
|
}
|
|
3868
3984
|
}
|
|
3869
3985
|
catch (error) {
|
|
3870
|
-
|
|
3871
|
-
throw error;
|
|
3872
|
-
}
|
|
3986
|
+
assertsError(error);
|
|
3873
3987
|
console.error(error);
|
|
3874
3988
|
return VALUE_STRINGS.unserializable;
|
|
3875
3989
|
}
|
|
@@ -3926,9 +4040,7 @@
|
|
|
3926
4040
|
}
|
|
3927
4041
|
}
|
|
3928
4042
|
catch (error) {
|
|
3929
|
-
|
|
3930
|
-
throw error;
|
|
3931
|
-
}
|
|
4043
|
+
assertsError(error);
|
|
3932
4044
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
3933
4045
|
Can not extract variables from the script
|
|
3934
4046
|
${block(error.stack || error.message)}
|
|
@@ -4047,6 +4159,46 @@
|
|
|
4047
4159
|
// encoding: 'utf-8',
|
|
4048
4160
|
});
|
|
4049
4161
|
|
|
4162
|
+
/**
|
|
4163
|
+
* Function to check if a string is valid CSV
|
|
4164
|
+
*
|
|
4165
|
+
* @param value The string to check
|
|
4166
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
4167
|
+
*
|
|
4168
|
+
* @public exported from `@promptbook/utils`
|
|
4169
|
+
*/
|
|
4170
|
+
function isValidCsvString(value) {
|
|
4171
|
+
try {
|
|
4172
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
4173
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
4174
|
+
return true;
|
|
4175
|
+
}
|
|
4176
|
+
return false;
|
|
4177
|
+
}
|
|
4178
|
+
catch (error) {
|
|
4179
|
+
assertsError(error);
|
|
4180
|
+
return false;
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
/**
|
|
4185
|
+
* Converts a CSV string into an object
|
|
4186
|
+
*
|
|
4187
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
4188
|
+
*
|
|
4189
|
+
* @private - for now until `@promptbook/csv` is released
|
|
4190
|
+
*/
|
|
4191
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
4192
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
4193
|
+
// Note: Autoheal invalid '\n' characters
|
|
4194
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
4195
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
4196
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
4197
|
+
}
|
|
4198
|
+
const csv = papaparse.parse(value, settings);
|
|
4199
|
+
return csv;
|
|
4200
|
+
}
|
|
4201
|
+
|
|
4050
4202
|
/**
|
|
4051
4203
|
* Definition for CSV spreadsheet
|
|
4052
4204
|
*
|
|
@@ -4057,7 +4209,7 @@
|
|
|
4057
4209
|
formatName: 'CSV',
|
|
4058
4210
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
4059
4211
|
isValid(value, settings, schema) {
|
|
4060
|
-
return
|
|
4212
|
+
return isValidCsvString(value);
|
|
4061
4213
|
},
|
|
4062
4214
|
canBeValid(partialValue, settings, schema) {
|
|
4063
4215
|
return true;
|
|
@@ -4069,8 +4221,7 @@
|
|
|
4069
4221
|
{
|
|
4070
4222
|
subvalueName: 'ROW',
|
|
4071
4223
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
4072
|
-
|
|
4073
|
-
const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4224
|
+
const csv = csvParse(value, settings);
|
|
4074
4225
|
if (csv.errors.length !== 0) {
|
|
4075
4226
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
4076
4227
|
CSV parsing error
|
|
@@ -4100,8 +4251,7 @@
|
|
|
4100
4251
|
{
|
|
4101
4252
|
subvalueName: 'CELL',
|
|
4102
4253
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
4103
|
-
|
|
4104
|
-
const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4254
|
+
const csv = csvParse(value, settings);
|
|
4105
4255
|
if (csv.errors.length !== 0) {
|
|
4106
4256
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
4107
4257
|
CSV parsing error
|
|
@@ -4211,6 +4361,30 @@
|
|
|
4211
4361
|
* TODO: [๐ข] Allow to expect something inside each item of list and other formats
|
|
4212
4362
|
*/
|
|
4213
4363
|
|
|
4364
|
+
/**
|
|
4365
|
+
* Function to check if a string is valid XML
|
|
4366
|
+
*
|
|
4367
|
+
* @param value
|
|
4368
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
4369
|
+
*
|
|
4370
|
+
* @public exported from `@promptbook/utils`
|
|
4371
|
+
*/
|
|
4372
|
+
function isValidXmlString(value) {
|
|
4373
|
+
try {
|
|
4374
|
+
const parser = new DOMParser();
|
|
4375
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
4376
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
4377
|
+
if (parserError.length > 0) {
|
|
4378
|
+
return false;
|
|
4379
|
+
}
|
|
4380
|
+
return true;
|
|
4381
|
+
}
|
|
4382
|
+
catch (error) {
|
|
4383
|
+
assertsError(error);
|
|
4384
|
+
return false;
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
|
|
4214
4388
|
/**
|
|
4215
4389
|
* Definition for XML format
|
|
4216
4390
|
*
|
|
@@ -4220,7 +4394,7 @@
|
|
|
4220
4394
|
formatName: 'XML',
|
|
4221
4395
|
mimeType: 'application/xml',
|
|
4222
4396
|
isValid(value, settings, schema) {
|
|
4223
|
-
return
|
|
4397
|
+
return isValidXmlString(value);
|
|
4224
4398
|
},
|
|
4225
4399
|
canBeValid(partialValue, settings, schema) {
|
|
4226
4400
|
return true;
|
|
@@ -4691,9 +4865,7 @@
|
|
|
4691
4865
|
break scripts;
|
|
4692
4866
|
}
|
|
4693
4867
|
catch (error) {
|
|
4694
|
-
|
|
4695
|
-
throw error;
|
|
4696
|
-
}
|
|
4868
|
+
assertsError(error);
|
|
4697
4869
|
if (error instanceof UnexpectedError) {
|
|
4698
4870
|
throw error;
|
|
4699
4871
|
}
|
|
@@ -4763,9 +4935,7 @@
|
|
|
4763
4935
|
break scripts;
|
|
4764
4936
|
}
|
|
4765
4937
|
catch (error) {
|
|
4766
|
-
|
|
4767
|
-
throw error;
|
|
4768
|
-
}
|
|
4938
|
+
assertsError(error);
|
|
4769
4939
|
if (error instanceof UnexpectedError) {
|
|
4770
4940
|
throw error;
|
|
4771
4941
|
}
|
|
@@ -5008,13 +5178,79 @@
|
|
|
5008
5178
|
/**
|
|
5009
5179
|
* @@@
|
|
5010
5180
|
*
|
|
5181
|
+
* Here is the place where RAG (retrieval-augmented generation) happens
|
|
5182
|
+
*
|
|
5011
5183
|
* @private internal utility of `createPipelineExecutor`
|
|
5012
5184
|
*/
|
|
5013
5185
|
async function getKnowledgeForTask(options) {
|
|
5014
|
-
const { preparedPipeline, task } = options;
|
|
5015
|
-
|
|
5186
|
+
const { tools, preparedPipeline, task } = options;
|
|
5187
|
+
const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
|
|
5188
|
+
const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
|
|
5189
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
|
|
5190
|
+
if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
|
|
5191
|
+
return 'No knowledge pieces found';
|
|
5192
|
+
}
|
|
5193
|
+
// TODO: [๐] Make arrayable LLMs -> single LLM DRY
|
|
5194
|
+
const _llms = arrayableToArray(tools.llm);
|
|
5195
|
+
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
5196
|
+
const taskEmbeddingPrompt = {
|
|
5197
|
+
title: 'Knowledge Search',
|
|
5198
|
+
modelRequirements: {
|
|
5199
|
+
modelVariant: 'EMBEDDING',
|
|
5200
|
+
modelName: firstKnowlegeIndex.modelName,
|
|
5201
|
+
},
|
|
5202
|
+
content: task.content,
|
|
5203
|
+
parameters: {
|
|
5204
|
+
/* !!!!!!!! */
|
|
5205
|
+
},
|
|
5206
|
+
};
|
|
5207
|
+
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
5208
|
+
const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
|
|
5209
|
+
const { index } = knowledgePiece;
|
|
5210
|
+
const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
|
|
5211
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model
|
|
5212
|
+
if (knowledgePieceIndex === undefined) {
|
|
5213
|
+
return {
|
|
5214
|
+
content: knowledgePiece.content,
|
|
5215
|
+
relevance: 0,
|
|
5216
|
+
};
|
|
5217
|
+
}
|
|
5218
|
+
const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
|
|
5219
|
+
return {
|
|
5220
|
+
content: knowledgePiece.content,
|
|
5221
|
+
relevance,
|
|
5222
|
+
};
|
|
5223
|
+
});
|
|
5224
|
+
const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
|
|
5225
|
+
const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
|
|
5226
|
+
console.log('!!! Embedding', {
|
|
5227
|
+
task,
|
|
5228
|
+
taskEmbeddingPrompt,
|
|
5229
|
+
taskEmbeddingResult,
|
|
5230
|
+
firstKnowlegePiece,
|
|
5231
|
+
firstKnowlegeIndex,
|
|
5232
|
+
knowledgePiecesWithRelevance,
|
|
5233
|
+
knowledgePiecesSorted,
|
|
5234
|
+
knowledgePiecesLimited,
|
|
5235
|
+
});
|
|
5236
|
+
return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
|
|
5016
5237
|
// <- TODO: [๐ง ] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
|
|
5017
5238
|
}
|
|
5239
|
+
// TODO: !!!!!! Annotate + to new file
|
|
5240
|
+
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5241
|
+
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5242
|
+
throw new TypeError('Embedding vectors must have the same length');
|
|
5243
|
+
}
|
|
5244
|
+
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5245
|
+
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5246
|
+
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5247
|
+
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5248
|
+
}
|
|
5249
|
+
/**
|
|
5250
|
+
* TODO: !!!! Verify if this is working
|
|
5251
|
+
* TODO: [โจ] Implement Better - use keyword search
|
|
5252
|
+
* TODO: [โจ] Examples of values
|
|
5253
|
+
*/
|
|
5018
5254
|
|
|
5019
5255
|
/**
|
|
5020
5256
|
* @@@
|
|
@@ -5022,9 +5258,9 @@
|
|
|
5022
5258
|
* @private internal utility of `createPipelineExecutor`
|
|
5023
5259
|
*/
|
|
5024
5260
|
async function getReservedParametersForTask(options) {
|
|
5025
|
-
const { preparedPipeline, task, pipelineIdentification } = options;
|
|
5261
|
+
const { tools, preparedPipeline, task, pipelineIdentification } = options;
|
|
5026
5262
|
const context = await getContextForTask(); // <- [๐]
|
|
5027
|
-
const knowledge = await getKnowledgeForTask({ preparedPipeline, task });
|
|
5263
|
+
const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
|
|
5028
5264
|
const examples = await getExamplesForTask();
|
|
5029
5265
|
const currentDate = new Date().toISOString(); // <- TODO: [๐ง ][๐ฉ] Better
|
|
5030
5266
|
const modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
@@ -5086,6 +5322,7 @@
|
|
|
5086
5322
|
}
|
|
5087
5323
|
const definedParameters = Object.freeze({
|
|
5088
5324
|
...(await getReservedParametersForTask({
|
|
5325
|
+
tools,
|
|
5089
5326
|
preparedPipeline,
|
|
5090
5327
|
task: currentTask,
|
|
5091
5328
|
pipelineIdentification,
|
|
@@ -5386,9 +5623,7 @@
|
|
|
5386
5623
|
await Promise.all(resolving);
|
|
5387
5624
|
}
|
|
5388
5625
|
catch (error /* <- Note: [3] */) {
|
|
5389
|
-
|
|
5390
|
-
throw error;
|
|
5391
|
-
}
|
|
5626
|
+
assertsError(error);
|
|
5392
5627
|
// Note: No need to rethrow UnexpectedError
|
|
5393
5628
|
// if (error instanceof UnexpectedError) {
|
|
5394
5629
|
// Note: Count usage, [๐ง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐คนโโ๏ธ]
|