@promptbook/core 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.
@@ -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 DEBUG_ALLOW_PAYED_TESTING: boolean;
50
+ export declare const RESERVED_PARAMETER_MISSING_VALUE: string;
47
51
  /**
48
- * Nonce which is used for replacing things in strings
52
+ * @@@
49
53
  */
50
- export declare const REPLACING_NONCE = "u$k42k%!V2zo34w7Fu#@QUHYPW";
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
- * Whether the execution was successful, details are aviable in `executionReport`
19
- */
20
- readonly isSuccessful: boolean;
21
- /**
22
- * Added usage of whole execution, detailed usage is aviable in `executionReport`
23
- */
24
- readonly usage: PromptResultUsage;
25
- /**
26
- * Errors that occured during the execution, details are aviable in `executionReport`
27
- */
28
- readonly errors: Array<PipelineExecutionError | Error>;
29
- /**
30
- * The report of the execution with all details
31
- */
32
- readonly executionReport: ExecutionReportJson;
33
- /**
34
- * Result parameters of the execution
35
- *
36
- * Note: If the execution was not successful, there are only some of the result parameters
37
- */
38
- readonly outputParameters: Parameters;
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/core",
3
- "version": "0.61.0-21",
3
+ "version": "0.61.0-23",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -473,19 +473,26 @@
473
473
  * The maximum number of attempts to execute LLM task before giving up
474
474
  */
475
475
  var MAX_EXECUTION_ATTEMPTS = 3;
476
+ /**
477
+ * Nonce which is used for replacing things in strings
478
+ */
479
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
476
480
  /**
477
481
  * The names of the parameters that are reserved for special purposes
478
482
  */
479
483
  var RESERVED_PARAMETER_NAMES = deepFreeze([
480
484
  'context',
485
+ 'knowledge',
486
+ 'samples',
487
+ 'modelName',
481
488
  'currentDate',
482
489
  // <- TODO: Add more like 'date', 'modelName',...
483
490
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
484
491
  ]);
485
492
  /**
486
- * Nonce which is used for replacing things in strings
493
+ * @@@
487
494
  */
488
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
495
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
489
496
  /*
490
497
  TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
491
498
  */
@@ -760,7 +767,7 @@
760
767
  throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
761
768
  }
762
769
  if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
763
- throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use fifferent name"));
770
+ throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name"));
764
771
  }
765
772
  definedParameters.add(template.resultingParameterName);
766
773
  if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
@@ -937,6 +944,7 @@
937
944
  }
938
945
  /**
939
946
  * TODO: [🔼] !!! Export via `@promptbook/core`
947
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
940
948
  * TODO: Write tests for `preparePipeline`
941
949
  */
942
950
 
@@ -1454,7 +1462,7 @@
1454
1462
  });
1455
1463
  }
1456
1464
 
1457
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-20",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-20",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-20",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-20",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-20",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-20",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-20",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-20",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"}];
1465
+ 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"}];
1458
1466
 
1459
1467
  var defaultDiacriticsRemovalMap = [
1460
1468
  {
@@ -1827,7 +1835,11 @@
1827
1835
  throw errors[0];
1828
1836
  }
1829
1837
  else {
1830
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
1838
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
1839
+ .map(function (error, index) {
1840
+ return spaceTrim.spaceTrim(function (block) { return "\n Error ".concat(index + 1, ":\n ").concat(block(error.stack || error.message), "\n "); });
1841
+ })
1842
+ .join('\n')), "\n "); }));
1831
1843
  }
1832
1844
  }
1833
1845
  /**
@@ -2246,22 +2258,21 @@
2246
2258
  // Note: Ignoring `pipeline.preparations` @@@
2247
2259
  // Note: Ignoring `pipeline.knowledgePieces` @@@
2248
2260
  if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2249
- console.log('!!!!', 'Not all personas have modelRequirements');
2250
2261
  return false;
2251
2262
  }
2252
2263
  if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2253
- console.log('!!!!', 'Not all knowledgeSources have preparationIds');
2254
2264
  return false;
2255
2265
  }
2256
- // TODO: !!!!! Is context in each template
2257
- // TODO: !!!!! Are samples prepared
2258
- // TODO: !!!!! Are templates prepared
2259
2266
  return true;
2260
2267
  }
2261
2268
  /**
2262
2269
  * TODO: [🐠] Maybe base this on `makeValidator`
2263
2270
  * TODO: [🔼] Export via core or utils
2264
2271
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2272
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2273
+ * - Is context in each template
2274
+ * - Are samples prepared
2275
+ * - Are templates prepared
2265
2276
  */
2266
2277
 
2267
2278
  /**
@@ -2323,6 +2334,22 @@
2323
2334
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
2324
2335
  */
2325
2336
  function replaceParameters(template, parameters) {
2337
+ var e_1, _a;
2338
+ try {
2339
+ for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
2340
+ var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
2341
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
2342
+ throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
2343
+ }
2344
+ }
2345
+ }
2346
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2347
+ finally {
2348
+ try {
2349
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2350
+ }
2351
+ finally { if (e_1) throw e_1.error; }
2352
+ }
2326
2353
  var replacedTemplate = template;
2327
2354
  var match;
2328
2355
  var loopLimit = LOOP_LIMIT;
@@ -2448,7 +2475,7 @@
2448
2475
  /**
2449
2476
  * The version of the Promptbook library
2450
2477
  */
2451
- var PROMPTBOOK_VERSION = '0.61.0-20';
2478
+ var PROMPTBOOK_VERSION = '0.61.0-22';
2452
2479
  // TODO: !!!! List here all the versions and annotate + put into script
2453
2480
 
2454
2481
  /**
@@ -2602,11 +2629,21 @@
2602
2629
  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 ")));
2603
2630
  }
2604
2631
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2632
+ // TODO: !!!!! Extract to separate functions and files - ALL FUNCTIONS BELOW
2605
2633
  function getContextForTemplate(// <- TODO: [🧠][🥜]
2606
2634
  template) {
2607
2635
  return __awaiter(this, void 0, void 0, function () {
2608
2636
  return __generator(this, function (_a) {
2609
- // TODO: !!!!!! Implement Better - use real index and keyword search
2637
+ TODO_USE(template);
2638
+ return [2 /*return*/, ''];
2639
+ });
2640
+ });
2641
+ }
2642
+ function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
2643
+ template) {
2644
+ return __awaiter(this, void 0, void 0, function () {
2645
+ return __generator(this, function (_a) {
2646
+ // TODO: !!!! Implement Better - use real index and keyword search
2610
2647
  TODO_USE(template);
2611
2648
  return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
2612
2649
  var content = _a.content;
@@ -2615,19 +2652,39 @@
2615
2652
  });
2616
2653
  });
2617
2654
  }
2655
+ function getSamplesForTemplate(// <- TODO: [🧠][🥜]
2656
+ template) {
2657
+ return __awaiter(this, void 0, void 0, function () {
2658
+ return __generator(this, function (_a) {
2659
+ // TODO: !!!! Implement Better - use real index and keyword search
2660
+ TODO_USE(template);
2661
+ return [2 /*return*/, ''];
2662
+ });
2663
+ });
2664
+ }
2618
2665
  function getReservedParametersForTemplate(template) {
2619
2666
  return __awaiter(this, void 0, void 0, function () {
2620
- var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
2667
+ var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
2621
2668
  var e_3, _a;
2622
2669
  return __generator(this, function (_b) {
2623
2670
  switch (_b.label) {
2624
2671
  case 0: return [4 /*yield*/, getContextForTemplate(template)];
2625
2672
  case 1:
2626
2673
  context = _b.sent();
2674
+ return [4 /*yield*/, getKnowledgeForTemplate(template)];
2675
+ case 2:
2676
+ knowledge = _b.sent();
2677
+ return [4 /*yield*/, getSamplesForTemplate(template)];
2678
+ case 3:
2679
+ samples = _b.sent();
2627
2680
  currentDate = new Date().toISOString();
2681
+ modelName = RESERVED_PARAMETER_MISSING_VALUE;
2628
2682
  reservedParameters = {
2629
2683
  context: context,
2684
+ knowledge: knowledge,
2685
+ samples: samples,
2630
2686
  currentDate: currentDate,
2687
+ modelName: modelName,
2631
2688
  };
2632
2689
  try {
2633
2690
  // Note: Doublecheck that ALL reserved parameters are defined:
@@ -3114,7 +3171,7 @@
3114
3171
  var parameter = _c.value;
3115
3172
  if (parametersToPass[parameter.name] === undefined) {
3116
3173
  // [4]
3117
- errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
3174
+ warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not be resolved")));
3118
3175
  continue;
3119
3176
  }
3120
3177
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -3129,7 +3186,7 @@
3129
3186
  }
3130
3187
  return outputParameters;
3131
3188
  }
3132
- var executionReport, _a, _b, parameter, errors, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameters_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
3189
+ 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;
3133
3190
  var e_1, _e, e_2, _f;
3134
3191
  return __generator(this, function (_g) {
3135
3192
  switch (_g.label) {
@@ -3164,8 +3221,8 @@
3164
3221
  isSuccessful: false,
3165
3222
  errors: [
3166
3223
  new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
3167
- // <- TODO: !!!!! Test this error
3168
3224
  ],
3225
+ warnings: [],
3169
3226
  executionReport: executionReport,
3170
3227
  outputParameters: {},
3171
3228
  usage: ZERO_USAGE,
@@ -3181,21 +3238,22 @@
3181
3238
  finally { if (e_1) throw e_1.error; }
3182
3239
  }
3183
3240
  errors = [];
3241
+ warnings = [];
3184
3242
  _loop_1 = function (parameterName) {
3185
3243
  var parameter = pipeline.parameters.find(function (_a) {
3186
3244
  var name = _a.name;
3187
3245
  return name === parameterName;
3188
3246
  });
3189
3247
  if (parameter === undefined) {
3190
- errors.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is passed as input parameter")));
3248
+ warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
3191
3249
  }
3192
3250
  else if (parameter.isInput === false) {
3193
3251
  return { value: deepFreezeWithSameType({
3194
3252
  isSuccessful: false,
3195
3253
  errors: [
3196
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but is not input")),
3197
- // <- TODO: !!!!! Test this error
3254
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input")),
3198
3255
  ],
3256
+ warnings: warnings,
3199
3257
  executionReport: executionReport,
3200
3258
  outputParameters: {},
3201
3259
  usage: ZERO_USAGE,
@@ -3222,7 +3280,7 @@
3222
3280
  _g.label = 3;
3223
3281
  case 3:
3224
3282
  _g.trys.push([3, 8, , 9]);
3225
- resovedParameters_1 = pipeline.parameters
3283
+ resovedParameterNames_1 = pipeline.parameters
3226
3284
  .filter(function (_a) {
3227
3285
  var isInput = _a.isInput;
3228
3286
  return isInput;
@@ -3244,7 +3302,9 @@
3244
3302
  throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
3245
3303
  }
3246
3304
  currentTemplate = unresovedTemplates_1.find(function (template) {
3247
- return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
3305
+ return template.dependentParameterNames.every(function (name) {
3306
+ return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
3307
+ });
3248
3308
  });
3249
3309
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
3250
3310
  throw new UnexpectedError(
@@ -3256,7 +3316,7 @@
3256
3316
  .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
3257
3317
  .join(' and '));
3258
3318
  })
3259
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
3319
+ .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 "); }));
3260
3320
  case 1:
3261
3321
  if (!!currentTemplate) return [3 /*break*/, 3];
3262
3322
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
@@ -3267,7 +3327,7 @@
3267
3327
  unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
3268
3328
  work_1 = executeSingleTemplate(currentTemplate)
3269
3329
  .then(function () {
3270
- resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
3330
+ resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
3271
3331
  })
3272
3332
  .then(function () {
3273
3333
  resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
@@ -3302,6 +3362,7 @@
3302
3362
  return [2 /*return*/, deepFreezeWithSameType({
3303
3363
  isSuccessful: false,
3304
3364
  errors: __spreadArray([error_1], __read(errors), false),
3365
+ warnings: warnings,
3305
3366
  usage: usage_1,
3306
3367
  executionReport: executionReport,
3307
3368
  outputParameters: outputParameters_1,
@@ -3315,6 +3376,7 @@
3315
3376
  return [2 /*return*/, deepFreezeWithSameType({
3316
3377
  isSuccessful: true,
3317
3378
  errors: errors,
3379
+ warnings: warnings,
3318
3380
  usage: usage,
3319
3381
  executionReport: executionReport,
3320
3382
  outputParameters: outputParameters,
@@ -3341,7 +3403,7 @@
3341
3403
  */
3342
3404
  function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
3343
3405
  return __awaiter(this, void 0, void 0, function () {
3344
- var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
3406
+ var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
3345
3407
  var _f, _g, _h;
3346
3408
  var _this = this;
3347
3409
  return __generator(this, function (_j) {
@@ -3382,8 +3444,8 @@
3382
3444
  result = _j.sent();
3383
3445
  assertsExecutionSuccessful(result);
3384
3446
  outputParameters = result.outputParameters;
3385
- knowledgeRaw = outputParameters.knowledge;
3386
- knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
3447
+ knowledgePiecesRaw = outputParameters.knowledgePieces;
3448
+ knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
3387
3449
  if (isVerbose) {
3388
3450
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
3389
3451
  }
@@ -3651,7 +3713,8 @@
3651
3713
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3652
3714
  // ----- /Knowledge preparation -----
3653
3715
  // TODO: !!!!! Add context to each template (if missing)
3654
- // TODO: !!!!! Apply samples to each template (if missing)
3716
+ // TODO: !!!!! Add knowledge to each template (if missing and is in pipeline defined)
3717
+ // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
3655
3718
  return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3656
3719
  }
3657
3720
  });