@promptbook/markdown-utils 0.80.0 → 0.81.0-6
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 +6 -0
- package/esm/index.es.js +141 -36
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +15 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -6
- package/esm/typings/src/_packages/editable.index.d.ts +10 -0
- package/esm/typings/src/_packages/templates.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +10 -2
- package/esm/typings/src/config.d.ts +26 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
- package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
- package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
- package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
- package/esm/typings/src/high-level-abstractions/index.d.ts +10 -0
- package/esm/typings/src/other/templates/getBookTemplate.d.ts +12 -0
- package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
- package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +10 -0
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +7 -0
- package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
- package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
- package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
- package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +6 -2
- package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
- package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/asSerializable.d.ts +4 -0
- package/package.json +1 -1
- package/umd/index.umd.js +141 -36
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/formatNumber.d.ts +0 -6
- /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
- /package/esm/typings/src/utils/{formatNumber.test.d.ts → parameters/numberToString.test.d.ts} +0 -0
- /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/markdown-utils`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -247,6 +251,8 @@ Or you can install them separately:
|
|
|
247
251
|
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
248
252
|
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
249
253
|
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
|
254
|
+
- **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
|
|
255
|
+
- **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
|
|
250
256
|
- **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
|
|
251
257
|
- **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
|
|
252
258
|
|
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
23
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-5';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -356,7 +356,7 @@ function extractJsonBlock(markdown) {
|
|
|
356
356
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
357
357
|
*/
|
|
358
358
|
|
|
359
|
-
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:[],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:[],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:[],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:[],sourceFile:"./books/prepare-persona.book.md"}];
|
|
359
|
+
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"}];
|
|
360
360
|
|
|
361
361
|
/**
|
|
362
362
|
* Prettify the html code
|
|
@@ -658,6 +658,26 @@ var DEFAULT_TITLE = "Untitled";
|
|
|
658
658
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
659
659
|
*/
|
|
660
660
|
var LOOP_LIMIT = 1000;
|
|
661
|
+
/**
|
|
662
|
+
* Strings to represent various values in the context of parameter values
|
|
663
|
+
*
|
|
664
|
+
* @public exported from `@promptbook/utils`
|
|
665
|
+
*/
|
|
666
|
+
var VALUE_STRINGS = {
|
|
667
|
+
empty: '(nothing; empty string)',
|
|
668
|
+
null: '(no value; null)',
|
|
669
|
+
undefined: '(unknown value; undefined)',
|
|
670
|
+
nan: '(not a number; NaN)',
|
|
671
|
+
infinity: '(infinity; ∞)',
|
|
672
|
+
negativeInfinity: '(negative infinity; -∞)',
|
|
673
|
+
unserializable: '(unserializable value)',
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* Small number limit
|
|
677
|
+
*
|
|
678
|
+
* @public exported from `@promptbook/utils`
|
|
679
|
+
*/
|
|
680
|
+
var SMALL_NUMBER = 0.001;
|
|
661
681
|
/**
|
|
662
682
|
* Short time interval to prevent race conditions in milliseconds
|
|
663
683
|
*
|
|
@@ -1001,6 +1021,7 @@ function exportJson(options) {
|
|
|
1001
1021
|
* @public exported from `@promptbook/core`
|
|
1002
1022
|
*/
|
|
1003
1023
|
var ORDER_OF_PIPELINE_JSON = [
|
|
1024
|
+
// Note: [🍙] In this order will be pipeline serialized
|
|
1004
1025
|
'title',
|
|
1005
1026
|
'pipelineUrl',
|
|
1006
1027
|
'bookVersion',
|
|
@@ -1012,6 +1033,7 @@ var ORDER_OF_PIPELINE_JSON = [
|
|
|
1012
1033
|
'preparations',
|
|
1013
1034
|
'knowledgeSources',
|
|
1014
1035
|
'knowledgePieces',
|
|
1036
|
+
'sources', // <- TODO: [🧠] Where should the `sources` be
|
|
1015
1037
|
];
|
|
1016
1038
|
/**
|
|
1017
1039
|
* Nonce which is used for replacing things in strings
|
|
@@ -3400,6 +3422,30 @@ function isValidFilePath(filename) {
|
|
|
3400
3422
|
return false;
|
|
3401
3423
|
}
|
|
3402
3424
|
|
|
3425
|
+
/**
|
|
3426
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3427
|
+
*
|
|
3428
|
+
* @private as default `fetch` function used in Promptbook scrapers
|
|
3429
|
+
*/
|
|
3430
|
+
var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3431
|
+
var error_1;
|
|
3432
|
+
return __generator(this, function (_a) {
|
|
3433
|
+
switch (_a.label) {
|
|
3434
|
+
case 0:
|
|
3435
|
+
_a.trys.push([0, 2, , 3]);
|
|
3436
|
+
return [4 /*yield*/, fetch(url, init)];
|
|
3437
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
3438
|
+
case 2:
|
|
3439
|
+
error_1 = _a.sent();
|
|
3440
|
+
if (!(error_1 instanceof Error)) {
|
|
3441
|
+
throw error_1;
|
|
3442
|
+
}
|
|
3443
|
+
throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
|
|
3444
|
+
case 3: return [2 /*return*/];
|
|
3445
|
+
}
|
|
3446
|
+
});
|
|
3447
|
+
}); };
|
|
3448
|
+
|
|
3403
3449
|
/**
|
|
3404
3450
|
* @@@
|
|
3405
3451
|
*
|
|
@@ -3408,13 +3454,14 @@ function isValidFilePath(filename) {
|
|
|
3408
3454
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3409
3455
|
var _a;
|
|
3410
3456
|
return __awaiter(this, void 0, void 0, function () {
|
|
3411
|
-
var sourceContent, name,
|
|
3412
|
-
return __generator(this, function (
|
|
3413
|
-
switch (
|
|
3457
|
+
var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3458
|
+
return __generator(this, function (_f) {
|
|
3459
|
+
switch (_f.label) {
|
|
3414
3460
|
case 0:
|
|
3461
|
+
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3415
3462
|
sourceContent = knowledgeSource.sourceContent;
|
|
3416
3463
|
name = knowledgeSource.name;
|
|
3417
|
-
|
|
3464
|
+
_c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
|
|
3418
3465
|
if (!name) {
|
|
3419
3466
|
name = sourceContentToName(sourceContent);
|
|
3420
3467
|
}
|
|
@@ -3422,7 +3469,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3422
3469
|
url = sourceContent;
|
|
3423
3470
|
return [4 /*yield*/, fetch(url)];
|
|
3424
3471
|
case 1:
|
|
3425
|
-
response_1 =
|
|
3472
|
+
response_1 = _f.sent();
|
|
3426
3473
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3427
3474
|
return [2 /*return*/, {
|
|
3428
3475
|
source: name,
|
|
@@ -3479,7 +3526,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3479
3526
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3480
3527
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3481
3528
|
case 3:
|
|
3482
|
-
if (!(
|
|
3529
|
+
if (!(_f.sent())) {
|
|
3483
3530
|
throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
3484
3531
|
}
|
|
3485
3532
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -4370,16 +4417,94 @@ function mapAvailableToExpectedParameters(options) {
|
|
|
4370
4417
|
return mappedParameters;
|
|
4371
4418
|
}
|
|
4372
4419
|
|
|
4420
|
+
/**
|
|
4421
|
+
* Format either small or big number
|
|
4422
|
+
*
|
|
4423
|
+
* @public exported from `@promptbook/utils`
|
|
4424
|
+
*/
|
|
4425
|
+
function numberToString(value) {
|
|
4426
|
+
if (value === 0) {
|
|
4427
|
+
return '0';
|
|
4428
|
+
}
|
|
4429
|
+
else if (Number.isNaN(value)) {
|
|
4430
|
+
return VALUE_STRINGS.nan;
|
|
4431
|
+
}
|
|
4432
|
+
else if (value === Infinity) {
|
|
4433
|
+
return VALUE_STRINGS.infinity;
|
|
4434
|
+
}
|
|
4435
|
+
else if (value === -Infinity) {
|
|
4436
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4437
|
+
}
|
|
4438
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4439
|
+
var factor = Math.pow(10, exponent);
|
|
4440
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4441
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4442
|
+
return valueRounded.toFixed(exponent);
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
return value.toString();
|
|
4446
|
+
}
|
|
4447
|
+
|
|
4448
|
+
/**
|
|
4449
|
+
* Function `valueToString` will convert the given value to string
|
|
4450
|
+
* This is useful and used in the `templateParameters` function
|
|
4451
|
+
*
|
|
4452
|
+
* Note: This function is not just calling `toString` method
|
|
4453
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4454
|
+
* See `VALUE_STRINGS`
|
|
4455
|
+
*
|
|
4456
|
+
* Note: There are 2 similar functions
|
|
4457
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4458
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4459
|
+
*
|
|
4460
|
+
* @public exported from `@promptbook/utils`
|
|
4461
|
+
*/
|
|
4462
|
+
function valueToString(value) {
|
|
4463
|
+
try {
|
|
4464
|
+
if (value === '') {
|
|
4465
|
+
return VALUE_STRINGS.empty;
|
|
4466
|
+
}
|
|
4467
|
+
else if (value === null) {
|
|
4468
|
+
return VALUE_STRINGS.null;
|
|
4469
|
+
}
|
|
4470
|
+
else if (value === undefined) {
|
|
4471
|
+
return VALUE_STRINGS.undefined;
|
|
4472
|
+
}
|
|
4473
|
+
else if (typeof value === 'string') {
|
|
4474
|
+
return value;
|
|
4475
|
+
}
|
|
4476
|
+
else if (typeof value === 'number') {
|
|
4477
|
+
return numberToString(value);
|
|
4478
|
+
}
|
|
4479
|
+
else if (value instanceof Date) {
|
|
4480
|
+
return value.toISOString();
|
|
4481
|
+
}
|
|
4482
|
+
else {
|
|
4483
|
+
return JSON.stringify(value);
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
catch (error) {
|
|
4487
|
+
if (!(error instanceof Error)) {
|
|
4488
|
+
throw error;
|
|
4489
|
+
}
|
|
4490
|
+
console.error(error);
|
|
4491
|
+
return VALUE_STRINGS.unserializable;
|
|
4492
|
+
}
|
|
4493
|
+
}
|
|
4494
|
+
|
|
4373
4495
|
/**
|
|
4374
4496
|
* Replaces parameters in template with values from parameters object
|
|
4375
4497
|
*
|
|
4498
|
+
* Note: This function is not places strings into string,
|
|
4499
|
+
* It's more complex and can handle this operation specifically for LLM models
|
|
4500
|
+
*
|
|
4376
4501
|
* @param template the template with parameters in {curly} braces
|
|
4377
4502
|
* @param parameters the object with parameters
|
|
4378
4503
|
* @returns the template with replaced parameters
|
|
4379
4504
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
4380
4505
|
* @public exported from `@promptbook/utils`
|
|
4381
4506
|
*/
|
|
4382
|
-
function
|
|
4507
|
+
function templateParameters(template, parameters) {
|
|
4383
4508
|
var e_1, _a;
|
|
4384
4509
|
try {
|
|
4385
4510
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -4405,7 +4530,7 @@ function replaceParameters(template, parameters) {
|
|
|
4405
4530
|
var loopLimit = LOOP_LIMIT;
|
|
4406
4531
|
var _loop_1 = function () {
|
|
4407
4532
|
if (loopLimit-- < 0) {
|
|
4408
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
4533
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
4409
4534
|
}
|
|
4410
4535
|
var precol = match.groups.precol;
|
|
4411
4536
|
var parameterName = match.groups.parameterName;
|
|
@@ -4422,7 +4547,7 @@ function replaceParameters(template, parameters) {
|
|
|
4422
4547
|
if (parameterValue === undefined) {
|
|
4423
4548
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
4424
4549
|
}
|
|
4425
|
-
parameterValue = parameterValue
|
|
4550
|
+
parameterValue = valueToString(parameterValue);
|
|
4426
4551
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
4427
4552
|
parameterValue = parameterValue
|
|
4428
4553
|
.split('\n')
|
|
@@ -4657,7 +4782,7 @@ function executeAttempts(options) {
|
|
|
4657
4782
|
}
|
|
4658
4783
|
return [3 /*break*/, 24];
|
|
4659
4784
|
case 2:
|
|
4660
|
-
$ongoingTaskResult.$resultString =
|
|
4785
|
+
$ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
|
|
4661
4786
|
return [3 /*break*/, 25];
|
|
4662
4787
|
case 3:
|
|
4663
4788
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
@@ -4780,8 +4905,8 @@ function executeAttempts(options) {
|
|
|
4780
4905
|
_j = $ongoingTaskResult;
|
|
4781
4906
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
4782
4907
|
promptTitle: task.title,
|
|
4783
|
-
promptMessage:
|
|
4784
|
-
defaultValue:
|
|
4908
|
+
promptMessage: templateParameters(task.description || '', parameters),
|
|
4909
|
+
defaultValue: templateParameters(preparedContent, parameters),
|
|
4785
4910
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
4786
4911
|
placeholder: undefined,
|
|
4787
4912
|
priority: priority,
|
|
@@ -4905,7 +5030,7 @@ function executeAttempts(options) {
|
|
|
4905
5030
|
if (!isJokerAttempt &&
|
|
4906
5031
|
task.taskType === 'PROMPT_TASK' &&
|
|
4907
5032
|
$ongoingTaskResult.$prompt
|
|
4908
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in
|
|
5033
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
|
|
4909
5034
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
4910
5035
|
) {
|
|
4911
5036
|
// TODO: [🧠] Maybe put other taskTypes into report
|
|
@@ -6019,26 +6144,6 @@ function addAutoGeneratedSection(content, options) {
|
|
|
6019
6144
|
* TODO: [🏛] This can be part of markdown builder
|
|
6020
6145
|
*/
|
|
6021
6146
|
|
|
6022
|
-
/**
|
|
6023
|
-
* Format either small or big number
|
|
6024
|
-
*
|
|
6025
|
-
* @private within the repository
|
|
6026
|
-
*/
|
|
6027
|
-
function formatNumber(value) {
|
|
6028
|
-
if (value === 0) {
|
|
6029
|
-
return '0';
|
|
6030
|
-
}
|
|
6031
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
6032
|
-
var factor = Math.pow(10, exponent);
|
|
6033
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
6034
|
-
if (Math.abs(value - valueRounded) / value <
|
|
6035
|
-
0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
|
|
6036
|
-
return valueRounded.toFixed(exponent);
|
|
6037
|
-
}
|
|
6038
|
-
}
|
|
6039
|
-
return value.toString();
|
|
6040
|
-
}
|
|
6041
|
-
|
|
6042
6147
|
/**
|
|
6043
6148
|
* Create a markdown table from a 2D array of strings
|
|
6044
6149
|
*
|
|
@@ -6098,7 +6203,7 @@ function createMarkdownChart(options) {
|
|
|
6098
6203
|
}
|
|
6099
6204
|
finally { if (e_1) throw e_1.error; }
|
|
6100
6205
|
}
|
|
6101
|
-
var legend = "_Note: Each \u2588 represents ".concat(
|
|
6206
|
+
var legend = "_Note: Each \u2588 represents ".concat(numberToString(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(numberToString(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
|
|
6102
6207
|
return createMarkdownTable(table) + '\n\n' + legend;
|
|
6103
6208
|
}
|
|
6104
6209
|
/**
|