@promptbook/pdf 0.81.0-8 → 0.82.0-0
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.
- package/README.md +25 -4
- package/esm/index.es.js +263 -169
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +38 -0
- package/esm/typings/src/_packages/core.index.d.ts +12 -4
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/node.index.d.ts +0 -2
- package/esm/typings/src/_packages/remote-client.index.d.ts +7 -3
- package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
- package/esm/typings/src/_packages/templates.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +34 -30
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +2 -2
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -0
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/commands/index.d.ts +1 -1
- package/esm/typings/src/config.d.ts +3 -3
- package/esm/typings/src/conversion/compilePipeline.d.ts +1 -4
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +18 -0
- package/esm/typings/src/conversion/{precompilePipeline.d.ts → parsePipeline.d.ts} +3 -3
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +7 -7
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +1 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -2
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +9 -4
- package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
- package/esm/typings/src/formfactors/index.d.ts +31 -9
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
- package/esm/typings/src/high-level-abstractions/index.d.ts +3 -3
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +3 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +1 -1
- package/esm/typings/src/other/templates/getBookTemplates.d.ts +22 -0
- package/esm/typings/src/personas/preparePersona.d.ts +4 -4
- package/esm/typings/src/pipeline/PipelineString.d.ts +0 -3
- package/esm/typings/src/pipeline/book-notation.d.ts +14 -0
- package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
- package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -1
- package/esm/typings/src/prepare/preparePipeline.d.ts +4 -2
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +14 -0
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Error.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Request.d.ts +4 -4
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Response.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Progress.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Request.d.ts +5 -5
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Response.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteLlmExecutionToolsOptions.d.ts +7 -7
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteServerOptions.d.ts +10 -10
- package/esm/typings/src/scrapers/_common/Converter.d.ts +1 -0
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +3 -0
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -0
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +3 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +2 -1
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -1
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
- package/esm/typings/src/types/typeAliases.d.ts +16 -2
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/{removeContentComments.d.ts → removeMarkdownComments.d.ts} +2 -2
- package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -2
- package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
- package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
- package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +52 -8
- package/package.json +2 -2
- package/umd/index.umd.js +263 -169
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/other/templates/getBookTemplate.d.ts +0 -21
- package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
- /package/esm/typings/src/conversion/{precompilePipeline.test.d.ts → parsePipeline.test.d.ts} +0 -0
- /package/esm/typings/src/{llm-providers/remote → remote-server}/startRemoteServer.d.ts +0 -0
- /package/esm/typings/src/utils/markdown/{removeContentComments.test.d.ts → removeMarkdownComments.test.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -22,7 +22,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
22
22
|
* @generated
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -176,7 +176,67 @@ var NotYetImplementedError = /** @class */ (function (_super) {
|
|
|
176
176
|
function TODO_USE() {
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",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.md`\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.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",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.md`\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.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",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- Title should be concise and clear\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 Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\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- Title should be concise and clear\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.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",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 Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\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.md"}];
|
|
179
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",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.md`\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.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",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.md`\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.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",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- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\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.md`\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- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\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.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",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.md`\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.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",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 task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon",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.md`\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 task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
183
|
+
*
|
|
184
|
+
* @public exported from `@promptbook/utils`
|
|
185
|
+
*/
|
|
186
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
187
|
+
try {
|
|
188
|
+
JSON.parse(value);
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (!(error instanceof Error)) {
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
if (error.message.includes('Unexpected token')) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
204
|
+
*
|
|
205
|
+
* @public exported from `@promptbook/core`
|
|
206
|
+
*/
|
|
207
|
+
var ParseError = /** @class */ (function (_super) {
|
|
208
|
+
__extends(ParseError, _super);
|
|
209
|
+
function ParseError(message) {
|
|
210
|
+
var _this = _super.call(this, message) || this;
|
|
211
|
+
_this.name = 'ParseError';
|
|
212
|
+
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
213
|
+
return _this;
|
|
214
|
+
}
|
|
215
|
+
return ParseError;
|
|
216
|
+
}(Error));
|
|
217
|
+
/**
|
|
218
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
223
|
+
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
226
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
227
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
228
|
+
* @public exported from `@promptbook/core`
|
|
229
|
+
*/
|
|
230
|
+
function validatePipelineString(pipelineString) {
|
|
231
|
+
if (isValidJsonString(pipelineString)) {
|
|
232
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
233
|
+
}
|
|
234
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
235
|
+
return pipelineString;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
239
|
+
*/
|
|
180
240
|
|
|
181
241
|
/**
|
|
182
242
|
* Prettify the html code
|
|
@@ -244,7 +304,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
244
304
|
if (bookVersion !== "undefined") {
|
|
245
305
|
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
246
306
|
}
|
|
247
|
-
// TODO: [main]
|
|
307
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
248
308
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
249
309
|
try {
|
|
250
310
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -392,12 +452,12 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
392
452
|
pipelineString += '```' + contentLanguage;
|
|
393
453
|
pipelineString += '\n';
|
|
394
454
|
pipelineString += spaceTrim$1(content);
|
|
395
|
-
// <- TODO: [main]
|
|
455
|
+
// <- TODO: [main] !!3 Escape
|
|
396
456
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
397
457
|
pipelineString += '\n';
|
|
398
458
|
pipelineString += '```';
|
|
399
459
|
pipelineString += '\n\n';
|
|
400
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main]
|
|
460
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
401
461
|
}
|
|
402
462
|
}
|
|
403
463
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -407,7 +467,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
407
467
|
}
|
|
408
468
|
finally { if (e_3) throw e_3.error; }
|
|
409
469
|
}
|
|
410
|
-
return pipelineString;
|
|
470
|
+
return validatePipelineString(pipelineString);
|
|
411
471
|
}
|
|
412
472
|
/**
|
|
413
473
|
* @private internal utility of `pipelineJsonToString`
|
|
@@ -468,6 +528,12 @@ var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
|
468
528
|
* @public exported from `@promptbook/core`
|
|
469
529
|
*/
|
|
470
530
|
var ADMIN_GITHUB_NAME = 'hejny';
|
|
531
|
+
/**
|
|
532
|
+
* When the title is not provided, the default title is used
|
|
533
|
+
*
|
|
534
|
+
* @public exported from `@promptbook/core`
|
|
535
|
+
*/
|
|
536
|
+
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
471
537
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
472
538
|
/**
|
|
473
539
|
* The maximum number of iterations for a loops
|
|
@@ -619,7 +685,7 @@ function $deepFreeze(objectValue) {
|
|
|
619
685
|
/**
|
|
620
686
|
* Make error report URL for the given error
|
|
621
687
|
*
|
|
622
|
-
* @private
|
|
688
|
+
* @private private within the repository
|
|
623
689
|
*/
|
|
624
690
|
function getErrorReportUrl(error) {
|
|
625
691
|
var report = {
|
|
@@ -740,7 +806,7 @@ function checkSerializableAsJson(options) {
|
|
|
740
806
|
if (!(error instanceof Error)) {
|
|
741
807
|
throw error;
|
|
742
808
|
}
|
|
743
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.
|
|
809
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
744
810
|
}
|
|
745
811
|
/*
|
|
746
812
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -770,7 +836,7 @@ function checkSerializableAsJson(options) {
|
|
|
770
836
|
}
|
|
771
837
|
/**
|
|
772
838
|
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
773
|
-
* TODO: [🧠][main]
|
|
839
|
+
* TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
774
840
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
775
841
|
*/
|
|
776
842
|
|
|
@@ -782,7 +848,6 @@ function checkSerializableAsJson(options) {
|
|
|
782
848
|
function deepClone(objectValue) {
|
|
783
849
|
return JSON.parse(JSON.stringify(objectValue));
|
|
784
850
|
/*
|
|
785
|
-
!!!!!!!!
|
|
786
851
|
TODO: [🧠] Is there a better implementation?
|
|
787
852
|
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
788
853
|
> for (const propertyName of propertyNames) {
|
|
@@ -894,25 +959,6 @@ var RESERVED_PARAMETER_NAMES = exportJson({
|
|
|
894
959
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
895
960
|
*/
|
|
896
961
|
|
|
897
|
-
/**
|
|
898
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
899
|
-
*
|
|
900
|
-
* @public exported from `@promptbook/core`
|
|
901
|
-
*/
|
|
902
|
-
var ParseError = /** @class */ (function (_super) {
|
|
903
|
-
__extends(ParseError, _super);
|
|
904
|
-
function ParseError(message) {
|
|
905
|
-
var _this = _super.call(this, message) || this;
|
|
906
|
-
_this.name = 'ParseError';
|
|
907
|
-
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
908
|
-
return _this;
|
|
909
|
-
}
|
|
910
|
-
return ParseError;
|
|
911
|
-
}(Error));
|
|
912
|
-
/**
|
|
913
|
-
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
914
|
-
*/
|
|
915
|
-
|
|
916
962
|
/**
|
|
917
963
|
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
918
964
|
*
|
|
@@ -967,7 +1013,7 @@ function isValidPromptbookVersion(version) {
|
|
|
967
1013
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
968
1014
|
return false;
|
|
969
1015
|
}
|
|
970
|
-
// <- TODO: [main]
|
|
1016
|
+
// <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
|
|
971
1017
|
return true;
|
|
972
1018
|
}
|
|
973
1019
|
|
|
@@ -1067,9 +1113,6 @@ function isValidPipelineUrl(url) {
|
|
|
1067
1113
|
if (!url.startsWith('https://')) {
|
|
1068
1114
|
return false;
|
|
1069
1115
|
}
|
|
1070
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
1071
|
-
return false;
|
|
1072
|
-
}
|
|
1073
1116
|
if (url.includes('#')) {
|
|
1074
1117
|
// TODO: [🐠]
|
|
1075
1118
|
return false;
|
|
@@ -1100,11 +1143,11 @@ function isValidPipelineUrl(url) {
|
|
|
1100
1143
|
*/
|
|
1101
1144
|
function validatePipeline(pipeline) {
|
|
1102
1145
|
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
1103
|
-
|
|
1146
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1104
1147
|
}
|
|
1105
1148
|
else {
|
|
1106
1149
|
try {
|
|
1107
|
-
|
|
1150
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1108
1151
|
}
|
|
1109
1152
|
catch (error) {
|
|
1110
1153
|
if (!(error instanceof PipelineLogicError)) {
|
|
@@ -1118,7 +1161,7 @@ function validatePipeline(pipeline) {
|
|
|
1118
1161
|
/**
|
|
1119
1162
|
* @private internal function for `validatePipeline`
|
|
1120
1163
|
*/
|
|
1121
|
-
function
|
|
1164
|
+
function validatePipeline_InnerFunction(pipeline) {
|
|
1122
1165
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
1123
1166
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1124
1167
|
var pipelineIdentification = (function () {
|
|
@@ -1342,11 +1385,11 @@ function validatePipelineCore(pipeline) {
|
|
|
1342
1385
|
_loop_3();
|
|
1343
1386
|
}
|
|
1344
1387
|
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
1345
|
-
// TODO:
|
|
1388
|
+
// TODO: !!6 Implement this
|
|
1346
1389
|
// pipeline.formfactorName
|
|
1347
1390
|
}
|
|
1348
1391
|
/**
|
|
1349
|
-
* TODO:
|
|
1392
|
+
* TODO: [🧞♀️] Do not allow joker + foreach
|
|
1350
1393
|
* TODO: [🧠] Work with promptbookVersion
|
|
1351
1394
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
1352
1395
|
* > /**
|
|
@@ -1358,11 +1401,11 @@ function validatePipelineCore(pipeline) {
|
|
|
1358
1401
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1359
1402
|
*/
|
|
1360
1403
|
/**
|
|
1361
|
-
* TODO: [🧳][main]
|
|
1362
|
-
* TODO: [🧳][🐝][main]
|
|
1363
|
-
* TODO: [🧳][main]
|
|
1364
|
-
* TODO: [🧳][main]
|
|
1365
|
-
* TODO: [🧳][main]
|
|
1404
|
+
* TODO: [🧳][main] !!4 Validate that all examples match expectations
|
|
1405
|
+
* TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
|
|
1406
|
+
* TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
|
|
1407
|
+
* TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1408
|
+
* TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
|
|
1366
1409
|
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1367
1410
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1368
1411
|
*/
|
|
@@ -1498,7 +1541,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1498
1541
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1499
1542
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1500
1543
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1501
|
-
throw new PipelineUrlError(spaceTrim("\n Pipeline with URL
|
|
1544
|
+
throw new PipelineUrlError(spaceTrim("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
1502
1545
|
}
|
|
1503
1546
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1504
1547
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1818,11 +1861,16 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1818
1861
|
/**
|
|
1819
1862
|
* Determine if the pipeline is fully prepared
|
|
1820
1863
|
*
|
|
1864
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
1865
|
+
*
|
|
1821
1866
|
* @public exported from `@promptbook/core`
|
|
1822
1867
|
*/
|
|
1823
1868
|
function isPipelinePrepared(pipeline) {
|
|
1824
1869
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
1825
1870
|
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
1871
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
1872
|
+
return false;
|
|
1873
|
+
}
|
|
1826
1874
|
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
1827
1875
|
return false;
|
|
1828
1876
|
}
|
|
@@ -1838,7 +1886,7 @@ function isPipelinePrepared(pipeline) {
|
|
|
1838
1886
|
return true;
|
|
1839
1887
|
}
|
|
1840
1888
|
/**
|
|
1841
|
-
* TODO: [🔃][main]
|
|
1889
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
1842
1890
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
1843
1891
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
1844
1892
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1847,6 +1895,81 @@ function isPipelinePrepared(pipeline) {
|
|
|
1847
1895
|
* - [♨] Are tasks prepared
|
|
1848
1896
|
*/
|
|
1849
1897
|
|
|
1898
|
+
/**
|
|
1899
|
+
* Format either small or big number
|
|
1900
|
+
*
|
|
1901
|
+
* @public exported from `@promptbook/utils`
|
|
1902
|
+
*/
|
|
1903
|
+
function numberToString(value) {
|
|
1904
|
+
if (value === 0) {
|
|
1905
|
+
return '0';
|
|
1906
|
+
}
|
|
1907
|
+
else if (Number.isNaN(value)) {
|
|
1908
|
+
return VALUE_STRINGS.nan;
|
|
1909
|
+
}
|
|
1910
|
+
else if (value === Infinity) {
|
|
1911
|
+
return VALUE_STRINGS.infinity;
|
|
1912
|
+
}
|
|
1913
|
+
else if (value === -Infinity) {
|
|
1914
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
1915
|
+
}
|
|
1916
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
1917
|
+
var factor = Math.pow(10, exponent);
|
|
1918
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
1919
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
1920
|
+
return valueRounded.toFixed(exponent);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return value.toString();
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
/**
|
|
1927
|
+
* Function `valueToString` will convert the given value to string
|
|
1928
|
+
* This is useful and used in the `templateParameters` function
|
|
1929
|
+
*
|
|
1930
|
+
* Note: This function is not just calling `toString` method
|
|
1931
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
1932
|
+
* See `VALUE_STRINGS`
|
|
1933
|
+
*
|
|
1934
|
+
* Note: There are 2 similar functions
|
|
1935
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
1936
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
1937
|
+
*
|
|
1938
|
+
* @public exported from `@promptbook/utils`
|
|
1939
|
+
*/
|
|
1940
|
+
function valueToString(value) {
|
|
1941
|
+
try {
|
|
1942
|
+
if (value === '') {
|
|
1943
|
+
return VALUE_STRINGS.empty;
|
|
1944
|
+
}
|
|
1945
|
+
else if (value === null) {
|
|
1946
|
+
return VALUE_STRINGS.null;
|
|
1947
|
+
}
|
|
1948
|
+
else if (value === undefined) {
|
|
1949
|
+
return VALUE_STRINGS.undefined;
|
|
1950
|
+
}
|
|
1951
|
+
else if (typeof value === 'string') {
|
|
1952
|
+
return value;
|
|
1953
|
+
}
|
|
1954
|
+
else if (typeof value === 'number') {
|
|
1955
|
+
return numberToString(value);
|
|
1956
|
+
}
|
|
1957
|
+
else if (value instanceof Date) {
|
|
1958
|
+
return value.toISOString();
|
|
1959
|
+
}
|
|
1960
|
+
else {
|
|
1961
|
+
return JSON.stringify(value);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
catch (error) {
|
|
1965
|
+
if (!(error instanceof Error)) {
|
|
1966
|
+
throw error;
|
|
1967
|
+
}
|
|
1968
|
+
console.error(error);
|
|
1969
|
+
return VALUE_STRINGS.unserializable;
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1850
1973
|
/**
|
|
1851
1974
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
1852
1975
|
*
|
|
@@ -2528,10 +2651,10 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
2528
2651
|
});
|
|
2529
2652
|
}
|
|
2530
2653
|
/**
|
|
2531
|
-
* TODO: [🔃][main]
|
|
2532
|
-
* TODO: [🏢]
|
|
2533
|
-
* TODO: [🏢]
|
|
2534
|
-
* TODO: [🏢]
|
|
2654
|
+
* TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
|
|
2655
|
+
* TODO: [🏢] Check validity of `modelName` in pipeline
|
|
2656
|
+
* TODO: [🏢] Check validity of `systemMessage` in pipeline
|
|
2657
|
+
* TODO: [🏢] Check validity of `temperature` in pipeline
|
|
2535
2658
|
*/
|
|
2536
2659
|
|
|
2537
2660
|
/**
|
|
@@ -3226,21 +3349,44 @@ function isValidFilePath(filename) {
|
|
|
3226
3349
|
if (typeof filename !== 'string') {
|
|
3227
3350
|
return false;
|
|
3228
3351
|
}
|
|
3352
|
+
if (filename.split('\n').length > 1) {
|
|
3353
|
+
return false;
|
|
3354
|
+
}
|
|
3355
|
+
if (filename.split(' ').length >
|
|
3356
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
3357
|
+
return false;
|
|
3358
|
+
}
|
|
3229
3359
|
var filenameSlashes = filename.split('\\').join('/');
|
|
3230
3360
|
// Absolute Unix path: /hello.txt
|
|
3231
3361
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
3362
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
3232
3363
|
return true;
|
|
3233
3364
|
}
|
|
3234
3365
|
// Absolute Windows path: /hello.txt
|
|
3235
3366
|
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
3367
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
3236
3368
|
return true;
|
|
3237
3369
|
}
|
|
3238
3370
|
// Relative path: ./hello.txt
|
|
3239
3371
|
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
3372
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
3373
|
+
return true;
|
|
3374
|
+
}
|
|
3375
|
+
// Allow paths like foo/hello
|
|
3376
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
3377
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
3378
|
+
return true;
|
|
3379
|
+
}
|
|
3380
|
+
// Allow paths like hello.book
|
|
3381
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
3382
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
3240
3383
|
return true;
|
|
3241
3384
|
}
|
|
3242
3385
|
return false;
|
|
3243
3386
|
}
|
|
3387
|
+
/**
|
|
3388
|
+
* TODO: [🍏] Implement for MacOs
|
|
3389
|
+
*/
|
|
3244
3390
|
|
|
3245
3391
|
/**
|
|
3246
3392
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
@@ -3265,6 +3411,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3265
3411
|
}
|
|
3266
3412
|
});
|
|
3267
3413
|
}); };
|
|
3414
|
+
/**
|
|
3415
|
+
* TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
|
|
3416
|
+
*/
|
|
3268
3417
|
|
|
3269
3418
|
/**
|
|
3270
3419
|
* @@@
|
|
@@ -3332,7 +3481,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3332
3481
|
},
|
|
3333
3482
|
}];
|
|
3334
3483
|
case 2:
|
|
3335
|
-
if (!
|
|
3484
|
+
if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
|
|
3336
3485
|
if (tools.fs === undefined) {
|
|
3337
3486
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3338
3487
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3347,7 +3496,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3347
3496
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3348
3497
|
case 3:
|
|
3349
3498
|
if (!(_f.sent())) {
|
|
3350
|
-
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
3499
|
+
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(sourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
3351
3500
|
}
|
|
3352
3501
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
3353
3502
|
return [2 /*return*/, {
|
|
@@ -3460,7 +3609,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3460
3609
|
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
3461
3610
|
return [2 /*return*/, "break"];
|
|
3462
3611
|
}
|
|
3463
|
-
console.warn(spaceTrim$1(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n
|
|
3612
|
+
console.warn(spaceTrim$1(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.sourceContent
|
|
3464
3613
|
.split('\n')
|
|
3465
3614
|
.map(function (line) { return "> ".concat(line); })
|
|
3466
3615
|
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -3498,7 +3647,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3498
3647
|
return [7 /*endfinally*/];
|
|
3499
3648
|
case 9:
|
|
3500
3649
|
if (partialPieces === null) {
|
|
3501
|
-
throw new KnowledgeScrapeError(spaceTrim$1(function (block) { return "\n Cannot scrape knowledge\n
|
|
3650
|
+
throw new KnowledgeScrapeError(spaceTrim$1(function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
|
|
3502
3651
|
.split('\n')
|
|
3503
3652
|
.map(function (line) { return "> ".concat(line); })
|
|
3504
3653
|
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -3589,7 +3738,7 @@ function prepareTasks(pipeline, tools, options) {
|
|
|
3589
3738
|
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
3590
3739
|
* TODO: [🧠] Add context to each task (if missing)
|
|
3591
3740
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
3592
|
-
* TODO: [♨][main]
|
|
3741
|
+
* TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
|
|
3593
3742
|
* TODO: Write tests for `preparePipeline`
|
|
3594
3743
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3595
3744
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3597,7 +3746,9 @@ function prepareTasks(pipeline, tools, options) {
|
|
|
3597
3746
|
*/
|
|
3598
3747
|
|
|
3599
3748
|
/**
|
|
3600
|
-
* Prepare pipeline
|
|
3749
|
+
* Prepare pipeline locally
|
|
3750
|
+
*
|
|
3751
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
3601
3752
|
*
|
|
3602
3753
|
* Note: This function does not validate logic of the pipeline
|
|
3603
3754
|
* Note: This function acts as part of compilation process
|
|
@@ -3611,16 +3762,17 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3611
3762
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3612
3763
|
knowledgeSources /*
|
|
3613
3764
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3614
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3765
|
+
<- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3766
|
+
var _d;
|
|
3615
3767
|
var _this = this;
|
|
3616
|
-
return __generator(this, function (
|
|
3617
|
-
switch (
|
|
3768
|
+
return __generator(this, function (_e) {
|
|
3769
|
+
switch (_e.label) {
|
|
3618
3770
|
case 0:
|
|
3619
3771
|
if (isPipelinePrepared(pipeline)) {
|
|
3620
3772
|
return [2 /*return*/, pipeline];
|
|
3621
3773
|
}
|
|
3622
3774
|
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
3623
|
-
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3775
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
|
|
3624
3776
|
if (tools === undefined || tools.llm === undefined) {
|
|
3625
3777
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
3626
3778
|
}
|
|
@@ -3638,6 +3790,33 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3638
3790
|
// <- TODO: [🧊]
|
|
3639
3791
|
currentPreparation,
|
|
3640
3792
|
];
|
|
3793
|
+
title = pipeline.title;
|
|
3794
|
+
if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
|
|
3795
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3796
|
+
_c = createPipelineExecutor;
|
|
3797
|
+
_d = {};
|
|
3798
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
|
|
3799
|
+
case 1:
|
|
3800
|
+
prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
|
|
3801
|
+
_d.tools = tools,
|
|
3802
|
+
_d)]);
|
|
3803
|
+
return [4 /*yield*/, prepareTitleExecutor({
|
|
3804
|
+
book: sources.map(function (_a) {
|
|
3805
|
+
var content = _a.content;
|
|
3806
|
+
return content;
|
|
3807
|
+
}).join('\n\n'),
|
|
3808
|
+
})];
|
|
3809
|
+
case 2:
|
|
3810
|
+
result = _e.sent();
|
|
3811
|
+
assertsExecutionSuccessful(result);
|
|
3812
|
+
outputParameters = result.outputParameters;
|
|
3813
|
+
titleRaw = outputParameters.title;
|
|
3814
|
+
if (isVerbose) {
|
|
3815
|
+
console.info("The title is \"".concat(titleRaw, "\""));
|
|
3816
|
+
}
|
|
3817
|
+
title = titleRaw || DEFAULT_BOOK_TITLE;
|
|
3818
|
+
_e.label = 3;
|
|
3819
|
+
case 3:
|
|
3641
3820
|
preparedPersonas = new Array(personas.length);
|
|
3642
3821
|
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3643
3822
|
var modelRequirements, preparedPersona;
|
|
@@ -3656,12 +3835,12 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3656
3835
|
}
|
|
3657
3836
|
});
|
|
3658
3837
|
}); })];
|
|
3659
|
-
case
|
|
3660
|
-
|
|
3838
|
+
case 4:
|
|
3839
|
+
_e.sent();
|
|
3661
3840
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3662
3841
|
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
3663
|
-
case
|
|
3664
|
-
partialknowledgePiecesPrepared =
|
|
3842
|
+
case 5:
|
|
3843
|
+
partialknowledgePiecesPrepared = _e.sent();
|
|
3665
3844
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3666
3845
|
return [4 /*yield*/, prepareTasks({
|
|
3667
3846
|
parameters: parameters,
|
|
@@ -3672,8 +3851,8 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3672
3851
|
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3673
3852
|
isVerbose: isVerbose,
|
|
3674
3853
|
})];
|
|
3675
|
-
case
|
|
3676
|
-
tasksPrepared = (
|
|
3854
|
+
case 6:
|
|
3855
|
+
tasksPrepared = (_e.sent()).tasksPrepared;
|
|
3677
3856
|
// ----- /Tasks preparation -----
|
|
3678
3857
|
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
3679
3858
|
// Note: Count total usage
|
|
@@ -3684,7 +3863,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3684
3863
|
order: ORDER_OF_PIPELINE_JSON,
|
|
3685
3864
|
value: __assign(__assign({}, pipeline), {
|
|
3686
3865
|
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
3687
|
-
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3866
|
+
title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3688
3867
|
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3689
3868
|
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
3690
3869
|
})];
|
|
@@ -3693,7 +3872,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3693
3872
|
});
|
|
3694
3873
|
}
|
|
3695
3874
|
/**
|
|
3696
|
-
* TODO: Write tests for `preparePipeline`
|
|
3875
|
+
* TODO: Write tests for `preparePipeline` and `preparePipelineOnRemoteServer`
|
|
3697
3876
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3698
3877
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3699
3878
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
@@ -3755,7 +3934,7 @@ function extractVariablesFromScript(script) {
|
|
|
3755
3934
|
if (!(error instanceof Error)) {
|
|
3756
3935
|
throw error;
|
|
3757
3936
|
}
|
|
3758
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n
|
|
3937
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
|
|
3759
3938
|
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3760
3939
|
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3761
3940
|
}
|
|
@@ -4035,27 +4214,6 @@ var CsvFormatDefinition = {
|
|
|
4035
4214
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
4036
4215
|
*/
|
|
4037
4216
|
|
|
4038
|
-
/**
|
|
4039
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
4040
|
-
*
|
|
4041
|
-
* @public exported from `@promptbook/utils`
|
|
4042
|
-
*/
|
|
4043
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
4044
|
-
try {
|
|
4045
|
-
JSON.parse(value);
|
|
4046
|
-
return true;
|
|
4047
|
-
}
|
|
4048
|
-
catch (error) {
|
|
4049
|
-
if (!(error instanceof Error)) {
|
|
4050
|
-
throw error;
|
|
4051
|
-
}
|
|
4052
|
-
if (error.message.includes('Unexpected token')) {
|
|
4053
|
-
return false;
|
|
4054
|
-
}
|
|
4055
|
-
return false;
|
|
4056
|
-
}
|
|
4057
|
-
}
|
|
4058
|
-
|
|
4059
4217
|
/**
|
|
4060
4218
|
* Definition for JSON format
|
|
4061
4219
|
*
|
|
@@ -4374,81 +4532,6 @@ function extractJsonBlock(markdown) {
|
|
|
4374
4532
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
4375
4533
|
*/
|
|
4376
4534
|
|
|
4377
|
-
/**
|
|
4378
|
-
* Format either small or big number
|
|
4379
|
-
*
|
|
4380
|
-
* @public exported from `@promptbook/utils`
|
|
4381
|
-
*/
|
|
4382
|
-
function numberToString(value) {
|
|
4383
|
-
if (value === 0) {
|
|
4384
|
-
return '0';
|
|
4385
|
-
}
|
|
4386
|
-
else if (Number.isNaN(value)) {
|
|
4387
|
-
return VALUE_STRINGS.nan;
|
|
4388
|
-
}
|
|
4389
|
-
else if (value === Infinity) {
|
|
4390
|
-
return VALUE_STRINGS.infinity;
|
|
4391
|
-
}
|
|
4392
|
-
else if (value === -Infinity) {
|
|
4393
|
-
return VALUE_STRINGS.negativeInfinity;
|
|
4394
|
-
}
|
|
4395
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4396
|
-
var factor = Math.pow(10, exponent);
|
|
4397
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
4398
|
-
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4399
|
-
return valueRounded.toFixed(exponent);
|
|
4400
|
-
}
|
|
4401
|
-
}
|
|
4402
|
-
return value.toString();
|
|
4403
|
-
}
|
|
4404
|
-
|
|
4405
|
-
/**
|
|
4406
|
-
* Function `valueToString` will convert the given value to string
|
|
4407
|
-
* This is useful and used in the `templateParameters` function
|
|
4408
|
-
*
|
|
4409
|
-
* Note: This function is not just calling `toString` method
|
|
4410
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
4411
|
-
* See `VALUE_STRINGS`
|
|
4412
|
-
*
|
|
4413
|
-
* Note: There are 2 similar functions
|
|
4414
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4415
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4416
|
-
*
|
|
4417
|
-
* @public exported from `@promptbook/utils`
|
|
4418
|
-
*/
|
|
4419
|
-
function valueToString(value) {
|
|
4420
|
-
try {
|
|
4421
|
-
if (value === '') {
|
|
4422
|
-
return VALUE_STRINGS.empty;
|
|
4423
|
-
}
|
|
4424
|
-
else if (value === null) {
|
|
4425
|
-
return VALUE_STRINGS.null;
|
|
4426
|
-
}
|
|
4427
|
-
else if (value === undefined) {
|
|
4428
|
-
return VALUE_STRINGS.undefined;
|
|
4429
|
-
}
|
|
4430
|
-
else if (typeof value === 'string') {
|
|
4431
|
-
return value;
|
|
4432
|
-
}
|
|
4433
|
-
else if (typeof value === 'number') {
|
|
4434
|
-
return numberToString(value);
|
|
4435
|
-
}
|
|
4436
|
-
else if (value instanceof Date) {
|
|
4437
|
-
return value.toISOString();
|
|
4438
|
-
}
|
|
4439
|
-
else {
|
|
4440
|
-
return JSON.stringify(value);
|
|
4441
|
-
}
|
|
4442
|
-
}
|
|
4443
|
-
catch (error) {
|
|
4444
|
-
if (!(error instanceof Error)) {
|
|
4445
|
-
throw error;
|
|
4446
|
-
}
|
|
4447
|
-
console.error(error);
|
|
4448
|
-
return VALUE_STRINGS.unserializable;
|
|
4449
|
-
}
|
|
4450
|
-
}
|
|
4451
|
-
|
|
4452
4535
|
/**
|
|
4453
4536
|
* Replaces parameters in template with values from parameters object
|
|
4454
4537
|
*
|
|
@@ -4505,6 +4588,8 @@ function templateParameters(template, parameters) {
|
|
|
4505
4588
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
4506
4589
|
}
|
|
4507
4590
|
parameterValue = valueToString(parameterValue);
|
|
4591
|
+
// Escape curly braces in parameter values to prevent prompt-injection
|
|
4592
|
+
parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
|
|
4508
4593
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
4509
4594
|
parameterValue = parameterValue
|
|
4510
4595
|
.split('\n')
|
|
@@ -4864,7 +4949,7 @@ function executeAttempts(options) {
|
|
|
4864
4949
|
promptTitle: task.title,
|
|
4865
4950
|
promptMessage: templateParameters(task.description || '', parameters),
|
|
4866
4951
|
defaultValue: templateParameters(preparedContent, parameters),
|
|
4867
|
-
// TODO: [🧠]
|
|
4952
|
+
// TODO: [🧠] Figure out how to define placeholder in .book.md file
|
|
4868
4953
|
placeholder: undefined,
|
|
4869
4954
|
priority: priority,
|
|
4870
4955
|
}))];
|
|
@@ -5564,7 +5649,10 @@ function executePipeline(options) {
|
|
|
5564
5649
|
finally { if (e_2) throw e_2.error; }
|
|
5565
5650
|
return [7 /*endfinally*/];
|
|
5566
5651
|
case 19:
|
|
5567
|
-
parametersToPass = inputParameters
|
|
5652
|
+
parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
|
|
5653
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
5654
|
+
return [key, valueToString(value)];
|
|
5655
|
+
}));
|
|
5568
5656
|
_g.label = 20;
|
|
5569
5657
|
case 20:
|
|
5570
5658
|
_g.trys.push([20, 25, , 28]);
|
|
@@ -5851,6 +5939,7 @@ var markdownScraperMetadata = $deepFreeze({
|
|
|
5851
5939
|
mimeTypes: ['text/markdown', 'text/plain'],
|
|
5852
5940
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
5853
5941
|
isAvilableInBrowser: true,
|
|
5942
|
+
// <- 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
|
|
5854
5943
|
requiredExecutables: [],
|
|
5855
5944
|
}); /* <- Note: [🤛] */
|
|
5856
5945
|
/**
|
|
@@ -5859,6 +5948,7 @@ var markdownScraperMetadata = $deepFreeze({
|
|
|
5859
5948
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
5860
5949
|
*
|
|
5861
5950
|
* @public exported from `@promptbook/core`
|
|
5951
|
+
* @public exported from `@promptbook/wizzard`
|
|
5862
5952
|
* @public exported from `@promptbook/cli`
|
|
5863
5953
|
*/
|
|
5864
5954
|
$scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
@@ -5944,12 +6034,12 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
5944
6034
|
outputParameters = result.outputParameters;
|
|
5945
6035
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
5946
6036
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
5947
|
-
// <- TODO: [main]
|
|
6037
|
+
// <- TODO: [main] Smarter split and filter out empty pieces
|
|
5948
6038
|
if (isVerbose) {
|
|
5949
6039
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
5950
6040
|
}
|
|
5951
6041
|
return [4 /*yield*/, Promise.all(
|
|
5952
|
-
// TODO: [🪂]
|
|
6042
|
+
// TODO: [🪂] Do not send all at once but in chunks
|
|
5953
6043
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
5954
6044
|
var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
5955
6045
|
return __generator(this, function (_c) {
|
|
@@ -6047,7 +6137,8 @@ var pdfScraperMetadata = $deepFreeze({
|
|
|
6047
6137
|
className: 'PdfScraper',
|
|
6048
6138
|
mimeTypes: ['application/pdf'],
|
|
6049
6139
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
6050
|
-
isAvilableInBrowser:
|
|
6140
|
+
isAvilableInBrowser: false,
|
|
6141
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
6051
6142
|
requiredExecutables: [],
|
|
6052
6143
|
}); /* <- Note: [🤛] */
|
|
6053
6144
|
/**
|
|
@@ -6056,6 +6147,7 @@ var pdfScraperMetadata = $deepFreeze({
|
|
|
6056
6147
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6057
6148
|
*
|
|
6058
6149
|
* @public exported from `@promptbook/core`
|
|
6150
|
+
* @public exported from `@promptbook/wizzard`
|
|
6059
6151
|
* @public exported from `@promptbook/cli`
|
|
6060
6152
|
*/
|
|
6061
6153
|
$scrapersMetadataRegister.register(pdfScraperMetadata);
|
|
@@ -6120,6 +6212,7 @@ var PdfScraper = /** @class */ (function () {
|
|
|
6120
6212
|
* TODO: [👣] Converted pdf documents can act as cached items - there is no need to run conversion each time
|
|
6121
6213
|
* TODO: [🪂] Do it in parallel 11:11
|
|
6122
6214
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
6215
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
6123
6216
|
*/
|
|
6124
6217
|
|
|
6125
6218
|
/**
|
|
@@ -6140,6 +6233,7 @@ var createPdfScraper = Object.assign(function (tools, options) {
|
|
|
6140
6233
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6141
6234
|
*
|
|
6142
6235
|
* @public exported from `@promptbook/pdf`
|
|
6236
|
+
* @public exported from `@promptbook/wizzard`
|
|
6143
6237
|
* @public exported from `@promptbook/cli`
|
|
6144
6238
|
*/
|
|
6145
6239
|
var _PdfScraperRegistration = $scrapersRegister.register(createPdfScraper);
|