@promptbook/cli 0.61.0-15 → 0.61.0-17
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 +876 -626
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +12 -15
- package/esm/typings/src/_packages/core.index.d.ts +2 -1
- package/esm/typings/src/_packages/node.index.d.ts +2 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -3
- package/esm/typings/src/_packages/utils.index.d.ts +4 -3
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +28 -3
- package/esm/typings/src/config.d.ts +26 -1
- package/esm/typings/src/config.test.d.ts +4 -0
- package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +3 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -3
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +2 -3
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +16 -3
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +10 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +5 -3
- package/esm/typings/src/types/Prompt.d.ts +7 -10
- package/esm/typings/src/types/typeAliases.d.ts +44 -4
- package/esm/typings/src/utils/deepFreeze.d.ts +10 -1
- package/esm/typings/src/utils/extractParameters.d.ts +2 -2
- package/esm/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
- package/esm/typings/src/utils/sets/difference.d.ts +3 -0
- package/package.json +2 -2
- package/umd/index.umd.js +876 -626
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +12 -15
- package/umd/typings/src/_packages/core.index.d.ts +2 -1
- package/umd/typings/src/_packages/node.index.d.ts +2 -1
- package/umd/typings/src/_packages/types.index.d.ts +2 -3
- package/umd/typings/src/_packages/utils.index.d.ts +4 -3
- package/umd/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +28 -3
- package/umd/typings/src/config.d.ts +26 -1
- package/umd/typings/src/config.test.d.ts +4 -0
- package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +3 -0
- package/umd/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -3
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +2 -3
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +16 -3
- package/umd/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -2
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
- package/umd/typings/src/prepare/isPipelinePrepared.d.ts +10 -0
- package/umd/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -1
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +4 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +5 -3
- package/umd/typings/src/types/Prompt.d.ts +7 -10
- package/umd/typings/src/types/typeAliases.d.ts +44 -4
- package/umd/typings/src/utils/deepFreeze.d.ts +10 -1
- package/umd/typings/src/utils/extractParameters.d.ts +2 -2
- package/umd/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
- package/umd/typings/src/utils/replaceParameters.test.d.ts +1 -0
- package/umd/typings/src/utils/sets/difference.d.ts +3 -0
- package/esm/typings/src/types/Parameters.d.ts +0 -14
- package/umd/typings/src/types/Parameters.d.ts +0 -14
- /package/esm/typings/src/{execution/utils/replaceParameters.test.d.ts → prepare/isPipelinePrepared.test.d.ts} +0 -0
- /package/{umd/typings/src/execution → esm/typings/src}/utils/replaceParameters.test.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -150,7 +150,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
150
150
|
/**
|
|
151
151
|
* The version of the Promptbook library
|
|
152
152
|
*/
|
|
153
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
153
|
+
var PROMPTBOOK_VERSION = '0.61.0-16';
|
|
154
154
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
155
155
|
|
|
156
156
|
/**
|
|
@@ -216,7 +216,7 @@ function collectionToJson(collection) {
|
|
|
216
216
|
*
|
|
217
217
|
* @returns The same object as the input, but deeply frozen
|
|
218
218
|
*
|
|
219
|
-
* Note: This function mutates the object
|
|
219
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
220
220
|
*/
|
|
221
221
|
function deepFreeze(objectValue) {
|
|
222
222
|
var e_1, _a;
|
|
@@ -239,6 +239,17 @@ function deepFreeze(objectValue) {
|
|
|
239
239
|
}
|
|
240
240
|
return Object.freeze(objectValue);
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* @@@
|
|
244
|
+
* @@@
|
|
245
|
+
*
|
|
246
|
+
* @returns The same object as the input, but deeply frozen
|
|
247
|
+
*
|
|
248
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
249
|
+
*/
|
|
250
|
+
function deepFreezeWithSameType(objectValue) {
|
|
251
|
+
return deepFreeze(objectValue);
|
|
252
|
+
}
|
|
242
253
|
/**
|
|
243
254
|
* TODO: [🔼] Export from `@promptbook/utils`
|
|
244
255
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -252,10 +263,18 @@ var LOOP_LIMIT = 1000;
|
|
|
252
263
|
* The maximum number of (LLM) tasks running in parallel
|
|
253
264
|
*/
|
|
254
265
|
var MAX_PARALLEL_COUNT = 5;
|
|
266
|
+
/**
|
|
267
|
+
* The maximum number of attempts to execute LLM task before giving up
|
|
268
|
+
*/
|
|
269
|
+
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
255
270
|
/**
|
|
256
271
|
* The maximum length of the (generated) filename
|
|
257
272
|
*/
|
|
258
273
|
var MAX_FILENAME_LENGTH = 30;
|
|
274
|
+
/**
|
|
275
|
+
* Where to store the cache of executions for promptbook CLI
|
|
276
|
+
*/
|
|
277
|
+
var EXECUTIONS_CACHE_DIRNAME = '/.promptbook/executions-cache';
|
|
259
278
|
/**
|
|
260
279
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
261
280
|
*/
|
|
@@ -265,6 +284,7 @@ var PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
|
265
284
|
*/
|
|
266
285
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
267
286
|
'context',
|
|
287
|
+
'currentDate',
|
|
268
288
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
269
289
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
270
290
|
]);
|
|
@@ -276,6 +296,9 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
276
296
|
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
277
297
|
*/
|
|
278
298
|
// [🟡][🟢][🔵][⚪]
|
|
299
|
+
/**
|
|
300
|
+
* TODO: [🔼] Export all to core
|
|
301
|
+
*/
|
|
279
302
|
|
|
280
303
|
/**
|
|
281
304
|
* @@@
|
|
@@ -469,7 +492,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
469
492
|
});
|
|
470
493
|
}
|
|
471
494
|
|
|
472
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
495
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-16",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",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:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",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-16",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-16",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-16",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-16",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-16",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-16",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"}];
|
|
473
496
|
|
|
474
497
|
/**
|
|
475
498
|
* Prettify the html code
|
|
@@ -575,7 +598,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
575
598
|
/* Note: Not using:> name, */
|
|
576
599
|
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
577
600
|
/* Note: dependentParameterNames, */
|
|
578
|
-
jokers = promptTemplate.
|
|
601
|
+
jokers = promptTemplate.jokerParameterNames, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessingFunctionNames, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
579
602
|
pipelineString += '\n\n';
|
|
580
603
|
pipelineString += "## ".concat(title_1);
|
|
581
604
|
if (description_1) {
|
|
@@ -915,7 +938,7 @@ function isValidPipelineUrl(url) {
|
|
|
915
938
|
*/
|
|
916
939
|
function validatePipeline(pipeline) {
|
|
917
940
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
918
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
941
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
919
942
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
920
943
|
// <- Note: [🚲]
|
|
921
944
|
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
|
|
@@ -952,19 +975,19 @@ function validatePipeline(pipeline) {
|
|
|
952
975
|
};
|
|
953
976
|
try {
|
|
954
977
|
// Note: Check each parameter individually
|
|
955
|
-
for (var
|
|
956
|
-
var parameter =
|
|
978
|
+
for (var _f = __values(pipeline.parameters), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
979
|
+
var parameter = _g.value;
|
|
957
980
|
_loop_1(parameter);
|
|
958
981
|
}
|
|
959
982
|
}
|
|
960
983
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
961
984
|
finally {
|
|
962
985
|
try {
|
|
963
|
-
if (
|
|
986
|
+
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
964
987
|
}
|
|
965
988
|
finally { if (e_1) throw e_1.error; }
|
|
966
989
|
}
|
|
967
|
-
// Note:
|
|
990
|
+
// Note: All input parameters are defined - so that they can be used as result of some template
|
|
968
991
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
969
992
|
var isInput = _a.isInput;
|
|
970
993
|
return isInput;
|
|
@@ -973,23 +996,27 @@ function validatePipeline(pipeline) {
|
|
|
973
996
|
return name;
|
|
974
997
|
}));
|
|
975
998
|
try {
|
|
976
|
-
|
|
977
|
-
|
|
999
|
+
// Note: Checking each template individually
|
|
1000
|
+
for (var _h = __values(pipeline.promptTemplates), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
1001
|
+
var template = _j.value;
|
|
978
1002
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
979
1003
|
throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
980
1004
|
}
|
|
1005
|
+
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
1006
|
+
throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use fifferent name"));
|
|
1007
|
+
}
|
|
981
1008
|
definedParameters.add(template.resultingParameterName);
|
|
982
1009
|
if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
983
1010
|
throw new PipelineLogicError(spaceTrim$1("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
984
1011
|
}
|
|
985
|
-
if (template.
|
|
1012
|
+
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
986
1013
|
if (!template.expectFormat &&
|
|
987
1014
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
988
1015
|
throw new PipelineLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
989
1016
|
}
|
|
990
1017
|
try {
|
|
991
|
-
for (var
|
|
992
|
-
var joker =
|
|
1018
|
+
for (var _k = (e_3 = void 0, __values(template.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
1019
|
+
var joker = _l.value;
|
|
993
1020
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
994
1021
|
throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
995
1022
|
}
|
|
@@ -998,15 +1025,15 @@ function validatePipeline(pipeline) {
|
|
|
998
1025
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
999
1026
|
finally {
|
|
1000
1027
|
try {
|
|
1001
|
-
if (
|
|
1028
|
+
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
1002
1029
|
}
|
|
1003
1030
|
finally { if (e_3) throw e_3.error; }
|
|
1004
1031
|
}
|
|
1005
1032
|
}
|
|
1006
1033
|
if (template.expectations) {
|
|
1007
1034
|
try {
|
|
1008
|
-
for (var
|
|
1009
|
-
var
|
|
1035
|
+
for (var _m = (e_4 = void 0, __values(Object.entries(template.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
1036
|
+
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
1010
1037
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1011
1038
|
throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
1012
1039
|
}
|
|
@@ -1021,7 +1048,7 @@ function validatePipeline(pipeline) {
|
|
|
1021
1048
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1022
1049
|
finally {
|
|
1023
1050
|
try {
|
|
1024
|
-
if (
|
|
1051
|
+
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
1025
1052
|
}
|
|
1026
1053
|
finally { if (e_4) throw e_4.error; }
|
|
1027
1054
|
}
|
|
@@ -1031,7 +1058,7 @@ function validatePipeline(pipeline) {
|
|
|
1031
1058
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1032
1059
|
finally {
|
|
1033
1060
|
try {
|
|
1034
|
-
if (
|
|
1061
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
1035
1062
|
}
|
|
1036
1063
|
finally { if (e_2) throw e_2.error; }
|
|
1037
1064
|
}
|
|
@@ -1045,7 +1072,22 @@ function validatePipeline(pipeline) {
|
|
|
1045
1072
|
var name = _a.name;
|
|
1046
1073
|
return name;
|
|
1047
1074
|
});
|
|
1075
|
+
try {
|
|
1076
|
+
// Note: All reserved parameters are resolved
|
|
1077
|
+
for (var RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
|
|
1078
|
+
var reservedParameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
1079
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), [reservedParameterName], false);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1083
|
+
finally {
|
|
1084
|
+
try {
|
|
1085
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_e = RESERVED_PARAMETER_NAMES_1.return)) _e.call(RESERVED_PARAMETER_NAMES_1);
|
|
1086
|
+
}
|
|
1087
|
+
finally { if (e_5) throw e_5.error; }
|
|
1088
|
+
}
|
|
1048
1089
|
var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
1090
|
+
// <- TODO: [🧠][🥜]
|
|
1049
1091
|
var loopLimit = LOOP_LIMIT;
|
|
1050
1092
|
var _loop_2 = function () {
|
|
1051
1093
|
if (loopLimit-- < 0) {
|
|
@@ -1059,11 +1101,11 @@ function validatePipeline(pipeline) {
|
|
|
1059
1101
|
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
1060
1102
|
.map(function (_a) {
|
|
1061
1103
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1062
|
-
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
1104
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
1063
1105
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
1064
|
-
.join('
|
|
1106
|
+
.join(' and '));
|
|
1065
1107
|
})
|
|
1066
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
1108
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
1067
1109
|
}
|
|
1068
1110
|
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
1069
1111
|
var resultingParameterName = _a.resultingParameterName;
|
|
@@ -1090,6 +1132,9 @@ function validatePipeline(pipeline) {
|
|
|
1090
1132
|
/**
|
|
1091
1133
|
* TODO: [🧠][🐣] !!!! Validate that all samples match expectations
|
|
1092
1134
|
* TODO: [🧠][🐣] !!!! Validate that knowledge is valid (non-void)
|
|
1135
|
+
* TODO: [🧠][🐣] !!!! Validate that persona can be used only with CHAT variant
|
|
1136
|
+
* TODO: !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1137
|
+
* TODO: !!!! Validate that reserved parameter is not used as joker
|
|
1093
1138
|
* TODO: [🧠] !!! Validationg not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1094
1139
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1095
1140
|
*/
|
|
@@ -1598,6 +1643,212 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1598
1643
|
* TODO: [🧠] Can this return type be better typed than void
|
|
1599
1644
|
*/
|
|
1600
1645
|
|
|
1646
|
+
/**
|
|
1647
|
+
* Create difference set of two sets.
|
|
1648
|
+
*
|
|
1649
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1650
|
+
*/
|
|
1651
|
+
function difference(a, b, isEqual) {
|
|
1652
|
+
var e_1, _a;
|
|
1653
|
+
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
1654
|
+
var diff = new Set();
|
|
1655
|
+
var _loop_1 = function (itemA) {
|
|
1656
|
+
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
1657
|
+
diff.add(itemA);
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
try {
|
|
1661
|
+
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1662
|
+
var itemA = _c.value;
|
|
1663
|
+
_loop_1(itemA);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1667
|
+
finally {
|
|
1668
|
+
try {
|
|
1669
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1670
|
+
}
|
|
1671
|
+
finally { if (e_1) throw e_1.error; }
|
|
1672
|
+
}
|
|
1673
|
+
return diff;
|
|
1674
|
+
}
|
|
1675
|
+
/**
|
|
1676
|
+
* TODO: [🧠][💯] Maybe also implement symmetricDifference
|
|
1677
|
+
*/
|
|
1678
|
+
|
|
1679
|
+
/**
|
|
1680
|
+
* Parses the template and returns the list of all parameter names
|
|
1681
|
+
*
|
|
1682
|
+
* @param template the template with parameters in {curly} braces
|
|
1683
|
+
* @returns the list of parameter names
|
|
1684
|
+
*/
|
|
1685
|
+
function extractParameters(template) {
|
|
1686
|
+
var e_1, _a;
|
|
1687
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
1688
|
+
var parameterNames = new Set();
|
|
1689
|
+
try {
|
|
1690
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1691
|
+
var match = matches_1_1.value;
|
|
1692
|
+
var parameterName = match[0].slice(1, -1);
|
|
1693
|
+
parameterNames.add(parameterName);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1697
|
+
finally {
|
|
1698
|
+
try {
|
|
1699
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1700
|
+
}
|
|
1701
|
+
finally { if (e_1) throw e_1.error; }
|
|
1702
|
+
}
|
|
1703
|
+
return parameterNames;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
/**
|
|
1707
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1708
|
+
*
|
|
1709
|
+
* @param script from which to extract the variables
|
|
1710
|
+
* @returns the list of variable names
|
|
1711
|
+
* @throws {ParsingError} if the script is invalid
|
|
1712
|
+
*/
|
|
1713
|
+
function extractVariables(script) {
|
|
1714
|
+
var variables = new Set();
|
|
1715
|
+
script = "(()=>{".concat(script, "})()");
|
|
1716
|
+
try {
|
|
1717
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
1718
|
+
try {
|
|
1719
|
+
eval(script);
|
|
1720
|
+
}
|
|
1721
|
+
catch (error) {
|
|
1722
|
+
if (!(error instanceof ReferenceError)) {
|
|
1723
|
+
throw error;
|
|
1724
|
+
}
|
|
1725
|
+
var undefinedName = error.message.split(' ')[0];
|
|
1726
|
+
/*
|
|
1727
|
+
Note: Parsing the error
|
|
1728
|
+
[ReferenceError: thing is not defined]
|
|
1729
|
+
*/
|
|
1730
|
+
if (!undefinedName) {
|
|
1731
|
+
throw error;
|
|
1732
|
+
}
|
|
1733
|
+
if (script.includes(undefinedName + '(')) {
|
|
1734
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
1735
|
+
}
|
|
1736
|
+
else {
|
|
1737
|
+
variables.add(undefinedName);
|
|
1738
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
catch (error) {
|
|
1743
|
+
if (!(error instanceof Error)) {
|
|
1744
|
+
throw error;
|
|
1745
|
+
}
|
|
1746
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
1747
|
+
}
|
|
1748
|
+
return variables;
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
1752
|
+
*/
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
1756
|
+
*
|
|
1757
|
+
* @param promptTemplate the template with used parameters
|
|
1758
|
+
* @returns the set of parameter names
|
|
1759
|
+
* @throws {ParsingError} if the script is invalid
|
|
1760
|
+
*/
|
|
1761
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
1762
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
1763
|
+
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1764
|
+
var parameterNames = new Set();
|
|
1765
|
+
try {
|
|
1766
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(title)), false), __read(extractParameters(description || '')), false), __read(extractParameters(content)), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1767
|
+
var parameterName = _e.value;
|
|
1768
|
+
parameterNames.add(parameterName);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1772
|
+
finally {
|
|
1773
|
+
try {
|
|
1774
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1775
|
+
}
|
|
1776
|
+
finally { if (e_1) throw e_1.error; }
|
|
1777
|
+
}
|
|
1778
|
+
if (blockType === 'SCRIPT') {
|
|
1779
|
+
try {
|
|
1780
|
+
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1781
|
+
var parameterName = _g.value;
|
|
1782
|
+
parameterNames.add(parameterName);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1786
|
+
finally {
|
|
1787
|
+
try {
|
|
1788
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1789
|
+
}
|
|
1790
|
+
finally { if (e_2) throw e_2.error; }
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
try {
|
|
1794
|
+
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
1795
|
+
var jokerName = _j.value;
|
|
1796
|
+
parameterNames.add(jokerName);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1800
|
+
finally {
|
|
1801
|
+
try {
|
|
1802
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
1803
|
+
}
|
|
1804
|
+
finally { if (e_3) throw e_3.error; }
|
|
1805
|
+
}
|
|
1806
|
+
return parameterNames;
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* TODO: [🔣] If script require contentLanguage
|
|
1810
|
+
*/
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* Creates a new set with all elements that are present in either set
|
|
1814
|
+
*
|
|
1815
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1816
|
+
*/
|
|
1817
|
+
function union() {
|
|
1818
|
+
var e_1, _a, e_2, _b;
|
|
1819
|
+
var sets = [];
|
|
1820
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1821
|
+
sets[_i] = arguments[_i];
|
|
1822
|
+
}
|
|
1823
|
+
var union = new Set();
|
|
1824
|
+
try {
|
|
1825
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
1826
|
+
var set = sets_1_1.value;
|
|
1827
|
+
try {
|
|
1828
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1829
|
+
var item = _d.value;
|
|
1830
|
+
union.add(item);
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1834
|
+
finally {
|
|
1835
|
+
try {
|
|
1836
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1837
|
+
}
|
|
1838
|
+
finally { if (e_2) throw e_2.error; }
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1843
|
+
finally {
|
|
1844
|
+
try {
|
|
1845
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
1846
|
+
}
|
|
1847
|
+
finally { if (e_1) throw e_1.error; }
|
|
1848
|
+
}
|
|
1849
|
+
return union;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1601
1852
|
/**
|
|
1602
1853
|
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
1603
1854
|
*
|
|
@@ -1870,6 +2121,31 @@ function joinLlmExecutionTools() {
|
|
|
1870
2121
|
return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
|
|
1871
2122
|
}
|
|
1872
2123
|
|
|
2124
|
+
/**
|
|
2125
|
+
* Determine if the pipeline is fully prepared
|
|
2126
|
+
*/
|
|
2127
|
+
function isPipelinePrepared(pipeline) {
|
|
2128
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2129
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2130
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2131
|
+
console.log('!!!!', 'Not all personas have modelRequirements');
|
|
2132
|
+
return false;
|
|
2133
|
+
}
|
|
2134
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2135
|
+
console.log('!!!!', 'Not all knowledgeSources have preparationIds');
|
|
2136
|
+
return false;
|
|
2137
|
+
}
|
|
2138
|
+
// TODO: !!!!! Is context in each template
|
|
2139
|
+
// TODO: !!!!! Are samples prepared
|
|
2140
|
+
// TODO: !!!!! Are templates prepared
|
|
2141
|
+
return true;
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2145
|
+
* TODO: [🔼] Export via core or utils
|
|
2146
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2147
|
+
*/
|
|
2148
|
+
|
|
1873
2149
|
/**
|
|
1874
2150
|
* Takes an item or an array of items and returns an array of items
|
|
1875
2151
|
*
|
|
@@ -1890,26 +2166,115 @@ function arrayableToArray(input) {
|
|
|
1890
2166
|
}
|
|
1891
2167
|
|
|
1892
2168
|
/**
|
|
1893
|
-
*
|
|
2169
|
+
* Just marks a place of place where should be something implemented
|
|
2170
|
+
* No side effects.
|
|
2171
|
+
*
|
|
2172
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2173
|
+
*
|
|
2174
|
+
* @param value any values
|
|
2175
|
+
* @returns void
|
|
2176
|
+
* @private within the repository
|
|
1894
2177
|
*/
|
|
1895
|
-
function
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
1901
|
-
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
1902
|
-
return text.length;
|
|
2178
|
+
function TODO_USE() {
|
|
2179
|
+
var value = [];
|
|
2180
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2181
|
+
value[_i] = arguments[_i];
|
|
2182
|
+
}
|
|
1903
2183
|
}
|
|
1904
2184
|
|
|
1905
2185
|
/**
|
|
1906
|
-
*
|
|
2186
|
+
* This error type indicates that some limit was reached
|
|
1907
2187
|
*/
|
|
1908
|
-
function
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
2188
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2189
|
+
__extends(LimitReachedError, _super);
|
|
2190
|
+
function LimitReachedError(message) {
|
|
2191
|
+
var _this = _super.call(this, message) || this;
|
|
2192
|
+
_this.name = 'LimitReachedError';
|
|
2193
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2194
|
+
return _this;
|
|
2195
|
+
}
|
|
2196
|
+
return LimitReachedError;
|
|
2197
|
+
}(Error));
|
|
2198
|
+
|
|
2199
|
+
/**
|
|
2200
|
+
* Replaces parameters in template with values from parameters object
|
|
2201
|
+
*
|
|
2202
|
+
* @param template the template with parameters in {curly} braces
|
|
2203
|
+
* @param parameters the object with parameters
|
|
2204
|
+
* @returns the template with replaced parameters
|
|
2205
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2206
|
+
*/
|
|
2207
|
+
function replaceParameters(template, parameters) {
|
|
2208
|
+
var replacedTemplate = template;
|
|
2209
|
+
var match;
|
|
2210
|
+
var loopLimit = LOOP_LIMIT;
|
|
2211
|
+
var _loop_1 = function () {
|
|
2212
|
+
if (loopLimit-- < 0) {
|
|
2213
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
2214
|
+
}
|
|
2215
|
+
var precol = match.groups.precol;
|
|
2216
|
+
var parameterName = match.groups.parameterName;
|
|
2217
|
+
if (parameterName === '') {
|
|
2218
|
+
return "continue";
|
|
2219
|
+
}
|
|
2220
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2221
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2222
|
+
}
|
|
2223
|
+
if (parameters[parameterName] === undefined) {
|
|
2224
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2225
|
+
}
|
|
2226
|
+
var parameterValue = parameters[parameterName];
|
|
2227
|
+
if (parameterValue === undefined) {
|
|
2228
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2229
|
+
}
|
|
2230
|
+
parameterValue = parameterValue.toString();
|
|
2231
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2232
|
+
parameterValue = parameterValue
|
|
2233
|
+
.split('\n')
|
|
2234
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2235
|
+
.join('\n');
|
|
2236
|
+
}
|
|
2237
|
+
replacedTemplate =
|
|
2238
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2239
|
+
parameterValue +
|
|
2240
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2241
|
+
};
|
|
2242
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2243
|
+
.exec(replacedTemplate))) {
|
|
2244
|
+
_loop_1();
|
|
2245
|
+
}
|
|
2246
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
2247
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
2248
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
2249
|
+
}
|
|
2250
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
2251
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
2252
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
2253
|
+
}
|
|
2254
|
+
return replacedTemplate;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
/**
|
|
2258
|
+
* Counts number of characters in the text
|
|
2259
|
+
*/
|
|
2260
|
+
function countCharacters(text) {
|
|
2261
|
+
// Remove null characters
|
|
2262
|
+
text = text.replace(/\0/g, '');
|
|
2263
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
2264
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
2265
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
2266
|
+
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
2267
|
+
return text.length;
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
/**
|
|
2271
|
+
* Counts number of lines in the text
|
|
2272
|
+
*/
|
|
2273
|
+
function countLines(text) {
|
|
2274
|
+
if (text === '') {
|
|
2275
|
+
return 0;
|
|
2276
|
+
}
|
|
2277
|
+
return text.split('\n').length;
|
|
1913
2278
|
}
|
|
1914
2279
|
|
|
1915
2280
|
/**
|
|
@@ -1999,80 +2364,6 @@ function checkExpectations(expectations, value) {
|
|
|
1999
2364
|
* TODO: [💝] Unite object for expecting amount and format
|
|
2000
2365
|
*/
|
|
2001
2366
|
|
|
2002
|
-
/**
|
|
2003
|
-
* This error type indicates that some limit was reached
|
|
2004
|
-
*/
|
|
2005
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2006
|
-
__extends(LimitReachedError, _super);
|
|
2007
|
-
function LimitReachedError(message) {
|
|
2008
|
-
var _this = _super.call(this, message) || this;
|
|
2009
|
-
_this.name = 'LimitReachedError';
|
|
2010
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2011
|
-
return _this;
|
|
2012
|
-
}
|
|
2013
|
-
return LimitReachedError;
|
|
2014
|
-
}(Error));
|
|
2015
|
-
|
|
2016
|
-
/**
|
|
2017
|
-
* Replaces parameters in template with values from parameters object
|
|
2018
|
-
*
|
|
2019
|
-
* @param template the template with parameters in {curly} braces
|
|
2020
|
-
* @param parameters the object with parameters
|
|
2021
|
-
* @returns the template with replaced parameters
|
|
2022
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2023
|
-
*
|
|
2024
|
-
* @private within the createPipelineExecutor
|
|
2025
|
-
*/
|
|
2026
|
-
function replaceParameters(template, parameters) {
|
|
2027
|
-
var replacedTemplate = template;
|
|
2028
|
-
var match;
|
|
2029
|
-
var loopLimit = LOOP_LIMIT;
|
|
2030
|
-
var _loop_1 = function () {
|
|
2031
|
-
if (loopLimit-- < 0) {
|
|
2032
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
2033
|
-
}
|
|
2034
|
-
var precol = match.groups.precol;
|
|
2035
|
-
var parameterName = match.groups.parameterName;
|
|
2036
|
-
if (parameterName === '') {
|
|
2037
|
-
return "continue";
|
|
2038
|
-
}
|
|
2039
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2040
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2041
|
-
}
|
|
2042
|
-
if (parameters[parameterName] === undefined) {
|
|
2043
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2044
|
-
}
|
|
2045
|
-
var parameterValue = parameters[parameterName];
|
|
2046
|
-
if (parameterValue === undefined) {
|
|
2047
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2048
|
-
}
|
|
2049
|
-
parameterValue = parameterValue.toString();
|
|
2050
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2051
|
-
parameterValue = parameterValue
|
|
2052
|
-
.split('\n')
|
|
2053
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2054
|
-
.join('\n');
|
|
2055
|
-
}
|
|
2056
|
-
replacedTemplate =
|
|
2057
|
-
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2058
|
-
parameterValue +
|
|
2059
|
-
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2060
|
-
};
|
|
2061
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2062
|
-
.exec(replacedTemplate))) {
|
|
2063
|
-
_loop_1();
|
|
2064
|
-
}
|
|
2065
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
2066
|
-
if (/{\w+$/.test(replacedTemplate)) {
|
|
2067
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
2068
|
-
}
|
|
2069
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
2070
|
-
if (/^\w+}/.test(replacedTemplate)) {
|
|
2071
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
2072
|
-
}
|
|
2073
|
-
return replacedTemplate;
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
2367
|
/**
|
|
2077
2368
|
* Creates executor function from pipeline and execution tools.
|
|
2078
2369
|
*
|
|
@@ -2081,18 +2372,73 @@ function replaceParameters(template, parameters) {
|
|
|
2081
2372
|
*/
|
|
2082
2373
|
function createPipelineExecutor(options) {
|
|
2083
2374
|
var _this = this;
|
|
2084
|
-
var
|
|
2085
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ?
|
|
2086
|
-
validatePipeline(
|
|
2375
|
+
var rawPipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2376
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? false : _d;
|
|
2377
|
+
validatePipeline(rawPipeline);
|
|
2087
2378
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2379
|
+
var pipeline;
|
|
2380
|
+
if (isPipelinePrepared(rawPipeline)) {
|
|
2381
|
+
pipeline = rawPipeline;
|
|
2382
|
+
}
|
|
2383
|
+
else {
|
|
2384
|
+
console.warn(spaceTrim$1("\n Pipeline is not prepared\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 "));
|
|
2385
|
+
}
|
|
2088
2386
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2387
|
+
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2388
|
+
template) {
|
|
2389
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2390
|
+
return __generator(this, function (_a) {
|
|
2391
|
+
// TODO: !!!!!! Implement Better - use real index and keyword search
|
|
2392
|
+
TODO_USE(template);
|
|
2393
|
+
return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
|
|
2394
|
+
var content = _a.content;
|
|
2395
|
+
return "- ".concat(content);
|
|
2396
|
+
}).join('\n')];
|
|
2397
|
+
});
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
function getReservedParametersForTemplate(template) {
|
|
2401
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2402
|
+
var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2403
|
+
var e_3, _a;
|
|
2404
|
+
return __generator(this, function (_b) {
|
|
2405
|
+
switch (_b.label) {
|
|
2406
|
+
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
2407
|
+
case 1:
|
|
2408
|
+
context = _b.sent();
|
|
2409
|
+
currentDate = new Date().toISOString();
|
|
2410
|
+
reservedParameters = {
|
|
2411
|
+
context: context,
|
|
2412
|
+
currentDate: currentDate,
|
|
2413
|
+
};
|
|
2414
|
+
try {
|
|
2415
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
2416
|
+
for (RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
|
|
2417
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
2418
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
2419
|
+
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2424
|
+
finally {
|
|
2425
|
+
try {
|
|
2426
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
2427
|
+
}
|
|
2428
|
+
finally { if (e_3) throw e_3.error; }
|
|
2429
|
+
}
|
|
2430
|
+
return [2 /*return*/, reservedParameters];
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2089
2435
|
function executeSingleTemplate(currentTemplate) {
|
|
2090
2436
|
return __awaiter(this, void 0, void 0, function () {
|
|
2091
|
-
var name, title, priority, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts,
|
|
2092
|
-
var
|
|
2437
|
+
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;
|
|
2438
|
+
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2093
2439
|
var _this = this;
|
|
2094
|
-
return __generator(this, function (
|
|
2095
|
-
switch (
|
|
2440
|
+
return __generator(this, function (_u) {
|
|
2441
|
+
switch (_u.label) {
|
|
2096
2442
|
case 0:
|
|
2097
2443
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
2098
2444
|
title = currentTemplate.title;
|
|
@@ -2109,64 +2455,108 @@ function createPipelineExecutor(options) {
|
|
|
2109
2455
|
// <- [3]
|
|
2110
2456
|
})];
|
|
2111
2457
|
case 1:
|
|
2112
|
-
|
|
2113
|
-
|
|
2458
|
+
_u.sent();
|
|
2459
|
+
_u.label = 2;
|
|
2114
2460
|
case 2:
|
|
2461
|
+
usedParameterNames = extractParametersFromPromptTemplate(currentTemplate);
|
|
2462
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2463
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2464
|
+
throw new UnexpectedError(spaceTrim$1("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
|
|
2465
|
+
}
|
|
2466
|
+
_b = (_a = Object).freeze;
|
|
2467
|
+
_c = [{}];
|
|
2468
|
+
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
2469
|
+
case 3:
|
|
2470
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_u.sent())])), parametersToPass])]);
|
|
2471
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
2472
|
+
parameters = {};
|
|
2473
|
+
try {
|
|
2474
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
2475
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2476
|
+
parameterName = _e.value;
|
|
2477
|
+
// Situation: Parameter is defined and used
|
|
2478
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2479
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
2480
|
+
}
|
|
2481
|
+
// Situation: Parameter is defined but NOT used
|
|
2482
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
2483
|
+
// Do not pass this parameter to prompt
|
|
2484
|
+
}
|
|
2485
|
+
// Situation: Parameter is NOT defined BUT used
|
|
2486
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2487
|
+
// Houston, we have a problem
|
|
2488
|
+
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2489
|
+
throw new UnexpectedError(spaceTrim$1("\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ")));
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2494
|
+
finally {
|
|
2495
|
+
try {
|
|
2496
|
+
if (_e && !_e.done && (_p = _d.return)) _p.call(_d);
|
|
2497
|
+
}
|
|
2498
|
+
finally { if (e_7) throw e_7.error; }
|
|
2499
|
+
}
|
|
2500
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
2501
|
+
Object.freeze(parameters);
|
|
2115
2502
|
result = null;
|
|
2116
2503
|
resultString = null;
|
|
2117
2504
|
expectError = null;
|
|
2118
2505
|
maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
2119
|
-
|
|
2120
|
-
attempt = -
|
|
2121
|
-
|
|
2122
|
-
case
|
|
2123
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
2506
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
2507
|
+
attempt = -jokerParameterNames.length;
|
|
2508
|
+
_u.label = 4;
|
|
2509
|
+
case 4:
|
|
2510
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 52];
|
|
2124
2511
|
isJokerAttempt = attempt < 0;
|
|
2125
|
-
|
|
2126
|
-
if (isJokerAttempt && !
|
|
2512
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
2513
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
2127
2514
|
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
2128
2515
|
}
|
|
2129
2516
|
result = null;
|
|
2130
2517
|
resultString = null;
|
|
2131
2518
|
expectError = null;
|
|
2132
2519
|
if (isJokerAttempt) {
|
|
2133
|
-
if (
|
|
2134
|
-
throw new PipelineExecutionError("Joker parameter {".concat(
|
|
2520
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
2521
|
+
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
2522
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
2523
|
+
}
|
|
2524
|
+
else {
|
|
2525
|
+
resultString = parameters[jokerParameterName];
|
|
2135
2526
|
}
|
|
2136
|
-
resultString = parametersToPass[joker];
|
|
2137
|
-
}
|
|
2138
|
-
_o.label = 4;
|
|
2139
|
-
case 4:
|
|
2140
|
-
_o.trys.push([4, 47, 48, 49]);
|
|
2141
|
-
if (!!isJokerAttempt) return [3 /*break*/, 29];
|
|
2142
|
-
_a = currentTemplate.blockType;
|
|
2143
|
-
switch (_a) {
|
|
2144
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
|
|
2145
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
|
|
2146
|
-
case 'SCRIPT': return [3 /*break*/, 15];
|
|
2147
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 26];
|
|
2148
2527
|
}
|
|
2149
|
-
|
|
2528
|
+
_u.label = 5;
|
|
2150
2529
|
case 5:
|
|
2151
|
-
|
|
2530
|
+
_u.trys.push([5, 48, 49, 50]);
|
|
2531
|
+
if (!!isJokerAttempt) return [3 /*break*/, 30];
|
|
2532
|
+
_f = currentTemplate.blockType;
|
|
2533
|
+
switch (_f) {
|
|
2534
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
2535
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
2536
|
+
case 'SCRIPT': return [3 /*break*/, 16];
|
|
2537
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
2538
|
+
}
|
|
2152
2539
|
return [3 /*break*/, 29];
|
|
2153
2540
|
case 6:
|
|
2541
|
+
resultString = replaceParameters(currentTemplate.content, parameters);
|
|
2542
|
+
return [3 /*break*/, 30];
|
|
2543
|
+
case 7:
|
|
2154
2544
|
prompt = {
|
|
2155
2545
|
title: currentTemplate.title,
|
|
2156
2546
|
pipelineUrl: "".concat(pipeline.pipelineUrl
|
|
2157
2547
|
? pipeline.pipelineUrl
|
|
2158
2548
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
2159
|
-
parameters:
|
|
2160
|
-
content:
|
|
2161
|
-
// <- TODO: !!!!! Apply {context} and knowledges
|
|
2162
|
-
// <- TODO: !!!!! Apply samples
|
|
2549
|
+
parameters: parameters,
|
|
2550
|
+
content: currentTemplate.content,
|
|
2163
2551
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2164
|
-
|
|
2165
|
-
|
|
2552
|
+
expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
|
|
2553
|
+
var name = _a.name;
|
|
2554
|
+
return name === currentTemplate.personaName;
|
|
2555
|
+
}) || {})), currentTemplate.expectations),
|
|
2166
2556
|
expectFormat: currentTemplate.expectFormat,
|
|
2167
|
-
postprocessing: (currentTemplate.
|
|
2168
|
-
var errors, _a, _b, scriptTools, error_5,
|
|
2169
|
-
var
|
|
2557
|
+
postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
2558
|
+
var errors, _a, _b, scriptTools, error_5, e_8_1;
|
|
2559
|
+
var e_8, _c;
|
|
2170
2560
|
return __generator(this, function (_d) {
|
|
2171
2561
|
switch (_d.label) {
|
|
2172
2562
|
case 0:
|
|
@@ -2187,7 +2577,7 @@ function createPipelineExecutor(options) {
|
|
|
2187
2577
|
script: "".concat(functionName, "(result)"),
|
|
2188
2578
|
parameters: {
|
|
2189
2579
|
result: result || '',
|
|
2190
|
-
// Note: No ...
|
|
2580
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2191
2581
|
},
|
|
2192
2582
|
})];
|
|
2193
2583
|
case 4: return [2 /*return*/, _d.sent()];
|
|
@@ -2196,6 +2586,9 @@ function createPipelineExecutor(options) {
|
|
|
2196
2586
|
if (!(error_5 instanceof Error)) {
|
|
2197
2587
|
throw error_5;
|
|
2198
2588
|
}
|
|
2589
|
+
if (error_5 instanceof UnexpectedError) {
|
|
2590
|
+
throw error_5;
|
|
2591
|
+
}
|
|
2199
2592
|
errors.push(error_5);
|
|
2200
2593
|
return [3 /*break*/, 6];
|
|
2201
2594
|
case 6:
|
|
@@ -2203,14 +2596,14 @@ function createPipelineExecutor(options) {
|
|
|
2203
2596
|
return [3 /*break*/, 2];
|
|
2204
2597
|
case 7: return [3 /*break*/, 10];
|
|
2205
2598
|
case 8:
|
|
2206
|
-
|
|
2207
|
-
|
|
2599
|
+
e_8_1 = _d.sent();
|
|
2600
|
+
e_8 = { error: e_8_1 };
|
|
2208
2601
|
return [3 /*break*/, 10];
|
|
2209
2602
|
case 9:
|
|
2210
2603
|
try {
|
|
2211
2604
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2212
2605
|
}
|
|
2213
|
-
finally { if (
|
|
2606
|
+
finally { if (e_8) throw e_8.error; }
|
|
2214
2607
|
return [7 /*endfinally*/];
|
|
2215
2608
|
case 10:
|
|
2216
2609
|
if (errors.length === 0) {
|
|
@@ -2226,35 +2619,35 @@ function createPipelineExecutor(options) {
|
|
|
2226
2619
|
});
|
|
2227
2620
|
}); }; }),
|
|
2228
2621
|
};
|
|
2229
|
-
|
|
2230
|
-
switch (
|
|
2231
|
-
case 'CHAT': return [3 /*break*/,
|
|
2232
|
-
case 'COMPLETION': return [3 /*break*/,
|
|
2233
|
-
case 'EMBEDDING': return [3 /*break*/,
|
|
2622
|
+
_g = currentTemplate.modelRequirements.modelVariant;
|
|
2623
|
+
switch (_g) {
|
|
2624
|
+
case 'CHAT': return [3 /*break*/, 8];
|
|
2625
|
+
case 'COMPLETION': return [3 /*break*/, 10];
|
|
2626
|
+
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
2234
2627
|
}
|
|
2235
|
-
return [3 /*break*/,
|
|
2236
|
-
case
|
|
2237
|
-
case
|
|
2238
|
-
chatResult =
|
|
2628
|
+
return [3 /*break*/, 14];
|
|
2629
|
+
case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
|
|
2630
|
+
case 9:
|
|
2631
|
+
chatResult = _u.sent();
|
|
2239
2632
|
// TODO: [🍬] Destroy chatThread
|
|
2240
2633
|
result = chatResult;
|
|
2241
2634
|
resultString = chatResult.content;
|
|
2242
|
-
return [3 /*break*/,
|
|
2243
|
-
case
|
|
2244
|
-
case
|
|
2245
|
-
completionResult =
|
|
2635
|
+
return [3 /*break*/, 15];
|
|
2636
|
+
case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
|
|
2637
|
+
case 11:
|
|
2638
|
+
completionResult = _u.sent();
|
|
2246
2639
|
result = completionResult;
|
|
2247
2640
|
resultString = completionResult.content;
|
|
2248
|
-
return [3 /*break*/,
|
|
2249
|
-
case
|
|
2250
|
-
case
|
|
2251
|
-
embeddingResult =
|
|
2641
|
+
return [3 /*break*/, 15];
|
|
2642
|
+
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
|
|
2643
|
+
case 13:
|
|
2644
|
+
embeddingResult = _u.sent();
|
|
2252
2645
|
result = embeddingResult;
|
|
2253
2646
|
resultString = embeddingResult.content.join(',');
|
|
2254
|
-
return [3 /*break*/,
|
|
2255
|
-
case
|
|
2256
|
-
case
|
|
2257
|
-
case
|
|
2647
|
+
return [3 /*break*/, 15];
|
|
2648
|
+
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
2649
|
+
case 15: return [3 /*break*/, 30];
|
|
2650
|
+
case 16:
|
|
2258
2651
|
if (arrayableToArray(tools.script).length === 0) {
|
|
2259
2652
|
throw new PipelineExecutionError('No script execution tools are available');
|
|
2260
2653
|
}
|
|
@@ -2263,49 +2656,52 @@ function createPipelineExecutor(options) {
|
|
|
2263
2656
|
}
|
|
2264
2657
|
// TODO: DRY [1]
|
|
2265
2658
|
scriptPipelineExecutionErrors = [];
|
|
2266
|
-
|
|
2267
|
-
case 16:
|
|
2268
|
-
_o.trys.push([16, 23, 24, 25]);
|
|
2269
|
-
_c = (e_2 = void 0, __values(arrayableToArray(tools.script))), _d = _c.next();
|
|
2270
|
-
_o.label = 17;
|
|
2659
|
+
_u.label = 17;
|
|
2271
2660
|
case 17:
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2661
|
+
_u.trys.push([17, 24, 25, 26]);
|
|
2662
|
+
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
2663
|
+
_u.label = 18;
|
|
2275
2664
|
case 18:
|
|
2276
|
-
|
|
2277
|
-
|
|
2665
|
+
if (!!_j.done) return [3 /*break*/, 23];
|
|
2666
|
+
scriptTools = _j.value;
|
|
2667
|
+
_u.label = 19;
|
|
2668
|
+
case 19:
|
|
2669
|
+
_u.trys.push([19, 21, , 22]);
|
|
2670
|
+
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2278
2671
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2279
2672
|
script: currentTemplate.content,
|
|
2280
|
-
parameters:
|
|
2281
|
-
})];
|
|
2282
|
-
case 19:
|
|
2283
|
-
resultString = _o.sent();
|
|
2284
|
-
return [3 /*break*/, 22];
|
|
2673
|
+
parameters: parameters,
|
|
2674
|
+
}))];
|
|
2285
2675
|
case 20:
|
|
2286
|
-
|
|
2676
|
+
resultString = _u.sent();
|
|
2677
|
+
return [3 /*break*/, 23];
|
|
2678
|
+
case 21:
|
|
2679
|
+
error_2 = _u.sent();
|
|
2287
2680
|
if (!(error_2 instanceof Error)) {
|
|
2288
2681
|
throw error_2;
|
|
2289
2682
|
}
|
|
2683
|
+
if (error_2 instanceof UnexpectedError) {
|
|
2684
|
+
throw error_2;
|
|
2685
|
+
}
|
|
2290
2686
|
scriptPipelineExecutionErrors.push(error_2);
|
|
2291
|
-
return [3 /*break*/,
|
|
2292
|
-
case
|
|
2293
|
-
|
|
2294
|
-
return [3 /*break*/,
|
|
2295
|
-
case
|
|
2296
|
-
case 23:
|
|
2297
|
-
e_2_1 = _o.sent();
|
|
2298
|
-
e_2 = { error: e_2_1 };
|
|
2299
|
-
return [3 /*break*/, 25];
|
|
2687
|
+
return [3 /*break*/, 22];
|
|
2688
|
+
case 22:
|
|
2689
|
+
_j = _h.next();
|
|
2690
|
+
return [3 /*break*/, 18];
|
|
2691
|
+
case 23: return [3 /*break*/, 26];
|
|
2300
2692
|
case 24:
|
|
2693
|
+
e_4_1 = _u.sent();
|
|
2694
|
+
e_4 = { error: e_4_1 };
|
|
2695
|
+
return [3 /*break*/, 26];
|
|
2696
|
+
case 25:
|
|
2301
2697
|
try {
|
|
2302
|
-
if (
|
|
2698
|
+
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
2303
2699
|
}
|
|
2304
|
-
finally { if (
|
|
2700
|
+
finally { if (e_4) throw e_4.error; }
|
|
2305
2701
|
return [7 /*endfinally*/];
|
|
2306
|
-
case
|
|
2702
|
+
case 26:
|
|
2307
2703
|
if (resultString !== null) {
|
|
2308
|
-
return [3 /*break*/,
|
|
2704
|
+
return [3 /*break*/, 30];
|
|
2309
2705
|
}
|
|
2310
2706
|
if (scriptPipelineExecutionErrors.length === 1) {
|
|
2311
2707
|
throw scriptPipelineExecutionErrors[0];
|
|
@@ -2315,101 +2711,104 @@ function createPipelineExecutor(options) {
|
|
|
2315
2711
|
.map(function (error) { return '- ' + error.message; })
|
|
2316
2712
|
.join('\n\n')), "\n "); }));
|
|
2317
2713
|
}
|
|
2318
|
-
case
|
|
2714
|
+
case 27:
|
|
2319
2715
|
if (tools.userInterface === undefined) {
|
|
2320
2716
|
throw new PipelineExecutionError('User interface tools are not available');
|
|
2321
2717
|
}
|
|
2322
|
-
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
2718
|
+
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2323
2719
|
promptTitle: currentTemplate.title,
|
|
2324
|
-
promptMessage: replaceParameters(currentTemplate.description || '',
|
|
2325
|
-
defaultValue: replaceParameters(currentTemplate.content,
|
|
2720
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
2721
|
+
defaultValue: replaceParameters(currentTemplate.content, parameters),
|
|
2326
2722
|
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
2327
2723
|
placeholder: undefined,
|
|
2328
2724
|
priority: priority,
|
|
2329
|
-
})];
|
|
2330
|
-
case
|
|
2725
|
+
}))];
|
|
2726
|
+
case 28:
|
|
2331
2727
|
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
2332
|
-
resultString =
|
|
2333
|
-
return [3 /*break*/,
|
|
2334
|
-
case
|
|
2335
|
-
case 29:
|
|
2336
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 46];
|
|
2337
|
-
_o.label = 30;
|
|
2728
|
+
resultString = _u.sent();
|
|
2729
|
+
return [3 /*break*/, 30];
|
|
2730
|
+
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
2338
2731
|
case 30:
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
_o.label = 31;
|
|
2732
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
2733
|
+
_u.label = 31;
|
|
2342
2734
|
case 31:
|
|
2343
|
-
|
|
2344
|
-
|
|
2735
|
+
_u.trys.push([31, 45, 46, 47]);
|
|
2736
|
+
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
2737
|
+
_u.label = 32;
|
|
2738
|
+
case 32:
|
|
2739
|
+
if (!!_l.done) return [3 /*break*/, 44];
|
|
2740
|
+
functionName = _l.value;
|
|
2345
2741
|
// TODO: DRY [1]
|
|
2346
2742
|
scriptPipelineExecutionErrors = [];
|
|
2347
2743
|
postprocessingError = null;
|
|
2348
|
-
|
|
2349
|
-
case 32:
|
|
2350
|
-
_o.trys.push([32, 39, 40, 41]);
|
|
2351
|
-
_g = (e_3 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
|
|
2352
|
-
_o.label = 33;
|
|
2744
|
+
_u.label = 33;
|
|
2353
2745
|
case 33:
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2746
|
+
_u.trys.push([33, 40, 41, 42]);
|
|
2747
|
+
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
2748
|
+
_u.label = 34;
|
|
2357
2749
|
case 34:
|
|
2358
|
-
_o.
|
|
2750
|
+
if (!!_o.done) return [3 /*break*/, 39];
|
|
2751
|
+
scriptTools = _o.value;
|
|
2752
|
+
_u.label = 35;
|
|
2753
|
+
case 35:
|
|
2754
|
+
_u.trys.push([35, 37, , 38]);
|
|
2359
2755
|
return [4 /*yield*/, scriptTools.execute({
|
|
2360
2756
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2361
2757
|
script: "".concat(functionName, "(resultString)"),
|
|
2362
2758
|
parameters: {
|
|
2363
2759
|
resultString: resultString || '',
|
|
2364
|
-
// Note: No ...
|
|
2760
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2365
2761
|
},
|
|
2366
2762
|
})];
|
|
2367
|
-
case 35:
|
|
2368
|
-
resultString = _o.sent();
|
|
2369
|
-
postprocessingError = null;
|
|
2370
|
-
return [3 /*break*/, 38];
|
|
2371
2763
|
case 36:
|
|
2372
|
-
|
|
2764
|
+
resultString = _u.sent();
|
|
2765
|
+
postprocessingError = null;
|
|
2766
|
+
return [3 /*break*/, 39];
|
|
2767
|
+
case 37:
|
|
2768
|
+
error_3 = _u.sent();
|
|
2373
2769
|
if (!(error_3 instanceof Error)) {
|
|
2374
2770
|
throw error_3;
|
|
2375
2771
|
}
|
|
2772
|
+
if (error_3 instanceof UnexpectedError) {
|
|
2773
|
+
throw error_3;
|
|
2774
|
+
}
|
|
2376
2775
|
postprocessingError = error_3;
|
|
2377
2776
|
scriptPipelineExecutionErrors.push(error_3);
|
|
2378
|
-
return [3 /*break*/,
|
|
2379
|
-
case
|
|
2380
|
-
|
|
2381
|
-
return [3 /*break*/,
|
|
2382
|
-
case
|
|
2383
|
-
case 39:
|
|
2384
|
-
e_3_1 = _o.sent();
|
|
2385
|
-
e_3 = { error: e_3_1 };
|
|
2386
|
-
return [3 /*break*/, 41];
|
|
2777
|
+
return [3 /*break*/, 38];
|
|
2778
|
+
case 38:
|
|
2779
|
+
_o = _m.next();
|
|
2780
|
+
return [3 /*break*/, 34];
|
|
2781
|
+
case 39: return [3 /*break*/, 42];
|
|
2387
2782
|
case 40:
|
|
2783
|
+
e_5_1 = _u.sent();
|
|
2784
|
+
e_5 = { error: e_5_1 };
|
|
2785
|
+
return [3 /*break*/, 42];
|
|
2786
|
+
case 41:
|
|
2388
2787
|
try {
|
|
2389
|
-
if (
|
|
2788
|
+
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
2390
2789
|
}
|
|
2391
|
-
finally { if (
|
|
2790
|
+
finally { if (e_5) throw e_5.error; }
|
|
2392
2791
|
return [7 /*endfinally*/];
|
|
2393
|
-
case
|
|
2792
|
+
case 42:
|
|
2394
2793
|
if (postprocessingError) {
|
|
2395
2794
|
throw postprocessingError;
|
|
2396
2795
|
}
|
|
2397
|
-
|
|
2398
|
-
case
|
|
2399
|
-
|
|
2400
|
-
return [3 /*break*/,
|
|
2401
|
-
case
|
|
2402
|
-
case 44:
|
|
2403
|
-
e_4_1 = _o.sent();
|
|
2404
|
-
e_4 = { error: e_4_1 };
|
|
2405
|
-
return [3 /*break*/, 46];
|
|
2796
|
+
_u.label = 43;
|
|
2797
|
+
case 43:
|
|
2798
|
+
_l = _k.next();
|
|
2799
|
+
return [3 /*break*/, 32];
|
|
2800
|
+
case 44: return [3 /*break*/, 47];
|
|
2406
2801
|
case 45:
|
|
2802
|
+
e_6_1 = _u.sent();
|
|
2803
|
+
e_6 = { error: e_6_1 };
|
|
2804
|
+
return [3 /*break*/, 47];
|
|
2805
|
+
case 46:
|
|
2407
2806
|
try {
|
|
2408
|
-
if (
|
|
2807
|
+
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
2409
2808
|
}
|
|
2410
|
-
finally { if (
|
|
2809
|
+
finally { if (e_6) throw e_6.error; }
|
|
2411
2810
|
return [7 /*endfinally*/];
|
|
2412
|
-
case
|
|
2811
|
+
case 47:
|
|
2413
2812
|
// TODO: [💝] Unite object for expecting amount and format
|
|
2414
2813
|
if (currentTemplate.expectFormat) {
|
|
2415
2814
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
@@ -2422,15 +2821,18 @@ function createPipelineExecutor(options) {
|
|
|
2422
2821
|
if (currentTemplate.expectations) {
|
|
2423
2822
|
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
2424
2823
|
}
|
|
2425
|
-
return [3 /*break*/,
|
|
2426
|
-
case
|
|
2427
|
-
error_4 =
|
|
2824
|
+
return [3 /*break*/, 52];
|
|
2825
|
+
case 48:
|
|
2826
|
+
error_4 = _u.sent();
|
|
2428
2827
|
if (!(error_4 instanceof ExpectError)) {
|
|
2429
2828
|
throw error_4;
|
|
2430
2829
|
}
|
|
2830
|
+
if (error_4 instanceof UnexpectedError) {
|
|
2831
|
+
throw error_4;
|
|
2832
|
+
}
|
|
2431
2833
|
expectError = error_4;
|
|
2432
|
-
return [3 /*break*/,
|
|
2433
|
-
case
|
|
2834
|
+
return [3 /*break*/, 50];
|
|
2835
|
+
case 49:
|
|
2434
2836
|
if (!isJokerAttempt &&
|
|
2435
2837
|
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
2436
2838
|
prompt
|
|
@@ -2452,15 +2854,15 @@ function createPipelineExecutor(options) {
|
|
|
2452
2854
|
});
|
|
2453
2855
|
}
|
|
2454
2856
|
return [7 /*endfinally*/];
|
|
2455
|
-
case
|
|
2857
|
+
case 50:
|
|
2456
2858
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
2457
2859
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
2458
2860
|
}
|
|
2459
|
-
|
|
2460
|
-
case 50:
|
|
2461
|
-
attempt++;
|
|
2462
|
-
return [3 /*break*/, 3];
|
|
2861
|
+
_u.label = 51;
|
|
2463
2862
|
case 51:
|
|
2863
|
+
attempt++;
|
|
2864
|
+
return [3 /*break*/, 4];
|
|
2865
|
+
case 52:
|
|
2464
2866
|
if (resultString === null) {
|
|
2465
2867
|
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
2466
2868
|
}
|
|
@@ -2476,18 +2878,27 @@ function createPipelineExecutor(options) {
|
|
|
2476
2878
|
// <- [3]
|
|
2477
2879
|
});
|
|
2478
2880
|
}
|
|
2479
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (
|
|
2881
|
+
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_t = {}, _t[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _t)));
|
|
2480
2882
|
return [2 /*return*/];
|
|
2481
2883
|
}
|
|
2482
2884
|
});
|
|
2483
2885
|
});
|
|
2484
2886
|
}
|
|
2485
|
-
var
|
|
2486
|
-
var e_1,
|
|
2487
|
-
return __generator(this, function (
|
|
2488
|
-
switch (
|
|
2887
|
+
var executionReport, _a, _b, parameter, parametersToPass, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, outputParameters, errors, _c, _d, parameter, usage;
|
|
2888
|
+
var e_1, _e, e_2, _f;
|
|
2889
|
+
return __generator(this, function (_g) {
|
|
2890
|
+
switch (_g.label) {
|
|
2489
2891
|
case 0:
|
|
2490
|
-
|
|
2892
|
+
if (!(pipeline === undefined)) return [3 /*break*/, 2];
|
|
2893
|
+
return [4 /*yield*/, preparePipeline(rawPipeline, {
|
|
2894
|
+
llmTools: llmTools,
|
|
2895
|
+
isVerbose: isVerbose,
|
|
2896
|
+
maxParallelCount: maxParallelCount,
|
|
2897
|
+
})];
|
|
2898
|
+
case 1:
|
|
2899
|
+
pipeline = _g.sent();
|
|
2900
|
+
_g.label = 2;
|
|
2901
|
+
case 2:
|
|
2491
2902
|
executionReport = {
|
|
2492
2903
|
pipelineUrl: pipeline.pipelineUrl,
|
|
2493
2904
|
title: pipeline.title,
|
|
@@ -2496,9 +2907,35 @@ function createPipelineExecutor(options) {
|
|
|
2496
2907
|
description: pipeline.description,
|
|
2497
2908
|
promptExecutions: [],
|
|
2498
2909
|
};
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2910
|
+
try {
|
|
2911
|
+
// Note: Check that all input input parameters are defined
|
|
2912
|
+
for (_a = __values(pipeline.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
2913
|
+
parameter = _b.value;
|
|
2914
|
+
if (parameter.isInput && inputParameters[parameter.name] === undefined) {
|
|
2915
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2916
|
+
isSuccessful: false,
|
|
2917
|
+
errors: [
|
|
2918
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
|
|
2919
|
+
// <- TODO: !!!!! Test this error
|
|
2920
|
+
],
|
|
2921
|
+
executionReport: executionReport,
|
|
2922
|
+
outputParameters: {},
|
|
2923
|
+
usage: ZERO_USAGE,
|
|
2924
|
+
})];
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2929
|
+
finally {
|
|
2930
|
+
try {
|
|
2931
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
2932
|
+
}
|
|
2933
|
+
finally { if (e_1) throw e_1.error; }
|
|
2934
|
+
}
|
|
2935
|
+
parametersToPass = inputParameters;
|
|
2936
|
+
_g.label = 3;
|
|
2937
|
+
case 3:
|
|
2938
|
+
_g.trys.push([3, 8, , 9]);
|
|
2502
2939
|
resovedParameters_1 = pipeline.parameters
|
|
2503
2940
|
.filter(function (_a) {
|
|
2504
2941
|
var isInput = _a.isInput;
|
|
@@ -2513,8 +2950,8 @@ function createPipelineExecutor(options) {
|
|
|
2513
2950
|
loopLimit = LOOP_LIMIT;
|
|
2514
2951
|
_loop_1 = function () {
|
|
2515
2952
|
var currentTemplate, work_1;
|
|
2516
|
-
return __generator(this, function (
|
|
2517
|
-
switch (
|
|
2953
|
+
return __generator(this, function (_h) {
|
|
2954
|
+
switch (_h.label) {
|
|
2518
2955
|
case 0:
|
|
2519
2956
|
if (loopLimit-- < 0) {
|
|
2520
2957
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
@@ -2529,7 +2966,7 @@ function createPipelineExecutor(options) {
|
|
|
2529
2966
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2530
2967
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
2531
2968
|
case 2:
|
|
2532
|
-
/* [5] */
|
|
2969
|
+
/* [5] */ _h.sent();
|
|
2533
2970
|
return [3 /*break*/, 4];
|
|
2534
2971
|
case 3:
|
|
2535
2972
|
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
@@ -2541,24 +2978,24 @@ function createPipelineExecutor(options) {
|
|
|
2541
2978
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
2542
2979
|
});
|
|
2543
2980
|
resolving_1.push(work_1);
|
|
2544
|
-
|
|
2981
|
+
_h.label = 4;
|
|
2545
2982
|
case 4: return [2 /*return*/];
|
|
2546
2983
|
}
|
|
2547
2984
|
});
|
|
2548
2985
|
};
|
|
2549
|
-
|
|
2550
|
-
case
|
|
2551
|
-
if (!(unresovedTemplates.length > 0)) return [3 /*break*/,
|
|
2986
|
+
_g.label = 4;
|
|
2987
|
+
case 4:
|
|
2988
|
+
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 6];
|
|
2552
2989
|
return [5 /*yield**/, _loop_1()];
|
|
2553
|
-
case 3:
|
|
2554
|
-
_d.sent();
|
|
2555
|
-
return [3 /*break*/, 2];
|
|
2556
|
-
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
2557
2990
|
case 5:
|
|
2558
|
-
|
|
2559
|
-
return [3 /*break*/,
|
|
2560
|
-
case 6:
|
|
2561
|
-
|
|
2991
|
+
_g.sent();
|
|
2992
|
+
return [3 /*break*/, 4];
|
|
2993
|
+
case 6: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
2994
|
+
case 7:
|
|
2995
|
+
_g.sent();
|
|
2996
|
+
return [3 /*break*/, 9];
|
|
2997
|
+
case 8:
|
|
2998
|
+
error_1 = _g.sent();
|
|
2562
2999
|
if (!(error_1 instanceof Error)) {
|
|
2563
3000
|
throw error_1;
|
|
2564
3001
|
}
|
|
@@ -2566,49 +3003,56 @@ function createPipelineExecutor(options) {
|
|
|
2566
3003
|
var result = _a.result;
|
|
2567
3004
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2568
3005
|
})), false));
|
|
2569
|
-
return [2 /*return*/, {
|
|
3006
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2570
3007
|
isSuccessful: false,
|
|
2571
3008
|
errors: [error_1],
|
|
2572
3009
|
usage: usage_1,
|
|
2573
3010
|
executionReport: executionReport,
|
|
2574
3011
|
outputParameters: parametersToPass,
|
|
2575
|
-
}];
|
|
2576
|
-
case
|
|
3012
|
+
})];
|
|
3013
|
+
case 9:
|
|
3014
|
+
outputParameters = {};
|
|
3015
|
+
errors = [];
|
|
2577
3016
|
try {
|
|
2578
3017
|
// Note: Filter ONLY output parameters
|
|
2579
|
-
for (
|
|
2580
|
-
|
|
2581
|
-
|
|
3018
|
+
for (_c = __values(pipeline.parameters.filter(function (_a) {
|
|
3019
|
+
var isOutput = _a.isOutput;
|
|
3020
|
+
return isOutput;
|
|
3021
|
+
})), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3022
|
+
parameter = _d.value;
|
|
3023
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3024
|
+
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
2582
3025
|
continue;
|
|
2583
3026
|
}
|
|
2584
|
-
|
|
3027
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
2585
3028
|
}
|
|
2586
3029
|
}
|
|
2587
|
-
catch (
|
|
3030
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2588
3031
|
finally {
|
|
2589
3032
|
try {
|
|
2590
|
-
if (
|
|
3033
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
2591
3034
|
}
|
|
2592
|
-
finally { if (
|
|
3035
|
+
finally { if (e_2) throw e_2.error; }
|
|
2593
3036
|
}
|
|
2594
3037
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2595
3038
|
var result = _a.result;
|
|
2596
3039
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2597
3040
|
})), false));
|
|
2598
|
-
return [2 /*return*/, {
|
|
3041
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2599
3042
|
isSuccessful: true,
|
|
2600
|
-
errors:
|
|
3043
|
+
errors: errors,
|
|
2601
3044
|
usage: usage,
|
|
2602
3045
|
executionReport: executionReport,
|
|
2603
|
-
outputParameters:
|
|
2604
|
-
}];
|
|
3046
|
+
outputParameters: outputParameters,
|
|
3047
|
+
})];
|
|
2605
3048
|
}
|
|
2606
3049
|
});
|
|
2607
3050
|
}); };
|
|
2608
3051
|
return pipelineExecutor;
|
|
2609
3052
|
}
|
|
2610
3053
|
/**
|
|
2611
|
-
* TODO:
|
|
3054
|
+
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3055
|
+
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
2612
3056
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2613
3057
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2614
3058
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
@@ -2617,23 +3061,6 @@ function createPipelineExecutor(options) {
|
|
|
2617
3061
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2618
3062
|
*/
|
|
2619
3063
|
|
|
2620
|
-
/**
|
|
2621
|
-
* Just marks a place of place where should be something implemented
|
|
2622
|
-
* No side effects.
|
|
2623
|
-
*
|
|
2624
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2625
|
-
*
|
|
2626
|
-
* @param value any values
|
|
2627
|
-
* @returns void
|
|
2628
|
-
* @private within the repository
|
|
2629
|
-
*/
|
|
2630
|
-
function TODO_USE() {
|
|
2631
|
-
var value = [];
|
|
2632
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2633
|
-
value[_i] = arguments[_i];
|
|
2634
|
-
}
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
3064
|
/**
|
|
2638
3065
|
* @@@
|
|
2639
3066
|
*/
|
|
@@ -2761,7 +3188,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
2761
3188
|
});
|
|
2762
3189
|
}
|
|
2763
3190
|
/**
|
|
2764
|
-
* TODO: [🔼] !!! Export via `@promptbook/markdown`
|
|
3191
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/markdown`
|
|
2765
3192
|
* TODO: [🪂] Do it in parallel 11:11
|
|
2766
3193
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2767
3194
|
*/
|
|
@@ -2784,7 +3211,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
2784
3211
|
var partialPieces, pieces;
|
|
2785
3212
|
return __generator(this, function (_a) {
|
|
2786
3213
|
switch (_a.label) {
|
|
2787
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝]
|
|
3214
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
2788
3215
|
options)];
|
|
2789
3216
|
case 1:
|
|
2790
3217
|
partialPieces = _a.sent();
|
|
@@ -2822,7 +3249,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
2822
3249
|
> ):
|
|
2823
3250
|
*/
|
|
2824
3251
|
/**
|
|
2825
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3252
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
2826
3253
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2827
3254
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2828
3255
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -2948,12 +3375,15 @@ function preparePipeline(pipeline, options) {
|
|
|
2948
3375
|
partialknowledgePiecesPrepared = _b.sent();
|
|
2949
3376
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2950
3377
|
// ----- /Knowledge preparation -----
|
|
3378
|
+
// TODO: !!!!! Add context to each template (if missing)
|
|
3379
|
+
// TODO: !!!!! Apply samples to each template (if missing)
|
|
2951
3380
|
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
2952
3381
|
}
|
|
2953
3382
|
});
|
|
2954
3383
|
});
|
|
2955
3384
|
}
|
|
2956
3385
|
/**
|
|
3386
|
+
* TODO: !!!!! Index the samples and maybe templates
|
|
2957
3387
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2958
3388
|
* TODO: Write tests for `preparePipeline`
|
|
2959
3389
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
@@ -3009,7 +3439,7 @@ var knowledgeCommandParser = {
|
|
|
3009
3439
|
/**
|
|
3010
3440
|
* Link to discussion
|
|
3011
3441
|
*/
|
|
3012
|
-
|
|
3442
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3013
3443
|
/**
|
|
3014
3444
|
* Example usages of the KNOWLEDGE command
|
|
3015
3445
|
*/
|
|
@@ -3046,8 +3476,9 @@ var knowledgeCommandParser = {
|
|
|
3046
3476
|
/**
|
|
3047
3477
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3048
3478
|
*/
|
|
3049
|
-
applyToPipelineJson: function (
|
|
3479
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3050
3480
|
var source = personaCommand.source;
|
|
3481
|
+
var pipelineJson = subjects.pipelineJson;
|
|
3051
3482
|
var name = titleToName(source);
|
|
3052
3483
|
pipelineJson.knowledgeSources.push({
|
|
3053
3484
|
name: name,
|
|
@@ -3082,7 +3513,7 @@ var personaCommandParser = {
|
|
|
3082
3513
|
/**
|
|
3083
3514
|
* Link to discussion
|
|
3084
3515
|
*/
|
|
3085
|
-
|
|
3516
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3086
3517
|
/**
|
|
3087
3518
|
* Example usages of the PERSONA command
|
|
3088
3519
|
*/
|
|
@@ -3110,8 +3541,15 @@ var personaCommandParser = {
|
|
|
3110
3541
|
/**
|
|
3111
3542
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3112
3543
|
*/
|
|
3113
|
-
applyToPipelineJson: function (
|
|
3544
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3114
3545
|
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
3546
|
+
var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
|
|
3547
|
+
if (templateJson !== null) {
|
|
3548
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
3549
|
+
throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
3550
|
+
}
|
|
3551
|
+
templateJson.personaName = personaName;
|
|
3552
|
+
}
|
|
3115
3553
|
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
3116
3554
|
if (persona === undefined) {
|
|
3117
3555
|
pipelineJson.personas.push({
|
|
@@ -3270,7 +3708,7 @@ var blockCommandParser = {
|
|
|
3270
3708
|
/**
|
|
3271
3709
|
* Link to discussion
|
|
3272
3710
|
*/
|
|
3273
|
-
|
|
3711
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
3274
3712
|
/**
|
|
3275
3713
|
* Example usages of the BLOCK command
|
|
3276
3714
|
*/
|
|
@@ -3298,6 +3736,7 @@ var blockCommandParser = {
|
|
|
3298
3736
|
//---
|
|
3299
3737
|
/* <- TODO: [🧠] Maybe dynamic */
|
|
3300
3738
|
],
|
|
3739
|
+
// TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
|
|
3301
3740
|
/**
|
|
3302
3741
|
* Parses the BLOCK command
|
|
3303
3742
|
*/
|
|
@@ -3414,7 +3853,7 @@ var expectCommandParser = {
|
|
|
3414
3853
|
/**
|
|
3415
3854
|
* Link to discussion
|
|
3416
3855
|
*/
|
|
3417
|
-
|
|
3856
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
3418
3857
|
/**
|
|
3419
3858
|
* Example usages of the EXPECT command
|
|
3420
3859
|
*/
|
|
@@ -3532,7 +3971,7 @@ var jokerCommandParser = {
|
|
|
3532
3971
|
/**
|
|
3533
3972
|
* Link to discussion
|
|
3534
3973
|
*/
|
|
3535
|
-
|
|
3974
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
|
|
3536
3975
|
/**
|
|
3537
3976
|
* Example usages of the JOKER command
|
|
3538
3977
|
*/
|
|
@@ -3575,7 +4014,11 @@ var modelCommandParser = {
|
|
|
3575
4014
|
/**
|
|
3576
4015
|
* BOILERPLATE command can be used in:
|
|
3577
4016
|
*/
|
|
3578
|
-
usagePlaces: [
|
|
4017
|
+
usagePlaces: [
|
|
4018
|
+
'PIPELINE_HEAD',
|
|
4019
|
+
// <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
|
|
4020
|
+
'PIPELINE_TEMPLATE',
|
|
4021
|
+
],
|
|
3579
4022
|
/**
|
|
3580
4023
|
* Description of the MODEL command
|
|
3581
4024
|
*/
|
|
@@ -3583,7 +4026,7 @@ var modelCommandParser = {
|
|
|
3583
4026
|
/**
|
|
3584
4027
|
* Link to discussion
|
|
3585
4028
|
*/
|
|
3586
|
-
|
|
4029
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
|
|
3587
4030
|
/**
|
|
3588
4031
|
* Example usages of the MODEL command
|
|
3589
4032
|
*/
|
|
@@ -3663,7 +4106,7 @@ var parameterCommandParser = {
|
|
|
3663
4106
|
/**
|
|
3664
4107
|
* Link to discussion
|
|
3665
4108
|
*/
|
|
3666
|
-
|
|
4109
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
|
|
3667
4110
|
/**
|
|
3668
4111
|
* Example usages of the PARAMETER command
|
|
3669
4112
|
*/
|
|
@@ -3727,7 +4170,7 @@ var postprocessCommandParser = {
|
|
|
3727
4170
|
/**
|
|
3728
4171
|
* Link to discussion
|
|
3729
4172
|
*/
|
|
3730
|
-
|
|
4173
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
|
|
3731
4174
|
/**
|
|
3732
4175
|
* Example usages of the POSTPROCESS command
|
|
3733
4176
|
*/
|
|
@@ -3782,7 +4225,7 @@ var promptbookVersionCommandParser = {
|
|
|
3782
4225
|
/**
|
|
3783
4226
|
* Link to discussion
|
|
3784
4227
|
*/
|
|
3785
|
-
|
|
4228
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
|
|
3786
4229
|
/**
|
|
3787
4230
|
* Example usages of the PROMPTBOOK_VERSION command
|
|
3788
4231
|
*/
|
|
@@ -3835,7 +4278,7 @@ var urlCommandParser = {
|
|
|
3835
4278
|
/**
|
|
3836
4279
|
* Link to discussion
|
|
3837
4280
|
*/
|
|
3838
|
-
|
|
4281
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
|
|
3839
4282
|
/**
|
|
3840
4283
|
* Example usages of the URL command
|
|
3841
4284
|
*/
|
|
@@ -3905,7 +4348,7 @@ var actionCommandParser = {
|
|
|
3905
4348
|
/**
|
|
3906
4349
|
* Link to discussion
|
|
3907
4350
|
*/
|
|
3908
|
-
|
|
4351
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
|
|
3909
4352
|
/**
|
|
3910
4353
|
* Example usages of the ACTION command
|
|
3911
4354
|
*/
|
|
@@ -3944,7 +4387,7 @@ var instrumentCommandParser = {
|
|
|
3944
4387
|
/**
|
|
3945
4388
|
* Link to discussion
|
|
3946
4389
|
*/
|
|
3947
|
-
|
|
4390
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
|
|
3948
4391
|
/**
|
|
3949
4392
|
* Example usages of the INSTRUMENT command
|
|
3950
4393
|
*/
|
|
@@ -3987,7 +4430,7 @@ var boilerplateCommandParser = {
|
|
|
3987
4430
|
/**
|
|
3988
4431
|
* Link to discussion
|
|
3989
4432
|
*/
|
|
3990
|
-
|
|
4433
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
3991
4434
|
/**
|
|
3992
4435
|
* Example usages of the BOILERPLATE command
|
|
3993
4436
|
*/
|
|
@@ -4121,9 +4564,9 @@ function parseCommand(raw, usagePlace) {
|
|
|
4121
4564
|
*/
|
|
4122
4565
|
function getSupportedCommandsMessage() {
|
|
4123
4566
|
return COMMANDS.flatMap(function (_a) {
|
|
4124
|
-
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description,
|
|
4567
|
+
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
|
|
4125
4568
|
return __spreadArray([
|
|
4126
|
-
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(
|
|
4569
|
+
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
4127
4570
|
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
4128
4571
|
}).join('\n');
|
|
4129
4572
|
}
|
|
@@ -4478,195 +4921,6 @@ function removeContentComments(content) {
|
|
|
4478
4921
|
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
4479
4922
|
}
|
|
4480
4923
|
|
|
4481
|
-
/**
|
|
4482
|
-
* Create difference set of two sets.
|
|
4483
|
-
*
|
|
4484
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
4485
|
-
*/
|
|
4486
|
-
function difference(a, b, isEqual) {
|
|
4487
|
-
var e_1, _a;
|
|
4488
|
-
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
4489
|
-
var diff = new Set();
|
|
4490
|
-
var _loop_1 = function (itemA) {
|
|
4491
|
-
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
4492
|
-
diff.add(itemA);
|
|
4493
|
-
}
|
|
4494
|
-
};
|
|
4495
|
-
try {
|
|
4496
|
-
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
4497
|
-
var itemA = _c.value;
|
|
4498
|
-
_loop_1(itemA);
|
|
4499
|
-
}
|
|
4500
|
-
}
|
|
4501
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4502
|
-
finally {
|
|
4503
|
-
try {
|
|
4504
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4505
|
-
}
|
|
4506
|
-
finally { if (e_1) throw e_1.error; }
|
|
4507
|
-
}
|
|
4508
|
-
return diff;
|
|
4509
|
-
}
|
|
4510
|
-
|
|
4511
|
-
/**
|
|
4512
|
-
* Creates a new set with all elements that are present in either set
|
|
4513
|
-
*
|
|
4514
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
4515
|
-
*/
|
|
4516
|
-
function union() {
|
|
4517
|
-
var e_1, _a, e_2, _b;
|
|
4518
|
-
var sets = [];
|
|
4519
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4520
|
-
sets[_i] = arguments[_i];
|
|
4521
|
-
}
|
|
4522
|
-
var union = new Set();
|
|
4523
|
-
try {
|
|
4524
|
-
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
4525
|
-
var set = sets_1_1.value;
|
|
4526
|
-
try {
|
|
4527
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4528
|
-
var item = _d.value;
|
|
4529
|
-
union.add(item);
|
|
4530
|
-
}
|
|
4531
|
-
}
|
|
4532
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4533
|
-
finally {
|
|
4534
|
-
try {
|
|
4535
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
4536
|
-
}
|
|
4537
|
-
finally { if (e_2) throw e_2.error; }
|
|
4538
|
-
}
|
|
4539
|
-
}
|
|
4540
|
-
}
|
|
4541
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4542
|
-
finally {
|
|
4543
|
-
try {
|
|
4544
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
4545
|
-
}
|
|
4546
|
-
finally { if (e_1) throw e_1.error; }
|
|
4547
|
-
}
|
|
4548
|
-
return union;
|
|
4549
|
-
}
|
|
4550
|
-
|
|
4551
|
-
/**
|
|
4552
|
-
* Parses the template and returns the list of all parameter names
|
|
4553
|
-
*
|
|
4554
|
-
* @param template the template with parameters in {curly} braces
|
|
4555
|
-
* @returns the list of parameter names
|
|
4556
|
-
*/
|
|
4557
|
-
function extractParameters(template) {
|
|
4558
|
-
var e_1, _a;
|
|
4559
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
4560
|
-
var parameterNames = new Set();
|
|
4561
|
-
try {
|
|
4562
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
4563
|
-
var match = matches_1_1.value;
|
|
4564
|
-
var parameterName = match[0].slice(1, -1);
|
|
4565
|
-
parameterNames.add(parameterName);
|
|
4566
|
-
}
|
|
4567
|
-
}
|
|
4568
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4569
|
-
finally {
|
|
4570
|
-
try {
|
|
4571
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
4572
|
-
}
|
|
4573
|
-
finally { if (e_1) throw e_1.error; }
|
|
4574
|
-
}
|
|
4575
|
-
return parameterNames;
|
|
4576
|
-
}
|
|
4577
|
-
|
|
4578
|
-
/**
|
|
4579
|
-
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4580
|
-
*
|
|
4581
|
-
* @param script from which to extract the variables
|
|
4582
|
-
* @returns the list of variable names
|
|
4583
|
-
* @throws {ParsingError} if the script is invalid
|
|
4584
|
-
*/
|
|
4585
|
-
function extractVariables(script) {
|
|
4586
|
-
var variables = new Set();
|
|
4587
|
-
script = "(()=>{".concat(script, "})()");
|
|
4588
|
-
try {
|
|
4589
|
-
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
4590
|
-
try {
|
|
4591
|
-
eval(script);
|
|
4592
|
-
}
|
|
4593
|
-
catch (error) {
|
|
4594
|
-
if (!(error instanceof ReferenceError)) {
|
|
4595
|
-
throw error;
|
|
4596
|
-
}
|
|
4597
|
-
var undefinedName = error.message.split(' ')[0];
|
|
4598
|
-
/*
|
|
4599
|
-
Note: Parsing the error
|
|
4600
|
-
[ReferenceError: thing is not defined]
|
|
4601
|
-
*/
|
|
4602
|
-
if (!undefinedName) {
|
|
4603
|
-
throw error;
|
|
4604
|
-
}
|
|
4605
|
-
if (script.includes(undefinedName + '(')) {
|
|
4606
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
4607
|
-
}
|
|
4608
|
-
else {
|
|
4609
|
-
variables.add(undefinedName);
|
|
4610
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
4611
|
-
}
|
|
4612
|
-
}
|
|
4613
|
-
}
|
|
4614
|
-
catch (error) {
|
|
4615
|
-
if (!(error instanceof Error)) {
|
|
4616
|
-
throw error;
|
|
4617
|
-
}
|
|
4618
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
4619
|
-
}
|
|
4620
|
-
return variables;
|
|
4621
|
-
}
|
|
4622
|
-
/**
|
|
4623
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4624
|
-
*/
|
|
4625
|
-
|
|
4626
|
-
/**
|
|
4627
|
-
* Parses the prompt template and returns the set of all used parameters
|
|
4628
|
-
*
|
|
4629
|
-
* @param promptTemplate the template with used parameters
|
|
4630
|
-
* @returns the set of parameter names
|
|
4631
|
-
* @throws {ParsingError} if the script is invalid
|
|
4632
|
-
*/
|
|
4633
|
-
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
4634
|
-
var e_1, _a, e_2, _b;
|
|
4635
|
-
var parameterNames = new Set();
|
|
4636
|
-
try {
|
|
4637
|
-
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4638
|
-
var parameterName = _d.value;
|
|
4639
|
-
parameterNames.add(parameterName);
|
|
4640
|
-
}
|
|
4641
|
-
}
|
|
4642
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4643
|
-
finally {
|
|
4644
|
-
try {
|
|
4645
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
4646
|
-
}
|
|
4647
|
-
finally { if (e_1) throw e_1.error; }
|
|
4648
|
-
}
|
|
4649
|
-
if (promptTemplate.blockType === 'SCRIPT') {
|
|
4650
|
-
try {
|
|
4651
|
-
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
4652
|
-
var parameterName = _f.value;
|
|
4653
|
-
parameterNames.add(parameterName);
|
|
4654
|
-
}
|
|
4655
|
-
}
|
|
4656
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4657
|
-
finally {
|
|
4658
|
-
try {
|
|
4659
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
4660
|
-
}
|
|
4661
|
-
finally { if (e_2) throw e_2.error; }
|
|
4662
|
-
}
|
|
4663
|
-
}
|
|
4664
|
-
return parameterNames;
|
|
4665
|
-
}
|
|
4666
|
-
/**
|
|
4667
|
-
* TODO: [🔣] If script require contentLanguage
|
|
4668
|
-
*/
|
|
4669
|
-
|
|
4670
4924
|
/**
|
|
4671
4925
|
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4672
4926
|
*
|
|
@@ -4776,7 +5030,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4776
5030
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4777
5031
|
break;
|
|
4778
5032
|
case 'KNOWLEDGE':
|
|
4779
|
-
knowledgeCommandParser.applyToPipelineJson(pipelineJson,
|
|
5033
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4780
5034
|
break;
|
|
4781
5035
|
case 'ACTION':
|
|
4782
5036
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4785,7 +5039,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4785
5039
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4786
5040
|
break;
|
|
4787
5041
|
case 'PERSONA':
|
|
4788
|
-
personaCommandParser.applyToPipelineJson(pipelineJson,
|
|
5042
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4789
5043
|
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4790
5044
|
break;
|
|
4791
5045
|
case 'BOILERPLATE':
|
|
@@ -4809,13 +5063,6 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4809
5063
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
4810
5064
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
4811
5065
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
4812
|
-
var dependentParameterNames = new Set();
|
|
4813
|
-
var blockType = 'PROMPT_TEMPLATE';
|
|
4814
|
-
var jokers = [];
|
|
4815
|
-
var postprocessing = [];
|
|
4816
|
-
var expectAmount = {};
|
|
4817
|
-
var expectFormat = undefined;
|
|
4818
|
-
var isBlockTypeSet = false;
|
|
4819
5066
|
var lastLine = section.content.split('\n').pop();
|
|
4820
5067
|
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4821
5068
|
var resultingParameterName = null;
|
|
@@ -4836,10 +5083,39 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4836
5083
|
.join('\n')), "\n "); }));
|
|
4837
5084
|
};
|
|
4838
5085
|
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
5086
|
+
// TODO: [🎾][1] DRY description
|
|
5087
|
+
var description_1 = section.content;
|
|
5088
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
5089
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
5090
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5091
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5092
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5093
|
+
description_1 = spaceTrim$1(description_1);
|
|
5094
|
+
if (description_1 === '') {
|
|
5095
|
+
description_1 = undefined;
|
|
5096
|
+
}
|
|
5097
|
+
var templateJson = {
|
|
5098
|
+
blockType: 'PROMPT_TEMPLATE',
|
|
5099
|
+
name: titleToName(section.title),
|
|
5100
|
+
title: section.title,
|
|
5101
|
+
description: description_1,
|
|
5102
|
+
modelRequirements: templateModelRequirements,
|
|
5103
|
+
content: content,
|
|
5104
|
+
};
|
|
5105
|
+
/**
|
|
5106
|
+
* This is nessesary because block type can be
|
|
5107
|
+
* - Set zero times, so anticipate 'PROMPT_TEMPLATE'
|
|
5108
|
+
* - Set one time
|
|
5109
|
+
* - Set more times - throw error
|
|
5110
|
+
*
|
|
5111
|
+
* Note: [2]
|
|
5112
|
+
*/
|
|
5113
|
+
var isBlockTypeSet = false;
|
|
4839
5114
|
try {
|
|
4840
5115
|
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
4841
5116
|
var listItem = listItems_2_1.value;
|
|
4842
5117
|
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5118
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
4843
5119
|
switch (command.type) {
|
|
4844
5120
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4845
5121
|
case 'BLOCK':
|
|
@@ -4857,9 +5133,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4857
5133
|
return "continue-templates";
|
|
4858
5134
|
}
|
|
4859
5135
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4860
|
-
knowledgeCommandParser.applyToPipelineJson(
|
|
5136
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
4861
5137
|
type: 'KNOWLEDGE',
|
|
4862
|
-
source: content, // <- TODO: [🐝]
|
|
5138
|
+
source: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5139
|
+
}, {
|
|
5140
|
+
pipelineJson: pipelineJson,
|
|
5141
|
+
templateJson: templateJson,
|
|
4863
5142
|
});
|
|
4864
5143
|
return "continue-templates";
|
|
4865
5144
|
}
|
|
@@ -4872,35 +5151,36 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4872
5151
|
return "continue-templates";
|
|
4873
5152
|
}
|
|
4874
5153
|
expectResultingParameterName();
|
|
4875
|
-
blockType = command.blockType;
|
|
4876
|
-
isBlockTypeSet = true;
|
|
5154
|
+
templateJson.blockType = command.blockType;
|
|
5155
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
4877
5156
|
break;
|
|
4878
5157
|
case 'EXPECT_AMOUNT':
|
|
4879
5158
|
// eslint-disable-next-line no-case-declarations
|
|
4880
5159
|
var unit = command.unit.toLowerCase();
|
|
4881
|
-
|
|
5160
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
5161
|
+
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
4882
5162
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
4883
|
-
if (
|
|
4884
|
-
throw new ParsingError("Already defined minumum ".concat(
|
|
5163
|
+
if (templateJson.expectations[unit].min !== undefined) {
|
|
5164
|
+
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
4885
5165
|
}
|
|
4886
|
-
|
|
5166
|
+
templateJson.expectations[unit].min = command.amount;
|
|
4887
5167
|
} /* not else */
|
|
4888
5168
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
4889
|
-
if (
|
|
4890
|
-
throw new ParsingError("Already defined maximum ".concat(
|
|
5169
|
+
if (templateJson.expectations[unit].max !== undefined) {
|
|
5170
|
+
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
4891
5171
|
}
|
|
4892
|
-
|
|
5172
|
+
templateJson.expectations[unit].max = command.amount;
|
|
4893
5173
|
}
|
|
4894
5174
|
break;
|
|
4895
5175
|
case 'EXPECT_FORMAT':
|
|
4896
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
4897
|
-
throw new ParsingError("Expect format is already defined to \"".concat(expectFormat, "\"
|
|
5176
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5177
|
+
throw new ParsingError(spaceTrim$1("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
|
|
4898
5178
|
}
|
|
4899
|
-
expectFormat = command.format;
|
|
5179
|
+
templateJson.expectFormat = command.format;
|
|
4900
5180
|
break;
|
|
4901
5181
|
case 'JOKER':
|
|
4902
|
-
|
|
4903
|
-
|
|
5182
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
5183
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
4904
5184
|
break;
|
|
4905
5185
|
case 'MODEL':
|
|
4906
5186
|
templateModelRequirements[command.key] = command.value;
|
|
@@ -4910,11 +5190,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4910
5190
|
defineParam(command);
|
|
4911
5191
|
break;
|
|
4912
5192
|
case 'POSTPROCESS':
|
|
4913
|
-
|
|
5193
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
5194
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
4914
5195
|
break;
|
|
4915
5196
|
case 'KNOWLEDGE':
|
|
4916
5197
|
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
4917
|
-
knowledgeCommandParser.applyToPipelineJson(pipelineJson,
|
|
5198
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
4918
5199
|
break;
|
|
4919
5200
|
case 'ACTION':
|
|
4920
5201
|
// TODO: [👙] The action is maybe relevant for just this template
|
|
@@ -4925,7 +5206,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4925
5206
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4926
5207
|
break;
|
|
4927
5208
|
case 'PERSONA':
|
|
4928
|
-
personaCommandParser.applyToPipelineJson(pipelineJson,
|
|
5209
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
4929
5210
|
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4930
5211
|
break;
|
|
4931
5212
|
case 'BOILERPLATE':
|
|
@@ -4944,60 +5225,29 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4944
5225
|
}
|
|
4945
5226
|
finally { if (e_3) throw e_3.error; }
|
|
4946
5227
|
}
|
|
4947
|
-
|
|
5228
|
+
// TODO: [🍧] Should be done in BLOCK command
|
|
5229
|
+
if (templateJson.blockType === 'SCRIPT') {
|
|
4948
5230
|
if (!language) {
|
|
4949
5231
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
4950
5232
|
}
|
|
4951
|
-
|
|
5233
|
+
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
4952
5234
|
throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
4953
5235
|
}
|
|
5236
|
+
templateJson.contentLanguage = language;
|
|
4954
5237
|
}
|
|
4955
|
-
// TODO: [
|
|
4956
|
-
var description_1 = section.content;
|
|
4957
|
-
// Note: Remove codeblocks - TODO: [🎾]
|
|
4958
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
4959
|
-
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
4960
|
-
//Note: Remove lists and return statement - TODO: [🎾]
|
|
4961
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4962
|
-
description_1 = spaceTrim$1(description_1);
|
|
4963
|
-
if (description_1 === '') {
|
|
4964
|
-
description_1 = undefined;
|
|
4965
|
-
}
|
|
4966
|
-
if (Object.keys(jokers).length === 0) {
|
|
4967
|
-
jokers = undefined;
|
|
4968
|
-
}
|
|
4969
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
4970
|
-
expectAmount = undefined;
|
|
4971
|
-
}
|
|
4972
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
4973
|
-
postprocessing = undefined;
|
|
4974
|
-
}
|
|
4975
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, blockType: blockType, content: content })));
|
|
5238
|
+
// TODO: [🍧][❔] Should be done in BLOCK command
|
|
4976
5239
|
if (templateModelRequirements.modelVariant === undefined) {
|
|
4977
5240
|
templateModelRequirements.modelVariant = 'CHAT';
|
|
4978
5241
|
}
|
|
4979
|
-
dependentParameterNames =
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
description: description_1,
|
|
4984
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
4985
|
-
blockType: blockType,
|
|
4986
|
-
jokers: jokers,
|
|
4987
|
-
postprocessing: postprocessing,
|
|
4988
|
-
expectations: expectAmount,
|
|
4989
|
-
expectFormat: expectFormat,
|
|
4990
|
-
personaName: null,
|
|
4991
|
-
modelRequirements: templateModelRequirements,
|
|
4992
|
-
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4993
|
-
content: content,
|
|
4994
|
-
resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
|
|
4995
|
-
};
|
|
4996
|
-
if (blockType !== 'PROMPT_TEMPLATE') {
|
|
4997
|
-
delete template.modelRequirements;
|
|
5242
|
+
templateJson.dependentParameterNames = Array.from(extractParametersFromPromptTemplate(templateJson));
|
|
5243
|
+
// TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
|
|
5244
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5245
|
+
delete templateJson.modelRequirements;
|
|
4998
5246
|
}
|
|
5247
|
+
// TODO: [🍧] Make this better - for example each command parser can call and apply this
|
|
5248
|
+
templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
|
|
4999
5249
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
5000
|
-
pipelineJson.promptTemplates.push(
|
|
5250
|
+
pipelineJson.promptTemplates.push(templateJson);
|
|
5001
5251
|
};
|
|
5002
5252
|
try {
|
|
5003
5253
|
// =============================================================
|
|
@@ -5713,14 +5963,14 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5713
5963
|
*/
|
|
5714
5964
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
5715
5965
|
return __awaiter(this, void 0, void 0, function () {
|
|
5716
|
-
var content, modelRequirements, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
5966
|
+
var content, parameters, modelRequirements, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
5717
5967
|
return __generator(this, function (_a) {
|
|
5718
5968
|
switch (_a.label) {
|
|
5719
5969
|
case 0:
|
|
5720
5970
|
if (this.options.isVerbose) {
|
|
5721
5971
|
console.info('💬 Anthropic Claude callChatModel call');
|
|
5722
5972
|
}
|
|
5723
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements;
|
|
5973
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
5724
5974
|
// TODO: [☂] Use here more modelRequirements
|
|
5725
5975
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
5726
5976
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -5736,7 +5986,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5736
5986
|
messages: [
|
|
5737
5987
|
{
|
|
5738
5988
|
role: 'user',
|
|
5739
|
-
content: content,
|
|
5989
|
+
content: replaceParameters(content, parameters),
|
|
5740
5990
|
},
|
|
5741
5991
|
],
|
|
5742
5992
|
// TODO: Is here some equivalent of user identification?> user: this.options.user,
|
|
@@ -5783,14 +6033,14 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5783
6033
|
/*
|
|
5784
6034
|
TODO: [👏]
|
|
5785
6035
|
public async callCompletionModel(
|
|
5786
|
-
prompt: Pick<Prompt, 'content' | 'modelRequirements'>,
|
|
6036
|
+
prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>,
|
|
5787
6037
|
): Promise<PromptCompletionResult> {
|
|
5788
6038
|
|
|
5789
6039
|
if (this.options.isVerbose) {
|
|
5790
6040
|
console.info('🖋 Anthropic Claude callCompletionModel call');
|
|
5791
6041
|
}
|
|
5792
6042
|
|
|
5793
|
-
const { content, modelRequirements } = prompt;
|
|
6043
|
+
const { content, parameters, modelRequirements } = prompt;
|
|
5794
6044
|
|
|
5795
6045
|
// TODO: [☂] Use here more modelRequirements
|
|
5796
6046
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
@@ -5807,7 +6057,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5807
6057
|
|
|
5808
6058
|
const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
|
|
5809
6059
|
...modelSettings,
|
|
5810
|
-
prompt: content,
|
|
6060
|
+
prompt: replaceParameters(content, parameters),
|
|
5811
6061
|
user: this.options.user,
|
|
5812
6062
|
};
|
|
5813
6063
|
const start: string_date_iso8601 = getCurrentIsoDate();
|
|
@@ -6314,14 +6564,14 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6314
6564
|
*/
|
|
6315
6565
|
OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
6316
6566
|
return __awaiter(this, void 0, void 0, function () {
|
|
6317
|
-
var content, modelRequirements, expectFormat, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6567
|
+
var content, parameters, modelRequirements, expectFormat, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6318
6568
|
return __generator(this, function (_a) {
|
|
6319
6569
|
switch (_a.label) {
|
|
6320
6570
|
case 0:
|
|
6321
6571
|
if (this.options.isVerbose) {
|
|
6322
6572
|
console.info('💬 OpenAI callChatModel call', { prompt: prompt });
|
|
6323
6573
|
}
|
|
6324
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
|
|
6574
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
|
|
6325
6575
|
// TODO: [☂] Use here more modelRequirements
|
|
6326
6576
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
6327
6577
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -6350,7 +6600,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6350
6600
|
])), false), [
|
|
6351
6601
|
{
|
|
6352
6602
|
role: 'user',
|
|
6353
|
-
content: content,
|
|
6603
|
+
content: replaceParameters(content, parameters),
|
|
6354
6604
|
},
|
|
6355
6605
|
], false), user: this.options.user });
|
|
6356
6606
|
start = getCurrentIsoDate();
|
|
@@ -6397,14 +6647,14 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6397
6647
|
*/
|
|
6398
6648
|
OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
6399
6649
|
return __awaiter(this, void 0, void 0, function () {
|
|
6400
|
-
var content, modelRequirements, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6650
|
+
var content, parameters, modelRequirements, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6401
6651
|
return __generator(this, function (_a) {
|
|
6402
6652
|
switch (_a.label) {
|
|
6403
6653
|
case 0:
|
|
6404
6654
|
if (this.options.isVerbose) {
|
|
6405
6655
|
console.info('🖋 OpenAI callCompletionModel call', { prompt: prompt });
|
|
6406
6656
|
}
|
|
6407
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements;
|
|
6657
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
6408
6658
|
// TODO: [☂] Use here more modelRequirements
|
|
6409
6659
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
6410
6660
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
@@ -6418,7 +6668,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6418
6668
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
6419
6669
|
// <- Note: [🧆]
|
|
6420
6670
|
};
|
|
6421
|
-
rawRequest = __assign(__assign({}, modelSettings), { prompt: content, user: this.options.user });
|
|
6671
|
+
rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, parameters), user: this.options.user });
|
|
6422
6672
|
start = getCurrentIsoDate();
|
|
6423
6673
|
if (this.options.isVerbose) {
|
|
6424
6674
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
@@ -6460,21 +6710,21 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6460
6710
|
*/
|
|
6461
6711
|
OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
|
|
6462
6712
|
return __awaiter(this, void 0, void 0, function () {
|
|
6463
|
-
var content, modelRequirements, model, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6713
|
+
var content, parameters, modelRequirements, model, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6464
6714
|
return __generator(this, function (_a) {
|
|
6465
6715
|
switch (_a.label) {
|
|
6466
6716
|
case 0:
|
|
6467
6717
|
if (this.options.isVerbose) {
|
|
6468
6718
|
console.info('🖋 OpenAI embedding call', { prompt: prompt });
|
|
6469
6719
|
}
|
|
6470
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements;
|
|
6720
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
6471
6721
|
// TODO: [☂] Use here more modelRequirements
|
|
6472
6722
|
if (modelRequirements.modelVariant !== 'EMBEDDING') {
|
|
6473
6723
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
6474
6724
|
}
|
|
6475
6725
|
model = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
|
|
6476
6726
|
rawRequest = {
|
|
6477
|
-
input: content,
|
|
6727
|
+
input: replaceParameters(content, parameters),
|
|
6478
6728
|
model: model,
|
|
6479
6729
|
// TODO: !!!! Test model 3 and dimensions
|
|
6480
6730
|
};
|
|
@@ -6794,7 +7044,7 @@ function getLlmToolsForCli() {
|
|
|
6794
7044
|
throw new EnvironmentMismatchError('Function `getLlmToolsForTestingAndScriptsAndPlayground` works only in Node.js environment');
|
|
6795
7045
|
}
|
|
6796
7046
|
return cacheLlmTools(createLlmToolsFromEnv(), {
|
|
6797
|
-
storage: new FilesStorage({ cacheFolderPath: join(process.cwd(),
|
|
7047
|
+
storage: new FilesStorage({ cacheFolderPath: join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
|
|
6798
7048
|
});
|
|
6799
7049
|
}
|
|
6800
7050
|
/**
|
|
@@ -6817,8 +7067,8 @@ function stringifyPipelineJson(pipeline) {
|
|
|
6817
7067
|
return pipelineJsonStringified;
|
|
6818
7068
|
}
|
|
6819
7069
|
/**
|
|
7070
|
+
* TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
6820
7071
|
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
6821
|
-
* TODO: [🔼] Export alongside pipelineStringToJson
|
|
6822
7072
|
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
6823
7073
|
*/
|
|
6824
7074
|
|