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