@promptbook/core 0.61.0-22 โ 0.61.0-24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +164 -43
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/config.d.ts +8 -4
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +32 -24
- package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +4 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
- package/package.json +1 -1
- package/umd/index.umd.js +164 -43
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/_packages/types.index.d.ts +2 -2
- package/umd/typings/src/config.d.ts +8 -4
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
- package/umd/typings/src/execution/PipelineExecutor.d.ts +32 -24
- package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -0
- package/umd/typings/src/prepare/isPipelinePrepared.d.ts +4 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
- package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
package/umd/index.umd.js
CHANGED
|
@@ -473,19 +473,26 @@
|
|
|
473
473
|
* The maximum number of attempts to execute LLM task before giving up
|
|
474
474
|
*/
|
|
475
475
|
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
476
|
+
/**
|
|
477
|
+
* Nonce which is used for replacing things in strings
|
|
478
|
+
*/
|
|
479
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
476
480
|
/**
|
|
477
481
|
* The names of the parameters that are reserved for special purposes
|
|
478
482
|
*/
|
|
479
483
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
480
484
|
'context',
|
|
485
|
+
'knowledge',
|
|
486
|
+
'samples',
|
|
487
|
+
'modelName',
|
|
481
488
|
'currentDate',
|
|
482
489
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
483
490
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
484
491
|
]);
|
|
485
492
|
/**
|
|
486
|
-
*
|
|
493
|
+
* @@@
|
|
487
494
|
*/
|
|
488
|
-
var
|
|
495
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
489
496
|
/*
|
|
490
497
|
TODO: !!! Just testing false-negative detection of [๐ก][๐ข][๐ต][โช] leak
|
|
491
498
|
*/
|
|
@@ -760,7 +767,7 @@
|
|
|
760
767
|
throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
761
768
|
}
|
|
762
769
|
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
763
|
-
throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use
|
|
770
|
+
throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name"));
|
|
764
771
|
}
|
|
765
772
|
definedParameters.add(template.resultingParameterName);
|
|
766
773
|
if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
@@ -930,14 +937,17 @@
|
|
|
930
937
|
* Unprepare just strips the preparation data of the pipeline
|
|
931
938
|
*/
|
|
932
939
|
function unpreparePipeline(pipeline) {
|
|
933
|
-
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
|
|
940
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
|
|
934
941
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
935
942
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
936
|
-
return __assign(__assign({},
|
|
943
|
+
promptTemplates = promptTemplates.map(function (promptTemplate) { return (__assign(__assign({}, promptTemplate), { preparedContent: undefined })); });
|
|
944
|
+
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
937
945
|
}
|
|
938
946
|
/**
|
|
939
947
|
* TODO: [๐ผ] !!! Export via `@promptbook/core`
|
|
948
|
+
* TODO: [๐งฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
940
949
|
* TODO: Write tests for `preparePipeline`
|
|
950
|
+
* TODO: [๐] Make some standart order of json properties
|
|
941
951
|
*/
|
|
942
952
|
|
|
943
953
|
/**
|
|
@@ -1454,7 +1464,7 @@
|
|
|
1454
1464
|
});
|
|
1455
1465
|
}
|
|
1456
1466
|
|
|
1457
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
1467
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-23",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-23",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-23",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-23",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1458
1468
|
|
|
1459
1469
|
var defaultDiacriticsRemovalMap = [
|
|
1460
1470
|
{
|
|
@@ -2250,22 +2260,27 @@
|
|
|
2250
2260
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
2251
2261
|
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2252
2262
|
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2253
|
-
console.log('!!!!', 'Not all personas have modelRequirements');
|
|
2254
2263
|
return false;
|
|
2255
2264
|
}
|
|
2256
2265
|
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2257
|
-
console.log('!!!!', 'Not all knowledgeSources have preparationIds');
|
|
2258
2266
|
return false;
|
|
2259
2267
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2268
|
+
/*
|
|
2269
|
+
TODO: [๐ง ][๐ซ] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
|
|
2270
|
+
> if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2271
|
+
> return false;
|
|
2272
|
+
> }
|
|
2273
|
+
*/
|
|
2263
2274
|
return true;
|
|
2264
2275
|
}
|
|
2265
2276
|
/**
|
|
2266
2277
|
* TODO: [๐ ] Maybe base this on `makeValidator`
|
|
2267
2278
|
* TODO: [๐ผ] Export via core or utils
|
|
2268
2279
|
* TODO: [๐ง] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2280
|
+
* TODO: [๐งฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2281
|
+
* - Is context in each template
|
|
2282
|
+
* - Are samples prepared
|
|
2283
|
+
* - Are templates prepared
|
|
2269
2284
|
*/
|
|
2270
2285
|
|
|
2271
2286
|
/**
|
|
@@ -2327,6 +2342,22 @@
|
|
|
2327
2342
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2328
2343
|
*/
|
|
2329
2344
|
function replaceParameters(template, parameters) {
|
|
2345
|
+
var e_1, _a;
|
|
2346
|
+
try {
|
|
2347
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2348
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
2349
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
2350
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2355
|
+
finally {
|
|
2356
|
+
try {
|
|
2357
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2358
|
+
}
|
|
2359
|
+
finally { if (e_1) throw e_1.error; }
|
|
2360
|
+
}
|
|
2330
2361
|
var replacedTemplate = template;
|
|
2331
2362
|
var match;
|
|
2332
2363
|
var loopLimit = LOOP_LIMIT;
|
|
@@ -2452,7 +2483,7 @@
|
|
|
2452
2483
|
/**
|
|
2453
2484
|
* The version of the Promptbook library
|
|
2454
2485
|
*/
|
|
2455
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
2486
|
+
var PROMPTBOOK_VERSION = '0.61.0-23';
|
|
2456
2487
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2457
2488
|
|
|
2458
2489
|
/**
|
|
@@ -2603,14 +2634,25 @@
|
|
|
2603
2634
|
pipeline = rawPipeline;
|
|
2604
2635
|
}
|
|
2605
2636
|
else {
|
|
2606
|
-
|
|
2637
|
+
// TODO: !!!! This should be maybe warning in report
|
|
2638
|
+
console.warn(spaceTrim.spaceTrim("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n ").concat(rawPipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
|
|
2607
2639
|
}
|
|
2608
2640
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2641
|
+
// TODO: !!!!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
2609
2642
|
function getContextForTemplate(// <- TODO: [๐ง ][๐ฅ]
|
|
2610
2643
|
template) {
|
|
2611
2644
|
return __awaiter(this, void 0, void 0, function () {
|
|
2612
2645
|
return __generator(this, function (_a) {
|
|
2613
|
-
|
|
2646
|
+
TODO_USE(template);
|
|
2647
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
|
|
2648
|
+
});
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
function getKnowledgeForTemplate(// <- TODO: [๐ง ][๐ฅ]
|
|
2652
|
+
template) {
|
|
2653
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2654
|
+
return __generator(this, function (_a) {
|
|
2655
|
+
// TODO: !!!! Implement Better - use real index and keyword search
|
|
2614
2656
|
TODO_USE(template);
|
|
2615
2657
|
return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
|
|
2616
2658
|
var content = _a.content;
|
|
@@ -2619,19 +2661,39 @@
|
|
|
2619
2661
|
});
|
|
2620
2662
|
});
|
|
2621
2663
|
}
|
|
2664
|
+
function getSamplesForTemplate(// <- TODO: [๐ง ][๐ฅ]
|
|
2665
|
+
template) {
|
|
2666
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2667
|
+
return __generator(this, function (_a) {
|
|
2668
|
+
// TODO: !!!! Implement Better - use real index and keyword search
|
|
2669
|
+
TODO_USE(template);
|
|
2670
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
|
|
2671
|
+
});
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2622
2674
|
function getReservedParametersForTemplate(template) {
|
|
2623
2675
|
return __awaiter(this, void 0, void 0, function () {
|
|
2624
|
-
var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2676
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2625
2677
|
var e_3, _a;
|
|
2626
2678
|
return __generator(this, function (_b) {
|
|
2627
2679
|
switch (_b.label) {
|
|
2628
2680
|
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
2629
2681
|
case 1:
|
|
2630
2682
|
context = _b.sent();
|
|
2683
|
+
return [4 /*yield*/, getKnowledgeForTemplate(template)];
|
|
2684
|
+
case 2:
|
|
2685
|
+
knowledge = _b.sent();
|
|
2686
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
2687
|
+
case 3:
|
|
2688
|
+
samples = _b.sent();
|
|
2631
2689
|
currentDate = new Date().toISOString();
|
|
2690
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
2632
2691
|
reservedParameters = {
|
|
2633
2692
|
context: context,
|
|
2693
|
+
knowledge: knowledge,
|
|
2694
|
+
samples: samples,
|
|
2634
2695
|
currentDate: currentDate,
|
|
2696
|
+
modelName: modelName,
|
|
2635
2697
|
};
|
|
2636
2698
|
try {
|
|
2637
2699
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
@@ -2656,7 +2718,7 @@
|
|
|
2656
2718
|
}
|
|
2657
2719
|
function executeSingleTemplate(currentTemplate) {
|
|
2658
2720
|
return __awaiter(this, void 0, void 0, function () {
|
|
2659
|
-
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
|
|
2721
|
+
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
|
|
2660
2722
|
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2661
2723
|
var _this = this;
|
|
2662
2724
|
return __generator(this, function (_u) {
|
|
@@ -2726,6 +2788,9 @@
|
|
|
2726
2788
|
expectError = null;
|
|
2727
2789
|
maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
2728
2790
|
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
2791
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
2792
|
+
.split('{content}')
|
|
2793
|
+
.join(currentTemplate.content);
|
|
2729
2794
|
attempt = -jokerParameterNames.length;
|
|
2730
2795
|
_u.label = 4;
|
|
2731
2796
|
case 4:
|
|
@@ -2760,7 +2825,7 @@
|
|
|
2760
2825
|
}
|
|
2761
2826
|
return [3 /*break*/, 29];
|
|
2762
2827
|
case 6:
|
|
2763
|
-
resultString = replaceParameters(
|
|
2828
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
2764
2829
|
return [3 /*break*/, 30];
|
|
2765
2830
|
case 7:
|
|
2766
2831
|
prompt = {
|
|
@@ -2769,7 +2834,7 @@
|
|
|
2769
2834
|
? pipeline.pipelineUrl
|
|
2770
2835
|
: 'anonymous' /* <- TODO: [๐ง ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
2771
2836
|
parameters: parameters,
|
|
2772
|
-
content:
|
|
2837
|
+
content: preparedContent,
|
|
2773
2838
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2774
2839
|
expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
|
|
2775
2840
|
var name = _a.name;
|
|
@@ -2891,7 +2956,7 @@
|
|
|
2891
2956
|
_u.trys.push([19, 21, , 22]);
|
|
2892
2957
|
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2893
2958
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2894
|
-
script:
|
|
2959
|
+
script: preparedContent,
|
|
2895
2960
|
parameters: parameters,
|
|
2896
2961
|
}))];
|
|
2897
2962
|
case 20:
|
|
@@ -2940,7 +3005,7 @@
|
|
|
2940
3005
|
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2941
3006
|
promptTitle: currentTemplate.title,
|
|
2942
3007
|
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
2943
|
-
defaultValue: replaceParameters(
|
|
3008
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
2944
3009
|
// TODO: [๐ง ] !! Figure out how to define placeholder in .ptbk.md file
|
|
2945
3010
|
placeholder: undefined,
|
|
2946
3011
|
priority: priority,
|
|
@@ -3118,7 +3183,7 @@
|
|
|
3118
3183
|
var parameter = _c.value;
|
|
3119
3184
|
if (parametersToPass[parameter.name] === undefined) {
|
|
3120
3185
|
// [4]
|
|
3121
|
-
|
|
3186
|
+
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3122
3187
|
continue;
|
|
3123
3188
|
}
|
|
3124
3189
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
@@ -3133,7 +3198,7 @@
|
|
|
3133
3198
|
}
|
|
3134
3199
|
return outputParameters;
|
|
3135
3200
|
}
|
|
3136
|
-
var executionReport, _a, _b, parameter,
|
|
3201
|
+
var errors, warnings, executionReport, _a, _b, parameter, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3137
3202
|
var e_1, _e, e_2, _f;
|
|
3138
3203
|
return __generator(this, function (_g) {
|
|
3139
3204
|
switch (_g.label) {
|
|
@@ -3148,6 +3213,8 @@
|
|
|
3148
3213
|
pipeline = _g.sent();
|
|
3149
3214
|
_g.label = 2;
|
|
3150
3215
|
case 2:
|
|
3216
|
+
errors = [];
|
|
3217
|
+
warnings = [];
|
|
3151
3218
|
executionReport = {
|
|
3152
3219
|
pipelineUrl: pipeline.pipelineUrl,
|
|
3153
3220
|
title: pipeline.title,
|
|
@@ -3166,10 +3233,10 @@
|
|
|
3166
3233
|
if (inputParameters[parameter.name] === undefined) {
|
|
3167
3234
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3168
3235
|
isSuccessful: false,
|
|
3169
|
-
errors: [
|
|
3170
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3171
|
-
|
|
3172
|
-
],
|
|
3236
|
+
errors: __spreadArray([
|
|
3237
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3238
|
+
], __read(errors), false),
|
|
3239
|
+
warnings: [],
|
|
3173
3240
|
executionReport: executionReport,
|
|
3174
3241
|
outputParameters: {},
|
|
3175
3242
|
usage: ZERO_USAGE,
|
|
@@ -3184,22 +3251,21 @@
|
|
|
3184
3251
|
}
|
|
3185
3252
|
finally { if (e_1) throw e_1.error; }
|
|
3186
3253
|
}
|
|
3187
|
-
errors = [];
|
|
3188
3254
|
_loop_1 = function (parameterName) {
|
|
3189
3255
|
var parameter = pipeline.parameters.find(function (_a) {
|
|
3190
3256
|
var name = _a.name;
|
|
3191
3257
|
return name === parameterName;
|
|
3192
3258
|
});
|
|
3193
3259
|
if (parameter === undefined) {
|
|
3194
|
-
|
|
3260
|
+
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3195
3261
|
}
|
|
3196
3262
|
else if (parameter.isInput === false) {
|
|
3197
3263
|
return { value: deepFreezeWithSameType({
|
|
3198
3264
|
isSuccessful: false,
|
|
3199
|
-
errors: [
|
|
3200
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but is not input"))
|
|
3201
|
-
|
|
3202
|
-
|
|
3265
|
+
errors: __spreadArray([
|
|
3266
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3267
|
+
], __read(errors), false),
|
|
3268
|
+
warnings: warnings,
|
|
3203
3269
|
executionReport: executionReport,
|
|
3204
3270
|
outputParameters: {},
|
|
3205
3271
|
usage: ZERO_USAGE,
|
|
@@ -3308,6 +3374,7 @@
|
|
|
3308
3374
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3309
3375
|
isSuccessful: false,
|
|
3310
3376
|
errors: __spreadArray([error_1], __read(errors), false),
|
|
3377
|
+
warnings: warnings,
|
|
3311
3378
|
usage: usage_1,
|
|
3312
3379
|
executionReport: executionReport,
|
|
3313
3380
|
outputParameters: outputParameters_1,
|
|
@@ -3321,6 +3388,7 @@
|
|
|
3321
3388
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3322
3389
|
isSuccessful: true,
|
|
3323
3390
|
errors: errors,
|
|
3391
|
+
warnings: warnings,
|
|
3324
3392
|
usage: usage,
|
|
3325
3393
|
executionReport: executionReport,
|
|
3326
3394
|
outputParameters: outputParameters,
|
|
@@ -3347,7 +3415,7 @@
|
|
|
3347
3415
|
*/
|
|
3348
3416
|
function prepareKnowledgeFromMarkdown(content /* <- TODO: [๐] (?maybe not) Always the file */, options) {
|
|
3349
3417
|
return __awaiter(this, void 0, void 0, function () {
|
|
3350
|
-
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters,
|
|
3418
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
|
|
3351
3419
|
var _f, _g, _h;
|
|
3352
3420
|
var _this = this;
|
|
3353
3421
|
return __generator(this, function (_j) {
|
|
@@ -3388,8 +3456,8 @@
|
|
|
3388
3456
|
result = _j.sent();
|
|
3389
3457
|
assertsExecutionSuccessful(result);
|
|
3390
3458
|
outputParameters = result.outputParameters;
|
|
3391
|
-
|
|
3392
|
-
knowledgeTextPieces = (
|
|
3459
|
+
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
3460
|
+
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
3393
3461
|
if (isVerbose) {
|
|
3394
3462
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
3395
3463
|
}
|
|
@@ -3603,6 +3671,53 @@
|
|
|
3603
3671
|
* TODO: [๐ข] !! Check validity of `temperature` in pipeline
|
|
3604
3672
|
*/
|
|
3605
3673
|
|
|
3674
|
+
/**
|
|
3675
|
+
* @@@
|
|
3676
|
+
*/
|
|
3677
|
+
function prepareTemplates(pipeline, options) {
|
|
3678
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3679
|
+
var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
|
|
3680
|
+
var _this = this;
|
|
3681
|
+
return __generator(this, function (_b) {
|
|
3682
|
+
switch (_b.label) {
|
|
3683
|
+
case 0:
|
|
3684
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3685
|
+
promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3686
|
+
// TODO: !!!! Apply samples to each template (if missing and is for the template defined)
|
|
3687
|
+
TODO_USE(parameters);
|
|
3688
|
+
promptTemplatesPrepared = new Array(promptTemplates.length);
|
|
3689
|
+
return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [๐ช] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3690
|
+
var preparedContent, preparedTemplate;
|
|
3691
|
+
return __generator(this, function (_a) {
|
|
3692
|
+
preparedContent = undefined;
|
|
3693
|
+
if (knowledgePiecesCount > 0) {
|
|
3694
|
+
preparedContent = spaceTrim.spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
3695
|
+
// <- TODO: [๐ง ][๐งป] Cutomize shape/language/formatting of the addition to the prompt
|
|
3696
|
+
}
|
|
3697
|
+
preparedTemplate = __assign(__assign({}, template), { preparedContent: preparedContent });
|
|
3698
|
+
promptTemplatesPrepared[index] = preparedTemplate;
|
|
3699
|
+
return [2 /*return*/];
|
|
3700
|
+
});
|
|
3701
|
+
}); })];
|
|
3702
|
+
case 1:
|
|
3703
|
+
_b.sent();
|
|
3704
|
+
return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
|
|
3705
|
+
}
|
|
3706
|
+
});
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
/**
|
|
3710
|
+
* TODO: [๐ง ] Add context to each template (if missing)
|
|
3711
|
+
* TODO: [๐ง ] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3712
|
+
* TODO: !!!!! Index the samples and maybe templates
|
|
3713
|
+
* TODO: [๐ผ] !!! Export via `@promptbook/core`
|
|
3714
|
+
* TODO: Write tests for `preparePipeline`
|
|
3715
|
+
* TODO: [๐] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3716
|
+
* TODO: [๐ง] In future one preparation can take data from previous preparation and save tokens and time
|
|
3717
|
+
* TODO: [๐ ] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3718
|
+
* TODO: [๐ง ][๐ฅ]
|
|
3719
|
+
*/
|
|
3720
|
+
|
|
3606
3721
|
/**
|
|
3607
3722
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
3608
3723
|
*
|
|
@@ -3611,18 +3726,18 @@
|
|
|
3611
3726
|
*/
|
|
3612
3727
|
function preparePipeline(pipeline, options) {
|
|
3613
3728
|
return __awaiter(this, void 0, void 0, function () {
|
|
3614
|
-
var _a, maxParallelCount,
|
|
3729
|
+
var _a, maxParallelCount, parameters, promptTemplates,
|
|
3615
3730
|
/*
|
|
3616
3731
|
<- TODO: [๐ง ][0] `promptbookVersion` */
|
|
3617
3732
|
knowledgeSources /*
|
|
3618
3733
|
<- TODO: [๐ง] `knowledgePieces` */, personas /*
|
|
3619
|
-
<- TODO: [๐ง] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared
|
|
3734
|
+
<- TODO: [๐ง] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3620
3735
|
var _this = this;
|
|
3621
3736
|
return __generator(this, function (_b) {
|
|
3622
3737
|
switch (_b.label) {
|
|
3623
3738
|
case 0:
|
|
3624
3739
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3625
|
-
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3740
|
+
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3626
3741
|
currentPreparation = {
|
|
3627
3742
|
id: 1,
|
|
3628
3743
|
// TODO: [๐ฅ]> date: $currentDate(),
|
|
@@ -3655,16 +3770,20 @@
|
|
|
3655
3770
|
case 2:
|
|
3656
3771
|
partialknowledgePiecesPrepared = _b.sent();
|
|
3657
3772
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [๐ง] -> */ currentPreparation.id] })); });
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3773
|
+
return [4 /*yield*/, prepareTemplates({
|
|
3774
|
+
parameters: parameters,
|
|
3775
|
+
promptTemplates: promptTemplates,
|
|
3776
|
+
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3777
|
+
}, options)];
|
|
3778
|
+
case 3:
|
|
3779
|
+
promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
|
|
3780
|
+
// ----- /Templates preparation -----
|
|
3781
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3662
3782
|
}
|
|
3663
3783
|
});
|
|
3664
3784
|
});
|
|
3665
3785
|
}
|
|
3666
3786
|
/**
|
|
3667
|
-
* TODO: !!!!! Index the samples and maybe templates
|
|
3668
3787
|
* TODO: [๐ผ] !!! Export via `@promptbook/core`
|
|
3669
3788
|
* TODO: Write tests for `preparePipeline`
|
|
3670
3789
|
* TODO: [๐] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
@@ -5580,6 +5699,7 @@
|
|
|
5580
5699
|
* TODO: [๐ฅ] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
5581
5700
|
* TODO: [โ] Probbably move expectations from templates to parameters
|
|
5582
5701
|
* TODO: [๐ ] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
5702
|
+
* TODO: [๐] Make some standart order of json properties
|
|
5583
5703
|
*/
|
|
5584
5704
|
|
|
5585
5705
|
/**
|
|
@@ -5816,6 +5936,7 @@
|
|
|
5816
5936
|
* TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
5817
5937
|
* TODO: [๐ง ][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
5818
5938
|
* TODO: [๐ง ] Maybe more elegant solution than replacing via regex
|
|
5939
|
+
* TODO: [๐] Make some standart order of json properties
|
|
5819
5940
|
*/
|
|
5820
5941
|
|
|
5821
5942
|
/**
|