@promptbook/node 0.61.0-21 → 0.61.0-23
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 +92 -25
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/config.d.ts +8 -4
- package/esm/typings/src/execution/PipelineExecutor.d.ts +32 -24
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +4 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +92 -25
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/_packages/types.index.d.ts +2 -2
- package/umd/typings/src/config.d.ts +8 -4
- package/umd/typings/src/execution/PipelineExecutor.d.ts +32 -24
- package/umd/typings/src/prepare/isPipelinePrepared.d.ts +4 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
|
@@ -4,7 +4,7 @@ import type { CommonExecutionToolsOptions } from '../execution/CommonExecutionTo
|
|
|
4
4
|
import { EmbeddingVector } from '../execution/EmbeddingVector';
|
|
5
5
|
import type { ExecutionTools } from '../execution/ExecutionTools';
|
|
6
6
|
import type { AvailableModel, LlmExecutionTools } from '../execution/LlmExecutionTools';
|
|
7
|
-
import type { PipelineExecutor } from '../execution/PipelineExecutor';
|
|
7
|
+
import type { PipelineExecutor, PipelineExecutorResult } from '../execution/PipelineExecutor';
|
|
8
8
|
import type { ChatPromptResult, CommonPromptResult, CompletionPromptResult, EmbeddingPromptResult, PromptResult } from '../execution/PromptResult';
|
|
9
9
|
import type { PromptResultUsage, PromptResultUsageCounts } from '../execution/PromptResultUsage';
|
|
10
10
|
import type { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
|
|
@@ -36,7 +36,7 @@ import type { FromtoItems } from '../utils/FromtoItems';
|
|
|
36
36
|
import { PROMPTBOOK_VERSION, string_promptbook_version } from '../version';
|
|
37
37
|
export { PROMPTBOOK_VERSION };
|
|
38
38
|
export { EXPECTATION_UNITS };
|
|
39
|
-
export type { AvailableModel, BlockType, CommonExecutionToolsOptions, EmbeddingVector, ExecutionReportJson, ExecutionTools, ExpectationAmount, ExpectationUnit, Expectations, FromtoItems, KnowledgePiecePreparedJson, KnowledgeSourceJson, KnowledgeSourcePreparedJson, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, PersonaJson, PersonaPreparedJson, PipelineCollection, PipelineExecutor, PipelineJson, PipelineString, PreparationJson, Prompt, ChatPromptResult as PromptChatResult, CommonPromptResult as PromptCommonResult, CompletionPromptResult as PromptCompletionResult, PromptDialogJson, EmbeddingPromptResult as PromptEmbeddingResult, PromptResult, PromptResultUsage, PromptResultUsageCounts, PromptTemplateJson, PromptTemplateParameterJson, ReservedParameters, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, TaskProgress, UncertainNumber, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, number_model_temperature, number_seed, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_emails, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_parameter_name, string_parameter_value, string_person_fullname, string_pipeline_url, string_pipeline_url_with_hashtemplate, string_prompt, string_promptbook_documentation_url, string_promptbook_version, string_reserved_parameter_name, string_script, string_semantic_version, string_sha256, string_system_message, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_uuid, };
|
|
39
|
+
export type { AvailableModel, BlockType, CommonExecutionToolsOptions, EmbeddingVector, ExecutionReportJson, ExecutionTools, ExpectationAmount, ExpectationUnit, Expectations, FromtoItems, KnowledgePiecePreparedJson, KnowledgeSourceJson, KnowledgeSourcePreparedJson, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, PersonaJson, PersonaPreparedJson, PipelineCollection, PipelineExecutor, PipelineExecutorResult, PipelineJson, PipelineString, PreparationJson, Prompt, ChatPromptResult as PromptChatResult, CommonPromptResult as PromptCommonResult, CompletionPromptResult as PromptCompletionResult, PromptDialogJson, EmbeddingPromptResult as PromptEmbeddingResult, PromptResult, PromptResultUsage, PromptResultUsageCounts, PromptTemplateJson, PromptTemplateParameterJson, ReservedParameters, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, TaskProgress, UncertainNumber, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, number_model_temperature, number_seed, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_emails, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_parameter_name, string_parameter_value, string_person_fullname, string_pipeline_url, string_pipeline_url_with_hashtemplate, string_prompt, string_promptbook_documentation_url, string_promptbook_version, string_reserved_parameter_name, string_script, string_semantic_version, string_sha256, string_system_message, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_uuid, };
|
|
40
40
|
/**
|
|
41
41
|
* TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
|
|
42
42
|
*/
|
|
@@ -36,18 +36,22 @@ export declare const EXECUTIONS_CACHE_DIRNAME = "/.promptbook/executions-cache";
|
|
|
36
36
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
37
37
|
*/
|
|
38
38
|
export declare const PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
39
|
+
/**
|
|
40
|
+
* Nonce which is used for replacing things in strings
|
|
41
|
+
*/
|
|
42
|
+
export declare const REPLACING_NONCE = "u$k42k%!V2zo34w7Fu#@QUHYPW";
|
|
39
43
|
/**
|
|
40
44
|
* The names of the parameters that are reserved for special purposes
|
|
41
45
|
*/
|
|
42
|
-
export declare const RESERVED_PARAMETER_NAMES: readonly ["context", "currentDate"];
|
|
46
|
+
export declare const RESERVED_PARAMETER_NAMES: readonly ["context", "knowledge", "samples", "modelName", "currentDate"];
|
|
43
47
|
/**
|
|
44
48
|
* @@@
|
|
45
49
|
*/
|
|
46
|
-
export declare const
|
|
50
|
+
export declare const RESERVED_PARAMETER_MISSING_VALUE: string;
|
|
47
51
|
/**
|
|
48
|
-
*
|
|
52
|
+
* @@@
|
|
49
53
|
*/
|
|
50
|
-
export declare const
|
|
54
|
+
export declare const DEBUG_ALLOW_PAYED_TESTING: boolean;
|
|
51
55
|
/**
|
|
52
56
|
* TODO: [🔼] Export all to core
|
|
53
57
|
*/
|
|
@@ -13,30 +13,38 @@ import type { PromptResultUsage } from './PromptResultUsage';
|
|
|
13
13
|
* @see https://github.com/webgptorg/promptbook#executor
|
|
14
14
|
*/
|
|
15
15
|
export type PipelineExecutor = {
|
|
16
|
-
(inputParameters: Parameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
(inputParameters: Parameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<PipelineExecutorResult>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @@@
|
|
20
|
+
*/
|
|
21
|
+
export type PipelineExecutorResult = {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the execution was successful, details are aviable in `executionReport`
|
|
24
|
+
*/
|
|
25
|
+
readonly isSuccessful: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Added usage of whole execution, detailed usage is aviable in `executionReport`
|
|
28
|
+
*/
|
|
29
|
+
readonly usage: PromptResultUsage;
|
|
30
|
+
/**
|
|
31
|
+
* Errors that occured during the execution, details are aviable in `executionReport`
|
|
32
|
+
*/
|
|
33
|
+
readonly errors: Array<PipelineExecutionError | Error>;
|
|
34
|
+
/**
|
|
35
|
+
* Warnings that occured during the execution, details are aviable in `executionReport`
|
|
36
|
+
*/
|
|
37
|
+
readonly warnings: Array<PipelineExecutionError | Error>;
|
|
38
|
+
/**
|
|
39
|
+
* The report of the execution with all details
|
|
40
|
+
*/
|
|
41
|
+
readonly executionReport: ExecutionReportJson;
|
|
42
|
+
/**
|
|
43
|
+
* Result parameters of the execution
|
|
44
|
+
*
|
|
45
|
+
* Note: If the execution was not successful, there are only some of the result parameters
|
|
46
|
+
*/
|
|
47
|
+
readonly outputParameters: Parameters;
|
|
40
48
|
};
|
|
41
49
|
/**
|
|
42
50
|
* TODO: [🧠] Should this file be in /execution or /types folder?
|
|
@@ -7,4 +7,8 @@ export declare function isPipelinePrepared(pipeline: PipelineJson): boolean;
|
|
|
7
7
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
8
8
|
* TODO: [🔼] Export via core or utils
|
|
9
9
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
10
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
11
|
+
* - Is context in each template
|
|
12
|
+
* - Are samples prepared
|
|
13
|
+
* - Are templates prepared
|
|
10
14
|
*/
|
|
@@ -5,5 +5,6 @@ import type { PipelineJson } from '../types/PipelineJson/PipelineJson';
|
|
|
5
5
|
export declare function unpreparePipeline(pipeline: PipelineJson): PipelineJson;
|
|
6
6
|
/**
|
|
7
7
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
8
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
8
9
|
* TODO: Write tests for `preparePipeline`
|
|
9
10
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.61.0-
|
|
3
|
+
"version": "0.61.0-23",
|
|
4
4
|
"description": "Supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
],
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@promptbook/core": "0.61.0-
|
|
54
|
+
"@promptbook/core": "0.61.0-23"
|
|
55
55
|
},
|
|
56
56
|
"main": "./umd/index.umd.js",
|
|
57
57
|
"module": "./esm/index.es.js",
|
package/umd/index.umd.js
CHANGED
|
@@ -191,15 +191,26 @@
|
|
|
191
191
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
192
192
|
*/
|
|
193
193
|
var PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
194
|
+
/**
|
|
195
|
+
* Nonce which is used for replacing things in strings
|
|
196
|
+
*/
|
|
197
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
194
198
|
/**
|
|
195
199
|
* The names of the parameters that are reserved for special purposes
|
|
196
200
|
*/
|
|
197
201
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
198
202
|
'context',
|
|
203
|
+
'knowledge',
|
|
204
|
+
'samples',
|
|
205
|
+
'modelName',
|
|
199
206
|
'currentDate',
|
|
200
207
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
201
208
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
202
209
|
]);
|
|
210
|
+
/**
|
|
211
|
+
* @@@
|
|
212
|
+
*/
|
|
213
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
203
214
|
/*
|
|
204
215
|
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
205
216
|
*/
|
|
@@ -643,7 +654,7 @@
|
|
|
643
654
|
});
|
|
644
655
|
}
|
|
645
656
|
|
|
646
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
657
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-22",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-22",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-22",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-22",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-22",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-22",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-22",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-22",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"}];
|
|
647
658
|
|
|
648
659
|
/**
|
|
649
660
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -911,7 +922,7 @@
|
|
|
911
922
|
throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
912
923
|
}
|
|
913
924
|
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
914
|
-
throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use
|
|
925
|
+
throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name"));
|
|
915
926
|
}
|
|
916
927
|
definedParameters.add(template.resultingParameterName);
|
|
917
928
|
if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
@@ -1088,6 +1099,7 @@
|
|
|
1088
1099
|
}
|
|
1089
1100
|
/**
|
|
1090
1101
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
1102
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1091
1103
|
* TODO: Write tests for `preparePipeline`
|
|
1092
1104
|
*/
|
|
1093
1105
|
|
|
@@ -1567,7 +1579,11 @@
|
|
|
1567
1579
|
throw errors[0];
|
|
1568
1580
|
}
|
|
1569
1581
|
else {
|
|
1570
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
|
|
1582
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
|
|
1583
|
+
.map(function (error, index) {
|
|
1584
|
+
return spaceTrim.spaceTrim(function (block) { return "\n Error ".concat(index + 1, ":\n ").concat(block(error.stack || error.message), "\n "); });
|
|
1585
|
+
})
|
|
1586
|
+
.join('\n')), "\n "); }));
|
|
1571
1587
|
}
|
|
1572
1588
|
}
|
|
1573
1589
|
/**
|
|
@@ -1986,22 +2002,21 @@
|
|
|
1986
2002
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
1987
2003
|
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
1988
2004
|
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
1989
|
-
console.log('!!!!', 'Not all personas have modelRequirements');
|
|
1990
2005
|
return false;
|
|
1991
2006
|
}
|
|
1992
2007
|
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
1993
|
-
console.log('!!!!', 'Not all knowledgeSources have preparationIds');
|
|
1994
2008
|
return false;
|
|
1995
2009
|
}
|
|
1996
|
-
// TODO: !!!!! Is context in each template
|
|
1997
|
-
// TODO: !!!!! Are samples prepared
|
|
1998
|
-
// TODO: !!!!! Are templates prepared
|
|
1999
2010
|
return true;
|
|
2000
2011
|
}
|
|
2001
2012
|
/**
|
|
2002
2013
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2003
2014
|
* TODO: [🔼] Export via core or utils
|
|
2004
2015
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2016
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2017
|
+
* - Is context in each template
|
|
2018
|
+
* - Are samples prepared
|
|
2019
|
+
* - Are templates prepared
|
|
2005
2020
|
*/
|
|
2006
2021
|
|
|
2007
2022
|
/**
|
|
@@ -2063,6 +2078,22 @@
|
|
|
2063
2078
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2064
2079
|
*/
|
|
2065
2080
|
function replaceParameters(template, parameters) {
|
|
2081
|
+
var e_1, _a;
|
|
2082
|
+
try {
|
|
2083
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2084
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
2085
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
2086
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2091
|
+
finally {
|
|
2092
|
+
try {
|
|
2093
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2094
|
+
}
|
|
2095
|
+
finally { if (e_1) throw e_1.error; }
|
|
2096
|
+
}
|
|
2066
2097
|
var replacedTemplate = template;
|
|
2067
2098
|
var match;
|
|
2068
2099
|
var loopLimit = LOOP_LIMIT;
|
|
@@ -2188,7 +2219,7 @@
|
|
|
2188
2219
|
/**
|
|
2189
2220
|
* The version of the Promptbook library
|
|
2190
2221
|
*/
|
|
2191
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
2222
|
+
var PROMPTBOOK_VERSION = '0.61.0-22';
|
|
2192
2223
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2193
2224
|
|
|
2194
2225
|
/**
|
|
@@ -2321,11 +2352,21 @@
|
|
|
2321
2352
|
console.warn(spaceTrim.spaceTrim("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " 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 ")));
|
|
2322
2353
|
}
|
|
2323
2354
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2355
|
+
// TODO: !!!!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
2324
2356
|
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2325
2357
|
template) {
|
|
2326
2358
|
return __awaiter(this, void 0, void 0, function () {
|
|
2327
2359
|
return __generator(this, function (_a) {
|
|
2328
|
-
|
|
2360
|
+
TODO_USE(template);
|
|
2361
|
+
return [2 /*return*/, ''];
|
|
2362
|
+
});
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2365
|
+
function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
|
|
2366
|
+
template) {
|
|
2367
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2368
|
+
return __generator(this, function (_a) {
|
|
2369
|
+
// TODO: !!!! Implement Better - use real index and keyword search
|
|
2329
2370
|
TODO_USE(template);
|
|
2330
2371
|
return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
|
|
2331
2372
|
var content = _a.content;
|
|
@@ -2334,19 +2375,39 @@
|
|
|
2334
2375
|
});
|
|
2335
2376
|
});
|
|
2336
2377
|
}
|
|
2378
|
+
function getSamplesForTemplate(// <- TODO: [🧠][🥜]
|
|
2379
|
+
template) {
|
|
2380
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2381
|
+
return __generator(this, function (_a) {
|
|
2382
|
+
// TODO: !!!! Implement Better - use real index and keyword search
|
|
2383
|
+
TODO_USE(template);
|
|
2384
|
+
return [2 /*return*/, ''];
|
|
2385
|
+
});
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2337
2388
|
function getReservedParametersForTemplate(template) {
|
|
2338
2389
|
return __awaiter(this, void 0, void 0, function () {
|
|
2339
|
-
var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2390
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2340
2391
|
var e_3, _a;
|
|
2341
2392
|
return __generator(this, function (_b) {
|
|
2342
2393
|
switch (_b.label) {
|
|
2343
2394
|
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
2344
2395
|
case 1:
|
|
2345
2396
|
context = _b.sent();
|
|
2397
|
+
return [4 /*yield*/, getKnowledgeForTemplate(template)];
|
|
2398
|
+
case 2:
|
|
2399
|
+
knowledge = _b.sent();
|
|
2400
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
2401
|
+
case 3:
|
|
2402
|
+
samples = _b.sent();
|
|
2346
2403
|
currentDate = new Date().toISOString();
|
|
2404
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
2347
2405
|
reservedParameters = {
|
|
2348
2406
|
context: context,
|
|
2407
|
+
knowledge: knowledge,
|
|
2408
|
+
samples: samples,
|
|
2349
2409
|
currentDate: currentDate,
|
|
2410
|
+
modelName: modelName,
|
|
2350
2411
|
};
|
|
2351
2412
|
try {
|
|
2352
2413
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
@@ -2833,7 +2894,7 @@
|
|
|
2833
2894
|
var parameter = _c.value;
|
|
2834
2895
|
if (parametersToPass[parameter.name] === undefined) {
|
|
2835
2896
|
// [4]
|
|
2836
|
-
|
|
2897
|
+
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not be resolved")));
|
|
2837
2898
|
continue;
|
|
2838
2899
|
}
|
|
2839
2900
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
@@ -2848,7 +2909,7 @@
|
|
|
2848
2909
|
}
|
|
2849
2910
|
return outputParameters;
|
|
2850
2911
|
}
|
|
2851
|
-
var executionReport, _a, _b, parameter, errors, _loop_1, _c, _d, parameterName, state_1, parametersToPass,
|
|
2912
|
+
var executionReport, _a, _b, parameter, errors, warnings, _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;
|
|
2852
2913
|
var e_1, _e, e_2, _f;
|
|
2853
2914
|
return __generator(this, function (_g) {
|
|
2854
2915
|
switch (_g.label) {
|
|
@@ -2883,8 +2944,8 @@
|
|
|
2883
2944
|
isSuccessful: false,
|
|
2884
2945
|
errors: [
|
|
2885
2946
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
|
|
2886
|
-
// <- TODO: !!!!! Test this error
|
|
2887
2947
|
],
|
|
2948
|
+
warnings: [],
|
|
2888
2949
|
executionReport: executionReport,
|
|
2889
2950
|
outputParameters: {},
|
|
2890
2951
|
usage: ZERO_USAGE,
|
|
@@ -2900,21 +2961,22 @@
|
|
|
2900
2961
|
finally { if (e_1) throw e_1.error; }
|
|
2901
2962
|
}
|
|
2902
2963
|
errors = [];
|
|
2964
|
+
warnings = [];
|
|
2903
2965
|
_loop_1 = function (parameterName) {
|
|
2904
2966
|
var parameter = pipeline.parameters.find(function (_a) {
|
|
2905
2967
|
var name = _a.name;
|
|
2906
2968
|
return name === parameterName;
|
|
2907
2969
|
});
|
|
2908
2970
|
if (parameter === undefined) {
|
|
2909
|
-
|
|
2971
|
+
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
2910
2972
|
}
|
|
2911
2973
|
else if (parameter.isInput === false) {
|
|
2912
2974
|
return { value: deepFreezeWithSameType({
|
|
2913
2975
|
isSuccessful: false,
|
|
2914
2976
|
errors: [
|
|
2915
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but is not input")),
|
|
2916
|
-
// <- TODO: !!!!! Test this error
|
|
2977
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input")),
|
|
2917
2978
|
],
|
|
2979
|
+
warnings: warnings,
|
|
2918
2980
|
executionReport: executionReport,
|
|
2919
2981
|
outputParameters: {},
|
|
2920
2982
|
usage: ZERO_USAGE,
|
|
@@ -2941,7 +3003,7 @@
|
|
|
2941
3003
|
_g.label = 3;
|
|
2942
3004
|
case 3:
|
|
2943
3005
|
_g.trys.push([3, 8, , 9]);
|
|
2944
|
-
|
|
3006
|
+
resovedParameterNames_1 = pipeline.parameters
|
|
2945
3007
|
.filter(function (_a) {
|
|
2946
3008
|
var isInput = _a.isInput;
|
|
2947
3009
|
return isInput;
|
|
@@ -2963,7 +3025,9 @@
|
|
|
2963
3025
|
throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
|
|
2964
3026
|
}
|
|
2965
3027
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
2966
|
-
return template.dependentParameterNames.every(function (name) {
|
|
3028
|
+
return template.dependentParameterNames.every(function (name) {
|
|
3029
|
+
return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
|
|
3030
|
+
});
|
|
2967
3031
|
});
|
|
2968
3032
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
2969
3033
|
throw new UnexpectedError(
|
|
@@ -2975,7 +3039,7 @@
|
|
|
2975
3039
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
2976
3040
|
.join(' and '));
|
|
2977
3041
|
})
|
|
2978
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(
|
|
3042
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
|
|
2979
3043
|
case 1:
|
|
2980
3044
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2981
3045
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -2986,7 +3050,7 @@
|
|
|
2986
3050
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
2987
3051
|
work_1 = executeSingleTemplate(currentTemplate)
|
|
2988
3052
|
.then(function () {
|
|
2989
|
-
|
|
3053
|
+
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
|
|
2990
3054
|
})
|
|
2991
3055
|
.then(function () {
|
|
2992
3056
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
@@ -3021,6 +3085,7 @@
|
|
|
3021
3085
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3022
3086
|
isSuccessful: false,
|
|
3023
3087
|
errors: __spreadArray([error_1], __read(errors), false),
|
|
3088
|
+
warnings: warnings,
|
|
3024
3089
|
usage: usage_1,
|
|
3025
3090
|
executionReport: executionReport,
|
|
3026
3091
|
outputParameters: outputParameters_1,
|
|
@@ -3034,6 +3099,7 @@
|
|
|
3034
3099
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3035
3100
|
isSuccessful: true,
|
|
3036
3101
|
errors: errors,
|
|
3102
|
+
warnings: warnings,
|
|
3037
3103
|
usage: usage,
|
|
3038
3104
|
executionReport: executionReport,
|
|
3039
3105
|
outputParameters: outputParameters,
|
|
@@ -3060,7 +3126,7 @@
|
|
|
3060
3126
|
*/
|
|
3061
3127
|
function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
3062
3128
|
return __awaiter(this, void 0, void 0, function () {
|
|
3063
|
-
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters,
|
|
3129
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
|
|
3064
3130
|
var _f, _g, _h;
|
|
3065
3131
|
var _this = this;
|
|
3066
3132
|
return __generator(this, function (_j) {
|
|
@@ -3101,8 +3167,8 @@
|
|
|
3101
3167
|
result = _j.sent();
|
|
3102
3168
|
assertsExecutionSuccessful(result);
|
|
3103
3169
|
outputParameters = result.outputParameters;
|
|
3104
|
-
|
|
3105
|
-
knowledgeTextPieces = (
|
|
3170
|
+
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
3171
|
+
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
3106
3172
|
if (isVerbose) {
|
|
3107
3173
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
3108
3174
|
}
|
|
@@ -3370,7 +3436,8 @@
|
|
|
3370
3436
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3371
3437
|
// ----- /Knowledge preparation -----
|
|
3372
3438
|
// TODO: !!!!! Add context to each template (if missing)
|
|
3373
|
-
// TODO: !!!!!
|
|
3439
|
+
// TODO: !!!!! Add knowledge to each template (if missing and is in pipeline defined)
|
|
3440
|
+
// TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
3374
3441
|
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3375
3442
|
}
|
|
3376
3443
|
});
|