@promptbook/node 0.61.0-10 → 0.61.0-11

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.
Files changed (123) hide show
  1. package/esm/index.es.js +339 -214
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/promptbook-collection/index.d.ts +83 -2
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/utils.index.d.ts +3 -1
  7. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
  8. package/esm/typings/src/config.d.ts +4 -0
  9. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
  10. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
  11. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +4 -0
  12. package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  13. package/{umd/typings/src/errors/VersionMismatch.d.ts → esm/typings/src/errors/VersionMismatchError.d.ts} +1 -1
  14. package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -1
  15. package/esm/typings/src/execution/PipelineExecutor.d.ts +4 -3
  16. package/esm/typings/src/execution/PromptResult.d.ts +12 -0
  17. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
  18. package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -0
  19. package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
  20. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  21. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  22. package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  23. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  24. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  25. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
  26. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
  27. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  28. package/esm/typings/src/llm-providers/utils/cache/CacheItem.d.ts +29 -0
  29. package/esm/typings/src/llm-providers/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  30. package/esm/typings/src/llm-providers/utils/cache/cacheLlmTools.d.ts +17 -0
  31. package/esm/typings/src/llm-providers/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  32. package/esm/typings/src/llm-providers/utils/count-total-cost/countTotalCost.d.ts +14 -0
  33. package/esm/typings/src/llm-providers/utils/createLlmToolsFromEnv.d.ts +21 -0
  34. package/esm/typings/src/personas/preparePersona.d.ts +0 -3
  35. package/esm/typings/src/prepare/preparePipeline.d.ts +2 -1
  36. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +24 -0
  37. package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  38. package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +28 -0
  39. package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +10 -0
  40. package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  41. package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  42. package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +8 -0
  43. package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +8 -0
  44. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +31 -0
  45. package/esm/typings/src/storage/utils/PrefixStorage.d.ts +23 -0
  46. package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +12 -0
  47. package/esm/typings/src/types/ModelRequirements.d.ts +21 -1
  48. package/esm/typings/src/types/Parameters.d.ts +0 -1
  49. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +0 -1
  50. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
  51. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
  52. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
  53. package/esm/typings/src/types/Prompt.d.ts +5 -2
  54. package/esm/typings/src/types/typeAliases.d.ts +35 -1
  55. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
  56. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
  57. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  58. package/esm/typings/src/utils/organization/notUsing.d.ts +11 -0
  59. package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
  60. package/package.json +2 -2
  61. package/umd/index.umd.js +339 -214
  62. package/umd/index.umd.js.map +1 -1
  63. package/umd/typings/promptbook-collection/index.d.ts +83 -2
  64. package/umd/typings/src/_packages/core.index.d.ts +2 -2
  65. package/umd/typings/src/_packages/types.index.d.ts +2 -2
  66. package/umd/typings/src/_packages/utils.index.d.ts +3 -1
  67. package/umd/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
  68. package/umd/typings/src/config.d.ts +4 -0
  69. package/umd/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
  70. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
  71. package/umd/typings/src/conversion/validation/validatePipeline.d.ts +4 -0
  72. package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  73. package/{esm/typings/src/errors/VersionMismatch.d.ts → umd/typings/src/errors/VersionMismatchError.d.ts} +1 -1
  74. package/umd/typings/src/execution/LlmExecutionTools.d.ts +3 -1
  75. package/umd/typings/src/execution/PipelineExecutor.d.ts +4 -3
  76. package/umd/typings/src/execution/PromptResult.d.ts +12 -0
  77. package/umd/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
  78. package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -0
  79. package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
  80. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  81. package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  82. package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  83. package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  84. package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  85. package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
  86. package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
  87. package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  88. package/umd/typings/src/llm-providers/utils/cache/CacheItem.d.ts +29 -0
  89. package/umd/typings/src/llm-providers/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  90. package/umd/typings/src/llm-providers/utils/cache/cacheLlmTools.d.ts +17 -0
  91. package/umd/typings/src/llm-providers/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  92. package/umd/typings/src/llm-providers/utils/count-total-cost/countTotalCost.d.ts +14 -0
  93. package/umd/typings/src/llm-providers/utils/createLlmToolsFromEnv.d.ts +21 -0
  94. package/umd/typings/src/personas/preparePersona.d.ts +0 -3
  95. package/umd/typings/src/prepare/preparePipeline.d.ts +2 -1
  96. package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +24 -0
  97. package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  98. package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +28 -0
  99. package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +10 -0
  100. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  101. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  102. package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +8 -0
  103. package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +8 -0
  104. package/umd/typings/src/storage/memory/MemoryStorage.d.ts +31 -0
  105. package/umd/typings/src/storage/utils/PrefixStorage.d.ts +23 -0
  106. package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +12 -0
  107. package/umd/typings/src/types/ModelRequirements.d.ts +21 -1
  108. package/umd/typings/src/types/Parameters.d.ts +0 -1
  109. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +0 -1
  110. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
  111. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
  112. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
  113. package/umd/typings/src/types/Prompt.d.ts +5 -2
  114. package/umd/typings/src/types/typeAliases.d.ts +35 -1
  115. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
  116. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
  117. package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  118. package/umd/typings/src/utils/organization/notUsing.d.ts +11 -0
  119. package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
  120. package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  121. package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
  122. package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  123. package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
package/esm/index.es.js CHANGED
@@ -310,7 +310,7 @@ function forEachAsync(array, options, callbackfunction) {
310
310
  });
311
311
  }
312
312
 
313
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-9",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,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}",resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.966Z",promptbookVersion:"0.61.0-9",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-9",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,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}",resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.970Z",promptbookVersion:"0.61.0-9",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-9",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,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}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.976Z",promptbookVersion:"0.61.0-9",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"}];
313
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-10",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,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}",resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",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-10",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,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}",resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",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-10",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,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}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",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-10",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:[{name:"make-model-requirements",title:"Make modelRequirements",dependentParameterNames:["availableModelNames","personaDescription"],blockType:"PROMPT_TEMPLATE",expectFormat:"JSON",personaName:null,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}",resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",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"}];
314
314
 
315
315
  /**
316
316
  * Prettify the html code
@@ -927,6 +927,10 @@ function validatePipeline(pipeline) {
927
927
  * > * - ...
928
928
  * > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
929
929
  */
930
+ /**
931
+ * TODO: [🧠] !!!!! Validate new things
932
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
933
+ */
930
934
 
931
935
  /**
932
936
  * This error indicates that promptbook not found in the collection
@@ -1608,7 +1612,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1608
1612
  };
1609
1613
  /**
1610
1614
  * List all available models that can be used
1611
- * This liost is a combination of all available models from all execution tools
1615
+ * This lists is a combination of all available models from all execution tools
1612
1616
  */
1613
1617
  MultipleLlmExecutionTools.prototype.listModels = function () {
1614
1618
  return __awaiter(this, void 0, void 0, function () {
@@ -1654,6 +1658,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1654
1658
  }());
1655
1659
  /**
1656
1660
  * TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
1661
+ * TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
1662
+ * Look how `countTotalUsage` (and `cacheLlmTools`) implements it
1657
1663
  */
1658
1664
 
1659
1665
  /**
@@ -1724,7 +1730,7 @@ function arrayableToArray(input) {
1724
1730
  /**
1725
1731
  * The version of the Promptbook library
1726
1732
  */
1727
- var PROMPTBOOK_VERSION = '0.61.0-9';
1733
+ var PROMPTBOOK_VERSION = '0.61.0-10';
1728
1734
  // TODO: !!!! List here all the versions and annotate + put into script
1729
1735
 
1730
1736
  /**
@@ -1907,7 +1913,6 @@ function createPipelineExecutor(options) {
1907
1913
  var _this = this;
1908
1914
  var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
1909
1915
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1910
- // TODO: !!!!! Implement new commands
1911
1916
  validatePipeline(pipeline);
1912
1917
  var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
1913
1918
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
@@ -1983,7 +1988,10 @@ function createPipelineExecutor(options) {
1983
1988
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
1984
1989
  parameters: parametersToPass,
1985
1990
  content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
1991
+ // <- TODO: !!!!! Apply {context} and knowledges
1992
+ // <- TODO: !!!!! Apply samples
1986
1993
  modelRequirements: currentTemplate.modelRequirements,
1994
+ // <- TODO: !!!!! Apply persona
1987
1995
  expectations: currentTemplate.expectations,
1988
1996
  expectFormat: currentTemplate.expectFormat,
1989
1997
  postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
@@ -2430,10 +2438,12 @@ function createPipelineExecutor(options) {
2430
2438
  }
2431
2439
  /**
2432
2440
  * TODO: [🪂] Pass maxParallelCount here
2441
+ * TODO: [♈] Probbably move expectations from templates to parameters
2433
2442
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
2434
2443
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
2435
2444
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
2436
2445
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
2446
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
2437
2447
  */
2438
2448
 
2439
2449
  /**
@@ -2451,7 +2461,6 @@ function TODO_USE() {
2451
2461
  value[_i] = arguments[_i];
2452
2462
  }
2453
2463
  }
2454
- // TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
2455
2464
 
2456
2465
  /**
2457
2466
  * @@@
@@ -2657,32 +2666,59 @@ TODO: [🧊] This is how it can look in future
2657
2666
  */
2658
2667
  function preparePersona(personaDescription, options) {
2659
2668
  return __awaiter(this, void 0, void 0, function () {
2660
- var llmTools, _a, maxParallelCount, _b, isVerbose;
2661
- return __generator(this, function (_c) {
2662
- llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
2663
- TODO_USE(maxParallelCount); // <- [🪂]
2664
- TODO_USE(personaDescription); // <- !!!!!
2665
- TODO_USE(llmTools); // <- !!!!!
2666
- TODO_USE(isVerbose); // <- !!!!!
2667
- return [2 /*return*/, {
2668
- modelVariant: 'CHAT',
2669
- modelName: 'gpt-4',
2670
- }];
2669
+ var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
2670
+ var _c;
2671
+ return __generator(this, function (_d) {
2672
+ switch (_d.label) {
2673
+ case 0:
2674
+ llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2675
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
2676
+ _b = createPipelineExecutor;
2677
+ _c = {};
2678
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
2679
+ case 1:
2680
+ preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
2681
+ _c.tools = {
2682
+ llm: llmTools,
2683
+ },
2684
+ _c)]);
2685
+ return [4 /*yield*/, llmTools.listModels()];
2686
+ case 2:
2687
+ availableModels = _d.sent();
2688
+ availableModelNames = availableModels
2689
+ .filter(function (_a) {
2690
+ var modelVariant = _a.modelVariant;
2691
+ return modelVariant === 'CHAT';
2692
+ })
2693
+ .map(function (_a) {
2694
+ var modelName = _a.modelName;
2695
+ return modelName;
2696
+ })
2697
+ .join(',');
2698
+ return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
2699
+ case 3:
2700
+ result = _d.sent();
2701
+ assertsExecutionSuccessful(result);
2702
+ outputParameters = result.outputParameters;
2703
+ modelRequirementsRaw = outputParameters.modelRequirements;
2704
+ modelRequirements = JSON.parse(modelRequirementsRaw);
2705
+ if (isVerbose) {
2706
+ console.info("PERSONA ".concat(personaDescription), modelRequirements);
2707
+ }
2708
+ modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
2709
+ // TODO: !!! Check validity of `modelName`
2710
+ // TODO: !!! Check validity of `systemMessage`
2711
+ // TODO: !!! Check validity of `temperature`
2712
+ return [2 /*return*/, {
2713
+ modelVariant: 'CHAT',
2714
+ modelName: modelName,
2715
+ systemMessage: systemMessage,
2716
+ temperature: temperature,
2717
+ }];
2718
+ }
2671
2719
  });
2672
2720
  });
2673
2721
  }
2674
- /**
2675
- * TODO: [🪂] Do it in parallel
2676
- */
2677
-
2678
- /**
2679
- * Simple wrapper `new Date().toISOString()`
2680
- *
2681
- * @returns string_date branded type
2682
- */
2683
- function $currentDate() {
2684
- return new Date().toISOString();
2685
- }
2686
2722
 
2687
2723
  /**
2688
2724
  * Prepare pipeline from string (markdown) format to JSON format
@@ -2706,7 +2742,7 @@ function preparePipeline(pipeline, options) {
2706
2742
  knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
2707
2743
  currentPreparation = {
2708
2744
  id: 1,
2709
- date: $currentDate(),
2745
+ // TODO: [🍥]> date: $currentDate(),
2710
2746
  promptbookVersion: PROMPTBOOK_VERSION,
2711
2747
  modelUsage: addUsage(),
2712
2748
  };
@@ -2715,8 +2751,8 @@ function preparePipeline(pipeline, options) {
2715
2751
  // <- TODO: [🧊]
2716
2752
  currentPreparation,
2717
2753
  ];
2718
- preparedPersonas = [];
2719
- return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona) { return __awaiter(_this, void 0, void 0, function () {
2754
+ preparedPersonas = new Array(personas.length);
2755
+ return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
2720
2756
  var modelRequirements, preparedPersona;
2721
2757
  return __generator(this, function (_a) {
2722
2758
  switch (_a.label) {
@@ -2724,7 +2760,7 @@ function preparePipeline(pipeline, options) {
2724
2760
  case 1:
2725
2761
  modelRequirements = _a.sent();
2726
2762
  preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
2727
- preparedPersonas.push(preparedPersona);
2763
+ preparedPersonas[index] = preparedPersona;
2728
2764
  return [2 /*return*/];
2729
2765
  }
2730
2766
  });
@@ -2746,8 +2782,182 @@ function preparePipeline(pipeline, options) {
2746
2782
  * TODO: Write tests for `preparePipeline`
2747
2783
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
2748
2784
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
2749
- * TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
2785
+ * TODO: !!!!! Use here countTotalUsage
2786
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
2787
+ */
2788
+
2789
+ /**
2790
+ * Tests if given string is valid URL.
2791
+ *
2792
+ * Note: This does not check if the file exists only if the path is valid
2750
2793
  */
2794
+ function isValidFilePath(filePath) {
2795
+ if (typeof filePath !== 'string') {
2796
+ return false;
2797
+ }
2798
+ var filePathSlashes = filePath.split('\\').join('/');
2799
+ // Absolute Unix path: /hello.txt
2800
+ if (/^(\/)/i.test(filePathSlashes)) {
2801
+ return true;
2802
+ }
2803
+ // Absolute Windows path: /hello.txt
2804
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
2805
+ return true;
2806
+ }
2807
+ // Relative path: ./hello.txt
2808
+ if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
2809
+ return true;
2810
+ }
2811
+ return false;
2812
+ }
2813
+
2814
+ /**
2815
+ * Parses the knowledge command
2816
+ *
2817
+ * @see ./KNOWLEDGE-README.md for more details
2818
+ * @private within the commands folder
2819
+ */
2820
+ var knowledgeCommandParser = {
2821
+ /**
2822
+ * Name of the command
2823
+ */
2824
+ name: 'KNOWLEDGE',
2825
+ /**
2826
+ * BOILERPLATE command can be used in:
2827
+ */
2828
+ usagePlaces: ['PIPELINE_HEAD'],
2829
+ /**
2830
+ * Description of the KNOWLEDGE command
2831
+ */
2832
+ description: "Tells promptbook which external knowledge to use",
2833
+ /**
2834
+ * Link to discussion
2835
+ */
2836
+ discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
2837
+ /**
2838
+ * Example usages of the KNOWLEDGE command
2839
+ */
2840
+ examples: [
2841
+ 'KNOWLEDGE https://www.pavolhejny.com/',
2842
+ 'KNOWLEDGE ./hejny-cv.txt',
2843
+ 'KNOWLEDGE ./hejny-cv.md',
2844
+ 'KNOWLEDGE ./hejny-cv.pdf',
2845
+ 'KNOWLEDGE ./hejny-cv.docx',
2846
+ ],
2847
+ /**
2848
+ * Parses the KNOWLEDGE command
2849
+ */
2850
+ parse: function (input) {
2851
+ var args = input.args;
2852
+ var source = args[0];
2853
+ if (source === undefined) {
2854
+ throw new ParsingError("Source is not defined");
2855
+ }
2856
+ if (source.startsWith('http://')) {
2857
+ throw new ParsingError("Source is not secure");
2858
+ }
2859
+ if (!(isValidFilePath(source) || isValidUrl(source))) {
2860
+ throw new ParsingError("Source not valid");
2861
+ }
2862
+ if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
2863
+ throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
2864
+ }
2865
+ return {
2866
+ type: 'KNOWLEDGE',
2867
+ source: source,
2868
+ };
2869
+ },
2870
+ /**
2871
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
2872
+ */
2873
+ applyToPipelineJson: function (pipelineJson, personaCommand) {
2874
+ var source = personaCommand.source;
2875
+ var name = titleToName(source);
2876
+ pipelineJson.knowledgeSources.push({
2877
+ name: name,
2878
+ source: source,
2879
+ });
2880
+ },
2881
+ };
2882
+
2883
+ /**
2884
+ * Parses the persona command
2885
+ *
2886
+ * @see ./PERSONA-README.md for more details
2887
+ * @private within the commands folder
2888
+ */
2889
+ var personaCommandParser = {
2890
+ /**
2891
+ * Name of the command
2892
+ */
2893
+ name: 'PERSONA',
2894
+ /**
2895
+ * Aliases for the PERSONA command
2896
+ */
2897
+ aliasNames: ['PERSON'],
2898
+ /**
2899
+ * PERSONA command can be used in:
2900
+ */
2901
+ usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
2902
+ /**
2903
+ * Description of the PERSONA command
2904
+ */
2905
+ description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
2906
+ /**
2907
+ * Link to discussion
2908
+ */
2909
+ discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
2910
+ /**
2911
+ * Example usages of the PERSONA command
2912
+ */
2913
+ examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
2914
+ /**
2915
+ * Parses the PERSONA command
2916
+ */
2917
+ parse: function (input) {
2918
+ var rawArgs = input.rawArgs;
2919
+ var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
2920
+ var personaName = (personaNameRaw || '').trim();
2921
+ if (personaName === '') {
2922
+ throw new ParsingError("You must set name for the persona");
2923
+ }
2924
+ var personaDescription = (personaDescriptionRaw || '').trim();
2925
+ if (personaDescription === '') {
2926
+ personaDescription = null;
2927
+ }
2928
+ return {
2929
+ type: 'PERSONA',
2930
+ personaName: personaName,
2931
+ personaDescription: personaDescription,
2932
+ };
2933
+ },
2934
+ /**
2935
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
2936
+ */
2937
+ applyToPipelineJson: function (pipelineJson, personaCommand) {
2938
+ var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
2939
+ var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
2940
+ if (persona === undefined) {
2941
+ pipelineJson.personas.push({
2942
+ name: personaName,
2943
+ description: personaDescription || '',
2944
+ });
2945
+ return;
2946
+ }
2947
+ if (persona.description === personaDescription) {
2948
+ return;
2949
+ }
2950
+ if (personaDescription === null) {
2951
+ return;
2952
+ }
2953
+ if (persona.description === '') {
2954
+ persona.description = personaDescription;
2955
+ return;
2956
+ }
2957
+ console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
2958
+ persona.description += spaceTrim('\n\n' + personaDescription);
2959
+ },
2960
+ };
2751
2961
 
2752
2962
  /**
2753
2963
  * Removes Markdown formatting tags from a string.
@@ -2920,7 +3130,6 @@ var blockCommandParser = {
2920
3130
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
2921
3131
  var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
2922
3132
  if (blockTypes.length !== 1) {
2923
- // console.log('!!!', { blockType });
2924
3133
  throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
2925
3134
  }
2926
3135
  // TODO: !!!! Not supported yet
@@ -3169,92 +3378,12 @@ var jokerCommandParser = {
3169
3378
  },
3170
3379
  };
3171
3380
 
3172
- /**
3173
- * Tests if given string is valid URL.
3174
- *
3175
- * Note: This does not check if the file exists only if the path is valid
3176
- */
3177
- function isValidFilePath(filePath) {
3178
- if (typeof filePath !== 'string') {
3179
- return false;
3180
- }
3181
- var filePathSlashes = filePath.split('\\').join('/');
3182
- // Absolute Unix path: /hello.txt
3183
- if (/^(\/)/i.test(filePathSlashes)) {
3184
- return true;
3185
- }
3186
- // Absolute Windows path: /hello.txt
3187
- if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
3188
- return true;
3189
- }
3190
- // Relative path: ./hello.txt
3191
- if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
3192
- return true;
3193
- }
3194
- return false;
3195
- }
3196
-
3197
- /**
3198
- * Parses the knowledge command
3199
- *
3200
- * @see ./KNOWLEDGE-README.md for more details
3201
- * @private within the commands folder
3202
- */
3203
- var knowledgeCommandParser = {
3204
- /**
3205
- * Name of the command
3206
- */
3207
- name: 'KNOWLEDGE',
3208
- /**
3209
- * BOILERPLATE command can be used in:
3210
- */
3211
- usagePlaces: ['PIPELINE_HEAD'],
3212
- /**
3213
- * Description of the KNOWLEDGE command
3214
- */
3215
- description: "Tells promptbook which external knowledge to use",
3216
- /**
3217
- * Link to discussion
3218
- */
3219
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
3220
- /**
3221
- * Example usages of the KNOWLEDGE command
3222
- */
3223
- examples: [
3224
- 'KNOWLEDGE https://www.pavolhejny.com/',
3225
- 'KNOWLEDGE ./hejny-cv.txt',
3226
- 'KNOWLEDGE ./hejny-cv.md',
3227
- 'KNOWLEDGE ./hejny-cv.pdf',
3228
- 'KNOWLEDGE ./hejny-cv.docx',
3229
- ],
3230
- /**
3231
- * Parses the KNOWLEDGE command
3232
- */
3233
- parse: function (input) {
3234
- var args = input.args;
3235
- var source = args[0];
3236
- if (source === undefined) {
3237
- throw new ParsingError("Source is not defined");
3238
- }
3239
- if (source.startsWith('http://')) {
3240
- throw new ParsingError("Source is not secure");
3241
- }
3242
- if (!(isValidFilePath(source) || isValidUrl(source))) {
3243
- throw new ParsingError("Source not valid");
3244
- }
3245
- if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
3246
- throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
3247
- }
3248
- return {
3249
- type: 'KNOWLEDGE',
3250
- source: source,
3251
- };
3252
- },
3253
- };
3254
-
3255
3381
  var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
3256
3382
  /**
3257
- * TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
3383
+ * TODO: [🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (simmilar that `user` identification is not here)
3384
+ * TODO: [🧠][💱] Add more model options: `stop_token`, `logit_bias`, `logprobs` (`top_logprobs`), `top_k`, `top_p`, `presence_penalty`, `frequency_penalty`, `bestOf`, `logitBias`, `logitBiasType`,...
3385
+ * [💱] Probbably keep using just `temperature` in Promptbook (not `top_k` and `top_p`)
3386
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3258
3387
  * TODO: Maybe figure out better word than "variant"
3259
3388
  * TODO: Add here more requirement options like max context size, max tokens, etc.
3260
3389
  * TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
@@ -3396,59 +3525,6 @@ var parameterCommandParser = {
3396
3525
  },
3397
3526
  };
3398
3527
 
3399
- /**
3400
- * Parses the persona command
3401
- *
3402
- * @see ./PERSONA-README.md for more details
3403
- * @private within the commands folder
3404
- */
3405
- var personaCommandParser = {
3406
- /**
3407
- * Name of the command
3408
- */
3409
- name: 'PERSONA',
3410
- /**
3411
- * Aliases for the PERSONA command
3412
- */
3413
- aliasNames: ['PERSON'],
3414
- /**
3415
- * PERSONA command can be used in:
3416
- */
3417
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
3418
- /**
3419
- * Description of the PERSONA command
3420
- */
3421
- description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
3422
- /**
3423
- * Link to discussion
3424
- */
3425
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
3426
- /**
3427
- * Example usages of the PERSONA command
3428
- */
3429
- examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
3430
- /**
3431
- * Parses the PERSONA command
3432
- */
3433
- parse: function (input) {
3434
- var rawArgs = input.rawArgs;
3435
- var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
3436
- var personaName = (personaNameRaw || '').trim();
3437
- if (personaName === '') {
3438
- throw new ParsingError("You must set name for the persona");
3439
- }
3440
- var personaDescription = (personaDescriptionRaw || '').trim();
3441
- if (personaDescription === '') {
3442
- personaDescription = null;
3443
- }
3444
- return {
3445
- type: 'PERSONA',
3446
- personaName: personaName,
3447
- personaDescription: personaDescription,
3448
- };
3449
- },
3450
- };
3451
-
3452
3528
  function isValidJavascriptName(javascriptName) {
3453
3529
  if (typeof javascriptName !== 'string') {
3454
3530
  return false;
@@ -3666,7 +3742,8 @@ var actionCommandParser = {
3666
3742
  * Parses the ACTION command
3667
3743
  */
3668
3744
  parse: function (input) {
3669
- input.args;
3745
+ var args = input.args;
3746
+ TODO_USE(args);
3670
3747
  return {
3671
3748
  type: 'ACTION',
3672
3749
  };
@@ -3704,7 +3781,8 @@ var instrumentCommandParser = {
3704
3781
  * Parses the INSTRUMENT command
3705
3782
  */
3706
3783
  parse: function (input) {
3707
- input.args;
3784
+ var args = input.args;
3785
+ TODO_USE(args);
3708
3786
  return {
3709
3787
  type: 'INSTRUMENT',
3710
3788
  };
@@ -3886,7 +3964,6 @@ function parseCommandVariant(input) {
3886
3964
  var _loop_1 = function (commandParser) {
3887
3965
  var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
3888
3966
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
3889
- // console.log('!!!', { commandName, names });
3890
3967
  if (names.includes(commandName)) {
3891
3968
  try {
3892
3969
  return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
@@ -3996,25 +4073,42 @@ function extractAllBlocksFromMarkdown(markdown) {
3996
4073
  var e_1, _a;
3997
4074
  var codeBlocks = [];
3998
4075
  var lines = markdown.split('\n');
4076
+ // Note: [0] Ensure that the last block notated by gt > will be closed
4077
+ lines.push('');
3999
4078
  var currentCodeBlock = null;
4000
4079
  try {
4001
4080
  for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
4002
4081
  var line = lines_1_1.value;
4082
+ if (line.startsWith('> ') || line === '>') {
4083
+ if (currentCodeBlock === null) {
4084
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
4085
+ } /* not else */
4086
+ if (currentCodeBlock.blockNotation === '>') {
4087
+ if (currentCodeBlock.content !== '') {
4088
+ currentCodeBlock.content += '\n';
4089
+ }
4090
+ currentCodeBlock.content += line.slice(2);
4091
+ }
4092
+ }
4093
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
4094
+ codeBlocks.push(currentCodeBlock);
4095
+ currentCodeBlock = null;
4096
+ }
4097
+ /* not else */
4003
4098
  if (line.startsWith('```')) {
4004
4099
  var language = line.slice(3).trim() || null;
4005
4100
  if (currentCodeBlock === null) {
4006
- currentCodeBlock = { language: language, content: '' };
4101
+ currentCodeBlock = { blockNotation: '```', language: language, content: '' };
4007
4102
  }
4008
4103
  else {
4009
4104
  if (language !== null) {
4010
- // [🌻]
4011
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
4105
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
4012
4106
  }
4013
4107
  codeBlocks.push(currentCodeBlock);
4014
4108
  currentCodeBlock = null;
4015
4109
  }
4016
4110
  }
4017
- else if (currentCodeBlock !== null) {
4111
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
4018
4112
  if (currentCodeBlock.content !== '') {
4019
4113
  currentCodeBlock.content += '\n';
4020
4114
  }
@@ -4030,11 +4124,13 @@ function extractAllBlocksFromMarkdown(markdown) {
4030
4124
  finally { if (e_1) throw e_1.error; }
4031
4125
  }
4032
4126
  if (currentCodeBlock !== null) {
4033
- // [🌻]
4034
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
4127
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
4035
4128
  }
4036
4129
  return codeBlocks;
4037
4130
  }
4131
+ /**
4132
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
4133
+ */
4038
4134
 
4039
4135
  /**
4040
4136
  * Extracts exactly ONE code block from markdown.
@@ -4052,13 +4148,12 @@ function extractAllBlocksFromMarkdown(markdown) {
4052
4148
  function extractOneBlockFromMarkdown(markdown) {
4053
4149
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
4054
4150
  if (codeBlocks.length !== 1) {
4055
- // TODO: Report more specific place where the error happened
4056
- throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
4151
+ throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
4057
4152
  }
4058
4153
  return codeBlocks[0];
4059
4154
  }
4060
4155
  /***
4061
- * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
4156
+ * TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
4062
4157
  */
4063
4158
 
4064
4159
  /**
@@ -4068,13 +4163,13 @@ function parseMarkdownSection(value) {
4068
4163
  var _a, _b;
4069
4164
  var lines = value.split('\n');
4070
4165
  if (!lines[0].startsWith('#')) {
4071
- throw new Error('Markdown section must start with heading');
4166
+ throw new ParsingError('Markdown section must start with heading');
4072
4167
  }
4073
4168
  var title = lines[0].replace(/^#+\s*/, '');
4074
4169
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
4075
4170
  var content = spaceTrim(lines.slice(1).join('\n'));
4076
4171
  if (level < 1 || level > 6) {
4077
- throw new Error('Markdown section must have heading level between 1 and 6');
4172
+ throw new ParsingError('Markdown section must have heading level between 1 and 6');
4078
4173
  }
4079
4174
  return { title: title, level: level, content: content };
4080
4175
  }
@@ -4456,7 +4551,7 @@ function pipelineStringToJsonSync(pipelineString) {
4456
4551
  existingParameter.description &&
4457
4552
  existingParameter.description !== parameterDescription &&
4458
4553
  parameterDescription) {
4459
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
4554
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
4460
4555
  }
4461
4556
  if (existingParameter) {
4462
4557
  if (parameterDescription) {
@@ -4475,11 +4570,12 @@ function pipelineStringToJsonSync(pipelineString) {
4475
4570
  // =============================================================
4476
4571
  // Note: 3️⃣ Process pipeline head
4477
4572
  pipelineJson.title = pipelineHead.title;
4478
- // TODO: [1] DRY description
4573
+ // TODO: [🎾][1] DRY description
4479
4574
  var description = pipelineHead.content;
4480
- // Note: Remove codeblocks - TODO: Maybe put this into util (exported from `@promptbool/utils`)
4575
+ // Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
4481
4576
  description = description.split(/^```.*^```/gms).join('');
4482
- //Note: Remove lists and return statement - TODO: Maybe put this into util (exported from `@promptbool/utils`)
4577
+ description = description.split(/^>.*$/gm).join('');
4578
+ //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
4483
4579
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4484
4580
  description = spaceTrim$1(description);
4485
4581
  if (description === '') {
@@ -4507,7 +4603,7 @@ function pipelineStringToJsonSync(pipelineString) {
4507
4603
  pipelineJson.pipelineUrl = command.pipelineUrl.href;
4508
4604
  break;
4509
4605
  case 'KNOWLEDGE':
4510
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4606
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
4511
4607
  break;
4512
4608
  case 'ACTION':
4513
4609
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
@@ -4516,7 +4612,8 @@ function pipelineStringToJsonSync(pipelineString) {
4516
4612
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4517
4613
  break;
4518
4614
  case 'PERSONA':
4519
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
4615
+ personaCommandParser.applyToPipelineJson(pipelineJson, command);
4616
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4520
4617
  break;
4521
4618
  case 'BOILERPLATE':
4522
4619
  throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
@@ -4545,7 +4642,27 @@ function pipelineStringToJsonSync(pipelineString) {
4545
4642
  var postprocessing = [];
4546
4643
  var expectAmount = {};
4547
4644
  var expectFormat = undefined;
4548
- var isBlockTypeChanged = false;
4645
+ var isBlockTypeSet = false;
4646
+ var lastLine = section.content.split('\n').pop();
4647
+ var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
4648
+ var resultingParameterName = null;
4649
+ if (resultingParameterNameMatch &&
4650
+ resultingParameterNameMatch.groups !== undefined &&
4651
+ resultingParameterNameMatch.groups.resultingParamName !== undefined) {
4652
+ resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
4653
+ }
4654
+ var expectResultingParameterName = function () {
4655
+ if (resultingParameterName !== null) {
4656
+ return resultingParameterName;
4657
+ }
4658
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
4659
+ // TODO: Show code of invalid sections each time + DRY
4660
+ section.content
4661
+ .split('\n')
4662
+ .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
4663
+ .join('\n')), "\n "); }));
4664
+ };
4665
+ var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
4549
4666
  try {
4550
4667
  for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
4551
4668
  var listItem = listItems_2_1.value;
@@ -4553,15 +4670,24 @@ function pipelineStringToJsonSync(pipelineString) {
4553
4670
  switch (command.type) {
4554
4671
  // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
4555
4672
  case 'BLOCK':
4556
- if (isBlockTypeChanged) {
4673
+ if (isBlockTypeSet) {
4557
4674
  throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
4558
4675
  }
4559
4676
  if (command.blockType === 'SAMPLE') {
4560
- console.error(new NotYetImplementedError('Block type SAMPLE is not implemented yet'));
4677
+ expectResultingParameterName();
4678
+ var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
4679
+ if (parameter === undefined) {
4680
+ throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
4681
+ }
4682
+ parameter.sampleValues = parameter.sampleValues || [];
4683
+ parameter.sampleValues.push(content);
4561
4684
  return "continue-templates";
4562
4685
  }
4563
4686
  if (command.blockType === 'KNOWLEDGE') {
4564
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4687
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, {
4688
+ type: 'KNOWLEDGE',
4689
+ source: content, // <- TODO: !!!! Working KNOWLEDGE which not referring to the source file/wweb, but its content itseld
4690
+ });
4565
4691
  return "continue-templates";
4566
4692
  }
4567
4693
  if (command.blockType === 'ACTION') {
@@ -4572,8 +4698,9 @@ function pipelineStringToJsonSync(pipelineString) {
4572
4698
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4573
4699
  return "continue-templates";
4574
4700
  }
4701
+ expectResultingParameterName();
4575
4702
  blockType = command.blockType;
4576
- isBlockTypeChanged = true;
4703
+ isBlockTypeSet = true;
4577
4704
  break;
4578
4705
  case 'EXPECT_AMOUNT':
4579
4706
  // eslint-disable-next-line no-case-declarations
@@ -4613,16 +4740,20 @@ function pipelineStringToJsonSync(pipelineString) {
4613
4740
  postprocessing.push(command.functionName);
4614
4741
  break;
4615
4742
  case 'KNOWLEDGE':
4616
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4743
+ // TODO: [👙] The knowledge is maybe relevant for just this template
4744
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
4617
4745
  break;
4618
4746
  case 'ACTION':
4747
+ // TODO: [👙] The action is maybe relevant for just this template
4619
4748
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
4620
4749
  break;
4621
4750
  case 'INSTRUMENT':
4751
+ // TODO: [👙] The instrument is maybe relevant for just this template
4622
4752
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4623
4753
  break;
4624
4754
  case 'PERSONA':
4625
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
4755
+ personaCommandParser.applyToPipelineJson(pipelineJson, command);
4756
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4626
4757
  break;
4627
4758
  case 'BOILERPLATE':
4628
4759
  console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
@@ -4640,7 +4771,6 @@ function pipelineStringToJsonSync(pipelineString) {
4640
4771
  }
4641
4772
  finally { if (e_3) throw e_3.error; }
4642
4773
  }
4643
- var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
4644
4774
  if (blockType === 'SCRIPT') {
4645
4775
  if (!language) {
4646
4776
  throw new ParsingError('You must specify the language of the script in the prompt template');
@@ -4649,22 +4779,12 @@ function pipelineStringToJsonSync(pipelineString) {
4649
4779
  throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
4650
4780
  }
4651
4781
  }
4652
- var lastLine = section.content.split('\n').pop();
4653
- var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
4654
- if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
4655
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
4656
- // TODO: Show code of invalid sections each time + DRY
4657
- section.content
4658
- .split('\n')
4659
- .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
4660
- .join('\n')), "\n "); }));
4661
- }
4662
- var resultingParameterName = match.groups.resultingParamName;
4663
- // TODO: [1] DRY description
4782
+ // TODO: [🎾][1] DRY description
4664
4783
  var description_1 = section.content;
4665
- // Note: Remove codeblocks
4784
+ // Note: Remove codeblocks - TODO: [🎾]
4666
4785
  description_1 = description_1.split(/^```.*^```/gms).join('');
4667
- //Note: Remove lists and return statement
4786
+ description_1 = description_1.split(/^>.*$/gm).join('');
4787
+ //Note: Remove lists and return statement - TODO: [🎾]
4668
4788
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4669
4789
  description_1 = spaceTrim$1(description_1);
4670
4790
  if (description_1 === '') {
@@ -4698,7 +4818,7 @@ function pipelineStringToJsonSync(pipelineString) {
4698
4818
  modelRequirements: templateModelRequirements,
4699
4819
  contentLanguage: blockType === 'SCRIPT' ? language : undefined,
4700
4820
  content: content,
4701
- resultingParameterName: resultingParameterName,
4821
+ resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
4702
4822
  };
4703
4823
  if (blockType !== 'PROMPT_TEMPLATE') {
4704
4824
  delete template.modelRequirements;
@@ -4771,6 +4891,8 @@ function pipelineStringToJsonSync(pipelineString) {
4771
4891
  * TODO: Use spaceTrim more effectively
4772
4892
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
4773
4893
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
4894
+ * TODO: [♈] Probbably move expectations from templates to parameters
4895
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4774
4896
  */
4775
4897
 
4776
4898
  /**
@@ -4810,6 +4932,7 @@ function pipelineStringToJson(pipelineString, options) {
4810
4932
  }
4811
4933
  /**
4812
4934
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
4935
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4813
4936
  */
4814
4937
 
4815
4938
  /**
@@ -4956,6 +5079,7 @@ function createCollectionFromDirectory(path, options) {
4956
5079
  else {
4957
5080
  colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
4958
5081
  // TODO: !! Implement;
5082
+ // TODO: [🌗]
4959
5083
  }
4960
5084
  _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
4961
5085
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -5000,6 +5124,7 @@ function createCollectionFromDirectory(path, options) {
5000
5124
  case 5:
5001
5125
  // TODO: Handle non-valid JSON files
5002
5126
  promptbook = _d.apply(_c, [_e.sent()]);
5127
+ // TODO: [🌗]
5003
5128
  promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5004
5129
  return [3 /*break*/, 7];
5005
5130
  case 6: