@promptbook/legacy-documents 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 +140 -15
- 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 +2 -2
- package/umd/index.umd.js +140 -15
- 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/umd/index.umd.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
26
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-5';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -195,6 +195,26 @@
|
|
|
195
195
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
196
196
|
*/
|
|
197
197
|
var LOOP_LIMIT = 1000;
|
|
198
|
+
/**
|
|
199
|
+
* Strings to represent various values in the context of parameter values
|
|
200
|
+
*
|
|
201
|
+
* @public exported from `@promptbook/utils`
|
|
202
|
+
*/
|
|
203
|
+
var VALUE_STRINGS = {
|
|
204
|
+
empty: '(nothing; empty string)',
|
|
205
|
+
null: '(no value; null)',
|
|
206
|
+
undefined: '(unknown value; undefined)',
|
|
207
|
+
nan: '(not a number; NaN)',
|
|
208
|
+
infinity: '(infinity; ∞)',
|
|
209
|
+
negativeInfinity: '(negative infinity; -∞)',
|
|
210
|
+
unserializable: '(unserializable value)',
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Small number limit
|
|
214
|
+
*
|
|
215
|
+
* @public exported from `@promptbook/utils`
|
|
216
|
+
*/
|
|
217
|
+
var SMALL_NUMBER = 0.001;
|
|
198
218
|
/**
|
|
199
219
|
* Short time interval to prevent race conditions in milliseconds
|
|
200
220
|
*
|
|
@@ -1063,7 +1083,7 @@
|
|
|
1063
1083
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
1064
1084
|
*/
|
|
1065
1085
|
|
|
1066
|
-
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"}];
|
|
1086
|
+
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"}];
|
|
1067
1087
|
|
|
1068
1088
|
/**
|
|
1069
1089
|
* Prettify the html code
|
|
@@ -1553,6 +1573,7 @@
|
|
|
1553
1573
|
* @public exported from `@promptbook/core`
|
|
1554
1574
|
*/
|
|
1555
1575
|
var ORDER_OF_PIPELINE_JSON = [
|
|
1576
|
+
// Note: [🍙] In this order will be pipeline serialized
|
|
1556
1577
|
'title',
|
|
1557
1578
|
'pipelineUrl',
|
|
1558
1579
|
'bookVersion',
|
|
@@ -1564,6 +1585,7 @@
|
|
|
1564
1585
|
'preparations',
|
|
1565
1586
|
'knowledgeSources',
|
|
1566
1587
|
'knowledgePieces',
|
|
1588
|
+
'sources', // <- TODO: [🧠] Where should the `sources` be
|
|
1567
1589
|
];
|
|
1568
1590
|
/**
|
|
1569
1591
|
* Nonce which is used for replacing things in strings
|
|
@@ -3499,6 +3521,30 @@
|
|
|
3499
3521
|
return mimeTypes.lookup(value) || 'application/octet-stream';
|
|
3500
3522
|
}
|
|
3501
3523
|
|
|
3524
|
+
/**
|
|
3525
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3526
|
+
*
|
|
3527
|
+
* @private as default `fetch` function used in Promptbook scrapers
|
|
3528
|
+
*/
|
|
3529
|
+
var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3530
|
+
var error_1;
|
|
3531
|
+
return __generator(this, function (_a) {
|
|
3532
|
+
switch (_a.label) {
|
|
3533
|
+
case 0:
|
|
3534
|
+
_a.trys.push([0, 2, , 3]);
|
|
3535
|
+
return [4 /*yield*/, fetch(url, init)];
|
|
3536
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
3537
|
+
case 2:
|
|
3538
|
+
error_1 = _a.sent();
|
|
3539
|
+
if (!(error_1 instanceof Error)) {
|
|
3540
|
+
throw error_1;
|
|
3541
|
+
}
|
|
3542
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
|
|
3543
|
+
case 3: return [2 /*return*/];
|
|
3544
|
+
}
|
|
3545
|
+
});
|
|
3546
|
+
}); };
|
|
3547
|
+
|
|
3502
3548
|
/**
|
|
3503
3549
|
* @@@
|
|
3504
3550
|
*
|
|
@@ -3507,13 +3553,14 @@
|
|
|
3507
3553
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3508
3554
|
var _a;
|
|
3509
3555
|
return __awaiter(this, void 0, void 0, function () {
|
|
3510
|
-
var sourceContent, name,
|
|
3511
|
-
return __generator(this, function (
|
|
3512
|
-
switch (
|
|
3556
|
+
var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3557
|
+
return __generator(this, function (_f) {
|
|
3558
|
+
switch (_f.label) {
|
|
3513
3559
|
case 0:
|
|
3560
|
+
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3514
3561
|
sourceContent = knowledgeSource.sourceContent;
|
|
3515
3562
|
name = knowledgeSource.name;
|
|
3516
|
-
|
|
3563
|
+
_c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
|
|
3517
3564
|
if (!name) {
|
|
3518
3565
|
name = sourceContentToName(sourceContent);
|
|
3519
3566
|
}
|
|
@@ -3521,7 +3568,7 @@
|
|
|
3521
3568
|
url = sourceContent;
|
|
3522
3569
|
return [4 /*yield*/, fetch(url)];
|
|
3523
3570
|
case 1:
|
|
3524
|
-
response_1 =
|
|
3571
|
+
response_1 = _f.sent();
|
|
3525
3572
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3526
3573
|
return [2 /*return*/, {
|
|
3527
3574
|
source: name,
|
|
@@ -3578,7 +3625,7 @@
|
|
|
3578
3625
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3579
3626
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3580
3627
|
case 3:
|
|
3581
|
-
if (!(
|
|
3628
|
+
if (!(_f.sent())) {
|
|
3582
3629
|
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 "); }));
|
|
3583
3630
|
}
|
|
3584
3631
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -4606,16 +4653,94 @@
|
|
|
4606
4653
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
4607
4654
|
*/
|
|
4608
4655
|
|
|
4656
|
+
/**
|
|
4657
|
+
* Format either small or big number
|
|
4658
|
+
*
|
|
4659
|
+
* @public exported from `@promptbook/utils`
|
|
4660
|
+
*/
|
|
4661
|
+
function numberToString(value) {
|
|
4662
|
+
if (value === 0) {
|
|
4663
|
+
return '0';
|
|
4664
|
+
}
|
|
4665
|
+
else if (Number.isNaN(value)) {
|
|
4666
|
+
return VALUE_STRINGS.nan;
|
|
4667
|
+
}
|
|
4668
|
+
else if (value === Infinity) {
|
|
4669
|
+
return VALUE_STRINGS.infinity;
|
|
4670
|
+
}
|
|
4671
|
+
else if (value === -Infinity) {
|
|
4672
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4673
|
+
}
|
|
4674
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4675
|
+
var factor = Math.pow(10, exponent);
|
|
4676
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4677
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4678
|
+
return valueRounded.toFixed(exponent);
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
return value.toString();
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4684
|
+
/**
|
|
4685
|
+
* Function `valueToString` will convert the given value to string
|
|
4686
|
+
* This is useful and used in the `templateParameters` function
|
|
4687
|
+
*
|
|
4688
|
+
* Note: This function is not just calling `toString` method
|
|
4689
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4690
|
+
* See `VALUE_STRINGS`
|
|
4691
|
+
*
|
|
4692
|
+
* Note: There are 2 similar functions
|
|
4693
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4694
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4695
|
+
*
|
|
4696
|
+
* @public exported from `@promptbook/utils`
|
|
4697
|
+
*/
|
|
4698
|
+
function valueToString(value) {
|
|
4699
|
+
try {
|
|
4700
|
+
if (value === '') {
|
|
4701
|
+
return VALUE_STRINGS.empty;
|
|
4702
|
+
}
|
|
4703
|
+
else if (value === null) {
|
|
4704
|
+
return VALUE_STRINGS.null;
|
|
4705
|
+
}
|
|
4706
|
+
else if (value === undefined) {
|
|
4707
|
+
return VALUE_STRINGS.undefined;
|
|
4708
|
+
}
|
|
4709
|
+
else if (typeof value === 'string') {
|
|
4710
|
+
return value;
|
|
4711
|
+
}
|
|
4712
|
+
else if (typeof value === 'number') {
|
|
4713
|
+
return numberToString(value);
|
|
4714
|
+
}
|
|
4715
|
+
else if (value instanceof Date) {
|
|
4716
|
+
return value.toISOString();
|
|
4717
|
+
}
|
|
4718
|
+
else {
|
|
4719
|
+
return JSON.stringify(value);
|
|
4720
|
+
}
|
|
4721
|
+
}
|
|
4722
|
+
catch (error) {
|
|
4723
|
+
if (!(error instanceof Error)) {
|
|
4724
|
+
throw error;
|
|
4725
|
+
}
|
|
4726
|
+
console.error(error);
|
|
4727
|
+
return VALUE_STRINGS.unserializable;
|
|
4728
|
+
}
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4609
4731
|
/**
|
|
4610
4732
|
* Replaces parameters in template with values from parameters object
|
|
4611
4733
|
*
|
|
4734
|
+
* Note: This function is not places strings into string,
|
|
4735
|
+
* It's more complex and can handle this operation specifically for LLM models
|
|
4736
|
+
*
|
|
4612
4737
|
* @param template the template with parameters in {curly} braces
|
|
4613
4738
|
* @param parameters the object with parameters
|
|
4614
4739
|
* @returns the template with replaced parameters
|
|
4615
4740
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
4616
4741
|
* @public exported from `@promptbook/utils`
|
|
4617
4742
|
*/
|
|
4618
|
-
function
|
|
4743
|
+
function templateParameters(template, parameters) {
|
|
4619
4744
|
var e_1, _a;
|
|
4620
4745
|
try {
|
|
4621
4746
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -4641,7 +4766,7 @@
|
|
|
4641
4766
|
var loopLimit = LOOP_LIMIT;
|
|
4642
4767
|
var _loop_1 = function () {
|
|
4643
4768
|
if (loopLimit-- < 0) {
|
|
4644
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
4769
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
4645
4770
|
}
|
|
4646
4771
|
var precol = match.groups.precol;
|
|
4647
4772
|
var parameterName = match.groups.parameterName;
|
|
@@ -4658,7 +4783,7 @@
|
|
|
4658
4783
|
if (parameterValue === undefined) {
|
|
4659
4784
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
4660
4785
|
}
|
|
4661
|
-
parameterValue = parameterValue
|
|
4786
|
+
parameterValue = valueToString(parameterValue);
|
|
4662
4787
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
4663
4788
|
parameterValue = parameterValue
|
|
4664
4789
|
.split('\n')
|
|
@@ -4893,7 +5018,7 @@
|
|
|
4893
5018
|
}
|
|
4894
5019
|
return [3 /*break*/, 24];
|
|
4895
5020
|
case 2:
|
|
4896
|
-
$ongoingTaskResult.$resultString =
|
|
5021
|
+
$ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
|
|
4897
5022
|
return [3 /*break*/, 25];
|
|
4898
5023
|
case 3:
|
|
4899
5024
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
@@ -5016,8 +5141,8 @@
|
|
|
5016
5141
|
_j = $ongoingTaskResult;
|
|
5017
5142
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
5018
5143
|
promptTitle: task.title,
|
|
5019
|
-
promptMessage:
|
|
5020
|
-
defaultValue:
|
|
5144
|
+
promptMessage: templateParameters(task.description || '', parameters),
|
|
5145
|
+
defaultValue: templateParameters(preparedContent, parameters),
|
|
5021
5146
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
5022
5147
|
placeholder: undefined,
|
|
5023
5148
|
priority: priority,
|
|
@@ -5141,7 +5266,7 @@
|
|
|
5141
5266
|
if (!isJokerAttempt &&
|
|
5142
5267
|
task.taskType === 'PROMPT_TASK' &&
|
|
5143
5268
|
$ongoingTaskResult.$prompt
|
|
5144
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in
|
|
5269
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
|
|
5145
5270
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
5146
5271
|
) {
|
|
5147
5272
|
// TODO: [🧠] Maybe put other taskTypes into report
|