@promptbook/node 0.80.0-0 → 0.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/esm/index.es.js +267 -266
- 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 +0 -4
- package/esm/typings/src/commands/_common/getParserForCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -1
- package/esm/typings/src/conversion/{pipelineStringToJson.d.ts → compilePipeline.d.ts} +3 -3
- package/esm/typings/src/conversion/{pipelineStringToJsonSync.d.ts → precompilePipeline.d.ts} +3 -3
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
- package/esm/typings/src/high-level-abstractions/index.d.ts +1 -1
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +267 -266
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/{pipelineStringToJson.test.d.ts → compilePipeline.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/{pipelineStringToJsonSync.test.d.ts → precompilePipeline.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
*
|
|
44
44
|
* @see https://github.com/webgptorg/promptbook
|
|
45
45
|
*/
|
|
46
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
46
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
|
|
47
47
|
/**
|
|
48
48
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
49
49
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -304,256 +304,6 @@
|
|
|
304
304
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
305
305
|
*/
|
|
306
306
|
|
|
307
|
-
/**
|
|
308
|
-
* Prettify the html code
|
|
309
|
-
*
|
|
310
|
-
* @param content raw html code
|
|
311
|
-
* @returns formatted html code
|
|
312
|
-
* @private withing the package because of HUGE size of prettier dependency
|
|
313
|
-
*/
|
|
314
|
-
function prettifyMarkdown(content) {
|
|
315
|
-
try {
|
|
316
|
-
return prettier.format(content, {
|
|
317
|
-
parser: 'markdown',
|
|
318
|
-
plugins: [parserHtml__default["default"]],
|
|
319
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
320
|
-
endOfLine: 'lf',
|
|
321
|
-
tabWidth: 4,
|
|
322
|
-
singleQuote: true,
|
|
323
|
-
trailingComma: 'all',
|
|
324
|
-
arrowParens: 'always',
|
|
325
|
-
printWidth: 120,
|
|
326
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
327
|
-
jsxBracketSameLine: false,
|
|
328
|
-
bracketSpacing: true,
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
catch (error) {
|
|
332
|
-
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
333
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
334
|
-
error: error,
|
|
335
|
-
html: content,
|
|
336
|
-
});
|
|
337
|
-
return content;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Makes first letter of a string uppercase
|
|
343
|
-
*
|
|
344
|
-
* @public exported from `@promptbook/utils`
|
|
345
|
-
*/
|
|
346
|
-
function capitalize(word) {
|
|
347
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Converts promptbook in JSON format to string format
|
|
352
|
-
*
|
|
353
|
-
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
354
|
-
* @param pipelineJson Promptbook in JSON format (.book.json)
|
|
355
|
-
* @returns Promptbook in string format (.book.md)
|
|
356
|
-
* @public exported from `@promptbook/core`
|
|
357
|
-
*/
|
|
358
|
-
function pipelineJsonToString(pipelineJson) {
|
|
359
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
360
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
|
|
361
|
-
var pipelineString = "# ".concat(title);
|
|
362
|
-
if (description) {
|
|
363
|
-
pipelineString += '\n\n';
|
|
364
|
-
pipelineString += description;
|
|
365
|
-
}
|
|
366
|
-
var commands = [];
|
|
367
|
-
if (pipelineUrl) {
|
|
368
|
-
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
369
|
-
}
|
|
370
|
-
if (bookVersion !== "undefined") {
|
|
371
|
-
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
372
|
-
}
|
|
373
|
-
// TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
|
|
374
|
-
pipelineString = prettifyMarkdown(pipelineString);
|
|
375
|
-
try {
|
|
376
|
-
for (var _g = __values(parameters.filter(function (_a) {
|
|
377
|
-
var isInput = _a.isInput;
|
|
378
|
-
return isInput;
|
|
379
|
-
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
380
|
-
var parameter = _h.value;
|
|
381
|
-
commands.push("INPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
385
|
-
finally {
|
|
386
|
-
try {
|
|
387
|
-
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
388
|
-
}
|
|
389
|
-
finally { if (e_1) throw e_1.error; }
|
|
390
|
-
}
|
|
391
|
-
try {
|
|
392
|
-
for (var _j = __values(parameters.filter(function (_a) {
|
|
393
|
-
var isOutput = _a.isOutput;
|
|
394
|
-
return isOutput;
|
|
395
|
-
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
396
|
-
var parameter = _k.value;
|
|
397
|
-
commands.push("OUTPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
401
|
-
finally {
|
|
402
|
-
try {
|
|
403
|
-
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
404
|
-
}
|
|
405
|
-
finally { if (e_2) throw e_2.error; }
|
|
406
|
-
}
|
|
407
|
-
pipelineString += '\n\n';
|
|
408
|
-
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
409
|
-
try {
|
|
410
|
-
for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
|
|
411
|
-
var task = tasks_1_1.value;
|
|
412
|
-
var
|
|
413
|
-
/* Note: Not using:> name, */
|
|
414
|
-
title_1 = task.title, description_1 = task.description,
|
|
415
|
-
/* Note: dependentParameterNames, */
|
|
416
|
-
jokers = task.jokerParameterNames, taskType = task.taskType, content = task.content, postprocessing = task.postprocessingFunctionNames, expectations = task.expectations, format = task.format, resultingParameterName = task.resultingParameterName;
|
|
417
|
-
pipelineString += '\n\n';
|
|
418
|
-
pipelineString += "## ".concat(title_1);
|
|
419
|
-
if (description_1) {
|
|
420
|
-
pipelineString += '\n\n';
|
|
421
|
-
pipelineString += description_1;
|
|
422
|
-
}
|
|
423
|
-
var commands_1 = [];
|
|
424
|
-
var contentLanguage = 'text';
|
|
425
|
-
if (taskType === 'PROMPT_TASK') {
|
|
426
|
-
var modelRequirements = task.modelRequirements;
|
|
427
|
-
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
428
|
-
// Note: Do nothing, it is default
|
|
429
|
-
// commands.push(`PROMPT`);
|
|
430
|
-
if (modelVariant) {
|
|
431
|
-
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
432
|
-
}
|
|
433
|
-
if (modelName) {
|
|
434
|
-
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
else if (taskType === 'SIMPLE_TASK') {
|
|
438
|
-
commands_1.push("SIMPLE TEMPLATE");
|
|
439
|
-
// Note: Nothing special here
|
|
440
|
-
}
|
|
441
|
-
else if (taskType === 'SCRIPT_TASK') {
|
|
442
|
-
commands_1.push("SCRIPT");
|
|
443
|
-
if (task.contentLanguage) {
|
|
444
|
-
contentLanguage = task.contentLanguage;
|
|
445
|
-
}
|
|
446
|
-
else {
|
|
447
|
-
contentLanguage = '';
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
else if (taskType === 'DIALOG_TASK') {
|
|
451
|
-
commands_1.push("DIALOG");
|
|
452
|
-
// Note: Nothing special here
|
|
453
|
-
} // <- }else if([🅱]
|
|
454
|
-
if (jokers) {
|
|
455
|
-
try {
|
|
456
|
-
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
457
|
-
var joker = jokers_1_1.value;
|
|
458
|
-
commands_1.push("JOKER {".concat(joker, "}"));
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
462
|
-
finally {
|
|
463
|
-
try {
|
|
464
|
-
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
465
|
-
}
|
|
466
|
-
finally { if (e_4) throw e_4.error; }
|
|
467
|
-
}
|
|
468
|
-
} /* not else */
|
|
469
|
-
if (postprocessing) {
|
|
470
|
-
try {
|
|
471
|
-
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
472
|
-
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
473
|
-
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
477
|
-
finally {
|
|
478
|
-
try {
|
|
479
|
-
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
480
|
-
}
|
|
481
|
-
finally { if (e_5) throw e_5.error; }
|
|
482
|
-
}
|
|
483
|
-
} /* not else */
|
|
484
|
-
if (expectations) {
|
|
485
|
-
try {
|
|
486
|
-
for (var _m = (e_6 = void 0, __values(Object.entries(expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
487
|
-
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
488
|
-
if (min === max) {
|
|
489
|
-
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
if (min !== undefined) {
|
|
493
|
-
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
494
|
-
} /* not else */
|
|
495
|
-
if (max !== undefined) {
|
|
496
|
-
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
502
|
-
finally {
|
|
503
|
-
try {
|
|
504
|
-
if (_o && !_o.done && (_f = _m.return)) _f.call(_m);
|
|
505
|
-
}
|
|
506
|
-
finally { if (e_6) throw e_6.error; }
|
|
507
|
-
}
|
|
508
|
-
} /* not else */
|
|
509
|
-
if (format) {
|
|
510
|
-
if (format === 'JSON') {
|
|
511
|
-
// TODO: @deprecated remove
|
|
512
|
-
commands_1.push("FORMAT JSON");
|
|
513
|
-
}
|
|
514
|
-
} /* not else */
|
|
515
|
-
pipelineString += '\n\n';
|
|
516
|
-
pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
517
|
-
pipelineString += '\n\n';
|
|
518
|
-
pipelineString += '```' + contentLanguage;
|
|
519
|
-
pipelineString += '\n';
|
|
520
|
-
pipelineString += spaceTrim__default["default"](content);
|
|
521
|
-
// <- TODO: [main] !!! Escape
|
|
522
|
-
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
523
|
-
pipelineString += '\n';
|
|
524
|
-
pipelineString += '```';
|
|
525
|
-
pipelineString += '\n\n';
|
|
526
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
530
|
-
finally {
|
|
531
|
-
try {
|
|
532
|
-
if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
|
|
533
|
-
}
|
|
534
|
-
finally { if (e_3) throw e_3.error; }
|
|
535
|
-
}
|
|
536
|
-
return pipelineString;
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* @private internal utility of `pipelineJsonToString`
|
|
540
|
-
*/
|
|
541
|
-
function taskParameterJsonToString(taskParameterJson) {
|
|
542
|
-
var name = taskParameterJson.name, description = taskParameterJson.description;
|
|
543
|
-
var parameterString = "{".concat(name, "}");
|
|
544
|
-
if (description) {
|
|
545
|
-
parameterString = "".concat(parameterString, " ").concat(description);
|
|
546
|
-
}
|
|
547
|
-
return parameterString;
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
551
|
-
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
552
|
-
* TODO: [🏛] Maybe make some markdown builder
|
|
553
|
-
* TODO: [🏛] Escape all
|
|
554
|
-
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
555
|
-
*/
|
|
556
|
-
|
|
557
307
|
/**
|
|
558
308
|
* Orders JSON object by keys
|
|
559
309
|
*
|
|
@@ -1497,6 +1247,256 @@
|
|
|
1497
1247
|
|
|
1498
1248
|
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",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:[],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",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:[],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",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- Title should be concise and clear\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:[],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",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:[],sourceFile:"./books/prepare-persona.book.md"}];
|
|
1499
1249
|
|
|
1250
|
+
/**
|
|
1251
|
+
* Prettify the html code
|
|
1252
|
+
*
|
|
1253
|
+
* @param content raw html code
|
|
1254
|
+
* @returns formatted html code
|
|
1255
|
+
* @private withing the package because of HUGE size of prettier dependency
|
|
1256
|
+
*/
|
|
1257
|
+
function prettifyMarkdown(content) {
|
|
1258
|
+
try {
|
|
1259
|
+
return prettier.format(content, {
|
|
1260
|
+
parser: 'markdown',
|
|
1261
|
+
plugins: [parserHtml__default["default"]],
|
|
1262
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1263
|
+
endOfLine: 'lf',
|
|
1264
|
+
tabWidth: 4,
|
|
1265
|
+
singleQuote: true,
|
|
1266
|
+
trailingComma: 'all',
|
|
1267
|
+
arrowParens: 'always',
|
|
1268
|
+
printWidth: 120,
|
|
1269
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
1270
|
+
jsxBracketSameLine: false,
|
|
1271
|
+
bracketSpacing: true,
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
catch (error) {
|
|
1275
|
+
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
1276
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1277
|
+
error: error,
|
|
1278
|
+
html: content,
|
|
1279
|
+
});
|
|
1280
|
+
return content;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Makes first letter of a string uppercase
|
|
1286
|
+
*
|
|
1287
|
+
* @public exported from `@promptbook/utils`
|
|
1288
|
+
*/
|
|
1289
|
+
function capitalize(word) {
|
|
1290
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Converts promptbook in JSON format to string format
|
|
1295
|
+
*
|
|
1296
|
+
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
1297
|
+
* @param pipelineJson Promptbook in JSON format (.book.json)
|
|
1298
|
+
* @returns Promptbook in string format (.book.md)
|
|
1299
|
+
* @public exported from `@promptbook/core`
|
|
1300
|
+
*/
|
|
1301
|
+
function pipelineJsonToString(pipelineJson) {
|
|
1302
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1303
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
|
|
1304
|
+
var pipelineString = "# ".concat(title);
|
|
1305
|
+
if (description) {
|
|
1306
|
+
pipelineString += '\n\n';
|
|
1307
|
+
pipelineString += description;
|
|
1308
|
+
}
|
|
1309
|
+
var commands = [];
|
|
1310
|
+
if (pipelineUrl) {
|
|
1311
|
+
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
1312
|
+
}
|
|
1313
|
+
if (bookVersion !== "undefined") {
|
|
1314
|
+
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
1315
|
+
}
|
|
1316
|
+
// TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
|
|
1317
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
1318
|
+
try {
|
|
1319
|
+
for (var _g = __values(parameters.filter(function (_a) {
|
|
1320
|
+
var isInput = _a.isInput;
|
|
1321
|
+
return isInput;
|
|
1322
|
+
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1323
|
+
var parameter = _h.value;
|
|
1324
|
+
commands.push("INPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1328
|
+
finally {
|
|
1329
|
+
try {
|
|
1330
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
1331
|
+
}
|
|
1332
|
+
finally { if (e_1) throw e_1.error; }
|
|
1333
|
+
}
|
|
1334
|
+
try {
|
|
1335
|
+
for (var _j = __values(parameters.filter(function (_a) {
|
|
1336
|
+
var isOutput = _a.isOutput;
|
|
1337
|
+
return isOutput;
|
|
1338
|
+
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1339
|
+
var parameter = _k.value;
|
|
1340
|
+
commands.push("OUTPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1344
|
+
finally {
|
|
1345
|
+
try {
|
|
1346
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
1347
|
+
}
|
|
1348
|
+
finally { if (e_2) throw e_2.error; }
|
|
1349
|
+
}
|
|
1350
|
+
pipelineString += '\n\n';
|
|
1351
|
+
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1352
|
+
try {
|
|
1353
|
+
for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
|
|
1354
|
+
var task = tasks_1_1.value;
|
|
1355
|
+
var
|
|
1356
|
+
/* Note: Not using:> name, */
|
|
1357
|
+
title_1 = task.title, description_1 = task.description,
|
|
1358
|
+
/* Note: dependentParameterNames, */
|
|
1359
|
+
jokers = task.jokerParameterNames, taskType = task.taskType, content = task.content, postprocessing = task.postprocessingFunctionNames, expectations = task.expectations, format = task.format, resultingParameterName = task.resultingParameterName;
|
|
1360
|
+
pipelineString += '\n\n';
|
|
1361
|
+
pipelineString += "## ".concat(title_1);
|
|
1362
|
+
if (description_1) {
|
|
1363
|
+
pipelineString += '\n\n';
|
|
1364
|
+
pipelineString += description_1;
|
|
1365
|
+
}
|
|
1366
|
+
var commands_1 = [];
|
|
1367
|
+
var contentLanguage = 'text';
|
|
1368
|
+
if (taskType === 'PROMPT_TASK') {
|
|
1369
|
+
var modelRequirements = task.modelRequirements;
|
|
1370
|
+
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
1371
|
+
// Note: Do nothing, it is default
|
|
1372
|
+
// commands.push(`PROMPT`);
|
|
1373
|
+
if (modelVariant) {
|
|
1374
|
+
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
1375
|
+
}
|
|
1376
|
+
if (modelName) {
|
|
1377
|
+
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
1381
|
+
commands_1.push("SIMPLE TEMPLATE");
|
|
1382
|
+
// Note: Nothing special here
|
|
1383
|
+
}
|
|
1384
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
1385
|
+
commands_1.push("SCRIPT");
|
|
1386
|
+
if (task.contentLanguage) {
|
|
1387
|
+
contentLanguage = task.contentLanguage;
|
|
1388
|
+
}
|
|
1389
|
+
else {
|
|
1390
|
+
contentLanguage = '';
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
1394
|
+
commands_1.push("DIALOG");
|
|
1395
|
+
// Note: Nothing special here
|
|
1396
|
+
} // <- }else if([🅱]
|
|
1397
|
+
if (jokers) {
|
|
1398
|
+
try {
|
|
1399
|
+
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
1400
|
+
var joker = jokers_1_1.value;
|
|
1401
|
+
commands_1.push("JOKER {".concat(joker, "}"));
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1405
|
+
finally {
|
|
1406
|
+
try {
|
|
1407
|
+
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
1408
|
+
}
|
|
1409
|
+
finally { if (e_4) throw e_4.error; }
|
|
1410
|
+
}
|
|
1411
|
+
} /* not else */
|
|
1412
|
+
if (postprocessing) {
|
|
1413
|
+
try {
|
|
1414
|
+
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
1415
|
+
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1416
|
+
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1420
|
+
finally {
|
|
1421
|
+
try {
|
|
1422
|
+
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
1423
|
+
}
|
|
1424
|
+
finally { if (e_5) throw e_5.error; }
|
|
1425
|
+
}
|
|
1426
|
+
} /* not else */
|
|
1427
|
+
if (expectations) {
|
|
1428
|
+
try {
|
|
1429
|
+
for (var _m = (e_6 = void 0, __values(Object.entries(expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
1430
|
+
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
1431
|
+
if (min === max) {
|
|
1432
|
+
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1433
|
+
}
|
|
1434
|
+
else {
|
|
1435
|
+
if (min !== undefined) {
|
|
1436
|
+
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1437
|
+
} /* not else */
|
|
1438
|
+
if (max !== undefined) {
|
|
1439
|
+
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1445
|
+
finally {
|
|
1446
|
+
try {
|
|
1447
|
+
if (_o && !_o.done && (_f = _m.return)) _f.call(_m);
|
|
1448
|
+
}
|
|
1449
|
+
finally { if (e_6) throw e_6.error; }
|
|
1450
|
+
}
|
|
1451
|
+
} /* not else */
|
|
1452
|
+
if (format) {
|
|
1453
|
+
if (format === 'JSON') {
|
|
1454
|
+
// TODO: @deprecated remove
|
|
1455
|
+
commands_1.push("FORMAT JSON");
|
|
1456
|
+
}
|
|
1457
|
+
} /* not else */
|
|
1458
|
+
pipelineString += '\n\n';
|
|
1459
|
+
pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1460
|
+
pipelineString += '\n\n';
|
|
1461
|
+
pipelineString += '```' + contentLanguage;
|
|
1462
|
+
pipelineString += '\n';
|
|
1463
|
+
pipelineString += spaceTrim__default["default"](content);
|
|
1464
|
+
// <- TODO: [main] !!! Escape
|
|
1465
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1466
|
+
pipelineString += '\n';
|
|
1467
|
+
pipelineString += '```';
|
|
1468
|
+
pipelineString += '\n\n';
|
|
1469
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1473
|
+
finally {
|
|
1474
|
+
try {
|
|
1475
|
+
if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
|
|
1476
|
+
}
|
|
1477
|
+
finally { if (e_3) throw e_3.error; }
|
|
1478
|
+
}
|
|
1479
|
+
return pipelineString;
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* @private internal utility of `pipelineJsonToString`
|
|
1483
|
+
*/
|
|
1484
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
1485
|
+
var name = taskParameterJson.name, description = taskParameterJson.description;
|
|
1486
|
+
var parameterString = "{".concat(name, "}");
|
|
1487
|
+
if (description) {
|
|
1488
|
+
parameterString = "".concat(parameterString, " ").concat(description);
|
|
1489
|
+
}
|
|
1490
|
+
return parameterString;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
1494
|
+
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
1495
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
1496
|
+
* TODO: [🏛] Escape all
|
|
1497
|
+
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
1498
|
+
*/
|
|
1499
|
+
|
|
1500
1500
|
/**
|
|
1501
1501
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
1502
1502
|
*
|
|
@@ -2033,6 +2033,7 @@
|
|
|
2033
2033
|
/**
|
|
2034
2034
|
* Unprepare just strips the preparation data of the pipeline
|
|
2035
2035
|
*
|
|
2036
|
+
* @deprecated In future version this function will be removed or deprecated
|
|
2036
2037
|
* @public exported from `@promptbook/core`
|
|
2037
2038
|
*/
|
|
2038
2039
|
function unpreparePipeline(pipeline) {
|
|
@@ -7384,7 +7385,7 @@
|
|
|
7384
7385
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
7385
7386
|
*/
|
|
7386
7387
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
7387
|
-
// Note: [🍣] Do nothing, its application is implemented separately in `
|
|
7388
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
|
|
7388
7389
|
},
|
|
7389
7390
|
/**
|
|
7390
7391
|
* Apply the PARAMETER command to the `pipelineJson`
|
|
@@ -7392,7 +7393,7 @@
|
|
|
7392
7393
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
7393
7394
|
*/
|
|
7394
7395
|
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
7395
|
-
// Note: [🍣] Do nothing, its application is implemented separately in `
|
|
7396
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
|
|
7396
7397
|
},
|
|
7397
7398
|
/**
|
|
7398
7399
|
* Converts the PARAMETER command back to string
|
|
@@ -7900,7 +7901,7 @@
|
|
|
7900
7901
|
* @returns the parser for the command
|
|
7901
7902
|
* @throws {UnexpectedError} if the parser is not found
|
|
7902
7903
|
*
|
|
7903
|
-
* @private within the
|
|
7904
|
+
* @private within the compilePipeline
|
|
7904
7905
|
*/
|
|
7905
7906
|
function getParserForCommand(command) {
|
|
7906
7907
|
var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
|
|
@@ -7936,7 +7937,7 @@
|
|
|
7936
7937
|
* @returns parsed command object
|
|
7937
7938
|
* @throws {ParseError} if the command is invalid
|
|
7938
7939
|
*
|
|
7939
|
-
* @private within the
|
|
7940
|
+
* @private within the compilePipeline
|
|
7940
7941
|
*/
|
|
7941
7942
|
function parseCommand(raw, usagePlace) {
|
|
7942
7943
|
if (raw.includes('\n') || raw.includes('\r')) {
|
|
@@ -8351,7 +8352,7 @@
|
|
|
8351
8352
|
/**
|
|
8352
8353
|
* All high-level abstractions
|
|
8353
8354
|
*
|
|
8354
|
-
* @private internal index of `
|
|
8355
|
+
* @private internal index of `precompilePipeline` (= used for sync) and `preparePipeline` (= used for async)
|
|
8355
8356
|
*/
|
|
8356
8357
|
var HIGH_LEVEL_ABSTRACTIONS = [
|
|
8357
8358
|
ImplicitFormfactorHla,
|
|
@@ -8625,8 +8626,8 @@
|
|
|
8625
8626
|
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
8626
8627
|
*
|
|
8627
8628
|
* Note: There are 3 similar functions:
|
|
8628
|
-
* - `
|
|
8629
|
-
* - `
|
|
8629
|
+
* - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
8630
|
+
* - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
8630
8631
|
* - `preparePipeline` - just one step in the compilation process
|
|
8631
8632
|
*
|
|
8632
8633
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
@@ -8637,7 +8638,7 @@
|
|
|
8637
8638
|
* @throws {ParseError} if the promptbook string is not valid
|
|
8638
8639
|
* @public exported from `@promptbook/core`
|
|
8639
8640
|
*/
|
|
8640
|
-
function
|
|
8641
|
+
function precompilePipeline(pipelineString) {
|
|
8641
8642
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
8642
8643
|
var $pipelineJson = {
|
|
8643
8644
|
title: DEFAULT_TITLE,
|
|
@@ -9057,7 +9058,7 @@
|
|
|
9057
9058
|
// TODO: [🍙] Maybe do reorder of `$pipelineJson` here
|
|
9058
9059
|
return exportJson({
|
|
9059
9060
|
name: 'pipelineJson',
|
|
9060
|
-
message: "Result of `
|
|
9061
|
+
message: "Result of `precompilePipeline`",
|
|
9061
9062
|
order: ORDER_OF_PIPELINE_JSON,
|
|
9062
9063
|
value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
|
|
9063
9064
|
});
|
|
@@ -9078,8 +9079,8 @@
|
|
|
9078
9079
|
* Compile pipeline from string (markdown) format to JSON format
|
|
9079
9080
|
*
|
|
9080
9081
|
* Note: There are 3 similar functions:
|
|
9081
|
-
* - `
|
|
9082
|
-
* - `
|
|
9082
|
+
* - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
9083
|
+
* - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
9083
9084
|
* - `preparePipeline` - just one step in the compilation process
|
|
9084
9085
|
*
|
|
9085
9086
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
@@ -9092,13 +9093,13 @@
|
|
|
9092
9093
|
* @throws {ParseError} if the promptbook string is not valid
|
|
9093
9094
|
* @public exported from `@promptbook/core`
|
|
9094
9095
|
*/
|
|
9095
|
-
function
|
|
9096
|
+
function compilePipeline(pipelineString, tools, options) {
|
|
9096
9097
|
return __awaiter(this, void 0, void 0, function () {
|
|
9097
9098
|
var pipelineJson;
|
|
9098
9099
|
return __generator(this, function (_a) {
|
|
9099
9100
|
switch (_a.label) {
|
|
9100
9101
|
case 0:
|
|
9101
|
-
pipelineJson =
|
|
9102
|
+
pipelineJson = precompilePipeline(pipelineString);
|
|
9102
9103
|
if (!(tools !== undefined && tools.llm !== undefined)) return [3 /*break*/, 2];
|
|
9103
9104
|
return [4 /*yield*/, preparePipeline(pipelineJson, tools, options || {
|
|
9104
9105
|
rootDirname: null,
|
|
@@ -9107,7 +9108,7 @@
|
|
|
9107
9108
|
pipelineJson = _a.sent();
|
|
9108
9109
|
_a.label = 2;
|
|
9109
9110
|
case 2:
|
|
9110
|
-
// Note: No need to use `$exportJson` because `
|
|
9111
|
+
// Note: No need to use `$exportJson` because `precompilePipeline` and `preparePipeline` already do that
|
|
9111
9112
|
return [2 /*return*/, pipelineJson];
|
|
9112
9113
|
}
|
|
9113
9114
|
});
|
|
@@ -10545,7 +10546,7 @@
|
|
|
10545
10546
|
return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
|
|
10546
10547
|
case 2:
|
|
10547
10548
|
pipelineString = (_e.sent());
|
|
10548
|
-
return [4 /*yield*/,
|
|
10549
|
+
return [4 /*yield*/, compilePipeline(pipelineString, tools, {
|
|
10549
10550
|
rootDirname: rootDirname,
|
|
10550
10551
|
})];
|
|
10551
10552
|
case 3:
|