@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/umd/index.umd.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* @generated
|
|
25
25
|
* @see https://github.com/webgptorg/promptbook
|
|
26
26
|
*/
|
|
27
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-
|
|
27
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
|
|
28
28
|
/**
|
|
29
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -178,7 +178,67 @@
|
|
|
178
178
|
function TODO_USE() {
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
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"}];
|
|
181
|
+
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"}];
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
185
|
+
*
|
|
186
|
+
* @public exported from `@promptbook/utils`
|
|
187
|
+
*/
|
|
188
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
189
|
+
try {
|
|
190
|
+
JSON.parse(value);
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
if (!(error instanceof Error)) {
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
if (error.message.includes('Unexpected token')) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
206
|
+
*
|
|
207
|
+
* @public exported from `@promptbook/core`
|
|
208
|
+
*/
|
|
209
|
+
var ParseError = /** @class */ (function (_super) {
|
|
210
|
+
__extends(ParseError, _super);
|
|
211
|
+
function ParseError(message) {
|
|
212
|
+
var _this = _super.call(this, message) || this;
|
|
213
|
+
_this.name = 'ParseError';
|
|
214
|
+
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
215
|
+
return _this;
|
|
216
|
+
}
|
|
217
|
+
return ParseError;
|
|
218
|
+
}(Error));
|
|
219
|
+
/**
|
|
220
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
225
|
+
* 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.
|
|
226
|
+
*
|
|
227
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
228
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
229
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
230
|
+
* @public exported from `@promptbook/core`
|
|
231
|
+
*/
|
|
232
|
+
function validatePipelineString(pipelineString) {
|
|
233
|
+
if (isValidJsonString(pipelineString)) {
|
|
234
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
235
|
+
}
|
|
236
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
237
|
+
return pipelineString;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
241
|
+
*/
|
|
182
242
|
|
|
183
243
|
/**
|
|
184
244
|
* Prettify the html code
|
|
@@ -246,7 +306,7 @@
|
|
|
246
306
|
if (bookVersion !== "undefined") {
|
|
247
307
|
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
248
308
|
}
|
|
249
|
-
// TODO: [main]
|
|
309
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
250
310
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
251
311
|
try {
|
|
252
312
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -394,12 +454,12 @@
|
|
|
394
454
|
pipelineString += '```' + contentLanguage;
|
|
395
455
|
pipelineString += '\n';
|
|
396
456
|
pipelineString += spaceTrim__default["default"](content);
|
|
397
|
-
// <- TODO: [main]
|
|
457
|
+
// <- TODO: [main] !!3 Escape
|
|
398
458
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
399
459
|
pipelineString += '\n';
|
|
400
460
|
pipelineString += '```';
|
|
401
461
|
pipelineString += '\n\n';
|
|
402
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main]
|
|
462
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
403
463
|
}
|
|
404
464
|
}
|
|
405
465
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -409,7 +469,7 @@
|
|
|
409
469
|
}
|
|
410
470
|
finally { if (e_3) throw e_3.error; }
|
|
411
471
|
}
|
|
412
|
-
return pipelineString;
|
|
472
|
+
return validatePipelineString(pipelineString);
|
|
413
473
|
}
|
|
414
474
|
/**
|
|
415
475
|
* @private internal utility of `pipelineJsonToString`
|
|
@@ -470,6 +530,12 @@
|
|
|
470
530
|
* @public exported from `@promptbook/core`
|
|
471
531
|
*/
|
|
472
532
|
var ADMIN_GITHUB_NAME = 'hejny';
|
|
533
|
+
/**
|
|
534
|
+
* When the title is not provided, the default title is used
|
|
535
|
+
*
|
|
536
|
+
* @public exported from `@promptbook/core`
|
|
537
|
+
*/
|
|
538
|
+
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
473
539
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
474
540
|
/**
|
|
475
541
|
* The maximum number of iterations for a loops
|
|
@@ -621,7 +687,7 @@
|
|
|
621
687
|
/**
|
|
622
688
|
* Make error report URL for the given error
|
|
623
689
|
*
|
|
624
|
-
* @private
|
|
690
|
+
* @private private within the repository
|
|
625
691
|
*/
|
|
626
692
|
function getErrorReportUrl(error) {
|
|
627
693
|
var report = {
|
|
@@ -742,7 +808,7 @@
|
|
|
742
808
|
if (!(error instanceof Error)) {
|
|
743
809
|
throw error;
|
|
744
810
|
}
|
|
745
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.
|
|
811
|
+
throw new UnexpectedError(spaceTrim__default["default"](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 "); }));
|
|
746
812
|
}
|
|
747
813
|
/*
|
|
748
814
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -772,7 +838,7 @@
|
|
|
772
838
|
}
|
|
773
839
|
/**
|
|
774
840
|
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
775
|
-
* TODO: [🧠][main]
|
|
841
|
+
* TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
776
842
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
777
843
|
*/
|
|
778
844
|
|
|
@@ -784,7 +850,6 @@
|
|
|
784
850
|
function deepClone(objectValue) {
|
|
785
851
|
return JSON.parse(JSON.stringify(objectValue));
|
|
786
852
|
/*
|
|
787
|
-
!!!!!!!!
|
|
788
853
|
TODO: [🧠] Is there a better implementation?
|
|
789
854
|
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
790
855
|
> for (const propertyName of propertyNames) {
|
|
@@ -896,25 +961,6 @@
|
|
|
896
961
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
897
962
|
*/
|
|
898
963
|
|
|
899
|
-
/**
|
|
900
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
901
|
-
*
|
|
902
|
-
* @public exported from `@promptbook/core`
|
|
903
|
-
*/
|
|
904
|
-
var ParseError = /** @class */ (function (_super) {
|
|
905
|
-
__extends(ParseError, _super);
|
|
906
|
-
function ParseError(message) {
|
|
907
|
-
var _this = _super.call(this, message) || this;
|
|
908
|
-
_this.name = 'ParseError';
|
|
909
|
-
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
910
|
-
return _this;
|
|
911
|
-
}
|
|
912
|
-
return ParseError;
|
|
913
|
-
}(Error));
|
|
914
|
-
/**
|
|
915
|
-
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
916
|
-
*/
|
|
917
|
-
|
|
918
964
|
/**
|
|
919
965
|
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
920
966
|
*
|
|
@@ -969,7 +1015,7 @@
|
|
|
969
1015
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
970
1016
|
return false;
|
|
971
1017
|
}
|
|
972
|
-
// <- TODO: [main]
|
|
1018
|
+
// <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
|
|
973
1019
|
return true;
|
|
974
1020
|
}
|
|
975
1021
|
|
|
@@ -1069,9 +1115,6 @@
|
|
|
1069
1115
|
if (!url.startsWith('https://')) {
|
|
1070
1116
|
return false;
|
|
1071
1117
|
}
|
|
1072
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
1073
|
-
return false;
|
|
1074
|
-
}
|
|
1075
1118
|
if (url.includes('#')) {
|
|
1076
1119
|
// TODO: [🐠]
|
|
1077
1120
|
return false;
|
|
@@ -1102,11 +1145,11 @@
|
|
|
1102
1145
|
*/
|
|
1103
1146
|
function validatePipeline(pipeline) {
|
|
1104
1147
|
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
1105
|
-
|
|
1148
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1106
1149
|
}
|
|
1107
1150
|
else {
|
|
1108
1151
|
try {
|
|
1109
|
-
|
|
1152
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1110
1153
|
}
|
|
1111
1154
|
catch (error) {
|
|
1112
1155
|
if (!(error instanceof PipelineLogicError)) {
|
|
@@ -1120,7 +1163,7 @@
|
|
|
1120
1163
|
/**
|
|
1121
1164
|
* @private internal function for `validatePipeline`
|
|
1122
1165
|
*/
|
|
1123
|
-
function
|
|
1166
|
+
function validatePipeline_InnerFunction(pipeline) {
|
|
1124
1167
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
1125
1168
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1126
1169
|
var pipelineIdentification = (function () {
|
|
@@ -1344,11 +1387,11 @@
|
|
|
1344
1387
|
_loop_3();
|
|
1345
1388
|
}
|
|
1346
1389
|
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
1347
|
-
// TODO:
|
|
1390
|
+
// TODO: !!6 Implement this
|
|
1348
1391
|
// pipeline.formfactorName
|
|
1349
1392
|
}
|
|
1350
1393
|
/**
|
|
1351
|
-
* TODO:
|
|
1394
|
+
* TODO: [🧞♀️] Do not allow joker + foreach
|
|
1352
1395
|
* TODO: [🧠] Work with promptbookVersion
|
|
1353
1396
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
1354
1397
|
* > /**
|
|
@@ -1360,11 +1403,11 @@
|
|
|
1360
1403
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1361
1404
|
*/
|
|
1362
1405
|
/**
|
|
1363
|
-
* TODO: [🧳][main]
|
|
1364
|
-
* TODO: [🧳][🐝][main]
|
|
1365
|
-
* TODO: [🧳][main]
|
|
1366
|
-
* TODO: [🧳][main]
|
|
1367
|
-
* TODO: [🧳][main]
|
|
1406
|
+
* TODO: [🧳][main] !!4 Validate that all examples match expectations
|
|
1407
|
+
* TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
|
|
1408
|
+
* TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
|
|
1409
|
+
* TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1410
|
+
* TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
|
|
1368
1411
|
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1369
1412
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1370
1413
|
*/
|
|
@@ -1500,7 +1543,7 @@
|
|
|
1500
1543
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1501
1544
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1502
1545
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1503
|
-
throw new PipelineUrlError(spaceTrim.spaceTrim("\n Pipeline with URL
|
|
1546
|
+
throw new PipelineUrlError(spaceTrim.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 ")));
|
|
1504
1547
|
}
|
|
1505
1548
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1506
1549
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1820,11 +1863,16 @@
|
|
|
1820
1863
|
/**
|
|
1821
1864
|
* Determine if the pipeline is fully prepared
|
|
1822
1865
|
*
|
|
1866
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
1867
|
+
*
|
|
1823
1868
|
* @public exported from `@promptbook/core`
|
|
1824
1869
|
*/
|
|
1825
1870
|
function isPipelinePrepared(pipeline) {
|
|
1826
1871
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
1827
1872
|
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
1873
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
1874
|
+
return false;
|
|
1875
|
+
}
|
|
1828
1876
|
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
1829
1877
|
return false;
|
|
1830
1878
|
}
|
|
@@ -1840,7 +1888,7 @@
|
|
|
1840
1888
|
return true;
|
|
1841
1889
|
}
|
|
1842
1890
|
/**
|
|
1843
|
-
* TODO: [🔃][main]
|
|
1891
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
1844
1892
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
1845
1893
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
1846
1894
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1849,6 +1897,81 @@
|
|
|
1849
1897
|
* - [♨] Are tasks prepared
|
|
1850
1898
|
*/
|
|
1851
1899
|
|
|
1900
|
+
/**
|
|
1901
|
+
* Format either small or big number
|
|
1902
|
+
*
|
|
1903
|
+
* @public exported from `@promptbook/utils`
|
|
1904
|
+
*/
|
|
1905
|
+
function numberToString(value) {
|
|
1906
|
+
if (value === 0) {
|
|
1907
|
+
return '0';
|
|
1908
|
+
}
|
|
1909
|
+
else if (Number.isNaN(value)) {
|
|
1910
|
+
return VALUE_STRINGS.nan;
|
|
1911
|
+
}
|
|
1912
|
+
else if (value === Infinity) {
|
|
1913
|
+
return VALUE_STRINGS.infinity;
|
|
1914
|
+
}
|
|
1915
|
+
else if (value === -Infinity) {
|
|
1916
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
1917
|
+
}
|
|
1918
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
1919
|
+
var factor = Math.pow(10, exponent);
|
|
1920
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
1921
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
1922
|
+
return valueRounded.toFixed(exponent);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
return value.toString();
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Function `valueToString` will convert the given value to string
|
|
1930
|
+
* This is useful and used in the `templateParameters` function
|
|
1931
|
+
*
|
|
1932
|
+
* Note: This function is not just calling `toString` method
|
|
1933
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
1934
|
+
* See `VALUE_STRINGS`
|
|
1935
|
+
*
|
|
1936
|
+
* Note: There are 2 similar functions
|
|
1937
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
1938
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
1939
|
+
*
|
|
1940
|
+
* @public exported from `@promptbook/utils`
|
|
1941
|
+
*/
|
|
1942
|
+
function valueToString(value) {
|
|
1943
|
+
try {
|
|
1944
|
+
if (value === '') {
|
|
1945
|
+
return VALUE_STRINGS.empty;
|
|
1946
|
+
}
|
|
1947
|
+
else if (value === null) {
|
|
1948
|
+
return VALUE_STRINGS.null;
|
|
1949
|
+
}
|
|
1950
|
+
else if (value === undefined) {
|
|
1951
|
+
return VALUE_STRINGS.undefined;
|
|
1952
|
+
}
|
|
1953
|
+
else if (typeof value === 'string') {
|
|
1954
|
+
return value;
|
|
1955
|
+
}
|
|
1956
|
+
else if (typeof value === 'number') {
|
|
1957
|
+
return numberToString(value);
|
|
1958
|
+
}
|
|
1959
|
+
else if (value instanceof Date) {
|
|
1960
|
+
return value.toISOString();
|
|
1961
|
+
}
|
|
1962
|
+
else {
|
|
1963
|
+
return JSON.stringify(value);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
catch (error) {
|
|
1967
|
+
if (!(error instanceof Error)) {
|
|
1968
|
+
throw error;
|
|
1969
|
+
}
|
|
1970
|
+
console.error(error);
|
|
1971
|
+
return VALUE_STRINGS.unserializable;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1852
1975
|
/**
|
|
1853
1976
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
1854
1977
|
*
|
|
@@ -2530,10 +2653,10 @@
|
|
|
2530
2653
|
});
|
|
2531
2654
|
}
|
|
2532
2655
|
/**
|
|
2533
|
-
* TODO: [🔃][main]
|
|
2534
|
-
* TODO: [🏢]
|
|
2535
|
-
* TODO: [🏢]
|
|
2536
|
-
* TODO: [🏢]
|
|
2656
|
+
* TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
|
|
2657
|
+
* TODO: [🏢] Check validity of `modelName` in pipeline
|
|
2658
|
+
* TODO: [🏢] Check validity of `systemMessage` in pipeline
|
|
2659
|
+
* TODO: [🏢] Check validity of `temperature` in pipeline
|
|
2537
2660
|
*/
|
|
2538
2661
|
|
|
2539
2662
|
/**
|
|
@@ -3228,21 +3351,44 @@
|
|
|
3228
3351
|
if (typeof filename !== 'string') {
|
|
3229
3352
|
return false;
|
|
3230
3353
|
}
|
|
3354
|
+
if (filename.split('\n').length > 1) {
|
|
3355
|
+
return false;
|
|
3356
|
+
}
|
|
3357
|
+
if (filename.split(' ').length >
|
|
3358
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
3359
|
+
return false;
|
|
3360
|
+
}
|
|
3231
3361
|
var filenameSlashes = filename.split('\\').join('/');
|
|
3232
3362
|
// Absolute Unix path: /hello.txt
|
|
3233
3363
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
3364
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
3234
3365
|
return true;
|
|
3235
3366
|
}
|
|
3236
3367
|
// Absolute Windows path: /hello.txt
|
|
3237
3368
|
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
3369
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
3238
3370
|
return true;
|
|
3239
3371
|
}
|
|
3240
3372
|
// Relative path: ./hello.txt
|
|
3241
3373
|
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
3374
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
3375
|
+
return true;
|
|
3376
|
+
}
|
|
3377
|
+
// Allow paths like foo/hello
|
|
3378
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
3379
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
3380
|
+
return true;
|
|
3381
|
+
}
|
|
3382
|
+
// Allow paths like hello.book
|
|
3383
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
3384
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
3242
3385
|
return true;
|
|
3243
3386
|
}
|
|
3244
3387
|
return false;
|
|
3245
3388
|
}
|
|
3389
|
+
/**
|
|
3390
|
+
* TODO: [🍏] Implement for MacOs
|
|
3391
|
+
*/
|
|
3246
3392
|
|
|
3247
3393
|
/**
|
|
3248
3394
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
@@ -3267,6 +3413,9 @@
|
|
|
3267
3413
|
}
|
|
3268
3414
|
});
|
|
3269
3415
|
}); };
|
|
3416
|
+
/**
|
|
3417
|
+
* TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
|
|
3418
|
+
*/
|
|
3270
3419
|
|
|
3271
3420
|
/**
|
|
3272
3421
|
* @@@
|
|
@@ -3334,7 +3483,7 @@
|
|
|
3334
3483
|
},
|
|
3335
3484
|
}];
|
|
3336
3485
|
case 2:
|
|
3337
|
-
if (!
|
|
3486
|
+
if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
|
|
3338
3487
|
if (tools.fs === undefined) {
|
|
3339
3488
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3340
3489
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3349,7 +3498,7 @@
|
|
|
3349
3498
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3350
3499
|
case 3:
|
|
3351
3500
|
if (!(_f.sent())) {
|
|
3352
|
-
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
3501
|
+
throw new NotFoundError(spaceTrim__default["default"](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 "); }));
|
|
3353
3502
|
}
|
|
3354
3503
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
3355
3504
|
return [2 /*return*/, {
|
|
@@ -3462,7 +3611,7 @@
|
|
|
3462
3611
|
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
3463
3612
|
return [2 /*return*/, "break"];
|
|
3464
3613
|
}
|
|
3465
|
-
console.warn(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n
|
|
3614
|
+
console.warn(spaceTrim__default["default"](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
|
|
3466
3615
|
.split('\n')
|
|
3467
3616
|
.map(function (line) { return "> ".concat(line); })
|
|
3468
3617
|
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -3500,7 +3649,7 @@
|
|
|
3500
3649
|
return [7 /*endfinally*/];
|
|
3501
3650
|
case 9:
|
|
3502
3651
|
if (partialPieces === null) {
|
|
3503
|
-
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n
|
|
3652
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
|
|
3504
3653
|
.split('\n')
|
|
3505
3654
|
.map(function (line) { return "> ".concat(line); })
|
|
3506
3655
|
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -3591,7 +3740,7 @@
|
|
|
3591
3740
|
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
3592
3741
|
* TODO: [🧠] Add context to each task (if missing)
|
|
3593
3742
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
3594
|
-
* TODO: [♨][main]
|
|
3743
|
+
* TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
|
|
3595
3744
|
* TODO: Write tests for `preparePipeline`
|
|
3596
3745
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3597
3746
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3599,7 +3748,9 @@
|
|
|
3599
3748
|
*/
|
|
3600
3749
|
|
|
3601
3750
|
/**
|
|
3602
|
-
* Prepare pipeline
|
|
3751
|
+
* Prepare pipeline locally
|
|
3752
|
+
*
|
|
3753
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
3603
3754
|
*
|
|
3604
3755
|
* Note: This function does not validate logic of the pipeline
|
|
3605
3756
|
* Note: This function acts as part of compilation process
|
|
@@ -3613,16 +3764,17 @@
|
|
|
3613
3764
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3614
3765
|
knowledgeSources /*
|
|
3615
3766
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3616
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3767
|
+
<- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3768
|
+
var _d;
|
|
3617
3769
|
var _this = this;
|
|
3618
|
-
return __generator(this, function (
|
|
3619
|
-
switch (
|
|
3770
|
+
return __generator(this, function (_e) {
|
|
3771
|
+
switch (_e.label) {
|
|
3620
3772
|
case 0:
|
|
3621
3773
|
if (isPipelinePrepared(pipeline)) {
|
|
3622
3774
|
return [2 /*return*/, pipeline];
|
|
3623
3775
|
}
|
|
3624
3776
|
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;
|
|
3625
|
-
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3777
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
|
|
3626
3778
|
if (tools === undefined || tools.llm === undefined) {
|
|
3627
3779
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
3628
3780
|
}
|
|
@@ -3640,6 +3792,33 @@
|
|
|
3640
3792
|
// <- TODO: [🧊]
|
|
3641
3793
|
currentPreparation,
|
|
3642
3794
|
];
|
|
3795
|
+
title = pipeline.title;
|
|
3796
|
+
if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
|
|
3797
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3798
|
+
_c = createPipelineExecutor;
|
|
3799
|
+
_d = {};
|
|
3800
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
|
|
3801
|
+
case 1:
|
|
3802
|
+
prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
|
|
3803
|
+
_d.tools = tools,
|
|
3804
|
+
_d)]);
|
|
3805
|
+
return [4 /*yield*/, prepareTitleExecutor({
|
|
3806
|
+
book: sources.map(function (_a) {
|
|
3807
|
+
var content = _a.content;
|
|
3808
|
+
return content;
|
|
3809
|
+
}).join('\n\n'),
|
|
3810
|
+
})];
|
|
3811
|
+
case 2:
|
|
3812
|
+
result = _e.sent();
|
|
3813
|
+
assertsExecutionSuccessful(result);
|
|
3814
|
+
outputParameters = result.outputParameters;
|
|
3815
|
+
titleRaw = outputParameters.title;
|
|
3816
|
+
if (isVerbose) {
|
|
3817
|
+
console.info("The title is \"".concat(titleRaw, "\""));
|
|
3818
|
+
}
|
|
3819
|
+
title = titleRaw || DEFAULT_BOOK_TITLE;
|
|
3820
|
+
_e.label = 3;
|
|
3821
|
+
case 3:
|
|
3643
3822
|
preparedPersonas = new Array(personas.length);
|
|
3644
3823
|
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 () {
|
|
3645
3824
|
var modelRequirements, preparedPersona;
|
|
@@ -3658,12 +3837,12 @@
|
|
|
3658
3837
|
}
|
|
3659
3838
|
});
|
|
3660
3839
|
}); })];
|
|
3661
|
-
case
|
|
3662
|
-
|
|
3840
|
+
case 4:
|
|
3841
|
+
_e.sent();
|
|
3663
3842
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3664
3843
|
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
3665
|
-
case
|
|
3666
|
-
partialknowledgePiecesPrepared =
|
|
3844
|
+
case 5:
|
|
3845
|
+
partialknowledgePiecesPrepared = _e.sent();
|
|
3667
3846
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3668
3847
|
return [4 /*yield*/, prepareTasks({
|
|
3669
3848
|
parameters: parameters,
|
|
@@ -3674,8 +3853,8 @@
|
|
|
3674
3853
|
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3675
3854
|
isVerbose: isVerbose,
|
|
3676
3855
|
})];
|
|
3677
|
-
case
|
|
3678
|
-
tasksPrepared = (
|
|
3856
|
+
case 6:
|
|
3857
|
+
tasksPrepared = (_e.sent()).tasksPrepared;
|
|
3679
3858
|
// ----- /Tasks preparation -----
|
|
3680
3859
|
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
3681
3860
|
// Note: Count total usage
|
|
@@ -3686,7 +3865,7 @@
|
|
|
3686
3865
|
order: ORDER_OF_PIPELINE_JSON,
|
|
3687
3866
|
value: __assign(__assign({}, pipeline), {
|
|
3688
3867
|
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
3689
|
-
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3868
|
+
title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3690
3869
|
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3691
3870
|
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
3692
3871
|
})];
|
|
@@ -3695,7 +3874,7 @@
|
|
|
3695
3874
|
});
|
|
3696
3875
|
}
|
|
3697
3876
|
/**
|
|
3698
|
-
* TODO: Write tests for `preparePipeline`
|
|
3877
|
+
* TODO: Write tests for `preparePipeline` and `preparePipelineOnRemoteServer`
|
|
3699
3878
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3700
3879
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3701
3880
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
@@ -3757,7 +3936,7 @@
|
|
|
3757
3936
|
if (!(error instanceof Error)) {
|
|
3758
3937
|
throw error;
|
|
3759
3938
|
}
|
|
3760
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n
|
|
3939
|
+
throw new ParseError(spaceTrim.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)
|
|
3761
3940
|
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3762
3941
|
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3763
3942
|
}
|
|
@@ -4037,27 +4216,6 @@
|
|
|
4037
4216
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
4038
4217
|
*/
|
|
4039
4218
|
|
|
4040
|
-
/**
|
|
4041
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
4042
|
-
*
|
|
4043
|
-
* @public exported from `@promptbook/utils`
|
|
4044
|
-
*/
|
|
4045
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
4046
|
-
try {
|
|
4047
|
-
JSON.parse(value);
|
|
4048
|
-
return true;
|
|
4049
|
-
}
|
|
4050
|
-
catch (error) {
|
|
4051
|
-
if (!(error instanceof Error)) {
|
|
4052
|
-
throw error;
|
|
4053
|
-
}
|
|
4054
|
-
if (error.message.includes('Unexpected token')) {
|
|
4055
|
-
return false;
|
|
4056
|
-
}
|
|
4057
|
-
return false;
|
|
4058
|
-
}
|
|
4059
|
-
}
|
|
4060
|
-
|
|
4061
4219
|
/**
|
|
4062
4220
|
* Definition for JSON format
|
|
4063
4221
|
*
|
|
@@ -4376,81 +4534,6 @@
|
|
|
4376
4534
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
4377
4535
|
*/
|
|
4378
4536
|
|
|
4379
|
-
/**
|
|
4380
|
-
* Format either small or big number
|
|
4381
|
-
*
|
|
4382
|
-
* @public exported from `@promptbook/utils`
|
|
4383
|
-
*/
|
|
4384
|
-
function numberToString(value) {
|
|
4385
|
-
if (value === 0) {
|
|
4386
|
-
return '0';
|
|
4387
|
-
}
|
|
4388
|
-
else if (Number.isNaN(value)) {
|
|
4389
|
-
return VALUE_STRINGS.nan;
|
|
4390
|
-
}
|
|
4391
|
-
else if (value === Infinity) {
|
|
4392
|
-
return VALUE_STRINGS.infinity;
|
|
4393
|
-
}
|
|
4394
|
-
else if (value === -Infinity) {
|
|
4395
|
-
return VALUE_STRINGS.negativeInfinity;
|
|
4396
|
-
}
|
|
4397
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4398
|
-
var factor = Math.pow(10, exponent);
|
|
4399
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
4400
|
-
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4401
|
-
return valueRounded.toFixed(exponent);
|
|
4402
|
-
}
|
|
4403
|
-
}
|
|
4404
|
-
return value.toString();
|
|
4405
|
-
}
|
|
4406
|
-
|
|
4407
|
-
/**
|
|
4408
|
-
* Function `valueToString` will convert the given value to string
|
|
4409
|
-
* This is useful and used in the `templateParameters` function
|
|
4410
|
-
*
|
|
4411
|
-
* Note: This function is not just calling `toString` method
|
|
4412
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
4413
|
-
* See `VALUE_STRINGS`
|
|
4414
|
-
*
|
|
4415
|
-
* Note: There are 2 similar functions
|
|
4416
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4417
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4418
|
-
*
|
|
4419
|
-
* @public exported from `@promptbook/utils`
|
|
4420
|
-
*/
|
|
4421
|
-
function valueToString(value) {
|
|
4422
|
-
try {
|
|
4423
|
-
if (value === '') {
|
|
4424
|
-
return VALUE_STRINGS.empty;
|
|
4425
|
-
}
|
|
4426
|
-
else if (value === null) {
|
|
4427
|
-
return VALUE_STRINGS.null;
|
|
4428
|
-
}
|
|
4429
|
-
else if (value === undefined) {
|
|
4430
|
-
return VALUE_STRINGS.undefined;
|
|
4431
|
-
}
|
|
4432
|
-
else if (typeof value === 'string') {
|
|
4433
|
-
return value;
|
|
4434
|
-
}
|
|
4435
|
-
else if (typeof value === 'number') {
|
|
4436
|
-
return numberToString(value);
|
|
4437
|
-
}
|
|
4438
|
-
else if (value instanceof Date) {
|
|
4439
|
-
return value.toISOString();
|
|
4440
|
-
}
|
|
4441
|
-
else {
|
|
4442
|
-
return JSON.stringify(value);
|
|
4443
|
-
}
|
|
4444
|
-
}
|
|
4445
|
-
catch (error) {
|
|
4446
|
-
if (!(error instanceof Error)) {
|
|
4447
|
-
throw error;
|
|
4448
|
-
}
|
|
4449
|
-
console.error(error);
|
|
4450
|
-
return VALUE_STRINGS.unserializable;
|
|
4451
|
-
}
|
|
4452
|
-
}
|
|
4453
|
-
|
|
4454
4537
|
/**
|
|
4455
4538
|
* Replaces parameters in template with values from parameters object
|
|
4456
4539
|
*
|
|
@@ -4507,6 +4590,8 @@
|
|
|
4507
4590
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
4508
4591
|
}
|
|
4509
4592
|
parameterValue = valueToString(parameterValue);
|
|
4593
|
+
// Escape curly braces in parameter values to prevent prompt-injection
|
|
4594
|
+
parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
|
|
4510
4595
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
4511
4596
|
parameterValue = parameterValue
|
|
4512
4597
|
.split('\n')
|
|
@@ -4866,7 +4951,7 @@
|
|
|
4866
4951
|
promptTitle: task.title,
|
|
4867
4952
|
promptMessage: templateParameters(task.description || '', parameters),
|
|
4868
4953
|
defaultValue: templateParameters(preparedContent, parameters),
|
|
4869
|
-
// TODO: [🧠]
|
|
4954
|
+
// TODO: [🧠] Figure out how to define placeholder in .book.md file
|
|
4870
4955
|
placeholder: undefined,
|
|
4871
4956
|
priority: priority,
|
|
4872
4957
|
}))];
|
|
@@ -5566,7 +5651,10 @@
|
|
|
5566
5651
|
finally { if (e_2) throw e_2.error; }
|
|
5567
5652
|
return [7 /*endfinally*/];
|
|
5568
5653
|
case 19:
|
|
5569
|
-
parametersToPass = inputParameters
|
|
5654
|
+
parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
|
|
5655
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
5656
|
+
return [key, valueToString(value)];
|
|
5657
|
+
}));
|
|
5570
5658
|
_g.label = 20;
|
|
5571
5659
|
case 20:
|
|
5572
5660
|
_g.trys.push([20, 25, , 28]);
|
|
@@ -5853,6 +5941,7 @@
|
|
|
5853
5941
|
mimeTypes: ['text/markdown', 'text/plain'],
|
|
5854
5942
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
5855
5943
|
isAvilableInBrowser: true,
|
|
5944
|
+
// <- 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
|
|
5856
5945
|
requiredExecutables: [],
|
|
5857
5946
|
}); /* <- Note: [🤛] */
|
|
5858
5947
|
/**
|
|
@@ -5861,6 +5950,7 @@
|
|
|
5861
5950
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
5862
5951
|
*
|
|
5863
5952
|
* @public exported from `@promptbook/core`
|
|
5953
|
+
* @public exported from `@promptbook/wizzard`
|
|
5864
5954
|
* @public exported from `@promptbook/cli`
|
|
5865
5955
|
*/
|
|
5866
5956
|
$scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
@@ -5946,12 +6036,12 @@
|
|
|
5946
6036
|
outputParameters = result.outputParameters;
|
|
5947
6037
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
5948
6038
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
5949
|
-
// <- TODO: [main]
|
|
6039
|
+
// <- TODO: [main] Smarter split and filter out empty pieces
|
|
5950
6040
|
if (isVerbose) {
|
|
5951
6041
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
5952
6042
|
}
|
|
5953
6043
|
return [4 /*yield*/, Promise.all(
|
|
5954
|
-
// TODO: [🪂]
|
|
6044
|
+
// TODO: [🪂] Do not send all at once but in chunks
|
|
5955
6045
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
5956
6046
|
var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
5957
6047
|
return __generator(this, function (_c) {
|
|
@@ -6049,7 +6139,8 @@
|
|
|
6049
6139
|
className: 'PdfScraper',
|
|
6050
6140
|
mimeTypes: ['application/pdf'],
|
|
6051
6141
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
6052
|
-
isAvilableInBrowser:
|
|
6142
|
+
isAvilableInBrowser: false,
|
|
6143
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
6053
6144
|
requiredExecutables: [],
|
|
6054
6145
|
}); /* <- Note: [🤛] */
|
|
6055
6146
|
/**
|
|
@@ -6058,6 +6149,7 @@
|
|
|
6058
6149
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6059
6150
|
*
|
|
6060
6151
|
* @public exported from `@promptbook/core`
|
|
6152
|
+
* @public exported from `@promptbook/wizzard`
|
|
6061
6153
|
* @public exported from `@promptbook/cli`
|
|
6062
6154
|
*/
|
|
6063
6155
|
$scrapersMetadataRegister.register(pdfScraperMetadata);
|
|
@@ -6122,6 +6214,7 @@
|
|
|
6122
6214
|
* TODO: [👣] Converted pdf documents can act as cached items - there is no need to run conversion each time
|
|
6123
6215
|
* TODO: [🪂] Do it in parallel 11:11
|
|
6124
6216
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
6217
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
6125
6218
|
*/
|
|
6126
6219
|
|
|
6127
6220
|
/**
|
|
@@ -6142,6 +6235,7 @@
|
|
|
6142
6235
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6143
6236
|
*
|
|
6144
6237
|
* @public exported from `@promptbook/pdf`
|
|
6238
|
+
* @public exported from `@promptbook/wizzard`
|
|
6145
6239
|
* @public exported from `@promptbook/cli`
|
|
6146
6240
|
*/
|
|
6147
6241
|
var _PdfScraperRegistration = $scrapersRegister.register(createPdfScraper);
|