@promptbook/cli 0.61.0-15 → 0.61.0-16
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 +870 -623
- 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/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 +9 -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 +870 -623
- 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/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 +9 -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-15';
|
|
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-15",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-15",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-15",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-15",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-15",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-15",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-15",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-15",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) {
|
|
@@ -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,28 @@ 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
|
+
return false;
|
|
2132
|
+
}
|
|
2133
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2134
|
+
return false;
|
|
2135
|
+
}
|
|
2136
|
+
// TODO: !!!!! Is context in each template
|
|
2137
|
+
// TODO: !!!!! Are samples prepared
|
|
2138
|
+
// TODO: !!!!! Are templates prepared
|
|
2139
|
+
return true;
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* TODO: [🔼] Export via core or utils
|
|
2143
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2144
|
+
*/
|
|
2145
|
+
|
|
1873
2146
|
/**
|
|
1874
2147
|
* Takes an item or an array of items and returns an array of items
|
|
1875
2148
|
*
|
|
@@ -1890,26 +2163,115 @@ function arrayableToArray(input) {
|
|
|
1890
2163
|
}
|
|
1891
2164
|
|
|
1892
2165
|
/**
|
|
1893
|
-
*
|
|
2166
|
+
* Just marks a place of place where should be something implemented
|
|
2167
|
+
* No side effects.
|
|
2168
|
+
*
|
|
2169
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2170
|
+
*
|
|
2171
|
+
* @param value any values
|
|
2172
|
+
* @returns void
|
|
2173
|
+
* @private within the repository
|
|
1894
2174
|
*/
|
|
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;
|
|
2175
|
+
function TODO_USE() {
|
|
2176
|
+
var value = [];
|
|
2177
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2178
|
+
value[_i] = arguments[_i];
|
|
2179
|
+
}
|
|
1903
2180
|
}
|
|
1904
2181
|
|
|
1905
2182
|
/**
|
|
1906
|
-
*
|
|
2183
|
+
* This error type indicates that some limit was reached
|
|
1907
2184
|
*/
|
|
1908
|
-
function
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
2185
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2186
|
+
__extends(LimitReachedError, _super);
|
|
2187
|
+
function LimitReachedError(message) {
|
|
2188
|
+
var _this = _super.call(this, message) || this;
|
|
2189
|
+
_this.name = 'LimitReachedError';
|
|
2190
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2191
|
+
return _this;
|
|
2192
|
+
}
|
|
2193
|
+
return LimitReachedError;
|
|
2194
|
+
}(Error));
|
|
2195
|
+
|
|
2196
|
+
/**
|
|
2197
|
+
* Replaces parameters in template with values from parameters object
|
|
2198
|
+
*
|
|
2199
|
+
* @param template the template with parameters in {curly} braces
|
|
2200
|
+
* @param parameters the object with parameters
|
|
2201
|
+
* @returns the template with replaced parameters
|
|
2202
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2203
|
+
*/
|
|
2204
|
+
function replaceParameters(template, parameters) {
|
|
2205
|
+
var replacedTemplate = template;
|
|
2206
|
+
var match;
|
|
2207
|
+
var loopLimit = LOOP_LIMIT;
|
|
2208
|
+
var _loop_1 = function () {
|
|
2209
|
+
if (loopLimit-- < 0) {
|
|
2210
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
2211
|
+
}
|
|
2212
|
+
var precol = match.groups.precol;
|
|
2213
|
+
var parameterName = match.groups.parameterName;
|
|
2214
|
+
if (parameterName === '') {
|
|
2215
|
+
return "continue";
|
|
2216
|
+
}
|
|
2217
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2218
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2219
|
+
}
|
|
2220
|
+
if (parameters[parameterName] === undefined) {
|
|
2221
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2222
|
+
}
|
|
2223
|
+
var parameterValue = parameters[parameterName];
|
|
2224
|
+
if (parameterValue === undefined) {
|
|
2225
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2226
|
+
}
|
|
2227
|
+
parameterValue = parameterValue.toString();
|
|
2228
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2229
|
+
parameterValue = parameterValue
|
|
2230
|
+
.split('\n')
|
|
2231
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2232
|
+
.join('\n');
|
|
2233
|
+
}
|
|
2234
|
+
replacedTemplate =
|
|
2235
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2236
|
+
parameterValue +
|
|
2237
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2238
|
+
};
|
|
2239
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2240
|
+
.exec(replacedTemplate))) {
|
|
2241
|
+
_loop_1();
|
|
2242
|
+
}
|
|
2243
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
2244
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
2245
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
2246
|
+
}
|
|
2247
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
2248
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
2249
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
2250
|
+
}
|
|
2251
|
+
return replacedTemplate;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
/**
|
|
2255
|
+
* Counts number of characters in the text
|
|
2256
|
+
*/
|
|
2257
|
+
function countCharacters(text) {
|
|
2258
|
+
// Remove null characters
|
|
2259
|
+
text = text.replace(/\0/g, '');
|
|
2260
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
2261
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
2262
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
2263
|
+
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
2264
|
+
return text.length;
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
/**
|
|
2268
|
+
* Counts number of lines in the text
|
|
2269
|
+
*/
|
|
2270
|
+
function countLines(text) {
|
|
2271
|
+
if (text === '') {
|
|
2272
|
+
return 0;
|
|
2273
|
+
}
|
|
2274
|
+
return text.split('\n').length;
|
|
1913
2275
|
}
|
|
1914
2276
|
|
|
1915
2277
|
/**
|
|
@@ -1999,80 +2361,6 @@ function checkExpectations(expectations, value) {
|
|
|
1999
2361
|
* TODO: [💝] Unite object for expecting amount and format
|
|
2000
2362
|
*/
|
|
2001
2363
|
|
|
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
2364
|
/**
|
|
2077
2365
|
* Creates executor function from pipeline and execution tools.
|
|
2078
2366
|
*
|
|
@@ -2081,18 +2369,73 @@ function replaceParameters(template, parameters) {
|
|
|
2081
2369
|
*/
|
|
2082
2370
|
function createPipelineExecutor(options) {
|
|
2083
2371
|
var _this = this;
|
|
2084
|
-
var
|
|
2085
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ?
|
|
2086
|
-
validatePipeline(
|
|
2372
|
+
var rawPipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2373
|
+
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;
|
|
2374
|
+
validatePipeline(rawPipeline);
|
|
2087
2375
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2376
|
+
var pipeline;
|
|
2377
|
+
if (isPipelinePrepared(rawPipeline)) {
|
|
2378
|
+
pipeline = rawPipeline;
|
|
2379
|
+
}
|
|
2380
|
+
else {
|
|
2381
|
+
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 "));
|
|
2382
|
+
}
|
|
2088
2383
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2384
|
+
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2385
|
+
template) {
|
|
2386
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2387
|
+
return __generator(this, function (_a) {
|
|
2388
|
+
// TODO: !!!!!! Implement Better - use real index and keyword search
|
|
2389
|
+
TODO_USE(template);
|
|
2390
|
+
return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
|
|
2391
|
+
var content = _a.content;
|
|
2392
|
+
return "- ".concat(content);
|
|
2393
|
+
}).join('\n')];
|
|
2394
|
+
});
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
function getReservedParametersForTemplate(template) {
|
|
2398
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2399
|
+
var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2400
|
+
var e_3, _a;
|
|
2401
|
+
return __generator(this, function (_b) {
|
|
2402
|
+
switch (_b.label) {
|
|
2403
|
+
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
2404
|
+
case 1:
|
|
2405
|
+
context = _b.sent();
|
|
2406
|
+
currentDate = new Date().toISOString();
|
|
2407
|
+
reservedParameters = {
|
|
2408
|
+
context: context,
|
|
2409
|
+
currentDate: currentDate,
|
|
2410
|
+
};
|
|
2411
|
+
try {
|
|
2412
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
2413
|
+
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()) {
|
|
2414
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
2415
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
2416
|
+
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2421
|
+
finally {
|
|
2422
|
+
try {
|
|
2423
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
2424
|
+
}
|
|
2425
|
+
finally { if (e_3) throw e_3.error; }
|
|
2426
|
+
}
|
|
2427
|
+
return [2 /*return*/, reservedParameters];
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2089
2432
|
function executeSingleTemplate(currentTemplate) {
|
|
2090
2433
|
return __awaiter(this, void 0, void 0, function () {
|
|
2091
|
-
var name, title, priority, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts,
|
|
2092
|
-
var
|
|
2434
|
+
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;
|
|
2435
|
+
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2093
2436
|
var _this = this;
|
|
2094
|
-
return __generator(this, function (
|
|
2095
|
-
switch (
|
|
2437
|
+
return __generator(this, function (_u) {
|
|
2438
|
+
switch (_u.label) {
|
|
2096
2439
|
case 0:
|
|
2097
2440
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
2098
2441
|
title = currentTemplate.title;
|
|
@@ -2109,64 +2452,108 @@ function createPipelineExecutor(options) {
|
|
|
2109
2452
|
// <- [3]
|
|
2110
2453
|
})];
|
|
2111
2454
|
case 1:
|
|
2112
|
-
|
|
2113
|
-
|
|
2455
|
+
_u.sent();
|
|
2456
|
+
_u.label = 2;
|
|
2114
2457
|
case 2:
|
|
2458
|
+
usedParameterNames = extractParametersFromPromptTemplate(currentTemplate);
|
|
2459
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2460
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2461
|
+
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 ")));
|
|
2462
|
+
}
|
|
2463
|
+
_b = (_a = Object).freeze;
|
|
2464
|
+
_c = [{}];
|
|
2465
|
+
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
2466
|
+
case 3:
|
|
2467
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_u.sent())])), parametersToPass])]);
|
|
2468
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
2469
|
+
parameters = {};
|
|
2470
|
+
try {
|
|
2471
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
2472
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2473
|
+
parameterName = _e.value;
|
|
2474
|
+
// Situation: Parameter is defined and used
|
|
2475
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2476
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
2477
|
+
}
|
|
2478
|
+
// Situation: Parameter is defined but NOT used
|
|
2479
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
2480
|
+
// Do not pass this parameter to prompt
|
|
2481
|
+
}
|
|
2482
|
+
// Situation: Parameter is NOT defined BUT used
|
|
2483
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2484
|
+
// Houston, we have a problem
|
|
2485
|
+
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2486
|
+
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 ")));
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2491
|
+
finally {
|
|
2492
|
+
try {
|
|
2493
|
+
if (_e && !_e.done && (_p = _d.return)) _p.call(_d);
|
|
2494
|
+
}
|
|
2495
|
+
finally { if (e_7) throw e_7.error; }
|
|
2496
|
+
}
|
|
2497
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
2498
|
+
Object.freeze(parameters);
|
|
2115
2499
|
result = null;
|
|
2116
2500
|
resultString = null;
|
|
2117
2501
|
expectError = null;
|
|
2118
2502
|
maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
2119
|
-
|
|
2120
|
-
attempt = -
|
|
2121
|
-
|
|
2122
|
-
case
|
|
2123
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
2503
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
2504
|
+
attempt = -jokerParameterNames.length;
|
|
2505
|
+
_u.label = 4;
|
|
2506
|
+
case 4:
|
|
2507
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 52];
|
|
2124
2508
|
isJokerAttempt = attempt < 0;
|
|
2125
|
-
|
|
2126
|
-
if (isJokerAttempt && !
|
|
2509
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
2510
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
2127
2511
|
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
2128
2512
|
}
|
|
2129
2513
|
result = null;
|
|
2130
2514
|
resultString = null;
|
|
2131
2515
|
expectError = null;
|
|
2132
2516
|
if (isJokerAttempt) {
|
|
2133
|
-
if (
|
|
2134
|
-
throw new PipelineExecutionError("Joker parameter {".concat(
|
|
2517
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
2518
|
+
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
2519
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
2520
|
+
}
|
|
2521
|
+
else {
|
|
2522
|
+
resultString = parameters[jokerParameterName];
|
|
2135
2523
|
}
|
|
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
2524
|
}
|
|
2149
|
-
|
|
2525
|
+
_u.label = 5;
|
|
2150
2526
|
case 5:
|
|
2151
|
-
|
|
2527
|
+
_u.trys.push([5, 48, 49, 50]);
|
|
2528
|
+
if (!!isJokerAttempt) return [3 /*break*/, 30];
|
|
2529
|
+
_f = currentTemplate.blockType;
|
|
2530
|
+
switch (_f) {
|
|
2531
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
2532
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
2533
|
+
case 'SCRIPT': return [3 /*break*/, 16];
|
|
2534
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
2535
|
+
}
|
|
2152
2536
|
return [3 /*break*/, 29];
|
|
2153
2537
|
case 6:
|
|
2538
|
+
resultString = replaceParameters(currentTemplate.content, parameters);
|
|
2539
|
+
return [3 /*break*/, 30];
|
|
2540
|
+
case 7:
|
|
2154
2541
|
prompt = {
|
|
2155
2542
|
title: currentTemplate.title,
|
|
2156
2543
|
pipelineUrl: "".concat(pipeline.pipelineUrl
|
|
2157
2544
|
? pipeline.pipelineUrl
|
|
2158
2545
|
: '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
|
|
2546
|
+
parameters: parameters,
|
|
2547
|
+
content: currentTemplate.content,
|
|
2163
2548
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2164
|
-
|
|
2165
|
-
|
|
2549
|
+
expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
|
|
2550
|
+
var name = _a.name;
|
|
2551
|
+
return name === currentTemplate.personaName;
|
|
2552
|
+
}) || {})), currentTemplate.expectations),
|
|
2166
2553
|
expectFormat: currentTemplate.expectFormat,
|
|
2167
|
-
postprocessing: (currentTemplate.
|
|
2168
|
-
var errors, _a, _b, scriptTools, error_5,
|
|
2169
|
-
var
|
|
2554
|
+
postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
2555
|
+
var errors, _a, _b, scriptTools, error_5, e_8_1;
|
|
2556
|
+
var e_8, _c;
|
|
2170
2557
|
return __generator(this, function (_d) {
|
|
2171
2558
|
switch (_d.label) {
|
|
2172
2559
|
case 0:
|
|
@@ -2187,7 +2574,7 @@ function createPipelineExecutor(options) {
|
|
|
2187
2574
|
script: "".concat(functionName, "(result)"),
|
|
2188
2575
|
parameters: {
|
|
2189
2576
|
result: result || '',
|
|
2190
|
-
// Note: No ...
|
|
2577
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2191
2578
|
},
|
|
2192
2579
|
})];
|
|
2193
2580
|
case 4: return [2 /*return*/, _d.sent()];
|
|
@@ -2196,6 +2583,9 @@ function createPipelineExecutor(options) {
|
|
|
2196
2583
|
if (!(error_5 instanceof Error)) {
|
|
2197
2584
|
throw error_5;
|
|
2198
2585
|
}
|
|
2586
|
+
if (error_5 instanceof UnexpectedError) {
|
|
2587
|
+
throw error_5;
|
|
2588
|
+
}
|
|
2199
2589
|
errors.push(error_5);
|
|
2200
2590
|
return [3 /*break*/, 6];
|
|
2201
2591
|
case 6:
|
|
@@ -2203,14 +2593,14 @@ function createPipelineExecutor(options) {
|
|
|
2203
2593
|
return [3 /*break*/, 2];
|
|
2204
2594
|
case 7: return [3 /*break*/, 10];
|
|
2205
2595
|
case 8:
|
|
2206
|
-
|
|
2207
|
-
|
|
2596
|
+
e_8_1 = _d.sent();
|
|
2597
|
+
e_8 = { error: e_8_1 };
|
|
2208
2598
|
return [3 /*break*/, 10];
|
|
2209
2599
|
case 9:
|
|
2210
2600
|
try {
|
|
2211
2601
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2212
2602
|
}
|
|
2213
|
-
finally { if (
|
|
2603
|
+
finally { if (e_8) throw e_8.error; }
|
|
2214
2604
|
return [7 /*endfinally*/];
|
|
2215
2605
|
case 10:
|
|
2216
2606
|
if (errors.length === 0) {
|
|
@@ -2226,35 +2616,35 @@ function createPipelineExecutor(options) {
|
|
|
2226
2616
|
});
|
|
2227
2617
|
}); }; }),
|
|
2228
2618
|
};
|
|
2229
|
-
|
|
2230
|
-
switch (
|
|
2231
|
-
case 'CHAT': return [3 /*break*/,
|
|
2232
|
-
case 'COMPLETION': return [3 /*break*/,
|
|
2233
|
-
case 'EMBEDDING': return [3 /*break*/,
|
|
2619
|
+
_g = currentTemplate.modelRequirements.modelVariant;
|
|
2620
|
+
switch (_g) {
|
|
2621
|
+
case 'CHAT': return [3 /*break*/, 8];
|
|
2622
|
+
case 'COMPLETION': return [3 /*break*/, 10];
|
|
2623
|
+
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
2234
2624
|
}
|
|
2235
|
-
return [3 /*break*/,
|
|
2236
|
-
case
|
|
2237
|
-
case
|
|
2238
|
-
chatResult =
|
|
2625
|
+
return [3 /*break*/, 14];
|
|
2626
|
+
case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
|
|
2627
|
+
case 9:
|
|
2628
|
+
chatResult = _u.sent();
|
|
2239
2629
|
// TODO: [🍬] Destroy chatThread
|
|
2240
2630
|
result = chatResult;
|
|
2241
2631
|
resultString = chatResult.content;
|
|
2242
|
-
return [3 /*break*/,
|
|
2243
|
-
case
|
|
2244
|
-
case
|
|
2245
|
-
completionResult =
|
|
2632
|
+
return [3 /*break*/, 15];
|
|
2633
|
+
case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
|
|
2634
|
+
case 11:
|
|
2635
|
+
completionResult = _u.sent();
|
|
2246
2636
|
result = completionResult;
|
|
2247
2637
|
resultString = completionResult.content;
|
|
2248
|
-
return [3 /*break*/,
|
|
2249
|
-
case
|
|
2250
|
-
case
|
|
2251
|
-
embeddingResult =
|
|
2638
|
+
return [3 /*break*/, 15];
|
|
2639
|
+
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
|
|
2640
|
+
case 13:
|
|
2641
|
+
embeddingResult = _u.sent();
|
|
2252
2642
|
result = embeddingResult;
|
|
2253
2643
|
resultString = embeddingResult.content.join(',');
|
|
2254
|
-
return [3 /*break*/,
|
|
2255
|
-
case
|
|
2256
|
-
case
|
|
2257
|
-
case
|
|
2644
|
+
return [3 /*break*/, 15];
|
|
2645
|
+
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
2646
|
+
case 15: return [3 /*break*/, 30];
|
|
2647
|
+
case 16:
|
|
2258
2648
|
if (arrayableToArray(tools.script).length === 0) {
|
|
2259
2649
|
throw new PipelineExecutionError('No script execution tools are available');
|
|
2260
2650
|
}
|
|
@@ -2263,49 +2653,52 @@ function createPipelineExecutor(options) {
|
|
|
2263
2653
|
}
|
|
2264
2654
|
// TODO: DRY [1]
|
|
2265
2655
|
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;
|
|
2656
|
+
_u.label = 17;
|
|
2271
2657
|
case 17:
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2658
|
+
_u.trys.push([17, 24, 25, 26]);
|
|
2659
|
+
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
2660
|
+
_u.label = 18;
|
|
2275
2661
|
case 18:
|
|
2276
|
-
|
|
2277
|
-
|
|
2662
|
+
if (!!_j.done) return [3 /*break*/, 23];
|
|
2663
|
+
scriptTools = _j.value;
|
|
2664
|
+
_u.label = 19;
|
|
2665
|
+
case 19:
|
|
2666
|
+
_u.trys.push([19, 21, , 22]);
|
|
2667
|
+
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2278
2668
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2279
2669
|
script: currentTemplate.content,
|
|
2280
|
-
parameters:
|
|
2281
|
-
})];
|
|
2282
|
-
case 19:
|
|
2283
|
-
resultString = _o.sent();
|
|
2284
|
-
return [3 /*break*/, 22];
|
|
2670
|
+
parameters: parameters,
|
|
2671
|
+
}))];
|
|
2285
2672
|
case 20:
|
|
2286
|
-
|
|
2673
|
+
resultString = _u.sent();
|
|
2674
|
+
return [3 /*break*/, 23];
|
|
2675
|
+
case 21:
|
|
2676
|
+
error_2 = _u.sent();
|
|
2287
2677
|
if (!(error_2 instanceof Error)) {
|
|
2288
2678
|
throw error_2;
|
|
2289
2679
|
}
|
|
2680
|
+
if (error_2 instanceof UnexpectedError) {
|
|
2681
|
+
throw error_2;
|
|
2682
|
+
}
|
|
2290
2683
|
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];
|
|
2684
|
+
return [3 /*break*/, 22];
|
|
2685
|
+
case 22:
|
|
2686
|
+
_j = _h.next();
|
|
2687
|
+
return [3 /*break*/, 18];
|
|
2688
|
+
case 23: return [3 /*break*/, 26];
|
|
2300
2689
|
case 24:
|
|
2690
|
+
e_4_1 = _u.sent();
|
|
2691
|
+
e_4 = { error: e_4_1 };
|
|
2692
|
+
return [3 /*break*/, 26];
|
|
2693
|
+
case 25:
|
|
2301
2694
|
try {
|
|
2302
|
-
if (
|
|
2695
|
+
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
2303
2696
|
}
|
|
2304
|
-
finally { if (
|
|
2697
|
+
finally { if (e_4) throw e_4.error; }
|
|
2305
2698
|
return [7 /*endfinally*/];
|
|
2306
|
-
case
|
|
2699
|
+
case 26:
|
|
2307
2700
|
if (resultString !== null) {
|
|
2308
|
-
return [3 /*break*/,
|
|
2701
|
+
return [3 /*break*/, 30];
|
|
2309
2702
|
}
|
|
2310
2703
|
if (scriptPipelineExecutionErrors.length === 1) {
|
|
2311
2704
|
throw scriptPipelineExecutionErrors[0];
|
|
@@ -2315,101 +2708,104 @@ function createPipelineExecutor(options) {
|
|
|
2315
2708
|
.map(function (error) { return '- ' + error.message; })
|
|
2316
2709
|
.join('\n\n')), "\n "); }));
|
|
2317
2710
|
}
|
|
2318
|
-
case
|
|
2711
|
+
case 27:
|
|
2319
2712
|
if (tools.userInterface === undefined) {
|
|
2320
2713
|
throw new PipelineExecutionError('User interface tools are not available');
|
|
2321
2714
|
}
|
|
2322
|
-
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
2715
|
+
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2323
2716
|
promptTitle: currentTemplate.title,
|
|
2324
|
-
promptMessage: replaceParameters(currentTemplate.description || '',
|
|
2325
|
-
defaultValue: replaceParameters(currentTemplate.content,
|
|
2717
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
2718
|
+
defaultValue: replaceParameters(currentTemplate.content, parameters),
|
|
2326
2719
|
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
2327
2720
|
placeholder: undefined,
|
|
2328
2721
|
priority: priority,
|
|
2329
|
-
})];
|
|
2330
|
-
case
|
|
2722
|
+
}))];
|
|
2723
|
+
case 28:
|
|
2331
2724
|
// 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;
|
|
2725
|
+
resultString = _u.sent();
|
|
2726
|
+
return [3 /*break*/, 30];
|
|
2727
|
+
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
2338
2728
|
case 30:
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
_o.label = 31;
|
|
2729
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
2730
|
+
_u.label = 31;
|
|
2342
2731
|
case 31:
|
|
2343
|
-
|
|
2344
|
-
|
|
2732
|
+
_u.trys.push([31, 45, 46, 47]);
|
|
2733
|
+
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
2734
|
+
_u.label = 32;
|
|
2735
|
+
case 32:
|
|
2736
|
+
if (!!_l.done) return [3 /*break*/, 44];
|
|
2737
|
+
functionName = _l.value;
|
|
2345
2738
|
// TODO: DRY [1]
|
|
2346
2739
|
scriptPipelineExecutionErrors = [];
|
|
2347
2740
|
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;
|
|
2741
|
+
_u.label = 33;
|
|
2353
2742
|
case 33:
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2743
|
+
_u.trys.push([33, 40, 41, 42]);
|
|
2744
|
+
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
2745
|
+
_u.label = 34;
|
|
2357
2746
|
case 34:
|
|
2358
|
-
_o.
|
|
2747
|
+
if (!!_o.done) return [3 /*break*/, 39];
|
|
2748
|
+
scriptTools = _o.value;
|
|
2749
|
+
_u.label = 35;
|
|
2750
|
+
case 35:
|
|
2751
|
+
_u.trys.push([35, 37, , 38]);
|
|
2359
2752
|
return [4 /*yield*/, scriptTools.execute({
|
|
2360
2753
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2361
2754
|
script: "".concat(functionName, "(resultString)"),
|
|
2362
2755
|
parameters: {
|
|
2363
2756
|
resultString: resultString || '',
|
|
2364
|
-
// Note: No ...
|
|
2757
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2365
2758
|
},
|
|
2366
2759
|
})];
|
|
2367
|
-
case 35:
|
|
2368
|
-
resultString = _o.sent();
|
|
2369
|
-
postprocessingError = null;
|
|
2370
|
-
return [3 /*break*/, 38];
|
|
2371
2760
|
case 36:
|
|
2372
|
-
|
|
2761
|
+
resultString = _u.sent();
|
|
2762
|
+
postprocessingError = null;
|
|
2763
|
+
return [3 /*break*/, 39];
|
|
2764
|
+
case 37:
|
|
2765
|
+
error_3 = _u.sent();
|
|
2373
2766
|
if (!(error_3 instanceof Error)) {
|
|
2374
2767
|
throw error_3;
|
|
2375
2768
|
}
|
|
2769
|
+
if (error_3 instanceof UnexpectedError) {
|
|
2770
|
+
throw error_3;
|
|
2771
|
+
}
|
|
2376
2772
|
postprocessingError = error_3;
|
|
2377
2773
|
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];
|
|
2774
|
+
return [3 /*break*/, 38];
|
|
2775
|
+
case 38:
|
|
2776
|
+
_o = _m.next();
|
|
2777
|
+
return [3 /*break*/, 34];
|
|
2778
|
+
case 39: return [3 /*break*/, 42];
|
|
2387
2779
|
case 40:
|
|
2780
|
+
e_5_1 = _u.sent();
|
|
2781
|
+
e_5 = { error: e_5_1 };
|
|
2782
|
+
return [3 /*break*/, 42];
|
|
2783
|
+
case 41:
|
|
2388
2784
|
try {
|
|
2389
|
-
if (
|
|
2785
|
+
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
2390
2786
|
}
|
|
2391
|
-
finally { if (
|
|
2787
|
+
finally { if (e_5) throw e_5.error; }
|
|
2392
2788
|
return [7 /*endfinally*/];
|
|
2393
|
-
case
|
|
2789
|
+
case 42:
|
|
2394
2790
|
if (postprocessingError) {
|
|
2395
2791
|
throw postprocessingError;
|
|
2396
2792
|
}
|
|
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];
|
|
2793
|
+
_u.label = 43;
|
|
2794
|
+
case 43:
|
|
2795
|
+
_l = _k.next();
|
|
2796
|
+
return [3 /*break*/, 32];
|
|
2797
|
+
case 44: return [3 /*break*/, 47];
|
|
2406
2798
|
case 45:
|
|
2799
|
+
e_6_1 = _u.sent();
|
|
2800
|
+
e_6 = { error: e_6_1 };
|
|
2801
|
+
return [3 /*break*/, 47];
|
|
2802
|
+
case 46:
|
|
2407
2803
|
try {
|
|
2408
|
-
if (
|
|
2804
|
+
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
2409
2805
|
}
|
|
2410
|
-
finally { if (
|
|
2806
|
+
finally { if (e_6) throw e_6.error; }
|
|
2411
2807
|
return [7 /*endfinally*/];
|
|
2412
|
-
case
|
|
2808
|
+
case 47:
|
|
2413
2809
|
// TODO: [💝] Unite object for expecting amount and format
|
|
2414
2810
|
if (currentTemplate.expectFormat) {
|
|
2415
2811
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
@@ -2422,15 +2818,18 @@ function createPipelineExecutor(options) {
|
|
|
2422
2818
|
if (currentTemplate.expectations) {
|
|
2423
2819
|
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
2424
2820
|
}
|
|
2425
|
-
return [3 /*break*/,
|
|
2426
|
-
case
|
|
2427
|
-
error_4 =
|
|
2821
|
+
return [3 /*break*/, 52];
|
|
2822
|
+
case 48:
|
|
2823
|
+
error_4 = _u.sent();
|
|
2428
2824
|
if (!(error_4 instanceof ExpectError)) {
|
|
2429
2825
|
throw error_4;
|
|
2430
2826
|
}
|
|
2827
|
+
if (error_4 instanceof UnexpectedError) {
|
|
2828
|
+
throw error_4;
|
|
2829
|
+
}
|
|
2431
2830
|
expectError = error_4;
|
|
2432
|
-
return [3 /*break*/,
|
|
2433
|
-
case
|
|
2831
|
+
return [3 /*break*/, 50];
|
|
2832
|
+
case 49:
|
|
2434
2833
|
if (!isJokerAttempt &&
|
|
2435
2834
|
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
2436
2835
|
prompt
|
|
@@ -2452,15 +2851,15 @@ function createPipelineExecutor(options) {
|
|
|
2452
2851
|
});
|
|
2453
2852
|
}
|
|
2454
2853
|
return [7 /*endfinally*/];
|
|
2455
|
-
case
|
|
2854
|
+
case 50:
|
|
2456
2855
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
2457
2856
|
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
2857
|
}
|
|
2459
|
-
|
|
2460
|
-
case 50:
|
|
2461
|
-
attempt++;
|
|
2462
|
-
return [3 /*break*/, 3];
|
|
2858
|
+
_u.label = 51;
|
|
2463
2859
|
case 51:
|
|
2860
|
+
attempt++;
|
|
2861
|
+
return [3 /*break*/, 4];
|
|
2862
|
+
case 52:
|
|
2464
2863
|
if (resultString === null) {
|
|
2465
2864
|
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
2466
2865
|
}
|
|
@@ -2476,18 +2875,27 @@ function createPipelineExecutor(options) {
|
|
|
2476
2875
|
// <- [3]
|
|
2477
2876
|
});
|
|
2478
2877
|
}
|
|
2479
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (
|
|
2878
|
+
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
2879
|
return [2 /*return*/];
|
|
2481
2880
|
}
|
|
2482
2881
|
});
|
|
2483
2882
|
});
|
|
2484
2883
|
}
|
|
2485
|
-
var
|
|
2486
|
-
var e_1,
|
|
2487
|
-
return __generator(this, function (
|
|
2488
|
-
switch (
|
|
2884
|
+
var executionReport, _a, _b, parameter, parametersToPass, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, outputParameters, errors, _c, _d, parameter, usage;
|
|
2885
|
+
var e_1, _e, e_2, _f;
|
|
2886
|
+
return __generator(this, function (_g) {
|
|
2887
|
+
switch (_g.label) {
|
|
2489
2888
|
case 0:
|
|
2490
|
-
|
|
2889
|
+
if (!(pipeline === undefined)) return [3 /*break*/, 2];
|
|
2890
|
+
return [4 /*yield*/, preparePipeline(rawPipeline, {
|
|
2891
|
+
llmTools: llmTools,
|
|
2892
|
+
isVerbose: isVerbose,
|
|
2893
|
+
maxParallelCount: maxParallelCount,
|
|
2894
|
+
})];
|
|
2895
|
+
case 1:
|
|
2896
|
+
pipeline = _g.sent();
|
|
2897
|
+
_g.label = 2;
|
|
2898
|
+
case 2:
|
|
2491
2899
|
executionReport = {
|
|
2492
2900
|
pipelineUrl: pipeline.pipelineUrl,
|
|
2493
2901
|
title: pipeline.title,
|
|
@@ -2496,9 +2904,35 @@ function createPipelineExecutor(options) {
|
|
|
2496
2904
|
description: pipeline.description,
|
|
2497
2905
|
promptExecutions: [],
|
|
2498
2906
|
};
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2907
|
+
try {
|
|
2908
|
+
// Note: Check that all input input parameters are defined
|
|
2909
|
+
for (_a = __values(pipeline.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
2910
|
+
parameter = _b.value;
|
|
2911
|
+
if (parameter.isInput && inputParameters[parameter.name] === undefined) {
|
|
2912
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2913
|
+
isSuccessful: false,
|
|
2914
|
+
errors: [
|
|
2915
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
|
|
2916
|
+
// <- TODO: !!!!! Test this error
|
|
2917
|
+
],
|
|
2918
|
+
executionReport: executionReport,
|
|
2919
|
+
outputParameters: {},
|
|
2920
|
+
usage: ZERO_USAGE,
|
|
2921
|
+
})];
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2926
|
+
finally {
|
|
2927
|
+
try {
|
|
2928
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
2929
|
+
}
|
|
2930
|
+
finally { if (e_1) throw e_1.error; }
|
|
2931
|
+
}
|
|
2932
|
+
parametersToPass = inputParameters;
|
|
2933
|
+
_g.label = 3;
|
|
2934
|
+
case 3:
|
|
2935
|
+
_g.trys.push([3, 8, , 9]);
|
|
2502
2936
|
resovedParameters_1 = pipeline.parameters
|
|
2503
2937
|
.filter(function (_a) {
|
|
2504
2938
|
var isInput = _a.isInput;
|
|
@@ -2513,8 +2947,8 @@ function createPipelineExecutor(options) {
|
|
|
2513
2947
|
loopLimit = LOOP_LIMIT;
|
|
2514
2948
|
_loop_1 = function () {
|
|
2515
2949
|
var currentTemplate, work_1;
|
|
2516
|
-
return __generator(this, function (
|
|
2517
|
-
switch (
|
|
2950
|
+
return __generator(this, function (_h) {
|
|
2951
|
+
switch (_h.label) {
|
|
2518
2952
|
case 0:
|
|
2519
2953
|
if (loopLimit-- < 0) {
|
|
2520
2954
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
@@ -2529,7 +2963,7 @@ function createPipelineExecutor(options) {
|
|
|
2529
2963
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2530
2964
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
2531
2965
|
case 2:
|
|
2532
|
-
/* [5] */
|
|
2966
|
+
/* [5] */ _h.sent();
|
|
2533
2967
|
return [3 /*break*/, 4];
|
|
2534
2968
|
case 3:
|
|
2535
2969
|
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
@@ -2541,24 +2975,24 @@ function createPipelineExecutor(options) {
|
|
|
2541
2975
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
2542
2976
|
});
|
|
2543
2977
|
resolving_1.push(work_1);
|
|
2544
|
-
|
|
2978
|
+
_h.label = 4;
|
|
2545
2979
|
case 4: return [2 /*return*/];
|
|
2546
2980
|
}
|
|
2547
2981
|
});
|
|
2548
2982
|
};
|
|
2549
|
-
|
|
2550
|
-
case
|
|
2551
|
-
if (!(unresovedTemplates.length > 0)) return [3 /*break*/,
|
|
2983
|
+
_g.label = 4;
|
|
2984
|
+
case 4:
|
|
2985
|
+
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 6];
|
|
2552
2986
|
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
2987
|
case 5:
|
|
2558
|
-
|
|
2559
|
-
return [3 /*break*/,
|
|
2560
|
-
case 6:
|
|
2561
|
-
|
|
2988
|
+
_g.sent();
|
|
2989
|
+
return [3 /*break*/, 4];
|
|
2990
|
+
case 6: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
2991
|
+
case 7:
|
|
2992
|
+
_g.sent();
|
|
2993
|
+
return [3 /*break*/, 9];
|
|
2994
|
+
case 8:
|
|
2995
|
+
error_1 = _g.sent();
|
|
2562
2996
|
if (!(error_1 instanceof Error)) {
|
|
2563
2997
|
throw error_1;
|
|
2564
2998
|
}
|
|
@@ -2566,49 +3000,56 @@ function createPipelineExecutor(options) {
|
|
|
2566
3000
|
var result = _a.result;
|
|
2567
3001
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2568
3002
|
})), false));
|
|
2569
|
-
return [2 /*return*/, {
|
|
3003
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2570
3004
|
isSuccessful: false,
|
|
2571
3005
|
errors: [error_1],
|
|
2572
3006
|
usage: usage_1,
|
|
2573
3007
|
executionReport: executionReport,
|
|
2574
3008
|
outputParameters: parametersToPass,
|
|
2575
|
-
}];
|
|
2576
|
-
case
|
|
3009
|
+
})];
|
|
3010
|
+
case 9:
|
|
3011
|
+
outputParameters = {};
|
|
3012
|
+
errors = [];
|
|
2577
3013
|
try {
|
|
2578
3014
|
// Note: Filter ONLY output parameters
|
|
2579
|
-
for (
|
|
2580
|
-
|
|
2581
|
-
|
|
3015
|
+
for (_c = __values(pipeline.parameters.filter(function (_a) {
|
|
3016
|
+
var isOutput = _a.isOutput;
|
|
3017
|
+
return isOutput;
|
|
3018
|
+
})), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3019
|
+
parameter = _d.value;
|
|
3020
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3021
|
+
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
2582
3022
|
continue;
|
|
2583
3023
|
}
|
|
2584
|
-
|
|
3024
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
2585
3025
|
}
|
|
2586
3026
|
}
|
|
2587
|
-
catch (
|
|
3027
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2588
3028
|
finally {
|
|
2589
3029
|
try {
|
|
2590
|
-
if (
|
|
3030
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
2591
3031
|
}
|
|
2592
|
-
finally { if (
|
|
3032
|
+
finally { if (e_2) throw e_2.error; }
|
|
2593
3033
|
}
|
|
2594
3034
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2595
3035
|
var result = _a.result;
|
|
2596
3036
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2597
3037
|
})), false));
|
|
2598
|
-
return [2 /*return*/, {
|
|
3038
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2599
3039
|
isSuccessful: true,
|
|
2600
|
-
errors:
|
|
3040
|
+
errors: errors,
|
|
2601
3041
|
usage: usage,
|
|
2602
3042
|
executionReport: executionReport,
|
|
2603
|
-
outputParameters:
|
|
2604
|
-
}];
|
|
3043
|
+
outputParameters: outputParameters,
|
|
3044
|
+
})];
|
|
2605
3045
|
}
|
|
2606
3046
|
});
|
|
2607
3047
|
}); };
|
|
2608
3048
|
return pipelineExecutor;
|
|
2609
3049
|
}
|
|
2610
3050
|
/**
|
|
2611
|
-
* TODO:
|
|
3051
|
+
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3052
|
+
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
2612
3053
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2613
3054
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2614
3055
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
@@ -2617,23 +3058,6 @@ function createPipelineExecutor(options) {
|
|
|
2617
3058
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2618
3059
|
*/
|
|
2619
3060
|
|
|
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
3061
|
/**
|
|
2638
3062
|
* @@@
|
|
2639
3063
|
*/
|
|
@@ -2761,7 +3185,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
2761
3185
|
});
|
|
2762
3186
|
}
|
|
2763
3187
|
/**
|
|
2764
|
-
* TODO: [🔼] !!! Export via `@promptbook/markdown`
|
|
3188
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/markdown`
|
|
2765
3189
|
* TODO: [🪂] Do it in parallel 11:11
|
|
2766
3190
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2767
3191
|
*/
|
|
@@ -2784,7 +3208,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
2784
3208
|
var partialPieces, pieces;
|
|
2785
3209
|
return __generator(this, function (_a) {
|
|
2786
3210
|
switch (_a.label) {
|
|
2787
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝]
|
|
3211
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
2788
3212
|
options)];
|
|
2789
3213
|
case 1:
|
|
2790
3214
|
partialPieces = _a.sent();
|
|
@@ -2822,7 +3246,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
2822
3246
|
> ):
|
|
2823
3247
|
*/
|
|
2824
3248
|
/**
|
|
2825
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3249
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
2826
3250
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2827
3251
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2828
3252
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -2948,12 +3372,15 @@ function preparePipeline(pipeline, options) {
|
|
|
2948
3372
|
partialknowledgePiecesPrepared = _b.sent();
|
|
2949
3373
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
2950
3374
|
// ----- /Knowledge preparation -----
|
|
3375
|
+
// TODO: !!!!! Add context to each template (if missing)
|
|
3376
|
+
// TODO: !!!!! Apply samples to each template (if missing)
|
|
2951
3377
|
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
2952
3378
|
}
|
|
2953
3379
|
});
|
|
2954
3380
|
});
|
|
2955
3381
|
}
|
|
2956
3382
|
/**
|
|
3383
|
+
* TODO: !!!!! Index the samples and maybe templates
|
|
2957
3384
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2958
3385
|
* TODO: Write tests for `preparePipeline`
|
|
2959
3386
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
@@ -3009,7 +3436,7 @@ var knowledgeCommandParser = {
|
|
|
3009
3436
|
/**
|
|
3010
3437
|
* Link to discussion
|
|
3011
3438
|
*/
|
|
3012
|
-
|
|
3439
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3013
3440
|
/**
|
|
3014
3441
|
* Example usages of the KNOWLEDGE command
|
|
3015
3442
|
*/
|
|
@@ -3046,8 +3473,9 @@ var knowledgeCommandParser = {
|
|
|
3046
3473
|
/**
|
|
3047
3474
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3048
3475
|
*/
|
|
3049
|
-
applyToPipelineJson: function (
|
|
3476
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3050
3477
|
var source = personaCommand.source;
|
|
3478
|
+
var pipelineJson = subjects.pipelineJson;
|
|
3051
3479
|
var name = titleToName(source);
|
|
3052
3480
|
pipelineJson.knowledgeSources.push({
|
|
3053
3481
|
name: name,
|
|
@@ -3082,7 +3510,7 @@ var personaCommandParser = {
|
|
|
3082
3510
|
/**
|
|
3083
3511
|
* Link to discussion
|
|
3084
3512
|
*/
|
|
3085
|
-
|
|
3513
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3086
3514
|
/**
|
|
3087
3515
|
* Example usages of the PERSONA command
|
|
3088
3516
|
*/
|
|
@@ -3110,8 +3538,15 @@ var personaCommandParser = {
|
|
|
3110
3538
|
/**
|
|
3111
3539
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3112
3540
|
*/
|
|
3113
|
-
applyToPipelineJson: function (
|
|
3541
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3114
3542
|
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
3543
|
+
var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
|
|
3544
|
+
if (templateJson !== null) {
|
|
3545
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
3546
|
+
throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
3547
|
+
}
|
|
3548
|
+
templateJson.personaName = personaName;
|
|
3549
|
+
}
|
|
3115
3550
|
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
3116
3551
|
if (persona === undefined) {
|
|
3117
3552
|
pipelineJson.personas.push({
|
|
@@ -3270,7 +3705,7 @@ var blockCommandParser = {
|
|
|
3270
3705
|
/**
|
|
3271
3706
|
* Link to discussion
|
|
3272
3707
|
*/
|
|
3273
|
-
|
|
3708
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
3274
3709
|
/**
|
|
3275
3710
|
* Example usages of the BLOCK command
|
|
3276
3711
|
*/
|
|
@@ -3298,6 +3733,7 @@ var blockCommandParser = {
|
|
|
3298
3733
|
//---
|
|
3299
3734
|
/* <- TODO: [🧠] Maybe dynamic */
|
|
3300
3735
|
],
|
|
3736
|
+
// TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
|
|
3301
3737
|
/**
|
|
3302
3738
|
* Parses the BLOCK command
|
|
3303
3739
|
*/
|
|
@@ -3414,7 +3850,7 @@ var expectCommandParser = {
|
|
|
3414
3850
|
/**
|
|
3415
3851
|
* Link to discussion
|
|
3416
3852
|
*/
|
|
3417
|
-
|
|
3853
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
3418
3854
|
/**
|
|
3419
3855
|
* Example usages of the EXPECT command
|
|
3420
3856
|
*/
|
|
@@ -3532,7 +3968,7 @@ var jokerCommandParser = {
|
|
|
3532
3968
|
/**
|
|
3533
3969
|
* Link to discussion
|
|
3534
3970
|
*/
|
|
3535
|
-
|
|
3971
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
|
|
3536
3972
|
/**
|
|
3537
3973
|
* Example usages of the JOKER command
|
|
3538
3974
|
*/
|
|
@@ -3575,7 +4011,11 @@ var modelCommandParser = {
|
|
|
3575
4011
|
/**
|
|
3576
4012
|
* BOILERPLATE command can be used in:
|
|
3577
4013
|
*/
|
|
3578
|
-
usagePlaces: [
|
|
4014
|
+
usagePlaces: [
|
|
4015
|
+
'PIPELINE_HEAD',
|
|
4016
|
+
// <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
|
|
4017
|
+
'PIPELINE_TEMPLATE',
|
|
4018
|
+
],
|
|
3579
4019
|
/**
|
|
3580
4020
|
* Description of the MODEL command
|
|
3581
4021
|
*/
|
|
@@ -3583,7 +4023,7 @@ var modelCommandParser = {
|
|
|
3583
4023
|
/**
|
|
3584
4024
|
* Link to discussion
|
|
3585
4025
|
*/
|
|
3586
|
-
|
|
4026
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
|
|
3587
4027
|
/**
|
|
3588
4028
|
* Example usages of the MODEL command
|
|
3589
4029
|
*/
|
|
@@ -3663,7 +4103,7 @@ var parameterCommandParser = {
|
|
|
3663
4103
|
/**
|
|
3664
4104
|
* Link to discussion
|
|
3665
4105
|
*/
|
|
3666
|
-
|
|
4106
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
|
|
3667
4107
|
/**
|
|
3668
4108
|
* Example usages of the PARAMETER command
|
|
3669
4109
|
*/
|
|
@@ -3727,7 +4167,7 @@ var postprocessCommandParser = {
|
|
|
3727
4167
|
/**
|
|
3728
4168
|
* Link to discussion
|
|
3729
4169
|
*/
|
|
3730
|
-
|
|
4170
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
|
|
3731
4171
|
/**
|
|
3732
4172
|
* Example usages of the POSTPROCESS command
|
|
3733
4173
|
*/
|
|
@@ -3782,7 +4222,7 @@ var promptbookVersionCommandParser = {
|
|
|
3782
4222
|
/**
|
|
3783
4223
|
* Link to discussion
|
|
3784
4224
|
*/
|
|
3785
|
-
|
|
4225
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
|
|
3786
4226
|
/**
|
|
3787
4227
|
* Example usages of the PROMPTBOOK_VERSION command
|
|
3788
4228
|
*/
|
|
@@ -3835,7 +4275,7 @@ var urlCommandParser = {
|
|
|
3835
4275
|
/**
|
|
3836
4276
|
* Link to discussion
|
|
3837
4277
|
*/
|
|
3838
|
-
|
|
4278
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
|
|
3839
4279
|
/**
|
|
3840
4280
|
* Example usages of the URL command
|
|
3841
4281
|
*/
|
|
@@ -3905,7 +4345,7 @@ var actionCommandParser = {
|
|
|
3905
4345
|
/**
|
|
3906
4346
|
* Link to discussion
|
|
3907
4347
|
*/
|
|
3908
|
-
|
|
4348
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
|
|
3909
4349
|
/**
|
|
3910
4350
|
* Example usages of the ACTION command
|
|
3911
4351
|
*/
|
|
@@ -3944,7 +4384,7 @@ var instrumentCommandParser = {
|
|
|
3944
4384
|
/**
|
|
3945
4385
|
* Link to discussion
|
|
3946
4386
|
*/
|
|
3947
|
-
|
|
4387
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
|
|
3948
4388
|
/**
|
|
3949
4389
|
* Example usages of the INSTRUMENT command
|
|
3950
4390
|
*/
|
|
@@ -3987,7 +4427,7 @@ var boilerplateCommandParser = {
|
|
|
3987
4427
|
/**
|
|
3988
4428
|
* Link to discussion
|
|
3989
4429
|
*/
|
|
3990
|
-
|
|
4430
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
3991
4431
|
/**
|
|
3992
4432
|
* Example usages of the BOILERPLATE command
|
|
3993
4433
|
*/
|
|
@@ -4121,9 +4561,9 @@ function parseCommand(raw, usagePlace) {
|
|
|
4121
4561
|
*/
|
|
4122
4562
|
function getSupportedCommandsMessage() {
|
|
4123
4563
|
return COMMANDS.flatMap(function (_a) {
|
|
4124
|
-
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description,
|
|
4564
|
+
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
|
|
4125
4565
|
return __spreadArray([
|
|
4126
|
-
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(
|
|
4566
|
+
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
4127
4567
|
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
4128
4568
|
}).join('\n');
|
|
4129
4569
|
}
|
|
@@ -4478,195 +4918,6 @@ function removeContentComments(content) {
|
|
|
4478
4918
|
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
4479
4919
|
}
|
|
4480
4920
|
|
|
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
4921
|
/**
|
|
4671
4922
|
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4672
4923
|
*
|
|
@@ -4776,7 +5027,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4776
5027
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4777
5028
|
break;
|
|
4778
5029
|
case 'KNOWLEDGE':
|
|
4779
|
-
knowledgeCommandParser.applyToPipelineJson(pipelineJson,
|
|
5030
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4780
5031
|
break;
|
|
4781
5032
|
case 'ACTION':
|
|
4782
5033
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4785,7 +5036,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4785
5036
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4786
5037
|
break;
|
|
4787
5038
|
case 'PERSONA':
|
|
4788
|
-
personaCommandParser.applyToPipelineJson(pipelineJson,
|
|
5039
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4789
5040
|
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4790
5041
|
break;
|
|
4791
5042
|
case 'BOILERPLATE':
|
|
@@ -4809,13 +5060,6 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4809
5060
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
4810
5061
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
4811
5062
|
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
5063
|
var lastLine = section.content.split('\n').pop();
|
|
4820
5064
|
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4821
5065
|
var resultingParameterName = null;
|
|
@@ -4836,10 +5080,39 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4836
5080
|
.join('\n')), "\n "); }));
|
|
4837
5081
|
};
|
|
4838
5082
|
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
5083
|
+
// TODO: [🎾][1] DRY description
|
|
5084
|
+
var description_1 = section.content;
|
|
5085
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
5086
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
5087
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5088
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5089
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5090
|
+
description_1 = spaceTrim$1(description_1);
|
|
5091
|
+
if (description_1 === '') {
|
|
5092
|
+
description_1 = undefined;
|
|
5093
|
+
}
|
|
5094
|
+
var templateJson = {
|
|
5095
|
+
blockType: 'PROMPT_TEMPLATE',
|
|
5096
|
+
name: titleToName(section.title),
|
|
5097
|
+
title: section.title,
|
|
5098
|
+
description: description_1,
|
|
5099
|
+
modelRequirements: templateModelRequirements,
|
|
5100
|
+
content: content,
|
|
5101
|
+
};
|
|
5102
|
+
/**
|
|
5103
|
+
* This is nessesary because block type can be
|
|
5104
|
+
* - Set zero times, so anticipate 'PROMPT_TEMPLATE'
|
|
5105
|
+
* - Set one time
|
|
5106
|
+
* - Set more times - throw error
|
|
5107
|
+
*
|
|
5108
|
+
* Note: [2]
|
|
5109
|
+
*/
|
|
5110
|
+
var isBlockTypeSet = false;
|
|
4839
5111
|
try {
|
|
4840
5112
|
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
5113
|
var listItem = listItems_2_1.value;
|
|
4842
5114
|
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5115
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
4843
5116
|
switch (command.type) {
|
|
4844
5117
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4845
5118
|
case 'BLOCK':
|
|
@@ -4857,9 +5130,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4857
5130
|
return "continue-templates";
|
|
4858
5131
|
}
|
|
4859
5132
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4860
|
-
knowledgeCommandParser.applyToPipelineJson(
|
|
5133
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
4861
5134
|
type: 'KNOWLEDGE',
|
|
4862
|
-
source: content, // <- TODO: [🐝]
|
|
5135
|
+
source: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5136
|
+
}, {
|
|
5137
|
+
pipelineJson: pipelineJson,
|
|
5138
|
+
templateJson: templateJson,
|
|
4863
5139
|
});
|
|
4864
5140
|
return "continue-templates";
|
|
4865
5141
|
}
|
|
@@ -4872,35 +5148,36 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4872
5148
|
return "continue-templates";
|
|
4873
5149
|
}
|
|
4874
5150
|
expectResultingParameterName();
|
|
4875
|
-
blockType = command.blockType;
|
|
4876
|
-
isBlockTypeSet = true;
|
|
5151
|
+
templateJson.blockType = command.blockType;
|
|
5152
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
4877
5153
|
break;
|
|
4878
5154
|
case 'EXPECT_AMOUNT':
|
|
4879
5155
|
// eslint-disable-next-line no-case-declarations
|
|
4880
5156
|
var unit = command.unit.toLowerCase();
|
|
4881
|
-
|
|
5157
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
5158
|
+
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
4882
5159
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
4883
|
-
if (
|
|
4884
|
-
throw new ParsingError("Already defined minumum ".concat(
|
|
5160
|
+
if (templateJson.expectations[unit].min !== undefined) {
|
|
5161
|
+
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
5162
|
}
|
|
4886
|
-
|
|
5163
|
+
templateJson.expectations[unit].min = command.amount;
|
|
4887
5164
|
} /* not else */
|
|
4888
5165
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
4889
|
-
if (
|
|
4890
|
-
throw new ParsingError("Already defined maximum ".concat(
|
|
5166
|
+
if (templateJson.expectations[unit].max !== undefined) {
|
|
5167
|
+
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
5168
|
}
|
|
4892
|
-
|
|
5169
|
+
templateJson.expectations[unit].max = command.amount;
|
|
4893
5170
|
}
|
|
4894
5171
|
break;
|
|
4895
5172
|
case 'EXPECT_FORMAT':
|
|
4896
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
4897
|
-
throw new ParsingError("Expect format is already defined to \"".concat(expectFormat, "\"
|
|
5173
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5174
|
+
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
5175
|
}
|
|
4899
|
-
expectFormat = command.format;
|
|
5176
|
+
templateJson.expectFormat = command.format;
|
|
4900
5177
|
break;
|
|
4901
5178
|
case 'JOKER':
|
|
4902
|
-
|
|
4903
|
-
|
|
5179
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
5180
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
4904
5181
|
break;
|
|
4905
5182
|
case 'MODEL':
|
|
4906
5183
|
templateModelRequirements[command.key] = command.value;
|
|
@@ -4910,11 +5187,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4910
5187
|
defineParam(command);
|
|
4911
5188
|
break;
|
|
4912
5189
|
case 'POSTPROCESS':
|
|
4913
|
-
|
|
5190
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
5191
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
4914
5192
|
break;
|
|
4915
5193
|
case 'KNOWLEDGE':
|
|
4916
5194
|
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
4917
|
-
knowledgeCommandParser.applyToPipelineJson(pipelineJson,
|
|
5195
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
4918
5196
|
break;
|
|
4919
5197
|
case 'ACTION':
|
|
4920
5198
|
// TODO: [👙] The action is maybe relevant for just this template
|
|
@@ -4925,7 +5203,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4925
5203
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4926
5204
|
break;
|
|
4927
5205
|
case 'PERSONA':
|
|
4928
|
-
personaCommandParser.applyToPipelineJson(pipelineJson,
|
|
5206
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
4929
5207
|
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4930
5208
|
break;
|
|
4931
5209
|
case 'BOILERPLATE':
|
|
@@ -4944,60 +5222,29 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4944
5222
|
}
|
|
4945
5223
|
finally { if (e_3) throw e_3.error; }
|
|
4946
5224
|
}
|
|
4947
|
-
|
|
5225
|
+
// TODO: [🍧] Should be done in BLOCK command
|
|
5226
|
+
if (templateJson.blockType === 'SCRIPT') {
|
|
4948
5227
|
if (!language) {
|
|
4949
5228
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
4950
5229
|
}
|
|
4951
|
-
|
|
5230
|
+
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
4952
5231
|
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
5232
|
}
|
|
5233
|
+
templateJson.contentLanguage = language;
|
|
4954
5234
|
}
|
|
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 })));
|
|
5235
|
+
// TODO: [🍧][❔] Should be done in BLOCK command
|
|
4976
5236
|
if (templateModelRequirements.modelVariant === undefined) {
|
|
4977
5237
|
templateModelRequirements.modelVariant = 'CHAT';
|
|
4978
5238
|
}
|
|
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;
|
|
5239
|
+
templateJson.dependentParameterNames = Array.from(extractParametersFromPromptTemplate(templateJson));
|
|
5240
|
+
// TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
|
|
5241
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5242
|
+
delete templateJson.modelRequirements;
|
|
4998
5243
|
}
|
|
5244
|
+
// TODO: [🍧] Make this better - for example each command parser can call and apply this
|
|
5245
|
+
templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
|
|
4999
5246
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
5000
|
-
pipelineJson.promptTemplates.push(
|
|
5247
|
+
pipelineJson.promptTemplates.push(templateJson);
|
|
5001
5248
|
};
|
|
5002
5249
|
try {
|
|
5003
5250
|
// =============================================================
|
|
@@ -5713,14 +5960,14 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5713
5960
|
*/
|
|
5714
5961
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
5715
5962
|
return __awaiter(this, void 0, void 0, function () {
|
|
5716
|
-
var content, modelRequirements, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
5963
|
+
var content, parameters, modelRequirements, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
5717
5964
|
return __generator(this, function (_a) {
|
|
5718
5965
|
switch (_a.label) {
|
|
5719
5966
|
case 0:
|
|
5720
5967
|
if (this.options.isVerbose) {
|
|
5721
5968
|
console.info('💬 Anthropic Claude callChatModel call');
|
|
5722
5969
|
}
|
|
5723
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements;
|
|
5970
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
5724
5971
|
// TODO: [☂] Use here more modelRequirements
|
|
5725
5972
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
5726
5973
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -5736,7 +5983,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5736
5983
|
messages: [
|
|
5737
5984
|
{
|
|
5738
5985
|
role: 'user',
|
|
5739
|
-
content: content,
|
|
5986
|
+
content: replaceParameters(content, parameters),
|
|
5740
5987
|
},
|
|
5741
5988
|
],
|
|
5742
5989
|
// TODO: Is here some equivalent of user identification?> user: this.options.user,
|
|
@@ -5783,14 +6030,14 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5783
6030
|
/*
|
|
5784
6031
|
TODO: [👏]
|
|
5785
6032
|
public async callCompletionModel(
|
|
5786
|
-
prompt: Pick<Prompt, 'content' | 'modelRequirements'>,
|
|
6033
|
+
prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>,
|
|
5787
6034
|
): Promise<PromptCompletionResult> {
|
|
5788
6035
|
|
|
5789
6036
|
if (this.options.isVerbose) {
|
|
5790
6037
|
console.info('🖋 Anthropic Claude callCompletionModel call');
|
|
5791
6038
|
}
|
|
5792
6039
|
|
|
5793
|
-
const { content, modelRequirements } = prompt;
|
|
6040
|
+
const { content, parameters, modelRequirements } = prompt;
|
|
5794
6041
|
|
|
5795
6042
|
// TODO: [☂] Use here more modelRequirements
|
|
5796
6043
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
@@ -5807,7 +6054,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5807
6054
|
|
|
5808
6055
|
const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
|
|
5809
6056
|
...modelSettings,
|
|
5810
|
-
prompt: content,
|
|
6057
|
+
prompt: replaceParameters(content, parameters),
|
|
5811
6058
|
user: this.options.user,
|
|
5812
6059
|
};
|
|
5813
6060
|
const start: string_date_iso8601 = getCurrentIsoDate();
|
|
@@ -6314,14 +6561,14 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6314
6561
|
*/
|
|
6315
6562
|
OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
6316
6563
|
return __awaiter(this, void 0, void 0, function () {
|
|
6317
|
-
var content, modelRequirements, expectFormat, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6564
|
+
var content, parameters, modelRequirements, expectFormat, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6318
6565
|
return __generator(this, function (_a) {
|
|
6319
6566
|
switch (_a.label) {
|
|
6320
6567
|
case 0:
|
|
6321
6568
|
if (this.options.isVerbose) {
|
|
6322
6569
|
console.info('💬 OpenAI callChatModel call', { prompt: prompt });
|
|
6323
6570
|
}
|
|
6324
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
|
|
6571
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
|
|
6325
6572
|
// TODO: [☂] Use here more modelRequirements
|
|
6326
6573
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
6327
6574
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -6350,7 +6597,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6350
6597
|
])), false), [
|
|
6351
6598
|
{
|
|
6352
6599
|
role: 'user',
|
|
6353
|
-
content: content,
|
|
6600
|
+
content: replaceParameters(content, parameters),
|
|
6354
6601
|
},
|
|
6355
6602
|
], false), user: this.options.user });
|
|
6356
6603
|
start = getCurrentIsoDate();
|
|
@@ -6397,14 +6644,14 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6397
6644
|
*/
|
|
6398
6645
|
OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
6399
6646
|
return __awaiter(this, void 0, void 0, function () {
|
|
6400
|
-
var content, modelRequirements, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6647
|
+
var content, parameters, modelRequirements, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6401
6648
|
return __generator(this, function (_a) {
|
|
6402
6649
|
switch (_a.label) {
|
|
6403
6650
|
case 0:
|
|
6404
6651
|
if (this.options.isVerbose) {
|
|
6405
6652
|
console.info('🖋 OpenAI callCompletionModel call', { prompt: prompt });
|
|
6406
6653
|
}
|
|
6407
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements;
|
|
6654
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
6408
6655
|
// TODO: [☂] Use here more modelRequirements
|
|
6409
6656
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
6410
6657
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
@@ -6418,7 +6665,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6418
6665
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
6419
6666
|
// <- Note: [🧆]
|
|
6420
6667
|
};
|
|
6421
|
-
rawRequest = __assign(__assign({}, modelSettings), { prompt: content, user: this.options.user });
|
|
6668
|
+
rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, parameters), user: this.options.user });
|
|
6422
6669
|
start = getCurrentIsoDate();
|
|
6423
6670
|
if (this.options.isVerbose) {
|
|
6424
6671
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
@@ -6460,21 +6707,21 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6460
6707
|
*/
|
|
6461
6708
|
OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
|
|
6462
6709
|
return __awaiter(this, void 0, void 0, function () {
|
|
6463
|
-
var content, modelRequirements, model, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6710
|
+
var content, parameters, modelRequirements, model, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6464
6711
|
return __generator(this, function (_a) {
|
|
6465
6712
|
switch (_a.label) {
|
|
6466
6713
|
case 0:
|
|
6467
6714
|
if (this.options.isVerbose) {
|
|
6468
6715
|
console.info('🖋 OpenAI embedding call', { prompt: prompt });
|
|
6469
6716
|
}
|
|
6470
|
-
content = prompt.content, modelRequirements = prompt.modelRequirements;
|
|
6717
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
6471
6718
|
// TODO: [☂] Use here more modelRequirements
|
|
6472
6719
|
if (modelRequirements.modelVariant !== 'EMBEDDING') {
|
|
6473
6720
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
6474
6721
|
}
|
|
6475
6722
|
model = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
|
|
6476
6723
|
rawRequest = {
|
|
6477
|
-
input: content,
|
|
6724
|
+
input: replaceParameters(content, parameters),
|
|
6478
6725
|
model: model,
|
|
6479
6726
|
// TODO: !!!! Test model 3 and dimensions
|
|
6480
6727
|
};
|
|
@@ -6794,7 +7041,7 @@ function getLlmToolsForCli() {
|
|
|
6794
7041
|
throw new EnvironmentMismatchError('Function `getLlmToolsForTestingAndScriptsAndPlayground` works only in Node.js environment');
|
|
6795
7042
|
}
|
|
6796
7043
|
return cacheLlmTools(createLlmToolsFromEnv(), {
|
|
6797
|
-
storage: new FilesStorage({ cacheFolderPath: join(process.cwd(),
|
|
7044
|
+
storage: new FilesStorage({ cacheFolderPath: join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
|
|
6798
7045
|
});
|
|
6799
7046
|
}
|
|
6800
7047
|
/**
|
|
@@ -6817,8 +7064,8 @@ function stringifyPipelineJson(pipeline) {
|
|
|
6817
7064
|
return pipelineJsonStringified;
|
|
6818
7065
|
}
|
|
6819
7066
|
/**
|
|
7067
|
+
* TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
6820
7068
|
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
6821
|
-
* TODO: [🔼] Export alongside pipelineStringToJson
|
|
6822
7069
|
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
6823
7070
|
*/
|
|
6824
7071
|
|