@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/umd/index.umd.js CHANGED
@@ -315,7 +315,7 @@
315
315
  });
316
316
  }
317
317
 
318
- 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"}];
318
+ 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"}];
319
319
 
320
320
  /**
321
321
  * Prettify the html code
@@ -932,6 +932,10 @@
932
932
  * > * - ...
933
933
  * > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
934
934
  */
935
+ /**
936
+ * TODO: [🧠] !!!!! Validate new things
937
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
938
+ */
935
939
 
936
940
  /**
937
941
  * This error indicates that promptbook not found in the collection
@@ -1613,7 +1617,7 @@
1613
1617
  };
1614
1618
  /**
1615
1619
  * List all available models that can be used
1616
- * This liost is a combination of all available models from all execution tools
1620
+ * This lists is a combination of all available models from all execution tools
1617
1621
  */
1618
1622
  MultipleLlmExecutionTools.prototype.listModels = function () {
1619
1623
  return __awaiter(this, void 0, void 0, function () {
@@ -1659,6 +1663,8 @@
1659
1663
  }());
1660
1664
  /**
1661
1665
  * TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
1666
+ * 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
1667
+ * Look how `countTotalUsage` (and `cacheLlmTools`) implements it
1662
1668
  */
1663
1669
 
1664
1670
  /**
@@ -1729,7 +1735,7 @@
1729
1735
  /**
1730
1736
  * The version of the Promptbook library
1731
1737
  */
1732
- var PROMPTBOOK_VERSION = '0.61.0-9';
1738
+ var PROMPTBOOK_VERSION = '0.61.0-10';
1733
1739
  // TODO: !!!! List here all the versions and annotate + put into script
1734
1740
 
1735
1741
  /**
@@ -1912,7 +1918,6 @@
1912
1918
  var _this = this;
1913
1919
  var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
1914
1920
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1915
- // TODO: !!!!! Implement new commands
1916
1921
  validatePipeline(pipeline);
1917
1922
  var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
1918
1923
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
@@ -1988,7 +1993,10 @@
1988
1993
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
1989
1994
  parameters: parametersToPass,
1990
1995
  content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
1996
+ // <- TODO: !!!!! Apply {context} and knowledges
1997
+ // <- TODO: !!!!! Apply samples
1991
1998
  modelRequirements: currentTemplate.modelRequirements,
1999
+ // <- TODO: !!!!! Apply persona
1992
2000
  expectations: currentTemplate.expectations,
1993
2001
  expectFormat: currentTemplate.expectFormat,
1994
2002
  postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
@@ -2435,10 +2443,12 @@
2435
2443
  }
2436
2444
  /**
2437
2445
  * TODO: [🪂] Pass maxParallelCount here
2446
+ * TODO: [♈] Probbably move expectations from templates to parameters
2438
2447
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
2439
2448
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
2440
2449
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
2441
2450
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
2451
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
2442
2452
  */
2443
2453
 
2444
2454
  /**
@@ -2456,7 +2466,6 @@
2456
2466
  value[_i] = arguments[_i];
2457
2467
  }
2458
2468
  }
2459
- // TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
2460
2469
 
2461
2470
  /**
2462
2471
  * @@@
@@ -2662,32 +2671,59 @@
2662
2671
  */
2663
2672
  function preparePersona(personaDescription, options) {
2664
2673
  return __awaiter(this, void 0, void 0, function () {
2665
- var llmTools, _a, maxParallelCount, _b, isVerbose;
2666
- return __generator(this, function (_c) {
2667
- llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
2668
- TODO_USE(maxParallelCount); // <- [🪂]
2669
- TODO_USE(personaDescription); // <- !!!!!
2670
- TODO_USE(llmTools); // <- !!!!!
2671
- TODO_USE(isVerbose); // <- !!!!!
2672
- return [2 /*return*/, {
2673
- modelVariant: 'CHAT',
2674
- modelName: 'gpt-4',
2675
- }];
2674
+ var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
2675
+ var _c;
2676
+ return __generator(this, function (_d) {
2677
+ switch (_d.label) {
2678
+ case 0:
2679
+ llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2680
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
2681
+ _b = createPipelineExecutor;
2682
+ _c = {};
2683
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
2684
+ case 1:
2685
+ preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
2686
+ _c.tools = {
2687
+ llm: llmTools,
2688
+ },
2689
+ _c)]);
2690
+ return [4 /*yield*/, llmTools.listModels()];
2691
+ case 2:
2692
+ availableModels = _d.sent();
2693
+ availableModelNames = availableModels
2694
+ .filter(function (_a) {
2695
+ var modelVariant = _a.modelVariant;
2696
+ return modelVariant === 'CHAT';
2697
+ })
2698
+ .map(function (_a) {
2699
+ var modelName = _a.modelName;
2700
+ return modelName;
2701
+ })
2702
+ .join(',');
2703
+ return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
2704
+ case 3:
2705
+ result = _d.sent();
2706
+ assertsExecutionSuccessful(result);
2707
+ outputParameters = result.outputParameters;
2708
+ modelRequirementsRaw = outputParameters.modelRequirements;
2709
+ modelRequirements = JSON.parse(modelRequirementsRaw);
2710
+ if (isVerbose) {
2711
+ console.info("PERSONA ".concat(personaDescription), modelRequirements);
2712
+ }
2713
+ modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
2714
+ // TODO: !!! Check validity of `modelName`
2715
+ // TODO: !!! Check validity of `systemMessage`
2716
+ // TODO: !!! Check validity of `temperature`
2717
+ return [2 /*return*/, {
2718
+ modelVariant: 'CHAT',
2719
+ modelName: modelName,
2720
+ systemMessage: systemMessage,
2721
+ temperature: temperature,
2722
+ }];
2723
+ }
2676
2724
  });
2677
2725
  });
2678
2726
  }
2679
- /**
2680
- * TODO: [🪂] Do it in parallel
2681
- */
2682
-
2683
- /**
2684
- * Simple wrapper `new Date().toISOString()`
2685
- *
2686
- * @returns string_date branded type
2687
- */
2688
- function $currentDate() {
2689
- return new Date().toISOString();
2690
- }
2691
2727
 
2692
2728
  /**
2693
2729
  * Prepare pipeline from string (markdown) format to JSON format
@@ -2711,7 +2747,7 @@
2711
2747
  knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
2712
2748
  currentPreparation = {
2713
2749
  id: 1,
2714
- date: $currentDate(),
2750
+ // TODO: [🍥]> date: $currentDate(),
2715
2751
  promptbookVersion: PROMPTBOOK_VERSION,
2716
2752
  modelUsage: addUsage(),
2717
2753
  };
@@ -2720,8 +2756,8 @@
2720
2756
  // <- TODO: [🧊]
2721
2757
  currentPreparation,
2722
2758
  ];
2723
- preparedPersonas = [];
2724
- 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 () {
2759
+ preparedPersonas = new Array(personas.length);
2760
+ 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 () {
2725
2761
  var modelRequirements, preparedPersona;
2726
2762
  return __generator(this, function (_a) {
2727
2763
  switch (_a.label) {
@@ -2729,7 +2765,7 @@
2729
2765
  case 1:
2730
2766
  modelRequirements = _a.sent();
2731
2767
  preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
2732
- preparedPersonas.push(preparedPersona);
2768
+ preparedPersonas[index] = preparedPersona;
2733
2769
  return [2 /*return*/];
2734
2770
  }
2735
2771
  });
@@ -2751,8 +2787,182 @@
2751
2787
  * TODO: Write tests for `preparePipeline`
2752
2788
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
2753
2789
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
2754
- * TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
2790
+ * TODO: !!!!! Use here countTotalUsage
2791
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
2792
+ */
2793
+
2794
+ /**
2795
+ * Tests if given string is valid URL.
2796
+ *
2797
+ * Note: This does not check if the file exists only if the path is valid
2755
2798
  */
2799
+ function isValidFilePath(filePath) {
2800
+ if (typeof filePath !== 'string') {
2801
+ return false;
2802
+ }
2803
+ var filePathSlashes = filePath.split('\\').join('/');
2804
+ // Absolute Unix path: /hello.txt
2805
+ if (/^(\/)/i.test(filePathSlashes)) {
2806
+ return true;
2807
+ }
2808
+ // Absolute Windows path: /hello.txt
2809
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
2810
+ return true;
2811
+ }
2812
+ // Relative path: ./hello.txt
2813
+ if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
2814
+ return true;
2815
+ }
2816
+ return false;
2817
+ }
2818
+
2819
+ /**
2820
+ * Parses the knowledge command
2821
+ *
2822
+ * @see ./KNOWLEDGE-README.md for more details
2823
+ * @private within the commands folder
2824
+ */
2825
+ var knowledgeCommandParser = {
2826
+ /**
2827
+ * Name of the command
2828
+ */
2829
+ name: 'KNOWLEDGE',
2830
+ /**
2831
+ * BOILERPLATE command can be used in:
2832
+ */
2833
+ usagePlaces: ['PIPELINE_HEAD'],
2834
+ /**
2835
+ * Description of the KNOWLEDGE command
2836
+ */
2837
+ description: "Tells promptbook which external knowledge to use",
2838
+ /**
2839
+ * Link to discussion
2840
+ */
2841
+ discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
2842
+ /**
2843
+ * Example usages of the KNOWLEDGE command
2844
+ */
2845
+ examples: [
2846
+ 'KNOWLEDGE https://www.pavolhejny.com/',
2847
+ 'KNOWLEDGE ./hejny-cv.txt',
2848
+ 'KNOWLEDGE ./hejny-cv.md',
2849
+ 'KNOWLEDGE ./hejny-cv.pdf',
2850
+ 'KNOWLEDGE ./hejny-cv.docx',
2851
+ ],
2852
+ /**
2853
+ * Parses the KNOWLEDGE command
2854
+ */
2855
+ parse: function (input) {
2856
+ var args = input.args;
2857
+ var source = args[0];
2858
+ if (source === undefined) {
2859
+ throw new ParsingError("Source is not defined");
2860
+ }
2861
+ if (source.startsWith('http://')) {
2862
+ throw new ParsingError("Source is not secure");
2863
+ }
2864
+ if (!(isValidFilePath(source) || isValidUrl(source))) {
2865
+ throw new ParsingError("Source not valid");
2866
+ }
2867
+ if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
2868
+ throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
2869
+ }
2870
+ return {
2871
+ type: 'KNOWLEDGE',
2872
+ source: source,
2873
+ };
2874
+ },
2875
+ /**
2876
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
2877
+ */
2878
+ applyToPipelineJson: function (pipelineJson, personaCommand) {
2879
+ var source = personaCommand.source;
2880
+ var name = titleToName(source);
2881
+ pipelineJson.knowledgeSources.push({
2882
+ name: name,
2883
+ source: source,
2884
+ });
2885
+ },
2886
+ };
2887
+
2888
+ /**
2889
+ * Parses the persona command
2890
+ *
2891
+ * @see ./PERSONA-README.md for more details
2892
+ * @private within the commands folder
2893
+ */
2894
+ var personaCommandParser = {
2895
+ /**
2896
+ * Name of the command
2897
+ */
2898
+ name: 'PERSONA',
2899
+ /**
2900
+ * Aliases for the PERSONA command
2901
+ */
2902
+ aliasNames: ['PERSON'],
2903
+ /**
2904
+ * PERSONA command can be used in:
2905
+ */
2906
+ usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
2907
+ /**
2908
+ * Description of the PERSONA command
2909
+ */
2910
+ description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
2911
+ /**
2912
+ * Link to discussion
2913
+ */
2914
+ discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
2915
+ /**
2916
+ * Example usages of the PERSONA command
2917
+ */
2918
+ examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
2919
+ /**
2920
+ * Parses the PERSONA command
2921
+ */
2922
+ parse: function (input) {
2923
+ var rawArgs = input.rawArgs;
2924
+ var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
2925
+ var personaName = (personaNameRaw || '').trim();
2926
+ if (personaName === '') {
2927
+ throw new ParsingError("You must set name for the persona");
2928
+ }
2929
+ var personaDescription = (personaDescriptionRaw || '').trim();
2930
+ if (personaDescription === '') {
2931
+ personaDescription = null;
2932
+ }
2933
+ return {
2934
+ type: 'PERSONA',
2935
+ personaName: personaName,
2936
+ personaDescription: personaDescription,
2937
+ };
2938
+ },
2939
+ /**
2940
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
2941
+ */
2942
+ applyToPipelineJson: function (pipelineJson, personaCommand) {
2943
+ var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
2944
+ var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
2945
+ if (persona === undefined) {
2946
+ pipelineJson.personas.push({
2947
+ name: personaName,
2948
+ description: personaDescription || '',
2949
+ });
2950
+ return;
2951
+ }
2952
+ if (persona.description === personaDescription) {
2953
+ return;
2954
+ }
2955
+ if (personaDescription === null) {
2956
+ return;
2957
+ }
2958
+ if (persona.description === '') {
2959
+ persona.description = personaDescription;
2960
+ return;
2961
+ }
2962
+ console.warn(spaceTrim__default["default"]("\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 ")));
2963
+ persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
2964
+ },
2965
+ };
2756
2966
 
2757
2967
  /**
2758
2968
  * Removes Markdown formatting tags from a string.
@@ -2925,7 +3135,6 @@
2925
3135
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
2926
3136
  var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
2927
3137
  if (blockTypes.length !== 1) {
2928
- // console.log('!!!', { blockType });
2929
3138
  throw new ParsingError(spaceTrim__default["default"](function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
2930
3139
  }
2931
3140
  // TODO: !!!! Not supported yet
@@ -3174,92 +3383,12 @@
3174
3383
  },
3175
3384
  };
3176
3385
 
3177
- /**
3178
- * Tests if given string is valid URL.
3179
- *
3180
- * Note: This does not check if the file exists only if the path is valid
3181
- */
3182
- function isValidFilePath(filePath) {
3183
- if (typeof filePath !== 'string') {
3184
- return false;
3185
- }
3186
- var filePathSlashes = filePath.split('\\').join('/');
3187
- // Absolute Unix path: /hello.txt
3188
- if (/^(\/)/i.test(filePathSlashes)) {
3189
- return true;
3190
- }
3191
- // Absolute Windows path: /hello.txt
3192
- if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
3193
- return true;
3194
- }
3195
- // Relative path: ./hello.txt
3196
- if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
3197
- return true;
3198
- }
3199
- return false;
3200
- }
3201
-
3202
- /**
3203
- * Parses the knowledge command
3204
- *
3205
- * @see ./KNOWLEDGE-README.md for more details
3206
- * @private within the commands folder
3207
- */
3208
- var knowledgeCommandParser = {
3209
- /**
3210
- * Name of the command
3211
- */
3212
- name: 'KNOWLEDGE',
3213
- /**
3214
- * BOILERPLATE command can be used in:
3215
- */
3216
- usagePlaces: ['PIPELINE_HEAD'],
3217
- /**
3218
- * Description of the KNOWLEDGE command
3219
- */
3220
- description: "Tells promptbook which external knowledge to use",
3221
- /**
3222
- * Link to discussion
3223
- */
3224
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
3225
- /**
3226
- * Example usages of the KNOWLEDGE command
3227
- */
3228
- examples: [
3229
- 'KNOWLEDGE https://www.pavolhejny.com/',
3230
- 'KNOWLEDGE ./hejny-cv.txt',
3231
- 'KNOWLEDGE ./hejny-cv.md',
3232
- 'KNOWLEDGE ./hejny-cv.pdf',
3233
- 'KNOWLEDGE ./hejny-cv.docx',
3234
- ],
3235
- /**
3236
- * Parses the KNOWLEDGE command
3237
- */
3238
- parse: function (input) {
3239
- var args = input.args;
3240
- var source = args[0];
3241
- if (source === undefined) {
3242
- throw new ParsingError("Source is not defined");
3243
- }
3244
- if (source.startsWith('http://')) {
3245
- throw new ParsingError("Source is not secure");
3246
- }
3247
- if (!(isValidFilePath(source) || isValidUrl(source))) {
3248
- throw new ParsingError("Source not valid");
3249
- }
3250
- if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
3251
- throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
3252
- }
3253
- return {
3254
- type: 'KNOWLEDGE',
3255
- source: source,
3256
- };
3257
- },
3258
- };
3259
-
3260
3386
  var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
3261
3387
  /**
3262
- * TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
3388
+ * TODO: [🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (simmilar that `user` identification is not here)
3389
+ * TODO: [🧠][💱] Add more model options: `stop_token`, `logit_bias`, `logprobs` (`top_logprobs`), `top_k`, `top_p`, `presence_penalty`, `frequency_penalty`, `bestOf`, `logitBias`, `logitBiasType`,...
3390
+ * [💱] Probbably keep using just `temperature` in Promptbook (not `top_k` and `top_p`)
3391
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3263
3392
  * TODO: Maybe figure out better word than "variant"
3264
3393
  * TODO: Add here more requirement options like max context size, max tokens, etc.
3265
3394
  * TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
@@ -3401,59 +3530,6 @@
3401
3530
  },
3402
3531
  };
3403
3532
 
3404
- /**
3405
- * Parses the persona command
3406
- *
3407
- * @see ./PERSONA-README.md for more details
3408
- * @private within the commands folder
3409
- */
3410
- var personaCommandParser = {
3411
- /**
3412
- * Name of the command
3413
- */
3414
- name: 'PERSONA',
3415
- /**
3416
- * Aliases for the PERSONA command
3417
- */
3418
- aliasNames: ['PERSON'],
3419
- /**
3420
- * PERSONA command can be used in:
3421
- */
3422
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
3423
- /**
3424
- * Description of the PERSONA command
3425
- */
3426
- description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
3427
- /**
3428
- * Link to discussion
3429
- */
3430
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
3431
- /**
3432
- * Example usages of the PERSONA command
3433
- */
3434
- examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
3435
- /**
3436
- * Parses the PERSONA command
3437
- */
3438
- parse: function (input) {
3439
- var rawArgs = input.rawArgs;
3440
- var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
3441
- var personaName = (personaNameRaw || '').trim();
3442
- if (personaName === '') {
3443
- throw new ParsingError("You must set name for the persona");
3444
- }
3445
- var personaDescription = (personaDescriptionRaw || '').trim();
3446
- if (personaDescription === '') {
3447
- personaDescription = null;
3448
- }
3449
- return {
3450
- type: 'PERSONA',
3451
- personaName: personaName,
3452
- personaDescription: personaDescription,
3453
- };
3454
- },
3455
- };
3456
-
3457
3533
  function isValidJavascriptName(javascriptName) {
3458
3534
  if (typeof javascriptName !== 'string') {
3459
3535
  return false;
@@ -3671,7 +3747,8 @@
3671
3747
  * Parses the ACTION command
3672
3748
  */
3673
3749
  parse: function (input) {
3674
- input.args;
3750
+ var args = input.args;
3751
+ TODO_USE(args);
3675
3752
  return {
3676
3753
  type: 'ACTION',
3677
3754
  };
@@ -3709,7 +3786,8 @@
3709
3786
  * Parses the INSTRUMENT command
3710
3787
  */
3711
3788
  parse: function (input) {
3712
- input.args;
3789
+ var args = input.args;
3790
+ TODO_USE(args);
3713
3791
  return {
3714
3792
  type: 'INSTRUMENT',
3715
3793
  };
@@ -3891,7 +3969,6 @@
3891
3969
  var _loop_1 = function (commandParser) {
3892
3970
  var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
3893
3971
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
3894
- // console.log('!!!', { commandName, names });
3895
3972
  if (names.includes(commandName)) {
3896
3973
  try {
3897
3974
  return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
@@ -4001,25 +4078,42 @@
4001
4078
  var e_1, _a;
4002
4079
  var codeBlocks = [];
4003
4080
  var lines = markdown.split('\n');
4081
+ // Note: [0] Ensure that the last block notated by gt > will be closed
4082
+ lines.push('');
4004
4083
  var currentCodeBlock = null;
4005
4084
  try {
4006
4085
  for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
4007
4086
  var line = lines_1_1.value;
4087
+ if (line.startsWith('> ') || line === '>') {
4088
+ if (currentCodeBlock === null) {
4089
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
4090
+ } /* not else */
4091
+ if (currentCodeBlock.blockNotation === '>') {
4092
+ if (currentCodeBlock.content !== '') {
4093
+ currentCodeBlock.content += '\n';
4094
+ }
4095
+ currentCodeBlock.content += line.slice(2);
4096
+ }
4097
+ }
4098
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
4099
+ codeBlocks.push(currentCodeBlock);
4100
+ currentCodeBlock = null;
4101
+ }
4102
+ /* not else */
4008
4103
  if (line.startsWith('```')) {
4009
4104
  var language = line.slice(3).trim() || null;
4010
4105
  if (currentCodeBlock === null) {
4011
- currentCodeBlock = { language: language, content: '' };
4106
+ currentCodeBlock = { blockNotation: '```', language: language, content: '' };
4012
4107
  }
4013
4108
  else {
4014
4109
  if (language !== null) {
4015
- // [🌻]
4016
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
4110
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
4017
4111
  }
4018
4112
  codeBlocks.push(currentCodeBlock);
4019
4113
  currentCodeBlock = null;
4020
4114
  }
4021
4115
  }
4022
- else if (currentCodeBlock !== null) {
4116
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
4023
4117
  if (currentCodeBlock.content !== '') {
4024
4118
  currentCodeBlock.content += '\n';
4025
4119
  }
@@ -4035,11 +4129,13 @@
4035
4129
  finally { if (e_1) throw e_1.error; }
4036
4130
  }
4037
4131
  if (currentCodeBlock !== null) {
4038
- // [🌻]
4039
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
4132
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
4040
4133
  }
4041
4134
  return codeBlocks;
4042
4135
  }
4136
+ /**
4137
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
4138
+ */
4043
4139
 
4044
4140
  /**
4045
4141
  * Extracts exactly ONE code block from markdown.
@@ -4057,13 +4153,12 @@
4057
4153
  function extractOneBlockFromMarkdown(markdown) {
4058
4154
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
4059
4155
  if (codeBlocks.length !== 1) {
4060
- // TODO: Report more specific place where the error happened
4061
- throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
4156
+ throw new ParsingError(spaceTrim__default["default"](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 "); }));
4062
4157
  }
4063
4158
  return codeBlocks[0];
4064
4159
  }
4065
4160
  /***
4066
- * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
4161
+ * TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
4067
4162
  */
4068
4163
 
4069
4164
  /**
@@ -4073,13 +4168,13 @@
4073
4168
  var _a, _b;
4074
4169
  var lines = value.split('\n');
4075
4170
  if (!lines[0].startsWith('#')) {
4076
- throw new Error('Markdown section must start with heading');
4171
+ throw new ParsingError('Markdown section must start with heading');
4077
4172
  }
4078
4173
  var title = lines[0].replace(/^#+\s*/, '');
4079
4174
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
4080
4175
  var content = spaceTrim__default["default"](lines.slice(1).join('\n'));
4081
4176
  if (level < 1 || level > 6) {
4082
- throw new Error('Markdown section must have heading level between 1 and 6');
4177
+ throw new ParsingError('Markdown section must have heading level between 1 and 6');
4083
4178
  }
4084
4179
  return { title: title, level: level, content: content };
4085
4180
  }
@@ -4461,7 +4556,7 @@
4461
4556
  existingParameter.description &&
4462
4557
  existingParameter.description !== parameterDescription &&
4463
4558
  parameterDescription) {
4464
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
4559
+ throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
4465
4560
  }
4466
4561
  if (existingParameter) {
4467
4562
  if (parameterDescription) {
@@ -4480,11 +4575,12 @@
4480
4575
  // =============================================================
4481
4576
  // Note: 3️⃣ Process pipeline head
4482
4577
  pipelineJson.title = pipelineHead.title;
4483
- // TODO: [1] DRY description
4578
+ // TODO: [🎾][1] DRY description
4484
4579
  var description = pipelineHead.content;
4485
- // Note: Remove codeblocks - TODO: Maybe put this into util (exported from `@promptbool/utils`)
4580
+ // Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
4486
4581
  description = description.split(/^```.*^```/gms).join('');
4487
- //Note: Remove lists and return statement - TODO: Maybe put this into util (exported from `@promptbool/utils`)
4582
+ description = description.split(/^>.*$/gm).join('');
4583
+ //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
4488
4584
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4489
4585
  description = spaceTrim.spaceTrim(description);
4490
4586
  if (description === '') {
@@ -4512,7 +4608,7 @@
4512
4608
  pipelineJson.pipelineUrl = command.pipelineUrl.href;
4513
4609
  break;
4514
4610
  case 'KNOWLEDGE':
4515
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4611
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
4516
4612
  break;
4517
4613
  case 'ACTION':
4518
4614
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
@@ -4521,7 +4617,8 @@
4521
4617
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4522
4618
  break;
4523
4619
  case 'PERSONA':
4524
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
4620
+ personaCommandParser.applyToPipelineJson(pipelineJson, command);
4621
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4525
4622
  break;
4526
4623
  case 'BOILERPLATE':
4527
4624
  throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
@@ -4550,7 +4647,27 @@
4550
4647
  var postprocessing = [];
4551
4648
  var expectAmount = {};
4552
4649
  var expectFormat = undefined;
4553
- var isBlockTypeChanged = false;
4650
+ var isBlockTypeSet = false;
4651
+ var lastLine = section.content.split('\n').pop();
4652
+ var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
4653
+ var resultingParameterName = null;
4654
+ if (resultingParameterNameMatch &&
4655
+ resultingParameterNameMatch.groups !== undefined &&
4656
+ resultingParameterNameMatch.groups.resultingParamName !== undefined) {
4657
+ resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
4658
+ }
4659
+ var expectResultingParameterName = function () {
4660
+ if (resultingParameterName !== null) {
4661
+ return resultingParameterName;
4662
+ }
4663
+ throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
4664
+ // TODO: Show code of invalid sections each time + DRY
4665
+ section.content
4666
+ .split('\n')
4667
+ .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
4668
+ .join('\n')), "\n "); }));
4669
+ };
4670
+ var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
4554
4671
  try {
4555
4672
  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()) {
4556
4673
  var listItem = listItems_2_1.value;
@@ -4558,15 +4675,24 @@
4558
4675
  switch (command.type) {
4559
4676
  // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
4560
4677
  case 'BLOCK':
4561
- if (isBlockTypeChanged) {
4678
+ if (isBlockTypeSet) {
4562
4679
  throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
4563
4680
  }
4564
4681
  if (command.blockType === 'SAMPLE') {
4565
- console.error(new NotYetImplementedError('Block type SAMPLE is not implemented yet'));
4682
+ expectResultingParameterName();
4683
+ var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
4684
+ if (parameter === undefined) {
4685
+ throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
4686
+ }
4687
+ parameter.sampleValues = parameter.sampleValues || [];
4688
+ parameter.sampleValues.push(content);
4566
4689
  return "continue-templates";
4567
4690
  }
4568
4691
  if (command.blockType === 'KNOWLEDGE') {
4569
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4692
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, {
4693
+ type: 'KNOWLEDGE',
4694
+ source: content, // <- TODO: !!!! Working KNOWLEDGE which not referring to the source file/wweb, but its content itseld
4695
+ });
4570
4696
  return "continue-templates";
4571
4697
  }
4572
4698
  if (command.blockType === 'ACTION') {
@@ -4577,8 +4703,9 @@
4577
4703
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4578
4704
  return "continue-templates";
4579
4705
  }
4706
+ expectResultingParameterName();
4580
4707
  blockType = command.blockType;
4581
- isBlockTypeChanged = true;
4708
+ isBlockTypeSet = true;
4582
4709
  break;
4583
4710
  case 'EXPECT_AMOUNT':
4584
4711
  // eslint-disable-next-line no-case-declarations
@@ -4618,16 +4745,20 @@
4618
4745
  postprocessing.push(command.functionName);
4619
4746
  break;
4620
4747
  case 'KNOWLEDGE':
4621
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4748
+ // TODO: [👙] The knowledge is maybe relevant for just this template
4749
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
4622
4750
  break;
4623
4751
  case 'ACTION':
4752
+ // TODO: [👙] The action is maybe relevant for just this template
4624
4753
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
4625
4754
  break;
4626
4755
  case 'INSTRUMENT':
4756
+ // TODO: [👙] The instrument is maybe relevant for just this template
4627
4757
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4628
4758
  break;
4629
4759
  case 'PERSONA':
4630
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
4760
+ personaCommandParser.applyToPipelineJson(pipelineJson, command);
4761
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4631
4762
  break;
4632
4763
  case 'BOILERPLATE':
4633
4764
  console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
@@ -4645,7 +4776,6 @@
4645
4776
  }
4646
4777
  finally { if (e_3) throw e_3.error; }
4647
4778
  }
4648
- var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
4649
4779
  if (blockType === 'SCRIPT') {
4650
4780
  if (!language) {
4651
4781
  throw new ParsingError('You must specify the language of the script in the prompt template');
@@ -4654,22 +4784,12 @@
4654
4784
  throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
4655
4785
  }
4656
4786
  }
4657
- var lastLine = section.content.split('\n').pop();
4658
- var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
4659
- if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
4660
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
4661
- // TODO: Show code of invalid sections each time + DRY
4662
- section.content
4663
- .split('\n')
4664
- .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
4665
- .join('\n')), "\n "); }));
4666
- }
4667
- var resultingParameterName = match.groups.resultingParamName;
4668
- // TODO: [1] DRY description
4787
+ // TODO: [🎾][1] DRY description
4669
4788
  var description_1 = section.content;
4670
- // Note: Remove codeblocks
4789
+ // Note: Remove codeblocks - TODO: [🎾]
4671
4790
  description_1 = description_1.split(/^```.*^```/gms).join('');
4672
- //Note: Remove lists and return statement
4791
+ description_1 = description_1.split(/^>.*$/gm).join('');
4792
+ //Note: Remove lists and return statement - TODO: [🎾]
4673
4793
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4674
4794
  description_1 = spaceTrim.spaceTrim(description_1);
4675
4795
  if (description_1 === '') {
@@ -4703,7 +4823,7 @@
4703
4823
  modelRequirements: templateModelRequirements,
4704
4824
  contentLanguage: blockType === 'SCRIPT' ? language : undefined,
4705
4825
  content: content,
4706
- resultingParameterName: resultingParameterName,
4826
+ resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
4707
4827
  };
4708
4828
  if (blockType !== 'PROMPT_TEMPLATE') {
4709
4829
  delete template.modelRequirements;
@@ -4776,6 +4896,8 @@
4776
4896
  * TODO: Use spaceTrim more effectively
4777
4897
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
4778
4898
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
4899
+ * TODO: [♈] Probbably move expectations from templates to parameters
4900
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4779
4901
  */
4780
4902
 
4781
4903
  /**
@@ -4815,6 +4937,7 @@
4815
4937
  }
4816
4938
  /**
4817
4939
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
4940
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4818
4941
  */
4819
4942
 
4820
4943
  /**
@@ -4961,6 +5084,7 @@
4961
5084
  else {
4962
5085
  colors__default["default"].green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
4963
5086
  // TODO: !! Implement;
5087
+ // TODO: [🌗]
4964
5088
  }
4965
5089
  _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;
4966
5090
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -5005,6 +5129,7 @@
5005
5129
  case 5:
5006
5130
  // TODO: Handle non-valid JSON files
5007
5131
  promptbook = _d.apply(_c, [_e.sent()]);
5132
+ // TODO: [🌗]
5008
5133
  promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5009
5134
  return [3 /*break*/, 7];
5010
5135
  case 6: