@promptbook/pdf 0.94.0 → 0.98.0-10

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 (75) hide show
  1. package/README.md +6 -2
  2. package/esm/index.es.js +229 -168
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/cli.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/openai.index.d.ts +10 -0
  8. package/esm/typings/src/_packages/types.index.d.ts +14 -4
  9. package/esm/typings/src/_packages/{wizzard.index.d.ts → wizard.index.d.ts} +6 -2
  10. package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -1
  11. package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -1
  12. package/esm/typings/src/config.d.ts +1 -1
  13. package/esm/typings/src/conversion/archive/loadArchive.d.ts +1 -1
  14. package/esm/typings/src/conversion/archive/saveArchive.d.ts +2 -2
  15. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +1 -1
  16. package/esm/typings/src/dialogs/callback/CallbackInterfaceTools.d.ts +1 -1
  17. package/esm/typings/src/execution/AbstractTaskResult.d.ts +2 -2
  18. package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +8 -0
  19. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +1 -1
  20. package/esm/typings/src/execution/execution-report/ExecutionPromptReportJson.d.ts +2 -2
  21. package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +1 -1
  22. package/esm/typings/src/execution/utils/validatePromptResult.d.ts +53 -0
  23. package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForWizzardOrCli.d.ts → $provideLlmToolsForWizardOrCli.d.ts} +2 -2
  24. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -3
  25. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
  26. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
  27. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +1 -1
  28. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -1
  29. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -1
  30. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +1 -1
  32. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/ollama/register-configuration.d.ts +1 -1
  35. package/esm/typings/src/llm-providers/ollama/register-constructor.d.ts +1 -1
  36. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -1
  37. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +2 -2
  38. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +4 -4
  39. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionToolsOptions.d.ts +52 -0
  40. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +3 -5
  41. package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +74 -0
  42. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +13 -2
  43. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +16 -2
  44. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +1 -1
  45. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
  46. package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +1 -1
  47. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +2 -2
  48. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
  49. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +1 -1
  50. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  51. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -1
  52. package/esm/typings/src/scrapers/document/register-metadata.d.ts +2 -2
  53. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +1 -1
  54. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -1
  55. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +2 -2
  56. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +1 -4
  57. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -1
  58. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +2 -2
  59. package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +1 -1
  60. package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +1 -1
  61. package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +2 -2
  62. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
  63. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -1
  64. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +2 -2
  65. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +1 -1
  66. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -1
  67. package/esm/typings/src/scrapers/website/register-metadata.d.ts +2 -2
  68. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  69. package/esm/typings/src/utils/files/listAllFiles.d.ts +1 -1
  70. package/esm/typings/src/version.d.ts +1 -1
  71. package/esm/typings/src/{wizzard → wizard}/$getCompiledBook.d.ts +2 -2
  72. package/esm/typings/src/{wizzard/wizzard.d.ts → wizard/wizard.d.ts} +6 -6
  73. package/package.json +2 -14
  74. package/umd/index.umd.js +229 -168
  75. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.94.0';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.98.0-10';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -174,7 +174,7 @@
174
174
  *
175
175
  * @public exported from `@promptbook/core`
176
176
  */
177
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
177
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 7; // <- TODO: [🤹‍♂️]
178
178
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
179
179
  // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
180
180
  /**
@@ -874,7 +874,7 @@
874
874
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
875
875
  */
876
876
 
877
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",parameters:[{name:"availableModels",description:"List of available model names together with their descriptions as JSON",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelsRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n```json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n```\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n```json\n{availableModels}\n```\n\n### Key `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### Key `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:"modelsRequirements",format:"JSON",dependentParameterNames:["availableModels","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModels}` List of available model names together with their descriptions as JSON\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelsRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n\\`\\`\\`json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n\\`\\`\\`json\n{availableModels}\n\\`\\`\\`\n\n### Key `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### Key `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}\n```\n\n`-> {modelsRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
877
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",parameters:[{name:"availableModels",description:"List of available model names together with their descriptions as JSON",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelsRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n```json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpful assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n```\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n```json\n{availableModels}\n```\n\n### Key `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### Key `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:"modelsRequirements",format:"JSON",dependentParameterNames:["availableModels","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModels}` List of available model names together with their descriptions as JSON\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelsRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n\\`\\`\\`json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpful assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n\\`\\`\\`json\n{availableModels}\n\\`\\`\\`\n\n### Key `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### Key `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}\n```\n\n`-> {modelsRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
878
878
 
879
879
  /**
880
880
  * Checks if value is valid email
@@ -1031,7 +1031,7 @@
1031
1031
  });
1032
1032
  }
1033
1033
  catch (error) {
1034
- // TODO: [🟥] Detect browser / node and make it colorfull
1034
+ // TODO: [🟥] Detect browser / node and make it colorful
1035
1035
  console.error('There was an error with prettifying the markdown, using the original as the fallback', {
1036
1036
  error,
1037
1037
  html: content,
@@ -1313,7 +1313,7 @@
1313
1313
  else {
1314
1314
  for (const [subName, subValue] of Object.entries(value)) {
1315
1315
  if (subValue === undefined) {
1316
- // Note: undefined in object is serializable - it is just omited
1316
+ // Note: undefined in object is serializable - it is just omitted
1317
1317
  continue;
1318
1318
  }
1319
1319
  checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
@@ -2003,7 +2003,7 @@
2003
2003
 
2004
2004
  Note: You have probably forgotten to run "ptbk make" to update the collection
2005
2005
  Note: Pipelines with the same URL are not allowed
2006
- Only exepction is when the pipelines are identical
2006
+ Only exception is when the pipelines are identical
2007
2007
 
2008
2008
  `));
2009
2009
  }
@@ -2400,7 +2400,7 @@
2400
2400
  throw new Error(spaceTrim__default["default"]((block) => `
2401
2401
  ${block(error.message)}
2402
2402
 
2403
- The JSON text:
2403
+ The expected JSON text:
2404
2404
  ${block(value)}
2405
2405
  `));
2406
2406
  }
@@ -2771,12 +2771,12 @@
2771
2771
  get title() {
2772
2772
  return `${llmTools.title} (+usage)`;
2773
2773
  // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2774
- // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2774
+ // <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
2775
2775
  },
2776
2776
  get description() {
2777
2777
  return `${llmTools.description} (+usage)`;
2778
2778
  // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2779
- // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2779
+ // <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
2780
2780
  },
2781
2781
  checkConfiguration() {
2782
2782
  return /* not await */ llmTools.checkConfiguration();
@@ -3003,13 +3003,13 @@
3003
3003
 
3004
3004
  Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.
3005
3005
  `);
3006
- // TODO: [🟥] Detect browser / node and make it colorfull
3006
+ // TODO: [🟥] Detect browser / node and make it colorful
3007
3007
  console.warn(warningMessage);
3008
3008
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3009
3009
  /*
3010
3010
  return {
3011
3011
  async listModels() {
3012
- // TODO: [🟥] Detect browser / node and make it colorfull
3012
+ // TODO: [🟥] Detect browser / node and make it colorful
3013
3013
  console.warn(
3014
3014
  spaceTrim(
3015
3015
  (block) => `
@@ -3285,17 +3285,17 @@
3285
3285
  * Mixes registered scrapers from $scrapersMetadataRegister and $scrapersRegister
3286
3286
  */
3287
3287
  const all = [];
3288
- for (const { packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser, } of $scrapersMetadataRegister.list()) {
3288
+ for (const { packageName, className, mimeTypes, documentationUrl, isAvailableInBrowser, } of $scrapersMetadataRegister.list()) {
3289
3289
  if (all.some((item) => item.packageName === packageName && item.className === className)) {
3290
3290
  continue;
3291
3291
  }
3292
- all.push({ packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser });
3292
+ all.push({ packageName, className, mimeTypes, documentationUrl, isAvailableInBrowser });
3293
3293
  }
3294
- for (const { packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser, } of $scrapersRegister.list()) {
3294
+ for (const { packageName, className, mimeTypes, documentationUrl, isAvailableInBrowser, } of $scrapersRegister.list()) {
3295
3295
  if (all.some((item) => item.packageName === packageName && item.className === className)) {
3296
3296
  continue;
3297
3297
  }
3298
- all.push({ packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser });
3298
+ all.push({ packageName, className, mimeTypes, documentationUrl, isAvailableInBrowser });
3299
3299
  }
3300
3300
  for (const { metadata } of availableScrapers) {
3301
3301
  all.push(metadata);
@@ -3307,8 +3307,8 @@
3307
3307
  const isInstalled = $scrapersRegister
3308
3308
  .list()
3309
3309
  .find(({ packageName, className }) => metadata.packageName === packageName && metadata.className === className);
3310
- const isAvilableInTools = availableScrapers.some(({ metadata: { packageName, className } }) => metadata.packageName === packageName && metadata.className === className);
3311
- return { ...metadata, isMetadataAviailable, isInstalled, isAvilableInTools };
3310
+ const isAvailableInTools = availableScrapers.some(({ metadata: { packageName, className } }) => metadata.packageName === packageName && metadata.className === className);
3311
+ return { ...metadata, isMetadataAviailable, isInstalled, isAvailableInTools };
3312
3312
  });
3313
3313
  if (metadata.length === 0) {
3314
3314
  return spaceTrim__default["default"](`
@@ -3321,7 +3321,7 @@
3321
3321
  return spaceTrim__default["default"]((block) => `
3322
3322
  Available scrapers are:
3323
3323
  ${block(metadata
3324
- .map(({ packageName, className, isMetadataAviailable, isInstalled, mimeTypes, isAvilableInBrowser, isAvilableInTools, }, i) => {
3324
+ .map(({ packageName, className, isMetadataAviailable, isInstalled, mimeTypes, isAvailableInBrowser, isAvailableInTools, }, i) => {
3325
3325
  const more = [];
3326
3326
  // TODO: [🧠] Maybe use `documentationUrl`
3327
3327
  if (isMetadataAviailable) {
@@ -3330,16 +3330,16 @@
3330
3330
  if (isInstalled) {
3331
3331
  more.push(`🟩 Installed`);
3332
3332
  } // not else
3333
- if (isAvilableInTools) {
3333
+ if (isAvailableInTools) {
3334
3334
  more.push(`🟦 Available in tools`);
3335
3335
  } // not else
3336
3336
  if (!isMetadataAviailable && isInstalled) {
3337
3337
  more.push(`When no metadata registered but scraper is installed, it is an unexpected behavior`);
3338
3338
  } // not else
3339
- if (!isInstalled && isAvilableInTools) {
3339
+ if (!isInstalled && isAvailableInTools) {
3340
3340
  more.push(`When the scraper is not installed but available in tools, it is an unexpected compatibility behavior`);
3341
3341
  } // not else
3342
- if (!isAvilableInBrowser) {
3342
+ if (!isAvailableInBrowser) {
3343
3343
  more.push(`Not usable in browser`);
3344
3344
  }
3345
3345
  const moreText = more.length === 0 ? '' : ` *(${more.join('; ')})*`;
@@ -3679,7 +3679,7 @@
3679
3679
  /**
3680
3680
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3681
3681
  * Put `knowledgePieces` into `PrepareKnowledgeOptions`
3682
- * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
3682
+ * TODO: [🪂] More than max things can run in parallel by accident [1,[2a,2b,_],[3a,3b,_]]
3683
3683
  * TODO: [🧠][❎] Do here proper M:N mapping
3684
3684
  * [x] One source can make multiple pieces
3685
3685
  * [ ] One piece can have multiple sources
@@ -4487,6 +4487,77 @@
4487
4487
  return mappedParameters;
4488
4488
  }
4489
4489
 
4490
+ /**
4491
+ * Replaces parameters in template with values from parameters object
4492
+ *
4493
+ * Note: This function is not places strings into string,
4494
+ * It's more complex and can handle this operation specifically for LLM models
4495
+ *
4496
+ * @param template the template with parameters in {curly} braces
4497
+ * @param parameters the object with parameters
4498
+ * @returns the template with replaced parameters
4499
+ * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
4500
+ * @public exported from `@promptbook/utils`
4501
+ */
4502
+ function templateParameters(template, parameters) {
4503
+ for (const [parameterName, parameterValue] of Object.entries(parameters)) {
4504
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
4505
+ throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
4506
+ }
4507
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
4508
+ // TODO: [🍵]
4509
+ throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
4510
+ }
4511
+ }
4512
+ let replacedTemplates = template;
4513
+ let match;
4514
+ let loopLimit = LOOP_LIMIT;
4515
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
4516
+ .exec(replacedTemplates))) {
4517
+ if (loopLimit-- < 0) {
4518
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
4519
+ }
4520
+ const precol = match.groups.precol;
4521
+ const parameterName = match.groups.parameterName;
4522
+ if (parameterName === '') {
4523
+ // Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
4524
+ continue;
4525
+ }
4526
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
4527
+ throw new PipelineExecutionError('Parameter is already opened or not closed');
4528
+ }
4529
+ if (parameters[parameterName] === undefined) {
4530
+ throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
4531
+ }
4532
+ let parameterValue = parameters[parameterName];
4533
+ if (parameterValue === undefined) {
4534
+ throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
4535
+ }
4536
+ parameterValue = valueToString(parameterValue);
4537
+ // Escape curly braces in parameter values to prevent prompt-injection
4538
+ parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
4539
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4540
+ parameterValue = parameterValue
4541
+ .split('\n')
4542
+ .map((line, index) => (index === 0 ? line : `${precol}${line}`))
4543
+ .join('\n');
4544
+ }
4545
+ replacedTemplates =
4546
+ replacedTemplates.substring(0, match.index + precol.length) +
4547
+ parameterValue +
4548
+ replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
4549
+ }
4550
+ // [💫] Check if there are parameters that are not closed properly
4551
+ if (/{\w+$/.test(replacedTemplates)) {
4552
+ throw new PipelineExecutionError('Parameter is not closed');
4553
+ }
4554
+ // [💫] Check if there are parameters that are not opened properly
4555
+ if (/^\w+}/.test(replacedTemplates)) {
4556
+ throw new PipelineExecutionError('Parameter is not opened');
4557
+ }
4558
+ return replacedTemplates;
4559
+ }
4560
+
4490
4561
  /**
4491
4562
  * Extracts all code blocks from markdown.
4492
4563
  *
@@ -4589,77 +4660,6 @@
4589
4660
  * TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
4590
4661
  */
4591
4662
 
4592
- /**
4593
- * Replaces parameters in template with values from parameters object
4594
- *
4595
- * Note: This function is not places strings into string,
4596
- * It's more complex and can handle this operation specifically for LLM models
4597
- *
4598
- * @param template the template with parameters in {curly} braces
4599
- * @param parameters the object with parameters
4600
- * @returns the template with replaced parameters
4601
- * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
4602
- * @public exported from `@promptbook/utils`
4603
- */
4604
- function templateParameters(template, parameters) {
4605
- for (const [parameterName, parameterValue] of Object.entries(parameters)) {
4606
- if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
4607
- throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
4608
- }
4609
- else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
4610
- // TODO: [🍵]
4611
- throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
4612
- }
4613
- }
4614
- let replacedTemplates = template;
4615
- let match;
4616
- let loopLimit = LOOP_LIMIT;
4617
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
4618
- .exec(replacedTemplates))) {
4619
- if (loopLimit-- < 0) {
4620
- throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
4621
- }
4622
- const precol = match.groups.precol;
4623
- const parameterName = match.groups.parameterName;
4624
- if (parameterName === '') {
4625
- // Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
4626
- continue;
4627
- }
4628
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
4629
- throw new PipelineExecutionError('Parameter is already opened or not closed');
4630
- }
4631
- if (parameters[parameterName] === undefined) {
4632
- throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
4633
- }
4634
- let parameterValue = parameters[parameterName];
4635
- if (parameterValue === undefined) {
4636
- throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
4637
- }
4638
- parameterValue = valueToString(parameterValue);
4639
- // Escape curly braces in parameter values to prevent prompt-injection
4640
- parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
4641
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4642
- parameterValue = parameterValue
4643
- .split('\n')
4644
- .map((line, index) => (index === 0 ? line : `${precol}${line}`))
4645
- .join('\n');
4646
- }
4647
- replacedTemplates =
4648
- replacedTemplates.substring(0, match.index + precol.length) +
4649
- parameterValue +
4650
- replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
4651
- }
4652
- // [💫] Check if there are parameters that are not closed properly
4653
- if (/{\w+$/.test(replacedTemplates)) {
4654
- throw new PipelineExecutionError('Parameter is not closed');
4655
- }
4656
- // [💫] Check if there are parameters that are not opened properly
4657
- if (/^\w+}/.test(replacedTemplates)) {
4658
- throw new PipelineExecutionError('Parameter is not opened');
4659
- }
4660
- return replacedTemplates;
4661
- }
4662
-
4663
4663
  /**
4664
4664
  * Counts number of characters in the text
4665
4665
  *
@@ -4820,6 +4820,68 @@
4820
4820
  * Note: [💝] and [🤠] are interconnected together
4821
4821
  */
4822
4822
 
4823
+ /**
4824
+ * Validates a prompt result against expectations and format requirements.
4825
+ * This function provides a common abstraction for result validation that can be used
4826
+ * by both execution logic and caching logic to ensure consistency.
4827
+ *
4828
+ * @param options - The validation options including result string, expectations, and format
4829
+ * @returns Validation result with processed string and validity status
4830
+ * @private internal function of `createPipelineExecutor` and `cacheLlmTools`
4831
+ */
4832
+ function validatePromptResult(options) {
4833
+ const { resultString, expectations, format } = options;
4834
+ let processedResultString = resultString;
4835
+ let validationError;
4836
+ try {
4837
+ // TODO: [💝] Unite object for expecting amount and format
4838
+ if (format) {
4839
+ if (format === 'JSON') {
4840
+ if (!isValidJsonString(processedResultString)) {
4841
+ // TODO: [🏢] Do more universally via `FormatParser`
4842
+ try {
4843
+ processedResultString = extractJsonBlock(processedResultString);
4844
+ }
4845
+ catch (error) {
4846
+ keepUnused(error);
4847
+ throw new ExpectError(spaceTrim.spaceTrim((block) => `
4848
+ Expected valid JSON string
4849
+
4850
+ The expected JSON text:
4851
+ ${block(processedResultString)}
4852
+ `));
4853
+ }
4854
+ }
4855
+ }
4856
+ else {
4857
+ throw new UnexpectedError(`Unknown format "${format}"`);
4858
+ }
4859
+ }
4860
+ // TODO: [💝] Unite object for expecting amount and format
4861
+ if (expectations) {
4862
+ checkExpectations(expectations, processedResultString);
4863
+ }
4864
+ return {
4865
+ isValid: true,
4866
+ processedResultString,
4867
+ };
4868
+ }
4869
+ catch (error) {
4870
+ if (error instanceof ExpectError) {
4871
+ validationError = error;
4872
+ }
4873
+ else {
4874
+ // Re-throw non-ExpectError errors (like UnexpectedError)
4875
+ throw error;
4876
+ }
4877
+ return {
4878
+ isValid: false,
4879
+ processedResultString,
4880
+ error: validationError,
4881
+ };
4882
+ }
4883
+ }
4884
+
4823
4885
  /**
4824
4886
  * Executes a pipeline task with multiple attempts, including joker and retry logic. Handles different task types
4825
4887
  * (prompt, script, dialog, etc.), applies postprocessing, checks expectations, and updates the execution report.
@@ -4837,17 +4899,18 @@
4837
4899
  $resultString: null,
4838
4900
  $expectError: null,
4839
4901
  $scriptPipelineExecutionErrors: [],
4902
+ $failedResults: [], // Track all failed attempts
4840
4903
  };
4841
4904
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
4842
4905
  const _llms = arrayableToArray(tools.llm);
4843
4906
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
4844
- attempts: for (let attempt = -jokerParameterNames.length; attempt < maxAttempts; attempt++) {
4845
- const isJokerAttempt = attempt < 0;
4846
- const jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
4907
+ attempts: for (let attemptIndex = -jokerParameterNames.length; attemptIndex < maxAttempts; attemptIndex++) {
4908
+ const isJokerAttempt = attemptIndex < 0;
4909
+ const jokerParameterName = jokerParameterNames[jokerParameterNames.length + attemptIndex];
4847
4910
  // TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
4848
4911
  if (isJokerAttempt && !jokerParameterName) {
4849
4912
  throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
4850
- Joker not found in attempt ${attempt}
4913
+ Joker not found in attempt ${attemptIndex}
4851
4914
 
4852
4915
  ${block(pipelineIdentification)}
4853
4916
  `));
@@ -5045,35 +5108,18 @@
5045
5108
  }
5046
5109
  }
5047
5110
  // TODO: [💝] Unite object for expecting amount and format
5048
- if (task.format) {
5049
- if (task.format === 'JSON') {
5050
- if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
5051
- // TODO: [🏢] Do more universally via `FormatParser`
5052
- try {
5053
- $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
5054
- }
5055
- catch (error) {
5056
- keepUnused(error);
5057
- throw new ExpectError(spaceTrim.spaceTrim((block) => `
5058
- Expected valid JSON string
5059
-
5060
- ${block(
5061
- /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ '')}
5062
- `));
5063
- }
5064
- }
5065
- }
5066
- else {
5067
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5068
- Unknown format "${task.format}"
5069
-
5070
- ${block(pipelineIdentification)}
5071
- `));
5111
+ // Use the common validation function for both format and expectations
5112
+ if (task.format || task.expectations) {
5113
+ const validationResult = validatePromptResult({
5114
+ resultString: $ongoingTaskResult.$resultString || '',
5115
+ expectations: task.expectations,
5116
+ format: task.format,
5117
+ });
5118
+ if (!validationResult.isValid) {
5119
+ throw validationResult.error;
5072
5120
  }
5073
- }
5074
- // TODO: [💝] Unite object for expecting amount and format
5075
- if (task.expectations) {
5076
- checkExpectations(task.expectations, $ongoingTaskResult.$resultString || '');
5121
+ // Update the result string in case format processing modified it (e.g., JSON extraction)
5122
+ $ongoingTaskResult.$resultString = validationResult.processedResultString;
5077
5123
  }
5078
5124
  break attempts;
5079
5125
  }
@@ -5082,6 +5128,15 @@
5082
5128
  throw error;
5083
5129
  }
5084
5130
  $ongoingTaskResult.$expectError = error;
5131
+ // Store each failed attempt
5132
+ if (!Array.isArray($ongoingTaskResult.$failedResults)) {
5133
+ $ongoingTaskResult.$failedResults = [];
5134
+ }
5135
+ $ongoingTaskResult.$failedResults.push({
5136
+ attemptIndex,
5137
+ result: $ongoingTaskResult.$resultString,
5138
+ error: error,
5139
+ });
5085
5140
  }
5086
5141
  finally {
5087
5142
  if (!isJokerAttempt &&
@@ -5103,35 +5158,41 @@
5103
5158
  });
5104
5159
  }
5105
5160
  }
5106
- if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
5161
+ if ($ongoingTaskResult.$expectError !== null && attemptIndex === maxAttempts - 1) {
5162
+ // Note: Create a summary of all failures
5163
+ const failuresSummary = $ongoingTaskResult.$failedResults
5164
+ .map((failure) => spaceTrim.spaceTrim((block) => {
5165
+ var _a, _b;
5166
+ return `
5167
+ Attempt ${failure.attemptIndex + 1}:
5168
+ Error ${((_a = failure.error) === null || _a === void 0 ? void 0 : _a.name) || ''}:
5169
+ ${block((_b = failure.error) === null || _b === void 0 ? void 0 : _b.message.split('\n').map((line) => `> ${line}`).join('\n'))}
5170
+
5171
+ Result:
5172
+ ${block(failure.result === null
5173
+ ? 'null'
5174
+ : spaceTrim.spaceTrim(failure.result)
5175
+ .split('\n')
5176
+ .map((line) => `> ${line}`)
5177
+ .join('\n'))}
5178
+ `;
5179
+ }))
5180
+ .join('\n\n---\n\n');
5107
5181
  throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => {
5108
- var _a, _b, _c;
5182
+ var _a;
5109
5183
  return `
5110
5184
  LLM execution failed ${maxExecutionAttempts}x
5111
5185
 
5112
5186
  ${block(pipelineIdentification)}
5113
5187
 
5114
- ---
5115
5188
  The Prompt:
5116
5189
  ${block((((_a = $ongoingTaskResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
5117
5190
  .split('\n')
5118
5191
  .map((line) => `> ${line}`)
5119
5192
  .join('\n'))}
5120
5193
 
5121
- Last error ${((_b = $ongoingTaskResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || ''}:
5122
- ${block((((_c = $ongoingTaskResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
5123
- .split('\n')
5124
- .map((line) => `> ${line}`)
5125
- .join('\n'))}
5126
-
5127
- Last result:
5128
- ${block($ongoingTaskResult.$resultString === null
5129
- ? 'null'
5130
- : spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
5131
- .split('\n')
5132
- .map((line) => `> ${line}`)
5133
- .join('\n'))}
5134
- ---
5194
+ All Failed Attempts:
5195
+ ${block(failuresSummary)}
5135
5196
  `;
5136
5197
  }));
5137
5198
  }
@@ -5351,10 +5412,10 @@
5351
5412
  */
5352
5413
  async function getKnowledgeForTask(options) {
5353
5414
  const { tools, preparedPipeline, task, parameters } = options;
5354
- const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
5355
- const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
5415
+ const firstKnowledgePiece = preparedPipeline.knowledgePieces[0];
5416
+ const firstKnowledgeIndex = firstKnowledgePiece === null || firstKnowledgePiece === void 0 ? void 0 : firstKnowledgePiece.index[0];
5356
5417
  // <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
5357
- if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
5418
+ if (firstKnowledgePiece === undefined || firstKnowledgeIndex === undefined) {
5358
5419
  return ''; // <- Note: Np knowledge present, return empty string
5359
5420
  }
5360
5421
  try {
@@ -5365,7 +5426,7 @@
5365
5426
  title: 'Knowledge Search',
5366
5427
  modelRequirements: {
5367
5428
  modelVariant: 'EMBEDDING',
5368
- modelName: firstKnowlegeIndex.modelName,
5429
+ modelName: firstKnowledgeIndex.modelName,
5369
5430
  },
5370
5431
  content: task.content,
5371
5432
  parameters,
@@ -5373,7 +5434,7 @@
5373
5434
  const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5374
5435
  const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5375
5436
  const { index } = knowledgePiece;
5376
- const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5437
+ const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowledgeIndex.modelName);
5377
5438
  // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5378
5439
  if (knowledgePieceIndex === undefined) {
5379
5440
  return {
@@ -5394,8 +5455,8 @@
5394
5455
  task,
5395
5456
  taskEmbeddingPrompt,
5396
5457
  taskEmbeddingResult,
5397
- firstKnowlegePiece,
5398
- firstKnowlegeIndex,
5458
+ firstKnowledgePiece,
5459
+ firstKnowledgeIndex,
5399
5460
  knowledgePiecesWithRelevance,
5400
5461
  knowledgePiecesSorted,
5401
5462
  knowledgePiecesLimited,
@@ -5464,7 +5525,7 @@
5464
5525
  * @private internal utility of `createPipelineExecutor`
5465
5526
  */
5466
5527
  async function executeTask(options) {
5467
- const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5528
+ const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSuppressed, } = options;
5468
5529
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5469
5530
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5470
5531
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
@@ -5552,7 +5613,7 @@
5552
5613
  cacheDirname,
5553
5614
  intermediateFilesStrategy,
5554
5615
  isAutoInstalled,
5555
- isNotPreparedWarningSupressed,
5616
+ isNotPreparedWarningSuppressed,
5556
5617
  });
5557
5618
  await onProgress({
5558
5619
  outputParameters: {
@@ -5647,7 +5708,7 @@
5647
5708
  }
5648
5709
  return exportJson({
5649
5710
  name: `executionReport`,
5650
- message: `Unuccessful PipelineExecutorResult (with missing parameter {${parameter.name}}) PipelineExecutorResult`,
5711
+ message: `Unsuccessful PipelineExecutorResult (with missing parameter {${parameter.name}}) PipelineExecutorResult`,
5651
5712
  order: [],
5652
5713
  value: {
5653
5714
  isSuccessful: false,
@@ -5684,7 +5745,7 @@
5684
5745
  return exportJson({
5685
5746
  name: 'pipelineExecutorResult',
5686
5747
  message: spaceTrim.spaceTrim((block) => `
5687
- Unuccessful PipelineExecutorResult (with extra parameter {${parameter.name}}) PipelineExecutorResult
5748
+ Unsuccessful PipelineExecutorResult (with extra parameter {${parameter.name}}) PipelineExecutorResult
5688
5749
 
5689
5750
  ${block(pipelineIdentification)}
5690
5751
  `),
@@ -5825,7 +5886,7 @@
5825
5886
  }
5826
5887
  return exportJson({
5827
5888
  name: 'pipelineExecutorResult',
5828
- message: `Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult`,
5889
+ message: `Unsuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult`,
5829
5890
  order: [],
5830
5891
  value: {
5831
5892
  isSuccessful: false,
@@ -5876,7 +5937,7 @@
5876
5937
  * @public exported from `@promptbook/core`
5877
5938
  */
5878
5939
  function createPipelineExecutor(options) {
5879
- const { pipeline, tools, maxExecutionAttempts = DEFAULT_MAX_EXECUTION_ATTEMPTS, maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, csvSettings = DEFAULT_CSV_SETTINGS, isVerbose = DEFAULT_IS_VERBOSE, isNotPreparedWarningSupressed = false, cacheDirname = DEFAULT_SCRAPE_CACHE_DIRNAME, intermediateFilesStrategy = DEFAULT_INTERMEDIATE_FILES_STRATEGY, isAutoInstalled = DEFAULT_IS_AUTO_INSTALLED, rootDirname = null, } = options;
5940
+ const { pipeline, tools, maxExecutionAttempts = DEFAULT_MAX_EXECUTION_ATTEMPTS, maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, csvSettings = DEFAULT_CSV_SETTINGS, isVerbose = DEFAULT_IS_VERBOSE, isNotPreparedWarningSuppressed = false, cacheDirname = DEFAULT_SCRAPE_CACHE_DIRNAME, intermediateFilesStrategy = DEFAULT_INTERMEDIATE_FILES_STRATEGY, isAutoInstalled = DEFAULT_IS_AUTO_INSTALLED, rootDirname = null, } = options;
5880
5941
  validatePipeline(pipeline);
5881
5942
  const pipelineIdentification = (() => {
5882
5943
  // Note: This is a 😐 implementation of [🚞]
@@ -5893,7 +5954,7 @@
5893
5954
  if (isPipelinePrepared(pipeline)) {
5894
5955
  preparedPipeline = pipeline;
5895
5956
  }
5896
- else if (isNotPreparedWarningSupressed !== true) {
5957
+ else if (isNotPreparedWarningSuppressed !== true) {
5897
5958
  console.warn(spaceTrim.spaceTrim((block) => `
5898
5959
  Pipeline is not prepared
5899
5960
 
@@ -5926,7 +5987,7 @@
5926
5987
  maxParallelCount,
5927
5988
  csvSettings,
5928
5989
  isVerbose,
5929
- isNotPreparedWarningSupressed,
5990
+ isNotPreparedWarningSuppressed,
5930
5991
  rootDirname,
5931
5992
  cacheDirname,
5932
5993
  intermediateFilesStrategy,
@@ -5935,7 +5996,7 @@
5935
5996
  assertsError(error);
5936
5997
  return exportJson({
5937
5998
  name: 'pipelineExecutorResult',
5938
- message: `Unuccessful PipelineExecutorResult, last catch`,
5999
+ message: `Unsuccessful PipelineExecutorResult, last catch`,
5939
6000
  order: [],
5940
6001
  value: {
5941
6002
  isSuccessful: false,
@@ -5973,7 +6034,7 @@
5973
6034
  className: 'MarkdownScraper',
5974
6035
  mimeTypes: ['text/markdown', 'text/plain'],
5975
6036
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5976
- isAvilableInBrowser: true,
6037
+ isAvailableInBrowser: true,
5977
6038
  // <- Note: [🌏] This is the only scraper which makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
5978
6039
  requiredExecutables: [],
5979
6040
  }); /* <- Note: [🤛] */
@@ -5983,7 +6044,7 @@
5983
6044
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
5984
6045
  *
5985
6046
  * @public exported from `@promptbook/core`
5986
- * @public exported from `@promptbook/wizzard`
6047
+ * @public exported from `@promptbook/wizard`
5987
6048
  * @public exported from `@promptbook/cli`
5988
6049
  */
5989
6050
  $scrapersMetadataRegister.register(markdownScraperMetadata);
@@ -6082,7 +6143,7 @@
6082
6143
  }
6083
6144
  // ---
6084
6145
  if (!llmTools.callEmbeddingModel) {
6085
- // TODO: [🟥] Detect browser / node and make it colorfull
6146
+ // TODO: [🟥] Detect browser / node and make it colorful
6086
6147
  console.error('No callEmbeddingModel function provided');
6087
6148
  }
6088
6149
  else {
@@ -6108,7 +6169,7 @@
6108
6169
  if (!(error instanceof PipelineExecutionError)) {
6109
6170
  throw error;
6110
6171
  }
6111
- // TODO: [🟥] Detect browser / node and make it colorfull
6172
+ // TODO: [🟥] Detect browser / node and make it colorful
6112
6173
  console.error(error, "<- Note: This error is not critical to prepare the pipeline, just knowledge pieces won't have embeddings");
6113
6174
  }
6114
6175
  return {
@@ -6144,7 +6205,7 @@
6144
6205
  // 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
6145
6206
  ],
6146
6207
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
6147
- isAvilableInBrowser: false,
6208
+ isAvailableInBrowser: false,
6148
6209
  // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
6149
6210
  requiredExecutables: [],
6150
6211
  }); /* <- Note: [🤛] */
@@ -6154,7 +6215,7 @@
6154
6215
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6155
6216
  *
6156
6217
  * @public exported from `@promptbook/core`
6157
- * @public exported from `@promptbook/wizzard`
6218
+ * @public exported from `@promptbook/wizard`
6158
6219
  * @public exported from `@promptbook/cli`
6159
6220
  */
6160
6221
  $scrapersMetadataRegister.register(markitdownScraperMetadata);
@@ -6291,7 +6352,7 @@
6291
6352
  *
6292
6353
  * @public exported from `@promptbook/markitdown`
6293
6354
  * @public exported from `@promptbook/pdf`
6294
- * @public exported from `@promptbook/wizzard`
6355
+ * @public exported from `@promptbook/wizard`
6295
6356
  * @public exported from `@promptbook/cli`
6296
6357
  */
6297
6358
  const _MarkitdownScraperRegistration = $scrapersRegister.register(createMarkitdownScraper);
@@ -6312,7 +6373,7 @@
6312
6373
  className: 'PdfScraper',
6313
6374
  mimeTypes: ['application/pdf-DISABLED'],
6314
6375
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
6315
- isAvilableInBrowser: false,
6376
+ isAvailableInBrowser: false,
6316
6377
  // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
6317
6378
  requiredExecutables: [],
6318
6379
  }); /* <- Note: [🤛] */
@@ -6322,7 +6383,7 @@
6322
6383
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6323
6384
  *
6324
6385
  * @public exported from `@promptbook/core`
6325
- * @public exported from `@promptbook/wizzard`
6386
+ * @public exported from `@promptbook/wizard`
6326
6387
  * @public exported from `@promptbook/cli`
6327
6388
  */
6328
6389
  $scrapersMetadataRegister.register(pdfScraperMetadata);
@@ -6397,7 +6458,7 @@
6397
6458
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6398
6459
  *
6399
6460
  * @public exported from `@promptbook/pdf`
6400
- * @public exported from `@promptbook/wizzard`
6461
+ * @public exported from `@promptbook/wizard`
6401
6462
  * @public exported from `@promptbook/cli`
6402
6463
  */
6403
6464
  const _PdfScraperRegistration = $scrapersRegister.register(createPdfScraper);