@promptbook/node 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 +154 -24
- 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 +154 -24
- 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/node`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -251,6 +255,8 @@ Or you can install them separately:
|
|
|
251
255
|
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
252
256
|
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
253
257
|
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
|
258
|
+
- **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
|
|
259
|
+
- **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
|
|
254
260
|
- **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
|
|
255
261
|
- **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
|
|
256
262
|
|
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
*
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-5';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -204,6 +204,26 @@ var DEFAULT_TITLE = "Untitled";
|
|
|
204
204
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
205
205
|
*/
|
|
206
206
|
var LOOP_LIMIT = 1000;
|
|
207
|
+
/**
|
|
208
|
+
* Strings to represent various values in the context of parameter values
|
|
209
|
+
*
|
|
210
|
+
* @public exported from `@promptbook/utils`
|
|
211
|
+
*/
|
|
212
|
+
var VALUE_STRINGS = {
|
|
213
|
+
empty: '(nothing; empty string)',
|
|
214
|
+
null: '(no value; null)',
|
|
215
|
+
undefined: '(unknown value; undefined)',
|
|
216
|
+
nan: '(not a number; NaN)',
|
|
217
|
+
infinity: '(infinity; ∞)',
|
|
218
|
+
negativeInfinity: '(negative infinity; -∞)',
|
|
219
|
+
unserializable: '(unserializable value)',
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Small number limit
|
|
223
|
+
*
|
|
224
|
+
* @public exported from `@promptbook/utils`
|
|
225
|
+
*/
|
|
226
|
+
var SMALL_NUMBER = 0.001;
|
|
207
227
|
/**
|
|
208
228
|
* Short time interval to prevent race conditions in milliseconds
|
|
209
229
|
*
|
|
@@ -559,6 +579,7 @@ function exportJson(options) {
|
|
|
559
579
|
* @public exported from `@promptbook/core`
|
|
560
580
|
*/
|
|
561
581
|
var ORDER_OF_PIPELINE_JSON = [
|
|
582
|
+
// Note: [🍙] In this order will be pipeline serialized
|
|
562
583
|
'title',
|
|
563
584
|
'pipelineUrl',
|
|
564
585
|
'bookVersion',
|
|
@@ -570,6 +591,7 @@ var ORDER_OF_PIPELINE_JSON = [
|
|
|
570
591
|
'preparations',
|
|
571
592
|
'knowledgeSources',
|
|
572
593
|
'knowledgePieces',
|
|
594
|
+
'sources', // <- TODO: [🧠] Where should the `sources` be
|
|
573
595
|
];
|
|
574
596
|
/**
|
|
575
597
|
* Nonce which is used for replacing things in strings
|
|
@@ -1228,7 +1250,7 @@ function joinLlmExecutionTools() {
|
|
|
1228
1250
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
1229
1251
|
*/
|
|
1230
1252
|
|
|
1231
|
-
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"}];
|
|
1253
|
+
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"}];
|
|
1232
1254
|
|
|
1233
1255
|
/**
|
|
1234
1256
|
* Prettify the html code
|
|
@@ -3126,16 +3148,94 @@ function arrayableToArray(input) {
|
|
|
3126
3148
|
return [input];
|
|
3127
3149
|
}
|
|
3128
3150
|
|
|
3151
|
+
/**
|
|
3152
|
+
* Format either small or big number
|
|
3153
|
+
*
|
|
3154
|
+
* @public exported from `@promptbook/utils`
|
|
3155
|
+
*/
|
|
3156
|
+
function numberToString(value) {
|
|
3157
|
+
if (value === 0) {
|
|
3158
|
+
return '0';
|
|
3159
|
+
}
|
|
3160
|
+
else if (Number.isNaN(value)) {
|
|
3161
|
+
return VALUE_STRINGS.nan;
|
|
3162
|
+
}
|
|
3163
|
+
else if (value === Infinity) {
|
|
3164
|
+
return VALUE_STRINGS.infinity;
|
|
3165
|
+
}
|
|
3166
|
+
else if (value === -Infinity) {
|
|
3167
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
3168
|
+
}
|
|
3169
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
3170
|
+
var factor = Math.pow(10, exponent);
|
|
3171
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
3172
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
3173
|
+
return valueRounded.toFixed(exponent);
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
return value.toString();
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
/**
|
|
3180
|
+
* Function `valueToString` will convert the given value to string
|
|
3181
|
+
* This is useful and used in the `templateParameters` function
|
|
3182
|
+
*
|
|
3183
|
+
* Note: This function is not just calling `toString` method
|
|
3184
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
3185
|
+
* See `VALUE_STRINGS`
|
|
3186
|
+
*
|
|
3187
|
+
* Note: There are 2 similar functions
|
|
3188
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
3189
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
3190
|
+
*
|
|
3191
|
+
* @public exported from `@promptbook/utils`
|
|
3192
|
+
*/
|
|
3193
|
+
function valueToString(value) {
|
|
3194
|
+
try {
|
|
3195
|
+
if (value === '') {
|
|
3196
|
+
return VALUE_STRINGS.empty;
|
|
3197
|
+
}
|
|
3198
|
+
else if (value === null) {
|
|
3199
|
+
return VALUE_STRINGS.null;
|
|
3200
|
+
}
|
|
3201
|
+
else if (value === undefined) {
|
|
3202
|
+
return VALUE_STRINGS.undefined;
|
|
3203
|
+
}
|
|
3204
|
+
else if (typeof value === 'string') {
|
|
3205
|
+
return value;
|
|
3206
|
+
}
|
|
3207
|
+
else if (typeof value === 'number') {
|
|
3208
|
+
return numberToString(value);
|
|
3209
|
+
}
|
|
3210
|
+
else if (value instanceof Date) {
|
|
3211
|
+
return value.toISOString();
|
|
3212
|
+
}
|
|
3213
|
+
else {
|
|
3214
|
+
return JSON.stringify(value);
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
catch (error) {
|
|
3218
|
+
if (!(error instanceof Error)) {
|
|
3219
|
+
throw error;
|
|
3220
|
+
}
|
|
3221
|
+
console.error(error);
|
|
3222
|
+
return VALUE_STRINGS.unserializable;
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3129
3226
|
/**
|
|
3130
3227
|
* Replaces parameters in template with values from parameters object
|
|
3131
3228
|
*
|
|
3229
|
+
* Note: This function is not places strings into string,
|
|
3230
|
+
* It's more complex and can handle this operation specifically for LLM models
|
|
3231
|
+
*
|
|
3132
3232
|
* @param template the template with parameters in {curly} braces
|
|
3133
3233
|
* @param parameters the object with parameters
|
|
3134
3234
|
* @returns the template with replaced parameters
|
|
3135
3235
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
3136
3236
|
* @public exported from `@promptbook/utils`
|
|
3137
3237
|
*/
|
|
3138
|
-
function
|
|
3238
|
+
function templateParameters(template, parameters) {
|
|
3139
3239
|
var e_1, _a;
|
|
3140
3240
|
try {
|
|
3141
3241
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -3161,7 +3261,7 @@ function replaceParameters(template, parameters) {
|
|
|
3161
3261
|
var loopLimit = LOOP_LIMIT;
|
|
3162
3262
|
var _loop_1 = function () {
|
|
3163
3263
|
if (loopLimit-- < 0) {
|
|
3164
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
3264
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
3165
3265
|
}
|
|
3166
3266
|
var precol = match.groups.precol;
|
|
3167
3267
|
var parameterName = match.groups.parameterName;
|
|
@@ -3178,7 +3278,7 @@ function replaceParameters(template, parameters) {
|
|
|
3178
3278
|
if (parameterValue === undefined) {
|
|
3179
3279
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
3180
3280
|
}
|
|
3181
|
-
parameterValue = parameterValue
|
|
3281
|
+
parameterValue = valueToString(parameterValue);
|
|
3182
3282
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
3183
3283
|
parameterValue = parameterValue
|
|
3184
3284
|
.split('\n')
|
|
@@ -3674,7 +3774,7 @@ function executeAttempts(options) {
|
|
|
3674
3774
|
}
|
|
3675
3775
|
return [3 /*break*/, 24];
|
|
3676
3776
|
case 2:
|
|
3677
|
-
$ongoingTaskResult.$resultString =
|
|
3777
|
+
$ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
|
|
3678
3778
|
return [3 /*break*/, 25];
|
|
3679
3779
|
case 3:
|
|
3680
3780
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
@@ -3797,8 +3897,8 @@ function executeAttempts(options) {
|
|
|
3797
3897
|
_j = $ongoingTaskResult;
|
|
3798
3898
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3799
3899
|
promptTitle: task.title,
|
|
3800
|
-
promptMessage:
|
|
3801
|
-
defaultValue:
|
|
3900
|
+
promptMessage: templateParameters(task.description || '', parameters),
|
|
3901
|
+
defaultValue: templateParameters(preparedContent, parameters),
|
|
3802
3902
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
3803
3903
|
placeholder: undefined,
|
|
3804
3904
|
priority: priority,
|
|
@@ -3922,7 +4022,7 @@ function executeAttempts(options) {
|
|
|
3922
4022
|
if (!isJokerAttempt &&
|
|
3923
4023
|
task.taskType === 'PROMPT_TASK' &&
|
|
3924
4024
|
$ongoingTaskResult.$prompt
|
|
3925
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in
|
|
4025
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
|
|
3926
4026
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
3927
4027
|
) {
|
|
3928
4028
|
// TODO: [🧠] Maybe put other taskTypes into report
|
|
@@ -5249,6 +5349,30 @@ function isValidFilePath(filename) {
|
|
|
5249
5349
|
return false;
|
|
5250
5350
|
}
|
|
5251
5351
|
|
|
5352
|
+
/**
|
|
5353
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5354
|
+
*
|
|
5355
|
+
* @private as default `fetch` function used in Promptbook scrapers
|
|
5356
|
+
*/
|
|
5357
|
+
var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
5358
|
+
var error_1;
|
|
5359
|
+
return __generator(this, function (_a) {
|
|
5360
|
+
switch (_a.label) {
|
|
5361
|
+
case 0:
|
|
5362
|
+
_a.trys.push([0, 2, , 3]);
|
|
5363
|
+
return [4 /*yield*/, fetch(url, init)];
|
|
5364
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5365
|
+
case 2:
|
|
5366
|
+
error_1 = _a.sent();
|
|
5367
|
+
if (!(error_1 instanceof Error)) {
|
|
5368
|
+
throw error_1;
|
|
5369
|
+
}
|
|
5370
|
+
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 "); }));
|
|
5371
|
+
case 3: return [2 /*return*/];
|
|
5372
|
+
}
|
|
5373
|
+
});
|
|
5374
|
+
}); };
|
|
5375
|
+
|
|
5252
5376
|
/**
|
|
5253
5377
|
* @@@
|
|
5254
5378
|
*
|
|
@@ -5257,13 +5381,14 @@ function isValidFilePath(filename) {
|
|
|
5257
5381
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5258
5382
|
var _a;
|
|
5259
5383
|
return __awaiter(this, void 0, void 0, function () {
|
|
5260
|
-
var sourceContent, name,
|
|
5261
|
-
return __generator(this, function (
|
|
5262
|
-
switch (
|
|
5384
|
+
var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
5385
|
+
return __generator(this, function (_f) {
|
|
5386
|
+
switch (_f.label) {
|
|
5263
5387
|
case 0:
|
|
5388
|
+
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
5264
5389
|
sourceContent = knowledgeSource.sourceContent;
|
|
5265
5390
|
name = knowledgeSource.name;
|
|
5266
|
-
|
|
5391
|
+
_c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
|
|
5267
5392
|
if (!name) {
|
|
5268
5393
|
name = sourceContentToName(sourceContent);
|
|
5269
5394
|
}
|
|
@@ -5271,7 +5396,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5271
5396
|
url = sourceContent;
|
|
5272
5397
|
return [4 /*yield*/, fetch(url)];
|
|
5273
5398
|
case 1:
|
|
5274
|
-
response_1 =
|
|
5399
|
+
response_1 = _f.sent();
|
|
5275
5400
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
5276
5401
|
return [2 /*return*/, {
|
|
5277
5402
|
source: name,
|
|
@@ -5328,7 +5453,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5328
5453
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
5329
5454
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5330
5455
|
case 3:
|
|
5331
|
-
if (!(
|
|
5456
|
+
if (!(_f.sent())) {
|
|
5332
5457
|
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 "); }));
|
|
5333
5458
|
}
|
|
5334
5459
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -8631,6 +8756,14 @@ function precompilePipeline(pipelineString) {
|
|
|
8631
8756
|
knowledgePieces: [],
|
|
8632
8757
|
personas: [],
|
|
8633
8758
|
preparations: [],
|
|
8759
|
+
sources: [
|
|
8760
|
+
{
|
|
8761
|
+
type: 'BOOK',
|
|
8762
|
+
path: null,
|
|
8763
|
+
// <- TODO: !!!!!! Pass here path of the file
|
|
8764
|
+
content: pipelineString,
|
|
8765
|
+
},
|
|
8766
|
+
],
|
|
8634
8767
|
};
|
|
8635
8768
|
function getPipelineIdentification() {
|
|
8636
8769
|
// Note: This is a 😐 implementation of [🚞]
|
|
@@ -9038,7 +9171,6 @@ function precompilePipeline(pipelineString) {
|
|
|
9038
9171
|
$pipelineJson.formfactorName = 'GENERIC';
|
|
9039
9172
|
}
|
|
9040
9173
|
// =============================================================
|
|
9041
|
-
// TODO: [🍙] Maybe do reorder of `$pipelineJson` here
|
|
9042
9174
|
return exportJson({
|
|
9043
9175
|
name: 'pipelineJson',
|
|
9044
9176
|
message: "Result of `precompilePipeline`",
|
|
@@ -10481,11 +10613,9 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
10481
10613
|
, ".json"));
|
|
10482
10614
|
return [4 /*yield*/, isFileExisting(makedLibraryFilePath, tools.fs)];
|
|
10483
10615
|
case 3:
|
|
10484
|
-
if (!(_f.sent()))
|
|
10485
|
-
console.info(colors.yellow("Tip: Prebuild your pipeline collection (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"ptbk make\" to speed up the collection creation.")));
|
|
10486
|
-
}
|
|
10616
|
+
if (!(_f.sent())) ;
|
|
10487
10617
|
else {
|
|
10488
|
-
colors.green("(In future, not implemented yet) Using your
|
|
10618
|
+
colors.green("(In future, not implemented yet) Using your compiled pipeline collection ".concat(makedLibraryFilePath));
|
|
10489
10619
|
// TODO: !! Implement;
|
|
10490
10620
|
// TODO: [🌗]
|
|
10491
10621
|
}
|
|
@@ -10505,10 +10635,10 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
10505
10635
|
// Note: First load all .book.json and then .book.md files
|
|
10506
10636
|
// .book.json can be prepared so it is faster to load
|
|
10507
10637
|
fileNames.sort(function (a, b) {
|
|
10508
|
-
if (a.endsWith('.
|
|
10638
|
+
if (a.endsWith('.json') && b.endsWith('.md')) {
|
|
10509
10639
|
return -1;
|
|
10510
10640
|
}
|
|
10511
|
-
if (a.endsWith('.
|
|
10641
|
+
if (a.endsWith('.md') && b.endsWith('.json')) {
|
|
10512
10642
|
return 1;
|
|
10513
10643
|
}
|
|
10514
10644
|
return 0;
|
|
@@ -10557,7 +10687,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
10557
10687
|
// TODO: [👠] DRY
|
|
10558
10688
|
if (pipeline.pipelineUrl === undefined) {
|
|
10559
10689
|
if (isVerbose) {
|
|
10560
|
-
console.info(colors.
|
|
10690
|
+
console.info(colors.yellow("Can not load pipeline from ".concat(fileName
|
|
10561
10691
|
.split('\\')
|
|
10562
10692
|
.join('/'), " because of missing URL")));
|
|
10563
10693
|
}
|
|
@@ -10691,7 +10821,7 @@ function isSerializableAsJson(value) {
|
|
|
10691
10821
|
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
10692
10822
|
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
10693
10823
|
*
|
|
10694
|
-
* @public exported from `@promptbook/
|
|
10824
|
+
* @public exported from `@promptbook/editable`
|
|
10695
10825
|
*/
|
|
10696
10826
|
function stringifyPipelineJson(pipeline) {
|
|
10697
10827
|
if (!isSerializableAsJson(pipeline)) {
|