@promptbook/core 0.61.0-23 → 0.61.0-25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/esm/index.es.js +170 -71
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/config.d.ts +5 -1
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +1 -1
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
- package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
- package/esm/typings/src/utils/extractParameters.d.ts +3 -0
- package/package.json +1 -1
- package/umd/index.umd.js +170 -71
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/config.d.ts +5 -1
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +1 -1
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
- package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -0
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
- package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
- package/umd/typings/src/utils/extractParameters.d.ts +3 -0
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ File `write-website-content.ptbk.md`:
|
|
|
88
88
|
> - PROMPTBOOK VERSION 0.0.1
|
|
89
89
|
> - INPUT PARAM `{rawTitle}` Automatically suggested a site name or empty text
|
|
90
90
|
> - INPUT PARAM `{rawAssigment}` Automatically generated site entry from image recognition
|
|
91
|
-
> - OUTPUT PARAM `{
|
|
91
|
+
> - OUTPUT PARAM `{websiteContent}` Web content
|
|
92
92
|
> - OUTPUT PARAM `{keywords}` Keywords
|
|
93
93
|
>
|
|
94
94
|
> ## 👤 Specifying the assigment
|
|
@@ -247,7 +247,7 @@ File `write-website-content.ptbk.md`:
|
|
|
247
247
|
> {contentBody}
|
|
248
248
|
> ```
|
|
249
249
|
>
|
|
250
|
-
> `-> {
|
|
250
|
+
> `-> {websiteContent}`
|
|
251
251
|
|
|
252
252
|
|
|
253
253
|
|
|
@@ -287,7 +287,7 @@ flowchart LR
|
|
|
287
287
|
templateCombineTheBeginning--"{contentBeginning}"-->templateCombineTheContent
|
|
288
288
|
templateWriteTheContent--"{contentBody}"-->templateCombineTheContent
|
|
289
289
|
|
|
290
|
-
templateCombineTheContent--"{
|
|
290
|
+
templateCombineTheContent--"{websiteContent}"-->output
|
|
291
291
|
output((Output)):::output
|
|
292
292
|
|
|
293
293
|
classDef input color: grey;
|
package/esm/index.es.js
CHANGED
|
@@ -474,6 +474,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
474
474
|
* The names of the parameters that are reserved for special purposes
|
|
475
475
|
*/
|
|
476
476
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
477
|
+
'content',
|
|
477
478
|
'context',
|
|
478
479
|
'knowledge',
|
|
479
480
|
'samples',
|
|
@@ -486,6 +487,10 @@ var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
|
486
487
|
* @@@
|
|
487
488
|
*/
|
|
488
489
|
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
490
|
+
/**
|
|
491
|
+
* @@@
|
|
492
|
+
*/
|
|
493
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
489
494
|
/*
|
|
490
495
|
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
491
496
|
*/
|
|
@@ -926,19 +931,58 @@ var ReferenceError$1 = /** @class */ (function (_super) {
|
|
|
926
931
|
return ReferenceError;
|
|
927
932
|
}(Error));
|
|
928
933
|
|
|
934
|
+
/**
|
|
935
|
+
* Parses the template and returns the list of all parameter names
|
|
936
|
+
*
|
|
937
|
+
* @param template the template with parameters in {curly} braces
|
|
938
|
+
* @returns the list of parameter names
|
|
939
|
+
*/
|
|
940
|
+
function extractParameters(template) {
|
|
941
|
+
var e_1, _a;
|
|
942
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
943
|
+
var parameterNames = new Set();
|
|
944
|
+
try {
|
|
945
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
946
|
+
var match = matches_1_1.value;
|
|
947
|
+
var parameterName = match[0].slice(1, -1);
|
|
948
|
+
parameterNames.add(parameterName);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
952
|
+
finally {
|
|
953
|
+
try {
|
|
954
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
955
|
+
}
|
|
956
|
+
finally { if (e_1) throw e_1.error; }
|
|
957
|
+
}
|
|
958
|
+
return parameterNames;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* TODO: !!!!! Rename to extractParameterNames
|
|
962
|
+
*/
|
|
963
|
+
|
|
929
964
|
/**
|
|
930
965
|
* Unprepare just strips the preparation data of the pipeline
|
|
931
966
|
*/
|
|
932
967
|
function unpreparePipeline(pipeline) {
|
|
933
|
-
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
|
|
968
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
|
|
934
969
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
935
970
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
936
|
-
|
|
971
|
+
promptTemplates = promptTemplates.map(function (promptTemplate) {
|
|
972
|
+
var dependentParameterNames = promptTemplate.dependentParameterNames;
|
|
973
|
+
var parameterNames = extractParameters(promptTemplate.preparedContent || '');
|
|
974
|
+
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
975
|
+
var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
|
|
976
|
+
delete promptTemplateUnprepared.preparedContent;
|
|
977
|
+
return promptTemplateUnprepared;
|
|
978
|
+
});
|
|
979
|
+
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
937
980
|
}
|
|
938
981
|
/**
|
|
939
982
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
940
983
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
941
984
|
* TODO: Write tests for `preparePipeline`
|
|
985
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
942
986
|
*/
|
|
943
987
|
|
|
944
988
|
/**
|
|
@@ -1455,7 +1499,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1455
1499
|
});
|
|
1456
1500
|
}
|
|
1457
1501
|
|
|
1458
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
1502
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-24",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-24",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-24",parameters:[{name:"knowledgePieceContent",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> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-24",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-24",parameters:[{name:"knowledgePieceContent",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> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-24",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-24",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-24",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"}];
|
|
1459
1503
|
|
|
1460
1504
|
var defaultDiacriticsRemovalMap = [
|
|
1461
1505
|
{
|
|
@@ -1839,33 +1883,6 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1839
1883
|
* TODO: [🧠] Can this return type be better typed than void
|
|
1840
1884
|
*/
|
|
1841
1885
|
|
|
1842
|
-
/**
|
|
1843
|
-
* Parses the template and returns the list of all parameter names
|
|
1844
|
-
*
|
|
1845
|
-
* @param template the template with parameters in {curly} braces
|
|
1846
|
-
* @returns the list of parameter names
|
|
1847
|
-
*/
|
|
1848
|
-
function extractParameters(template) {
|
|
1849
|
-
var e_1, _a;
|
|
1850
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
1851
|
-
var parameterNames = new Set();
|
|
1852
|
-
try {
|
|
1853
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1854
|
-
var match = matches_1_1.value;
|
|
1855
|
-
var parameterName = match[0].slice(1, -1);
|
|
1856
|
-
parameterNames.add(parameterName);
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1860
|
-
finally {
|
|
1861
|
-
try {
|
|
1862
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1863
|
-
}
|
|
1864
|
-
finally { if (e_1) throw e_1.error; }
|
|
1865
|
-
}
|
|
1866
|
-
return parameterNames;
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
1886
|
/**
|
|
1870
1887
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1871
1888
|
*
|
|
@@ -1923,10 +1940,10 @@ function extractVariables(script) {
|
|
|
1923
1940
|
*/
|
|
1924
1941
|
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
1925
1942
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1926
|
-
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1943
|
+
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1927
1944
|
var parameterNames = new Set();
|
|
1928
1945
|
try {
|
|
1929
|
-
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()) {
|
|
1946
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(title)), false), __read(extractParameters(description || '')), false), __read(extractParameters(content)), false), __read(extractParameters(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1930
1947
|
var parameterName = _e.value;
|
|
1931
1948
|
parameterNames.add(parameterName);
|
|
1932
1949
|
}
|
|
@@ -1966,6 +1983,8 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
1966
1983
|
}
|
|
1967
1984
|
finally { if (e_3) throw e_3.error; }
|
|
1968
1985
|
}
|
|
1986
|
+
parameterNames.delete('content');
|
|
1987
|
+
// <- Note {websiteContent} is used in `preparedContent`
|
|
1969
1988
|
return parameterNames;
|
|
1970
1989
|
}
|
|
1971
1990
|
/**
|
|
@@ -2135,7 +2154,14 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2135
2154
|
throw errors[0];
|
|
2136
2155
|
}
|
|
2137
2156
|
else if (errors.length > 1) {
|
|
2138
|
-
throw new PipelineExecutionError(
|
|
2157
|
+
throw new PipelineExecutionError(
|
|
2158
|
+
// TODO: Tell which execution tools failed like
|
|
2159
|
+
// 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2160
|
+
// 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2161
|
+
// 3) ...
|
|
2162
|
+
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2163
|
+
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2164
|
+
.join('\n')), "\n\n "); }));
|
|
2139
2165
|
}
|
|
2140
2166
|
else {
|
|
2141
2167
|
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
|
|
@@ -2256,6 +2282,12 @@ function isPipelinePrepared(pipeline) {
|
|
|
2256
2282
|
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2257
2283
|
return false;
|
|
2258
2284
|
}
|
|
2285
|
+
/*
|
|
2286
|
+
TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
|
|
2287
|
+
> if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2288
|
+
> return false;
|
|
2289
|
+
> }
|
|
2290
|
+
*/
|
|
2259
2291
|
return true;
|
|
2260
2292
|
}
|
|
2261
2293
|
/**
|
|
@@ -2334,6 +2366,10 @@ function replaceParameters(template, parameters) {
|
|
|
2334
2366
|
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
2335
2367
|
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
2336
2368
|
}
|
|
2369
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
2370
|
+
// TODO: [🍵]
|
|
2371
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
|
|
2372
|
+
}
|
|
2337
2373
|
}
|
|
2338
2374
|
}
|
|
2339
2375
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -2468,7 +2504,7 @@ function union() {
|
|
|
2468
2504
|
/**
|
|
2469
2505
|
* The version of the Promptbook library
|
|
2470
2506
|
*/
|
|
2471
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
2507
|
+
var PROMPTBOOK_VERSION = '0.61.0-24';
|
|
2472
2508
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2473
2509
|
|
|
2474
2510
|
/**
|
|
@@ -2619,16 +2655,17 @@ function createPipelineExecutor(options) {
|
|
|
2619
2655
|
pipeline = rawPipeline;
|
|
2620
2656
|
}
|
|
2621
2657
|
else {
|
|
2622
|
-
|
|
2658
|
+
// TODO: !!!! This should be maybe warning in report
|
|
2659
|
+
console.warn(spaceTrim$1("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n ").concat(rawPipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
|
|
2623
2660
|
}
|
|
2624
2661
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2625
|
-
// TODO:
|
|
2662
|
+
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
2626
2663
|
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2627
2664
|
template) {
|
|
2628
2665
|
return __awaiter(this, void 0, void 0, function () {
|
|
2629
2666
|
return __generator(this, function (_a) {
|
|
2630
2667
|
TODO_USE(template);
|
|
2631
|
-
return [2 /*return*/,
|
|
2668
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
|
|
2632
2669
|
});
|
|
2633
2670
|
});
|
|
2634
2671
|
}
|
|
@@ -2651,7 +2688,7 @@ function createPipelineExecutor(options) {
|
|
|
2651
2688
|
return __generator(this, function (_a) {
|
|
2652
2689
|
// TODO: !!!! Implement Better - use real index and keyword search
|
|
2653
2690
|
TODO_USE(template);
|
|
2654
|
-
return [2 /*return*/,
|
|
2691
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
|
|
2655
2692
|
});
|
|
2656
2693
|
});
|
|
2657
2694
|
}
|
|
@@ -2673,6 +2710,7 @@ function createPipelineExecutor(options) {
|
|
|
2673
2710
|
currentDate = new Date().toISOString();
|
|
2674
2711
|
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
2675
2712
|
reservedParameters = {
|
|
2713
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
2676
2714
|
context: context,
|
|
2677
2715
|
knowledge: knowledge,
|
|
2678
2716
|
samples: samples,
|
|
@@ -2702,7 +2740,7 @@ function createPipelineExecutor(options) {
|
|
|
2702
2740
|
}
|
|
2703
2741
|
function executeSingleTemplate(currentTemplate) {
|
|
2704
2742
|
return __awaiter(this, void 0, void 0, function () {
|
|
2705
|
-
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;
|
|
2743
|
+
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
|
|
2706
2744
|
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2707
2745
|
var _this = this;
|
|
2708
2746
|
return __generator(this, function (_u) {
|
|
@@ -2772,6 +2810,9 @@ function createPipelineExecutor(options) {
|
|
|
2772
2810
|
expectError = null;
|
|
2773
2811
|
maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
2774
2812
|
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
2813
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
2814
|
+
.split('{content}')
|
|
2815
|
+
.join(currentTemplate.content);
|
|
2775
2816
|
attempt = -jokerParameterNames.length;
|
|
2776
2817
|
_u.label = 4;
|
|
2777
2818
|
case 4:
|
|
@@ -2806,7 +2847,7 @@ function createPipelineExecutor(options) {
|
|
|
2806
2847
|
}
|
|
2807
2848
|
return [3 /*break*/, 29];
|
|
2808
2849
|
case 6:
|
|
2809
|
-
resultString = replaceParameters(
|
|
2850
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
2810
2851
|
return [3 /*break*/, 30];
|
|
2811
2852
|
case 7:
|
|
2812
2853
|
prompt = {
|
|
@@ -2815,7 +2856,7 @@ function createPipelineExecutor(options) {
|
|
|
2815
2856
|
? pipeline.pipelineUrl
|
|
2816
2857
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
2817
2858
|
parameters: parameters,
|
|
2818
|
-
content:
|
|
2859
|
+
content: preparedContent,
|
|
2819
2860
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2820
2861
|
expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
|
|
2821
2862
|
var name = _a.name;
|
|
@@ -2937,7 +2978,7 @@ function createPipelineExecutor(options) {
|
|
|
2937
2978
|
_u.trys.push([19, 21, , 22]);
|
|
2938
2979
|
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2939
2980
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2940
|
-
script:
|
|
2981
|
+
script: preparedContent,
|
|
2941
2982
|
parameters: parameters,
|
|
2942
2983
|
}))];
|
|
2943
2984
|
case 20:
|
|
@@ -2986,7 +3027,7 @@ function createPipelineExecutor(options) {
|
|
|
2986
3027
|
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2987
3028
|
promptTitle: currentTemplate.title,
|
|
2988
3029
|
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
2989
|
-
defaultValue: replaceParameters(
|
|
3030
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
2990
3031
|
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
2991
3032
|
placeholder: undefined,
|
|
2992
3033
|
priority: priority,
|
|
@@ -3164,7 +3205,7 @@ function createPipelineExecutor(options) {
|
|
|
3164
3205
|
var parameter = _c.value;
|
|
3165
3206
|
if (parametersToPass[parameter.name] === undefined) {
|
|
3166
3207
|
// [4]
|
|
3167
|
-
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not
|
|
3208
|
+
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3168
3209
|
continue;
|
|
3169
3210
|
}
|
|
3170
3211
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
@@ -3179,7 +3220,7 @@ function createPipelineExecutor(options) {
|
|
|
3179
3220
|
}
|
|
3180
3221
|
return outputParameters;
|
|
3181
3222
|
}
|
|
3182
|
-
var executionReport, _a, _b, parameter,
|
|
3223
|
+
var errors, warnings, executionReport, _a, _b, parameter, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3183
3224
|
var e_1, _e, e_2, _f;
|
|
3184
3225
|
return __generator(this, function (_g) {
|
|
3185
3226
|
switch (_g.label) {
|
|
@@ -3194,6 +3235,8 @@ function createPipelineExecutor(options) {
|
|
|
3194
3235
|
pipeline = _g.sent();
|
|
3195
3236
|
_g.label = 2;
|
|
3196
3237
|
case 2:
|
|
3238
|
+
errors = [];
|
|
3239
|
+
warnings = [];
|
|
3197
3240
|
executionReport = {
|
|
3198
3241
|
pipelineUrl: pipeline.pipelineUrl,
|
|
3199
3242
|
title: pipeline.title,
|
|
@@ -3212,9 +3255,9 @@ function createPipelineExecutor(options) {
|
|
|
3212
3255
|
if (inputParameters[parameter.name] === undefined) {
|
|
3213
3256
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3214
3257
|
isSuccessful: false,
|
|
3215
|
-
errors: [
|
|
3216
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3217
|
-
],
|
|
3258
|
+
errors: __spreadArray([
|
|
3259
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3260
|
+
], __read(errors), false),
|
|
3218
3261
|
warnings: [],
|
|
3219
3262
|
executionReport: executionReport,
|
|
3220
3263
|
outputParameters: {},
|
|
@@ -3230,8 +3273,6 @@ function createPipelineExecutor(options) {
|
|
|
3230
3273
|
}
|
|
3231
3274
|
finally { if (e_1) throw e_1.error; }
|
|
3232
3275
|
}
|
|
3233
|
-
errors = [];
|
|
3234
|
-
warnings = [];
|
|
3235
3276
|
_loop_1 = function (parameterName) {
|
|
3236
3277
|
var parameter = pipeline.parameters.find(function (_a) {
|
|
3237
3278
|
var name = _a.name;
|
|
@@ -3243,9 +3284,9 @@ function createPipelineExecutor(options) {
|
|
|
3243
3284
|
else if (parameter.isInput === false) {
|
|
3244
3285
|
return { value: deepFreezeWithSameType({
|
|
3245
3286
|
isSuccessful: false,
|
|
3246
|
-
errors: [
|
|
3247
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3248
|
-
],
|
|
3287
|
+
errors: __spreadArray([
|
|
3288
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3289
|
+
], __read(errors), false),
|
|
3249
3290
|
warnings: warnings,
|
|
3250
3291
|
executionReport: executionReport,
|
|
3251
3292
|
outputParameters: {},
|
|
@@ -3380,6 +3421,8 @@ function createPipelineExecutor(options) {
|
|
|
3380
3421
|
return pipelineExecutor;
|
|
3381
3422
|
}
|
|
3382
3423
|
/**
|
|
3424
|
+
* TODO: !!!! return `preparedPipeline` from execution
|
|
3425
|
+
* TODO: !!!! `isNotPreparedWarningSupressed`
|
|
3383
3426
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3384
3427
|
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
3385
3428
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
@@ -3394,7 +3437,7 @@ function createPipelineExecutor(options) {
|
|
|
3394
3437
|
/**
|
|
3395
3438
|
* @@@
|
|
3396
3439
|
*/
|
|
3397
|
-
function prepareKnowledgeFromMarkdown(
|
|
3440
|
+
function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
3398
3441
|
return __awaiter(this, void 0, void 0, function () {
|
|
3399
3442
|
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
|
|
3400
3443
|
var _f, _g, _h;
|
|
@@ -3432,7 +3475,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3432
3475
|
llm: llmTools,
|
|
3433
3476
|
},
|
|
3434
3477
|
_h)]);
|
|
3435
|
-
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({
|
|
3478
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
3436
3479
|
case 4:
|
|
3437
3480
|
result = _j.sent();
|
|
3438
3481
|
assertsExecutionSuccessful(result);
|
|
@@ -3445,25 +3488,25 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3445
3488
|
return [4 /*yield*/, Promise.all(
|
|
3446
3489
|
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
3447
3490
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
3448
|
-
var name, title,
|
|
3491
|
+
var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
3449
3492
|
return __generator(this, function (_c) {
|
|
3450
3493
|
switch (_c.label) {
|
|
3451
3494
|
case 0:
|
|
3452
3495
|
name = "piece-".concat(i);
|
|
3453
3496
|
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
3454
|
-
|
|
3497
|
+
knowledgePieceContent = spaceTrim(knowledgeTextPiece);
|
|
3455
3498
|
keywords = [];
|
|
3456
3499
|
index = [];
|
|
3457
3500
|
_c.label = 1;
|
|
3458
3501
|
case 1:
|
|
3459
3502
|
_c.trys.push([1, 7, , 8]);
|
|
3460
|
-
return [4 /*yield*/, prepareTitleExecutor({
|
|
3503
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
3461
3504
|
case 2:
|
|
3462
3505
|
titleResult = _c.sent();
|
|
3463
3506
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
3464
3507
|
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3465
3508
|
name = titleToName(title);
|
|
3466
|
-
return [4 /*yield*/, prepareKeywordsExecutor({
|
|
3509
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
3467
3510
|
case 3:
|
|
3468
3511
|
keywordsResult = _c.sent();
|
|
3469
3512
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|
|
@@ -3481,7 +3524,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3481
3524
|
case 4: return [4 /*yield*/, llmTools.callEmbeddingModel({
|
|
3482
3525
|
title: "Embedding for ".concat(title) /* <- Note: No impact on embedding result itself, just for logging */,
|
|
3483
3526
|
parameters: {},
|
|
3484
|
-
content:
|
|
3527
|
+
content: knowledgePieceContent,
|
|
3485
3528
|
modelRequirements: {
|
|
3486
3529
|
modelVariant: 'EMBEDDING',
|
|
3487
3530
|
},
|
|
@@ -3502,7 +3545,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3502
3545
|
case 8: return [2 /*return*/, {
|
|
3503
3546
|
name: name,
|
|
3504
3547
|
title: title,
|
|
3505
|
-
content:
|
|
3548
|
+
content: knowledgePieceContent,
|
|
3506
3549
|
keywords: keywords,
|
|
3507
3550
|
index: index,
|
|
3508
3551
|
// <- TODO: [☀] sources,
|
|
@@ -3652,6 +3695,57 @@ function preparePersona(personaDescription, options) {
|
|
|
3652
3695
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
3653
3696
|
*/
|
|
3654
3697
|
|
|
3698
|
+
/**
|
|
3699
|
+
* @@@
|
|
3700
|
+
*/
|
|
3701
|
+
function prepareTemplates(pipeline, options) {
|
|
3702
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3703
|
+
var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
|
|
3704
|
+
var _this = this;
|
|
3705
|
+
return __generator(this, function (_b) {
|
|
3706
|
+
switch (_b.label) {
|
|
3707
|
+
case 0:
|
|
3708
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3709
|
+
promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3710
|
+
// TODO: !!!! Apply samples to each template (if missing and is for the template defined)
|
|
3711
|
+
TODO_USE(parameters);
|
|
3712
|
+
promptTemplatesPrepared = new Array(promptTemplates.length);
|
|
3713
|
+
return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3714
|
+
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
3715
|
+
return __generator(this, function (_a) {
|
|
3716
|
+
dependentParameterNames = template.dependentParameterNames;
|
|
3717
|
+
preparedContent = undefined;
|
|
3718
|
+
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
3719
|
+
preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
3720
|
+
// <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
|
|
3721
|
+
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
3722
|
+
'knowledge',
|
|
3723
|
+
], false);
|
|
3724
|
+
}
|
|
3725
|
+
preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
3726
|
+
promptTemplatesPrepared[index] = preparedTemplate;
|
|
3727
|
+
return [2 /*return*/];
|
|
3728
|
+
});
|
|
3729
|
+
}); })];
|
|
3730
|
+
case 1:
|
|
3731
|
+
_b.sent();
|
|
3732
|
+
return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
|
|
3733
|
+
}
|
|
3734
|
+
});
|
|
3735
|
+
});
|
|
3736
|
+
}
|
|
3737
|
+
/**
|
|
3738
|
+
* TODO: [🧠] Add context to each template (if missing)
|
|
3739
|
+
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3740
|
+
* TODO: !!!!! Index the samples and maybe templates
|
|
3741
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3742
|
+
* TODO: Write tests for `preparePipeline`
|
|
3743
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3744
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3745
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3746
|
+
* TODO: [🧠][🥜]
|
|
3747
|
+
*/
|
|
3748
|
+
|
|
3655
3749
|
/**
|
|
3656
3750
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
3657
3751
|
*
|
|
@@ -3660,18 +3754,18 @@ function preparePersona(personaDescription, options) {
|
|
|
3660
3754
|
*/
|
|
3661
3755
|
function preparePipeline(pipeline, options) {
|
|
3662
3756
|
return __awaiter(this, void 0, void 0, function () {
|
|
3663
|
-
var _a, maxParallelCount,
|
|
3757
|
+
var _a, maxParallelCount, parameters, promptTemplates,
|
|
3664
3758
|
/*
|
|
3665
3759
|
<- TODO: [🧠][0] `promptbookVersion` */
|
|
3666
3760
|
knowledgeSources /*
|
|
3667
3761
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3668
|
-
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared
|
|
3762
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3669
3763
|
var _this = this;
|
|
3670
3764
|
return __generator(this, function (_b) {
|
|
3671
3765
|
switch (_b.label) {
|
|
3672
3766
|
case 0:
|
|
3673
3767
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3674
|
-
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3768
|
+
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3675
3769
|
currentPreparation = {
|
|
3676
3770
|
id: 1,
|
|
3677
3771
|
// TODO: [🍥]> date: $currentDate(),
|
|
@@ -3704,17 +3798,20 @@ function preparePipeline(pipeline, options) {
|
|
|
3704
3798
|
case 2:
|
|
3705
3799
|
partialknowledgePiecesPrepared = _b.sent();
|
|
3706
3800
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3801
|
+
return [4 /*yield*/, prepareTemplates({
|
|
3802
|
+
parameters: parameters,
|
|
3803
|
+
promptTemplates: promptTemplates,
|
|
3804
|
+
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3805
|
+
}, options)];
|
|
3806
|
+
case 3:
|
|
3807
|
+
promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
|
|
3808
|
+
// ----- /Templates preparation -----
|
|
3809
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3712
3810
|
}
|
|
3713
3811
|
});
|
|
3714
3812
|
});
|
|
3715
3813
|
}
|
|
3716
3814
|
/**
|
|
3717
|
-
* TODO: !!!!! Index the samples and maybe templates
|
|
3718
3815
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3719
3816
|
* TODO: Write tests for `preparePipeline`
|
|
3720
3817
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
@@ -4424,7 +4521,7 @@ var parameterCommandParser = {
|
|
|
4424
4521
|
/**
|
|
4425
4522
|
* Example usages of the PARAMETER command
|
|
4426
4523
|
*/
|
|
4427
|
-
examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {
|
|
4524
|
+
examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {websiteContent} Content of the book'],
|
|
4428
4525
|
/**
|
|
4429
4526
|
* Parses the PARAMETER command
|
|
4430
4527
|
*/
|
|
@@ -5630,6 +5727,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5630
5727
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
5631
5728
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
5632
5729
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
5730
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
5633
5731
|
*/
|
|
5634
5732
|
|
|
5635
5733
|
/**
|
|
@@ -5866,6 +5964,7 @@ function stringifyPipelineJson(pipeline) {
|
|
|
5866
5964
|
* TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
5867
5965
|
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
5868
5966
|
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
5967
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
5869
5968
|
*/
|
|
5870
5969
|
|
|
5871
5970
|
/**
|