@promptbook/legacy-documents 0.81.0-8 → 0.81.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 -8
- package/esm/index.es.js +261 -166
- 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/templates.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- 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/{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/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/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 +2 -0
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
- 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 +261 -166
- 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/utils/markdown/{removeContentComments.test.d.ts → removeMarkdownComments.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-24';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -190,6 +190,12 @@
|
|
|
190
190
|
* @public exported from `@promptbook/core`
|
|
191
191
|
*/
|
|
192
192
|
var ADMIN_GITHUB_NAME = 'hejny';
|
|
193
|
+
/**
|
|
194
|
+
* When the title is not provided, the default title is used
|
|
195
|
+
*
|
|
196
|
+
* @public exported from `@promptbook/core`
|
|
197
|
+
*/
|
|
198
|
+
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
193
199
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
194
200
|
/**
|
|
195
201
|
* The maximum number of iterations for a loops
|
|
@@ -339,7 +345,7 @@
|
|
|
339
345
|
/**
|
|
340
346
|
* Make error report URL for the given error
|
|
341
347
|
*
|
|
342
|
-
* @private
|
|
348
|
+
* @private private within the repository
|
|
343
349
|
*/
|
|
344
350
|
function getErrorReportUrl(error) {
|
|
345
351
|
var report = {
|
|
@@ -945,21 +951,44 @@
|
|
|
945
951
|
if (typeof filename !== 'string') {
|
|
946
952
|
return false;
|
|
947
953
|
}
|
|
954
|
+
if (filename.split('\n').length > 1) {
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
957
|
+
if (filename.split(' ').length >
|
|
958
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
948
961
|
var filenameSlashes = filename.split('\\').join('/');
|
|
949
962
|
// Absolute Unix path: /hello.txt
|
|
950
963
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
964
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
951
965
|
return true;
|
|
952
966
|
}
|
|
953
967
|
// Absolute Windows path: /hello.txt
|
|
954
968
|
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
969
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
955
970
|
return true;
|
|
956
971
|
}
|
|
957
972
|
// Relative path: ./hello.txt
|
|
958
973
|
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
974
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
975
|
+
return true;
|
|
976
|
+
}
|
|
977
|
+
// Allow paths like foo/hello
|
|
978
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
979
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
980
|
+
return true;
|
|
981
|
+
}
|
|
982
|
+
// Allow paths like hello.book
|
|
983
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
984
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
959
985
|
return true;
|
|
960
986
|
}
|
|
961
987
|
return false;
|
|
962
988
|
}
|
|
989
|
+
/**
|
|
990
|
+
* TODO: [🍏] Implement for MacOs
|
|
991
|
+
*/
|
|
963
992
|
|
|
964
993
|
/**
|
|
965
994
|
* Tests if given string is valid URL.
|
|
@@ -1085,7 +1114,67 @@
|
|
|
1085
1114
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
1086
1115
|
*/
|
|
1087
1116
|
|
|
1088
|
-
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"}];
|
|
1117
|
+
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- 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- 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 workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.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 workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1121
|
+
*
|
|
1122
|
+
* @public exported from `@promptbook/utils`
|
|
1123
|
+
*/
|
|
1124
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1125
|
+
try {
|
|
1126
|
+
JSON.parse(value);
|
|
1127
|
+
return true;
|
|
1128
|
+
}
|
|
1129
|
+
catch (error) {
|
|
1130
|
+
if (!(error instanceof Error)) {
|
|
1131
|
+
throw error;
|
|
1132
|
+
}
|
|
1133
|
+
if (error.message.includes('Unexpected token')) {
|
|
1134
|
+
return false;
|
|
1135
|
+
}
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
1142
|
+
*
|
|
1143
|
+
* @public exported from `@promptbook/core`
|
|
1144
|
+
*/
|
|
1145
|
+
var ParseError = /** @class */ (function (_super) {
|
|
1146
|
+
__extends(ParseError, _super);
|
|
1147
|
+
function ParseError(message) {
|
|
1148
|
+
var _this = _super.call(this, message) || this;
|
|
1149
|
+
_this.name = 'ParseError';
|
|
1150
|
+
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
1151
|
+
return _this;
|
|
1152
|
+
}
|
|
1153
|
+
return ParseError;
|
|
1154
|
+
}(Error));
|
|
1155
|
+
/**
|
|
1156
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1157
|
+
*/
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1161
|
+
* 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.
|
|
1162
|
+
*
|
|
1163
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
1164
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
1165
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
1166
|
+
* @public exported from `@promptbook/core`
|
|
1167
|
+
*/
|
|
1168
|
+
function validatePipelineString(pipelineString) {
|
|
1169
|
+
if (isValidJsonString(pipelineString)) {
|
|
1170
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
1171
|
+
}
|
|
1172
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1173
|
+
return pipelineString;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
1177
|
+
*/
|
|
1089
1178
|
|
|
1090
1179
|
/**
|
|
1091
1180
|
* Prettify the html code
|
|
@@ -1153,7 +1242,7 @@
|
|
|
1153
1242
|
if (bookVersion !== "undefined") {
|
|
1154
1243
|
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
1155
1244
|
}
|
|
1156
|
-
// TODO: [main]
|
|
1245
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
1157
1246
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
1158
1247
|
try {
|
|
1159
1248
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -1301,12 +1390,12 @@
|
|
|
1301
1390
|
pipelineString += '```' + contentLanguage;
|
|
1302
1391
|
pipelineString += '\n';
|
|
1303
1392
|
pipelineString += spaceTrim__default["default"](content);
|
|
1304
|
-
// <- TODO: [main]
|
|
1393
|
+
// <- TODO: [main] !!3 Escape
|
|
1305
1394
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1306
1395
|
pipelineString += '\n';
|
|
1307
1396
|
pipelineString += '```';
|
|
1308
1397
|
pipelineString += '\n\n';
|
|
1309
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main]
|
|
1398
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
1310
1399
|
}
|
|
1311
1400
|
}
|
|
1312
1401
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -1316,7 +1405,7 @@
|
|
|
1316
1405
|
}
|
|
1317
1406
|
finally { if (e_3) throw e_3.error; }
|
|
1318
1407
|
}
|
|
1319
|
-
return pipelineString;
|
|
1408
|
+
return validatePipelineString(pipelineString);
|
|
1320
1409
|
}
|
|
1321
1410
|
/**
|
|
1322
1411
|
* @private internal utility of `pipelineJsonToString`
|
|
@@ -1477,7 +1566,7 @@
|
|
|
1477
1566
|
if (!(error instanceof Error)) {
|
|
1478
1567
|
throw error;
|
|
1479
1568
|
}
|
|
1480
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.
|
|
1569
|
+
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 "); }));
|
|
1481
1570
|
}
|
|
1482
1571
|
/*
|
|
1483
1572
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -1507,7 +1596,7 @@
|
|
|
1507
1596
|
}
|
|
1508
1597
|
/**
|
|
1509
1598
|
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
1510
|
-
* TODO: [🧠][main]
|
|
1599
|
+
* TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
1511
1600
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1512
1601
|
*/
|
|
1513
1602
|
|
|
@@ -1519,7 +1608,6 @@
|
|
|
1519
1608
|
function deepClone(objectValue) {
|
|
1520
1609
|
return JSON.parse(JSON.stringify(objectValue));
|
|
1521
1610
|
/*
|
|
1522
|
-
!!!!!!!!
|
|
1523
1611
|
TODO: [🧠] Is there a better implementation?
|
|
1524
1612
|
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1525
1613
|
> for (const propertyName of propertyNames) {
|
|
@@ -1631,25 +1719,6 @@
|
|
|
1631
1719
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1632
1720
|
*/
|
|
1633
1721
|
|
|
1634
|
-
/**
|
|
1635
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
1636
|
-
*
|
|
1637
|
-
* @public exported from `@promptbook/core`
|
|
1638
|
-
*/
|
|
1639
|
-
var ParseError = /** @class */ (function (_super) {
|
|
1640
|
-
__extends(ParseError, _super);
|
|
1641
|
-
function ParseError(message) {
|
|
1642
|
-
var _this = _super.call(this, message) || this;
|
|
1643
|
-
_this.name = 'ParseError';
|
|
1644
|
-
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
1645
|
-
return _this;
|
|
1646
|
-
}
|
|
1647
|
-
return ParseError;
|
|
1648
|
-
}(Error));
|
|
1649
|
-
/**
|
|
1650
|
-
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1651
|
-
*/
|
|
1652
|
-
|
|
1653
1722
|
/**
|
|
1654
1723
|
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
1655
1724
|
*
|
|
@@ -1704,7 +1773,7 @@
|
|
|
1704
1773
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
1705
1774
|
return false;
|
|
1706
1775
|
}
|
|
1707
|
-
// <- TODO: [main]
|
|
1776
|
+
// <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
|
|
1708
1777
|
return true;
|
|
1709
1778
|
}
|
|
1710
1779
|
|
|
@@ -1775,9 +1844,6 @@
|
|
|
1775
1844
|
if (!url.startsWith('https://')) {
|
|
1776
1845
|
return false;
|
|
1777
1846
|
}
|
|
1778
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
1779
|
-
return false;
|
|
1780
|
-
}
|
|
1781
1847
|
if (url.includes('#')) {
|
|
1782
1848
|
// TODO: [🐠]
|
|
1783
1849
|
return false;
|
|
@@ -1808,11 +1874,11 @@
|
|
|
1808
1874
|
*/
|
|
1809
1875
|
function validatePipeline(pipeline) {
|
|
1810
1876
|
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
1811
|
-
|
|
1877
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1812
1878
|
}
|
|
1813
1879
|
else {
|
|
1814
1880
|
try {
|
|
1815
|
-
|
|
1881
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1816
1882
|
}
|
|
1817
1883
|
catch (error) {
|
|
1818
1884
|
if (!(error instanceof PipelineLogicError)) {
|
|
@@ -1826,7 +1892,7 @@
|
|
|
1826
1892
|
/**
|
|
1827
1893
|
* @private internal function for `validatePipeline`
|
|
1828
1894
|
*/
|
|
1829
|
-
function
|
|
1895
|
+
function validatePipeline_InnerFunction(pipeline) {
|
|
1830
1896
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
1831
1897
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1832
1898
|
var pipelineIdentification = (function () {
|
|
@@ -2050,11 +2116,11 @@
|
|
|
2050
2116
|
_loop_3();
|
|
2051
2117
|
}
|
|
2052
2118
|
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
2053
|
-
// TODO:
|
|
2119
|
+
// TODO: !!6 Implement this
|
|
2054
2120
|
// pipeline.formfactorName
|
|
2055
2121
|
}
|
|
2056
2122
|
/**
|
|
2057
|
-
* TODO:
|
|
2123
|
+
* TODO: [🧞♀️] Do not allow joker + foreach
|
|
2058
2124
|
* TODO: [🧠] Work with promptbookVersion
|
|
2059
2125
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
2060
2126
|
* > /**
|
|
@@ -2066,11 +2132,11 @@
|
|
|
2066
2132
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
2067
2133
|
*/
|
|
2068
2134
|
/**
|
|
2069
|
-
* TODO: [🧳][main]
|
|
2070
|
-
* TODO: [🧳][🐝][main]
|
|
2071
|
-
* TODO: [🧳][main]
|
|
2072
|
-
* TODO: [🧳][main]
|
|
2073
|
-
* TODO: [🧳][main]
|
|
2135
|
+
* TODO: [🧳][main] !!4 Validate that all examples match expectations
|
|
2136
|
+
* TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
|
|
2137
|
+
* TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
|
|
2138
|
+
* TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
2139
|
+
* TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
|
|
2074
2140
|
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
2075
2141
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2076
2142
|
*/
|
|
@@ -2206,7 +2272,7 @@
|
|
|
2206
2272
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
2207
2273
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
2208
2274
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
2209
|
-
throw new PipelineUrlError(spaceTrim.spaceTrim("\n Pipeline with URL
|
|
2275
|
+
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 ")));
|
|
2210
2276
|
}
|
|
2211
2277
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
2212
2278
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -2494,11 +2560,16 @@
|
|
|
2494
2560
|
/**
|
|
2495
2561
|
* Determine if the pipeline is fully prepared
|
|
2496
2562
|
*
|
|
2563
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2564
|
+
*
|
|
2497
2565
|
* @public exported from `@promptbook/core`
|
|
2498
2566
|
*/
|
|
2499
2567
|
function isPipelinePrepared(pipeline) {
|
|
2500
2568
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
2501
2569
|
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2570
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2571
|
+
return false;
|
|
2572
|
+
}
|
|
2502
2573
|
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2503
2574
|
return false;
|
|
2504
2575
|
}
|
|
@@ -2514,7 +2585,7 @@
|
|
|
2514
2585
|
return true;
|
|
2515
2586
|
}
|
|
2516
2587
|
/**
|
|
2517
|
-
* TODO: [🔃][main]
|
|
2588
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2518
2589
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2519
2590
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2520
2591
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -2523,6 +2594,81 @@
|
|
|
2523
2594
|
* - [♨] Are tasks prepared
|
|
2524
2595
|
*/
|
|
2525
2596
|
|
|
2597
|
+
/**
|
|
2598
|
+
* Format either small or big number
|
|
2599
|
+
*
|
|
2600
|
+
* @public exported from `@promptbook/utils`
|
|
2601
|
+
*/
|
|
2602
|
+
function numberToString(value) {
|
|
2603
|
+
if (value === 0) {
|
|
2604
|
+
return '0';
|
|
2605
|
+
}
|
|
2606
|
+
else if (Number.isNaN(value)) {
|
|
2607
|
+
return VALUE_STRINGS.nan;
|
|
2608
|
+
}
|
|
2609
|
+
else if (value === Infinity) {
|
|
2610
|
+
return VALUE_STRINGS.infinity;
|
|
2611
|
+
}
|
|
2612
|
+
else if (value === -Infinity) {
|
|
2613
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
2614
|
+
}
|
|
2615
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
2616
|
+
var factor = Math.pow(10, exponent);
|
|
2617
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
2618
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
2619
|
+
return valueRounded.toFixed(exponent);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
return value.toString();
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
/**
|
|
2626
|
+
* Function `valueToString` will convert the given value to string
|
|
2627
|
+
* This is useful and used in the `templateParameters` function
|
|
2628
|
+
*
|
|
2629
|
+
* Note: This function is not just calling `toString` method
|
|
2630
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
2631
|
+
* See `VALUE_STRINGS`
|
|
2632
|
+
*
|
|
2633
|
+
* Note: There are 2 similar functions
|
|
2634
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
2635
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
2636
|
+
*
|
|
2637
|
+
* @public exported from `@promptbook/utils`
|
|
2638
|
+
*/
|
|
2639
|
+
function valueToString(value) {
|
|
2640
|
+
try {
|
|
2641
|
+
if (value === '') {
|
|
2642
|
+
return VALUE_STRINGS.empty;
|
|
2643
|
+
}
|
|
2644
|
+
else if (value === null) {
|
|
2645
|
+
return VALUE_STRINGS.null;
|
|
2646
|
+
}
|
|
2647
|
+
else if (value === undefined) {
|
|
2648
|
+
return VALUE_STRINGS.undefined;
|
|
2649
|
+
}
|
|
2650
|
+
else if (typeof value === 'string') {
|
|
2651
|
+
return value;
|
|
2652
|
+
}
|
|
2653
|
+
else if (typeof value === 'number') {
|
|
2654
|
+
return numberToString(value);
|
|
2655
|
+
}
|
|
2656
|
+
else if (value instanceof Date) {
|
|
2657
|
+
return value.toISOString();
|
|
2658
|
+
}
|
|
2659
|
+
else {
|
|
2660
|
+
return JSON.stringify(value);
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
catch (error) {
|
|
2664
|
+
if (!(error instanceof Error)) {
|
|
2665
|
+
throw error;
|
|
2666
|
+
}
|
|
2667
|
+
console.error(error);
|
|
2668
|
+
return VALUE_STRINGS.unserializable;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2526
2672
|
/**
|
|
2527
2673
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
2528
2674
|
*
|
|
@@ -3204,10 +3350,10 @@
|
|
|
3204
3350
|
});
|
|
3205
3351
|
}
|
|
3206
3352
|
/**
|
|
3207
|
-
* TODO: [🔃][main]
|
|
3208
|
-
* TODO: [🏢]
|
|
3209
|
-
* TODO: [🏢]
|
|
3210
|
-
* TODO: [🏢]
|
|
3353
|
+
* TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
|
|
3354
|
+
* TODO: [🏢] Check validity of `modelName` in pipeline
|
|
3355
|
+
* TODO: [🏢] Check validity of `systemMessage` in pipeline
|
|
3356
|
+
* TODO: [🏢] Check validity of `temperature` in pipeline
|
|
3211
3357
|
*/
|
|
3212
3358
|
|
|
3213
3359
|
/**
|
|
@@ -3546,6 +3692,9 @@
|
|
|
3546
3692
|
}
|
|
3547
3693
|
});
|
|
3548
3694
|
}); };
|
|
3695
|
+
/**
|
|
3696
|
+
* TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
|
|
3697
|
+
*/
|
|
3549
3698
|
|
|
3550
3699
|
/**
|
|
3551
3700
|
* @@@
|
|
@@ -3613,7 +3762,7 @@
|
|
|
3613
3762
|
},
|
|
3614
3763
|
}];
|
|
3615
3764
|
case 2:
|
|
3616
|
-
if (!
|
|
3765
|
+
if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
|
|
3617
3766
|
if (tools.fs === undefined) {
|
|
3618
3767
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3619
3768
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3628,7 +3777,7 @@
|
|
|
3628
3777
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3629
3778
|
case 3:
|
|
3630
3779
|
if (!(_f.sent())) {
|
|
3631
|
-
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 "); }));
|
|
3780
|
+
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 "); }));
|
|
3632
3781
|
}
|
|
3633
3782
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
3634
3783
|
return [2 /*return*/, {
|
|
@@ -3741,7 +3890,7 @@
|
|
|
3741
3890
|
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
3742
3891
|
return [2 /*return*/, "break"];
|
|
3743
3892
|
}
|
|
3744
|
-
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
|
|
3893
|
+
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
|
|
3745
3894
|
.split('\n')
|
|
3746
3895
|
.map(function (line) { return "> ".concat(line); })
|
|
3747
3896
|
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -3779,7 +3928,7 @@
|
|
|
3779
3928
|
return [7 /*endfinally*/];
|
|
3780
3929
|
case 9:
|
|
3781
3930
|
if (partialPieces === null) {
|
|
3782
|
-
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n
|
|
3931
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
|
|
3783
3932
|
.split('\n')
|
|
3784
3933
|
.map(function (line) { return "> ".concat(line); })
|
|
3785
3934
|
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -3870,7 +4019,7 @@
|
|
|
3870
4019
|
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
3871
4020
|
* TODO: [🧠] Add context to each task (if missing)
|
|
3872
4021
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
3873
|
-
* TODO: [♨][main]
|
|
4022
|
+
* TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
|
|
3874
4023
|
* TODO: Write tests for `preparePipeline`
|
|
3875
4024
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3876
4025
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3880,6 +4029,8 @@
|
|
|
3880
4029
|
/**
|
|
3881
4030
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
3882
4031
|
*
|
|
4032
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
4033
|
+
*
|
|
3883
4034
|
* Note: This function does not validate logic of the pipeline
|
|
3884
4035
|
* Note: This function acts as part of compilation process
|
|
3885
4036
|
* Note: When the pipeline is already prepared, it returns the same pipeline
|
|
@@ -3892,16 +4043,17 @@
|
|
|
3892
4043
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3893
4044
|
knowledgeSources /*
|
|
3894
4045
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3895
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
4046
|
+
<- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
4047
|
+
var _d;
|
|
3896
4048
|
var _this = this;
|
|
3897
|
-
return __generator(this, function (
|
|
3898
|
-
switch (
|
|
4049
|
+
return __generator(this, function (_e) {
|
|
4050
|
+
switch (_e.label) {
|
|
3899
4051
|
case 0:
|
|
3900
4052
|
if (isPipelinePrepared(pipeline)) {
|
|
3901
4053
|
return [2 /*return*/, pipeline];
|
|
3902
4054
|
}
|
|
3903
4055
|
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;
|
|
3904
|
-
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
4056
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
|
|
3905
4057
|
if (tools === undefined || tools.llm === undefined) {
|
|
3906
4058
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
3907
4059
|
}
|
|
@@ -3919,6 +4071,33 @@
|
|
|
3919
4071
|
// <- TODO: [🧊]
|
|
3920
4072
|
currentPreparation,
|
|
3921
4073
|
];
|
|
4074
|
+
title = pipeline.title;
|
|
4075
|
+
if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
|
|
4076
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
4077
|
+
_c = createPipelineExecutor;
|
|
4078
|
+
_d = {};
|
|
4079
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
|
|
4080
|
+
case 1:
|
|
4081
|
+
prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
|
|
4082
|
+
_d.tools = tools,
|
|
4083
|
+
_d)]);
|
|
4084
|
+
return [4 /*yield*/, prepareTitleExecutor({
|
|
4085
|
+
book: sources.map(function (_a) {
|
|
4086
|
+
var content = _a.content;
|
|
4087
|
+
return content;
|
|
4088
|
+
}).join('\n\n'),
|
|
4089
|
+
})];
|
|
4090
|
+
case 2:
|
|
4091
|
+
result = _e.sent();
|
|
4092
|
+
assertsExecutionSuccessful(result);
|
|
4093
|
+
outputParameters = result.outputParameters;
|
|
4094
|
+
titleRaw = outputParameters.title;
|
|
4095
|
+
if (isVerbose) {
|
|
4096
|
+
console.info("The title is \"".concat(titleRaw, "\""));
|
|
4097
|
+
}
|
|
4098
|
+
title = titleRaw || DEFAULT_BOOK_TITLE;
|
|
4099
|
+
_e.label = 3;
|
|
4100
|
+
case 3:
|
|
3922
4101
|
preparedPersonas = new Array(personas.length);
|
|
3923
4102
|
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 () {
|
|
3924
4103
|
var modelRequirements, preparedPersona;
|
|
@@ -3937,12 +4116,12 @@
|
|
|
3937
4116
|
}
|
|
3938
4117
|
});
|
|
3939
4118
|
}); })];
|
|
3940
|
-
case
|
|
3941
|
-
|
|
4119
|
+
case 4:
|
|
4120
|
+
_e.sent();
|
|
3942
4121
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3943
4122
|
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
3944
|
-
case
|
|
3945
|
-
partialknowledgePiecesPrepared =
|
|
4123
|
+
case 5:
|
|
4124
|
+
partialknowledgePiecesPrepared = _e.sent();
|
|
3946
4125
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3947
4126
|
return [4 /*yield*/, prepareTasks({
|
|
3948
4127
|
parameters: parameters,
|
|
@@ -3953,8 +4132,8 @@
|
|
|
3953
4132
|
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3954
4133
|
isVerbose: isVerbose,
|
|
3955
4134
|
})];
|
|
3956
|
-
case
|
|
3957
|
-
tasksPrepared = (
|
|
4135
|
+
case 6:
|
|
4136
|
+
tasksPrepared = (_e.sent()).tasksPrepared;
|
|
3958
4137
|
// ----- /Tasks preparation -----
|
|
3959
4138
|
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
3960
4139
|
// Note: Count total usage
|
|
@@ -3965,7 +4144,7 @@
|
|
|
3965
4144
|
order: ORDER_OF_PIPELINE_JSON,
|
|
3966
4145
|
value: __assign(__assign({}, pipeline), {
|
|
3967
4146
|
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
3968
|
-
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
4147
|
+
title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3969
4148
|
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3970
4149
|
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
3971
4150
|
})];
|
|
@@ -4036,7 +4215,7 @@
|
|
|
4036
4215
|
if (!(error instanceof Error)) {
|
|
4037
4216
|
throw error;
|
|
4038
4217
|
}
|
|
4039
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n
|
|
4218
|
+
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)
|
|
4040
4219
|
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
4041
4220
|
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
4042
4221
|
}
|
|
@@ -4316,27 +4495,6 @@
|
|
|
4316
4495
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
4317
4496
|
*/
|
|
4318
4497
|
|
|
4319
|
-
/**
|
|
4320
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
4321
|
-
*
|
|
4322
|
-
* @public exported from `@promptbook/utils`
|
|
4323
|
-
*/
|
|
4324
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
4325
|
-
try {
|
|
4326
|
-
JSON.parse(value);
|
|
4327
|
-
return true;
|
|
4328
|
-
}
|
|
4329
|
-
catch (error) {
|
|
4330
|
-
if (!(error instanceof Error)) {
|
|
4331
|
-
throw error;
|
|
4332
|
-
}
|
|
4333
|
-
if (error.message.includes('Unexpected token')) {
|
|
4334
|
-
return false;
|
|
4335
|
-
}
|
|
4336
|
-
return false;
|
|
4337
|
-
}
|
|
4338
|
-
}
|
|
4339
|
-
|
|
4340
4498
|
/**
|
|
4341
4499
|
* Definition for JSON format
|
|
4342
4500
|
*
|
|
@@ -4655,81 +4813,6 @@
|
|
|
4655
4813
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
4656
4814
|
*/
|
|
4657
4815
|
|
|
4658
|
-
/**
|
|
4659
|
-
* Format either small or big number
|
|
4660
|
-
*
|
|
4661
|
-
* @public exported from `@promptbook/utils`
|
|
4662
|
-
*/
|
|
4663
|
-
function numberToString(value) {
|
|
4664
|
-
if (value === 0) {
|
|
4665
|
-
return '0';
|
|
4666
|
-
}
|
|
4667
|
-
else if (Number.isNaN(value)) {
|
|
4668
|
-
return VALUE_STRINGS.nan;
|
|
4669
|
-
}
|
|
4670
|
-
else if (value === Infinity) {
|
|
4671
|
-
return VALUE_STRINGS.infinity;
|
|
4672
|
-
}
|
|
4673
|
-
else if (value === -Infinity) {
|
|
4674
|
-
return VALUE_STRINGS.negativeInfinity;
|
|
4675
|
-
}
|
|
4676
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4677
|
-
var factor = Math.pow(10, exponent);
|
|
4678
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
4679
|
-
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4680
|
-
return valueRounded.toFixed(exponent);
|
|
4681
|
-
}
|
|
4682
|
-
}
|
|
4683
|
-
return value.toString();
|
|
4684
|
-
}
|
|
4685
|
-
|
|
4686
|
-
/**
|
|
4687
|
-
* Function `valueToString` will convert the given value to string
|
|
4688
|
-
* This is useful and used in the `templateParameters` function
|
|
4689
|
-
*
|
|
4690
|
-
* Note: This function is not just calling `toString` method
|
|
4691
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
4692
|
-
* See `VALUE_STRINGS`
|
|
4693
|
-
*
|
|
4694
|
-
* Note: There are 2 similar functions
|
|
4695
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4696
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4697
|
-
*
|
|
4698
|
-
* @public exported from `@promptbook/utils`
|
|
4699
|
-
*/
|
|
4700
|
-
function valueToString(value) {
|
|
4701
|
-
try {
|
|
4702
|
-
if (value === '') {
|
|
4703
|
-
return VALUE_STRINGS.empty;
|
|
4704
|
-
}
|
|
4705
|
-
else if (value === null) {
|
|
4706
|
-
return VALUE_STRINGS.null;
|
|
4707
|
-
}
|
|
4708
|
-
else if (value === undefined) {
|
|
4709
|
-
return VALUE_STRINGS.undefined;
|
|
4710
|
-
}
|
|
4711
|
-
else if (typeof value === 'string') {
|
|
4712
|
-
return value;
|
|
4713
|
-
}
|
|
4714
|
-
else if (typeof value === 'number') {
|
|
4715
|
-
return numberToString(value);
|
|
4716
|
-
}
|
|
4717
|
-
else if (value instanceof Date) {
|
|
4718
|
-
return value.toISOString();
|
|
4719
|
-
}
|
|
4720
|
-
else {
|
|
4721
|
-
return JSON.stringify(value);
|
|
4722
|
-
}
|
|
4723
|
-
}
|
|
4724
|
-
catch (error) {
|
|
4725
|
-
if (!(error instanceof Error)) {
|
|
4726
|
-
throw error;
|
|
4727
|
-
}
|
|
4728
|
-
console.error(error);
|
|
4729
|
-
return VALUE_STRINGS.unserializable;
|
|
4730
|
-
}
|
|
4731
|
-
}
|
|
4732
|
-
|
|
4733
4816
|
/**
|
|
4734
4817
|
* Replaces parameters in template with values from parameters object
|
|
4735
4818
|
*
|
|
@@ -4786,6 +4869,8 @@
|
|
|
4786
4869
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
4787
4870
|
}
|
|
4788
4871
|
parameterValue = valueToString(parameterValue);
|
|
4872
|
+
// Escape curly braces in parameter values to prevent prompt-injection
|
|
4873
|
+
parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
|
|
4789
4874
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
4790
4875
|
parameterValue = parameterValue
|
|
4791
4876
|
.split('\n')
|
|
@@ -5145,7 +5230,7 @@
|
|
|
5145
5230
|
promptTitle: task.title,
|
|
5146
5231
|
promptMessage: templateParameters(task.description || '', parameters),
|
|
5147
5232
|
defaultValue: templateParameters(preparedContent, parameters),
|
|
5148
|
-
// TODO: [🧠]
|
|
5233
|
+
// TODO: [🧠] Figure out how to define placeholder in .book.md file
|
|
5149
5234
|
placeholder: undefined,
|
|
5150
5235
|
priority: priority,
|
|
5151
5236
|
}))];
|
|
@@ -5845,7 +5930,10 @@
|
|
|
5845
5930
|
finally { if (e_2) throw e_2.error; }
|
|
5846
5931
|
return [7 /*endfinally*/];
|
|
5847
5932
|
case 19:
|
|
5848
|
-
parametersToPass = inputParameters
|
|
5933
|
+
parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
|
|
5934
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
5935
|
+
return [key, valueToString(value)];
|
|
5936
|
+
}));
|
|
5849
5937
|
_g.label = 20;
|
|
5850
5938
|
case 20:
|
|
5851
5939
|
_g.trys.push([20, 25, , 28]);
|
|
@@ -6092,6 +6180,7 @@
|
|
|
6092
6180
|
mimeTypes: ['text/markdown', 'text/plain'],
|
|
6093
6181
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
6094
6182
|
isAvilableInBrowser: true,
|
|
6183
|
+
// <- 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
|
|
6095
6184
|
requiredExecutables: [],
|
|
6096
6185
|
}); /* <- Note: [🤛] */
|
|
6097
6186
|
/**
|
|
@@ -6100,6 +6189,7 @@
|
|
|
6100
6189
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6101
6190
|
*
|
|
6102
6191
|
* @public exported from `@promptbook/core`
|
|
6192
|
+
* @public exported from `@promptbook/wizzard`
|
|
6103
6193
|
* @public exported from `@promptbook/cli`
|
|
6104
6194
|
*/
|
|
6105
6195
|
$scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
@@ -6185,12 +6275,12 @@
|
|
|
6185
6275
|
outputParameters = result.outputParameters;
|
|
6186
6276
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
6187
6277
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
6188
|
-
// <- TODO: [main]
|
|
6278
|
+
// <- TODO: [main] Smarter split and filter out empty pieces
|
|
6189
6279
|
if (isVerbose) {
|
|
6190
6280
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
6191
6281
|
}
|
|
6192
6282
|
return [4 /*yield*/, Promise.all(
|
|
6193
|
-
// TODO: [🪂]
|
|
6283
|
+
// TODO: [🪂] Do not send all at once but in chunks
|
|
6194
6284
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
6195
6285
|
var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
6196
6286
|
return __generator(this, function (_c) {
|
|
@@ -6289,6 +6379,7 @@
|
|
|
6289
6379
|
mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
6290
6380
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
6291
6381
|
isAvilableInBrowser: false,
|
|
6382
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
6292
6383
|
requiredExecutables: ['Pandoc'],
|
|
6293
6384
|
}); /* <- Note: [🤛] */
|
|
6294
6385
|
/**
|
|
@@ -6297,6 +6388,7 @@
|
|
|
6297
6388
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6298
6389
|
*
|
|
6299
6390
|
* @public exported from `@promptbook/core`
|
|
6391
|
+
* @public exported from `@promptbook/wizzard`
|
|
6300
6392
|
* @public exported from `@promptbook/cli`
|
|
6301
6393
|
*/
|
|
6302
6394
|
$scrapersMetadataRegister.register(documentScraperMetadata);
|
|
@@ -6452,6 +6544,7 @@
|
|
|
6452
6544
|
mimeTypes: ['application/msword', 'text/rtf'],
|
|
6453
6545
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
6454
6546
|
isAvilableInBrowser: false,
|
|
6547
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
6455
6548
|
requiredExecutables: [
|
|
6456
6549
|
'Pandoc',
|
|
6457
6550
|
'LibreOffice',
|
|
@@ -6464,6 +6557,7 @@
|
|
|
6464
6557
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6465
6558
|
*
|
|
6466
6559
|
* @public exported from `@promptbook/core`
|
|
6560
|
+
* @public exported from `@promptbook/wizzard`
|
|
6467
6561
|
* @public exported from `@promptbook/cli`
|
|
6468
6562
|
*/
|
|
6469
6563
|
$scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
|
|
@@ -6634,6 +6728,7 @@
|
|
|
6634
6728
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
6635
6729
|
*
|
|
6636
6730
|
* @public exported from `@promptbook/legacy-documents`
|
|
6731
|
+
* @public exported from `@promptbook/wizzard`
|
|
6637
6732
|
* @public exported from `@promptbook/cli`
|
|
6638
6733
|
*/
|
|
6639
6734
|
var _LegacyDocumentScraperRegistration = $scrapersRegister.register(createLegacyDocumentScraper);
|