@promptbook/website-crawler 0.89.0 → 0.92.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 (27) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +173 -30
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  5. package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/google.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  8. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +1 -1
  9. package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
  10. package/esm/typings/src/execution/CommonToolsOptions.d.ts +4 -0
  11. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -0
  12. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +5 -0
  13. package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
  14. package/esm/typings/src/formats/json/utils/jsonParse.d.ts +11 -0
  15. package/esm/typings/src/llm-providers/_common/filterModels.d.ts +15 -0
  16. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +43 -0
  17. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
  18. package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
  19. package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
  20. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
  21. package/esm/typings/src/personas/preparePersona.d.ts +1 -1
  22. package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
  23. package/esm/typings/src/remote-server/openapi-types.d.ts +348 -6
  24. package/esm/typings/src/remote-server/openapi.d.ts +397 -3
  25. package/package.json +2 -2
  26. package/umd/index.umd.js +173 -30
  27. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/website-crawler`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-11';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1025,7 +1025,7 @@ async function getScraperIntermediateSource(source, options) {
1025
1025
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
1026
1026
  */
1027
1027
 
1028
- 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:"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}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the 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\nPick from the following models:\n\n- {availableModelNames}\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:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","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 `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the 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\nPick from the following models:\n\n- {availableModelNames}\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`-> {modelRequirements}`\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"}];
1028
+ 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"}];
1029
1029
 
1030
1030
  /**
1031
1031
  * Checks if value is valid email
@@ -2041,7 +2041,7 @@ function extractParameterNames(template) {
2041
2041
  */
2042
2042
  function unpreparePipeline(pipeline) {
2043
2043
  let { personas, knowledgeSources, tasks } = pipeline;
2044
- personas = personas.map((persona) => ({ ...persona, modelRequirements: undefined, preparationIds: undefined }));
2044
+ personas = personas.map((persona) => ({ ...persona, modelsRequirements: undefined, preparationIds: undefined }));
2045
2045
  knowledgeSources = knowledgeSources.map((knowledgeSource) => ({ ...knowledgeSource, preparationIds: undefined }));
2046
2046
  tasks = tasks.map((task) => {
2047
2047
  let { dependentParameterNames } = task;
@@ -2251,7 +2251,7 @@ function isPipelinePrepared(pipeline) {
2251
2251
  if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2252
2252
  return false;
2253
2253
  }
2254
- if (!pipeline.personas.every((persona) => persona.modelRequirements !== undefined)) {
2254
+ if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
2255
2255
  return false;
2256
2256
  }
2257
2257
  if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
@@ -2275,6 +2275,45 @@ function isPipelinePrepared(pipeline) {
2275
2275
  * - [♨] Are tasks prepared
2276
2276
  */
2277
2277
 
2278
+ /**
2279
+ * Converts a JavaScript Object Notation (JSON) string into an object.
2280
+ *
2281
+ * Note: This is wrapper around `JSON.parse()` with better error and type handling
2282
+ *
2283
+ * @public exported from `@promptbook/utils`
2284
+ */
2285
+ function jsonParse(value) {
2286
+ if (value === undefined) {
2287
+ throw new Error(`Can not parse JSON from undefined value.`);
2288
+ }
2289
+ else if (typeof value !== 'string') {
2290
+ console.error('Can not parse JSON from non-string value.', { text: value });
2291
+ throw new Error(spaceTrim$1(`
2292
+ Can not parse JSON from non-string value.
2293
+
2294
+ The value type: ${typeof value}
2295
+ See more in console.
2296
+ `));
2297
+ }
2298
+ try {
2299
+ return JSON.parse(value);
2300
+ }
2301
+ catch (error) {
2302
+ if (!(error instanceof Error)) {
2303
+ throw error;
2304
+ }
2305
+ throw new Error(spaceTrim$1((block) => `
2306
+ ${block(error.message)}
2307
+
2308
+ The JSON text:
2309
+ ${block(value)}
2310
+ `));
2311
+ }
2312
+ }
2313
+ /**
2314
+ * TODO: !!!! Use in Promptbook.studio
2315
+ */
2316
+
2278
2317
  /**
2279
2318
  * Recursively converts JSON strings to JSON objects
2280
2319
 
@@ -2293,7 +2332,7 @@ function jsonStringsToJsons(object) {
2293
2332
  const newObject = { ...object };
2294
2333
  for (const [key, value] of Object.entries(object)) {
2295
2334
  if (typeof value === 'string' && isValidJsonString(value)) {
2296
- newObject[key] = JSON.parse(value);
2335
+ newObject[key] = jsonParse(value);
2297
2336
  }
2298
2337
  else {
2299
2338
  newObject[key] = jsonStringsToJsons(value);
@@ -3102,27 +3141,48 @@ async function preparePersona(personaDescription, tools, options) {
3102
3141
  pipeline: await collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book'),
3103
3142
  tools,
3104
3143
  });
3105
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
3106
3144
  const _llms = arrayableToArray(tools.llm);
3107
3145
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
3108
- const availableModels = await llmTools.listModels();
3109
- const availableModelNames = availableModels
3146
+ const availableModels = (await llmTools.listModels())
3110
3147
  .filter(({ modelVariant }) => modelVariant === 'CHAT')
3111
- .map(({ modelName }) => modelName)
3112
- .join(',');
3113
- const result = await preparePersonaExecutor({ availableModelNames, personaDescription }).asPromise();
3148
+ .map(({ modelName, modelDescription }) => ({
3149
+ modelName,
3150
+ modelDescription,
3151
+ // <- Note: `modelTitle` and `modelVariant` is not relevant for this task
3152
+ }));
3153
+ const result = await preparePersonaExecutor({
3154
+ availableModels /* <- Note: Passing as JSON */,
3155
+ personaDescription,
3156
+ }).asPromise();
3114
3157
  const { outputParameters } = result;
3115
- const { modelRequirements: modelRequirementsRaw } = outputParameters;
3116
- const modelRequirements = JSON.parse(modelRequirementsRaw);
3158
+ const { modelsRequirements: modelsRequirementsJson } = outputParameters;
3159
+ let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
3117
3160
  if (isVerbose) {
3118
- console.info(`PERSONA ${personaDescription}`, modelRequirements);
3161
+ console.info(`PERSONA ${personaDescription}`, modelsRequirementsUnchecked);
3119
3162
  }
3120
- const { modelName, systemMessage, temperature } = modelRequirements;
3121
- return {
3163
+ if (!Array.isArray(modelsRequirementsUnchecked)) {
3164
+ // <- TODO: Book should have syntax and system to enforce shape of JSON
3165
+ modelsRequirementsUnchecked = [modelsRequirementsUnchecked];
3166
+ /*
3167
+ throw new UnexpectedError(
3168
+ spaceTrim(
3169
+ (block) => `
3170
+ Invalid \`modelsRequirements\`:
3171
+
3172
+ \`\`\`json
3173
+ ${block(JSON.stringify(modelsRequirementsUnchecked, null, 4))}
3174
+ \`\`\`
3175
+ `,
3176
+ ),
3177
+ );
3178
+ */
3179
+ }
3180
+ const modelsRequirements = modelsRequirementsUnchecked.map((modelRequirements) => ({
3122
3181
  modelVariant: 'CHAT',
3123
- modelName,
3124
- systemMessage,
3125
- temperature,
3182
+ ...modelRequirements,
3183
+ }));
3184
+ return {
3185
+ modelsRequirements,
3126
3186
  };
3127
3187
  }
3128
3188
  /**
@@ -3446,7 +3506,7 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3446
3506
  > },
3447
3507
  */
3448
3508
  async asJson() {
3449
- return JSON.parse(await tools.fs.readFile(filename, 'utf-8'));
3509
+ return jsonParse(await tools.fs.readFile(filename, 'utf-8'));
3450
3510
  },
3451
3511
  async asText() {
3452
3512
  return await tools.fs.readFile(filename, 'utf-8');
@@ -3704,14 +3764,14 @@ async function preparePipeline(pipeline, tools, options) {
3704
3764
  // TODO: [🖌][🧠] Implement some `mapAsync` function
3705
3765
  const preparedPersonas = new Array(personas.length);
3706
3766
  await forEachAsync(personas, { maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, async (persona, index) => {
3707
- const modelRequirements = await preparePersona(persona.description, { ...tools, llm: llmToolsWithUsage }, {
3767
+ const { modelsRequirements } = await preparePersona(persona.description, { ...tools, llm: llmToolsWithUsage }, {
3708
3768
  rootDirname,
3709
3769
  maxParallelCount /* <- TODO: [🪂] */,
3710
3770
  isVerbose,
3711
3771
  });
3712
3772
  const preparedPersona = {
3713
3773
  ...persona,
3714
- modelRequirements,
3774
+ modelsRequirements,
3715
3775
  preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id],
3716
3776
  // <- TODO: [🍙] Make some standard order of json properties
3717
3777
  };
@@ -4050,6 +4110,24 @@ function isValidCsvString(value) {
4050
4110
  }
4051
4111
  }
4052
4112
 
4113
+ /**
4114
+ * Converts a CSV string into an object
4115
+ *
4116
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
4117
+ *
4118
+ * @private - for now until `@promptbook/csv` is released
4119
+ */
4120
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
4121
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
4122
+ // Note: Autoheal invalid '\n' characters
4123
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
4124
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
4125
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
4126
+ }
4127
+ const csv = parse(value, settings);
4128
+ return csv;
4129
+ }
4130
+
4053
4131
  /**
4054
4132
  * Definition for CSV spreadsheet
4055
4133
  *
@@ -4072,8 +4150,7 @@ const CsvFormatDefinition = {
4072
4150
  {
4073
4151
  subvalueName: 'ROW',
4074
4152
  async mapValues(value, outputParameterName, settings, mapCallback) {
4075
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4076
- const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4153
+ const csv = csvParse(value, settings);
4077
4154
  if (csv.errors.length !== 0) {
4078
4155
  throw new CsvFormatError(spaceTrim$1((block) => `
4079
4156
  CSV parsing error
@@ -4103,8 +4180,7 @@ const CsvFormatDefinition = {
4103
4180
  {
4104
4181
  subvalueName: 'CELL',
4105
4182
  async mapValues(value, outputParameterName, settings, mapCallback) {
4106
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4107
- const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4183
+ const csv = csvParse(value, settings);
4108
4184
  if (csv.errors.length !== 0) {
4109
4185
  throw new CsvFormatError(spaceTrim$1((block) => `
4110
4186
  CSV parsing error
@@ -5133,13 +5209,79 @@ async function getExamplesForTask(task) {
5133
5209
  /**
5134
5210
  * @@@
5135
5211
  *
5212
+ * Here is the place where RAG (retrieval-augmented generation) happens
5213
+ *
5136
5214
  * @private internal utility of `createPipelineExecutor`
5137
5215
  */
5138
5216
  async function getKnowledgeForTask(options) {
5139
- const { preparedPipeline, task } = options;
5140
- return preparedPipeline.knowledgePieces.map(({ content }) => `- ${content}`).join('\n');
5217
+ const { tools, preparedPipeline, task } = options;
5218
+ const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
5219
+ const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
5220
+ // <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
5221
+ if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
5222
+ return 'No knowledge pieces found';
5223
+ }
5224
+ // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5225
+ const _llms = arrayableToArray(tools.llm);
5226
+ const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5227
+ const taskEmbeddingPrompt = {
5228
+ title: 'Knowledge Search',
5229
+ modelRequirements: {
5230
+ modelVariant: 'EMBEDDING',
5231
+ modelName: firstKnowlegeIndex.modelName,
5232
+ },
5233
+ content: task.content,
5234
+ parameters: {
5235
+ /* !!!!!!!! */
5236
+ },
5237
+ };
5238
+ const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5239
+ const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5240
+ const { index } = knowledgePiece;
5241
+ const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5242
+ // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5243
+ if (knowledgePieceIndex === undefined) {
5244
+ return {
5245
+ content: knowledgePiece.content,
5246
+ relevance: 0,
5247
+ };
5248
+ }
5249
+ const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5250
+ return {
5251
+ content: knowledgePiece.content,
5252
+ relevance,
5253
+ };
5254
+ });
5255
+ const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5256
+ const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5257
+ console.log('!!! Embedding', {
5258
+ task,
5259
+ taskEmbeddingPrompt,
5260
+ taskEmbeddingResult,
5261
+ firstKnowlegePiece,
5262
+ firstKnowlegeIndex,
5263
+ knowledgePiecesWithRelevance,
5264
+ knowledgePiecesSorted,
5265
+ knowledgePiecesLimited,
5266
+ });
5267
+ return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
5141
5268
  // <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
5142
5269
  }
5270
+ // TODO: !!!!!! Annotate + to new file
5271
+ function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5272
+ if (embeddingVector1.length !== embeddingVector2.length) {
5273
+ throw new TypeError('Embedding vectors must have the same length');
5274
+ }
5275
+ const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5276
+ const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5277
+ const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5278
+ return 1 - dotProduct / (magnitude1 * magnitude2);
5279
+ }
5280
+ /**
5281
+ * TODO: !!!! Verify if this is working
5282
+ * TODO: [♨] Implement Better - use keyword search
5283
+ * TODO: [♨] Examples of values
5284
+ */
5143
5285
 
5144
5286
  /**
5145
5287
  * @@@
@@ -5147,9 +5289,9 @@ async function getKnowledgeForTask(options) {
5147
5289
  * @private internal utility of `createPipelineExecutor`
5148
5290
  */
5149
5291
  async function getReservedParametersForTask(options) {
5150
- const { preparedPipeline, task, pipelineIdentification } = options;
5292
+ const { tools, preparedPipeline, task, pipelineIdentification } = options;
5151
5293
  const context = await getContextForTask(); // <- [🏍]
5152
- const knowledge = await getKnowledgeForTask({ preparedPipeline, task });
5294
+ const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
5153
5295
  const examples = await getExamplesForTask();
5154
5296
  const currentDate = new Date().toISOString(); // <- TODO: [🧠][💩] Better
5155
5297
  const modelName = RESERVED_PARAMETER_MISSING_VALUE;
@@ -5211,6 +5353,7 @@ async function executeTask(options) {
5211
5353
  }
5212
5354
  const definedParameters = Object.freeze({
5213
5355
  ...(await getReservedParametersForTask({
5356
+ tools,
5214
5357
  preparedPipeline,
5215
5358
  task: currentTask,
5216
5359
  pipelineIdentification,