@promptbook/documents 0.84.0-9 → 0.85.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -5
- package/esm/index.es.js +376 -222
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +12 -4
- package/esm/typings/src/_packages/deepseek.index.d.ts +8 -0
- package/esm/typings/src/_packages/types.index.d.ts +16 -2
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/wizzard.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/about.d.ts +4 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/start-server.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +3 -1
- package/esm/typings/src/config.d.ts +27 -1
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/execution/AbstractTaskResult.d.ts +25 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +71 -0
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -5
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -15
- package/esm/typings/src/execution/PromptbookFetch.d.ts +8 -1
- package/esm/typings/src/execution/{assertsExecutionSuccessful.d.ts → assertsTaskSuccessful.d.ts} +4 -3
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +0 -3
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -6
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +3 -6
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +9 -0
- package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +9 -0
- package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +14 -0
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +14 -0
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +15 -0
- package/esm/typings/src/pipeline/book-notation.d.ts +3 -2
- package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -5
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +5 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +2 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +3 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +10 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +1 -0
- package/esm/typings/src/utils/random/$randomSeed.d.ts +2 -1
- package/esm/typings/src/utils/random/$randomToken.d.ts +13 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +8 -3
- package/package.json +11 -16
- package/umd/index.umd.js +377 -225
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/remote-server/socket-types/_common/PromptbookServer_Progress.d.ts +0 -10
- package/esm/typings/src/types/TaskProgress.d.ts +0 -43
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('mime-types'), require('papaparse')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'mime-types', 'papaparse'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-documents"] = {}, global.promises, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.mimeTypes, global.papaparse));
|
|
5
|
-
})(this, (function (exports, promises, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, path, prettier, parserHtml, mimeTypes, papaparse) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-documents"] = {}, global.promises, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.sha256, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, path, prettier, parserHtml, rxjs, crypto, sha256, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
11
11
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
12
12
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
13
|
+
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
13
14
|
|
|
14
15
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
15
16
|
/**
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
* @generated
|
|
26
27
|
* @see https://github.com/webgptorg/promptbook
|
|
27
28
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0';
|
|
29
30
|
/**
|
|
30
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -196,6 +197,12 @@
|
|
|
196
197
|
* @public exported from `@promptbook/core`
|
|
197
198
|
*/
|
|
198
199
|
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
200
|
+
/**
|
|
201
|
+
* Maximum file size limit
|
|
202
|
+
*
|
|
203
|
+
* @public exported from `@promptbook/core`
|
|
204
|
+
*/
|
|
205
|
+
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
199
206
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
200
207
|
/**
|
|
201
208
|
* The maximum number of iterations for a loops
|
|
@@ -229,6 +236,12 @@
|
|
|
229
236
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
230
237
|
*/
|
|
231
238
|
var IMMEDIATE_TIME = 10;
|
|
239
|
+
/**
|
|
240
|
+
* The maximum length of the (generated) filename
|
|
241
|
+
*
|
|
242
|
+
* @public exported from `@promptbook/core`
|
|
243
|
+
*/
|
|
244
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
232
245
|
/**
|
|
233
246
|
* Strategy for caching the intermediate results for knowledge sources
|
|
234
247
|
*
|
|
@@ -248,6 +261,15 @@
|
|
|
248
261
|
* @public exported from `@promptbook/core`
|
|
249
262
|
*/
|
|
250
263
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
264
|
+
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
265
|
+
/**
|
|
266
|
+
* Where to store the temporary downloads
|
|
267
|
+
*
|
|
268
|
+
* Note: When the folder does not exist, it is created recursively
|
|
269
|
+
*
|
|
270
|
+
* @public exported from `@promptbook/core`
|
|
271
|
+
*/
|
|
272
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
251
273
|
/**
|
|
252
274
|
* Where to store the scrape cache
|
|
253
275
|
*
|
|
@@ -384,6 +406,9 @@
|
|
|
384
406
|
* @public exported from `@promptbook/utils`
|
|
385
407
|
*/
|
|
386
408
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
409
|
+
/**
|
|
410
|
+
* TODO: [🎺]
|
|
411
|
+
*/
|
|
387
412
|
|
|
388
413
|
/**
|
|
389
414
|
* Normalize options for `execCommand` and `execCommands`
|
|
@@ -1117,24 +1142,18 @@
|
|
|
1117
1142
|
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
|
|
1118
1143
|
|
|
1119
1144
|
/**
|
|
1120
|
-
*
|
|
1145
|
+
* Checks if value is valid email
|
|
1121
1146
|
*
|
|
1122
1147
|
* @public exported from `@promptbook/utils`
|
|
1123
1148
|
*/
|
|
1124
|
-
function
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
return true;
|
|
1149
|
+
function isValidEmail(email) {
|
|
1150
|
+
if (typeof email !== 'string') {
|
|
1151
|
+
return false;
|
|
1128
1152
|
}
|
|
1129
|
-
|
|
1130
|
-
if (!(error instanceof Error)) {
|
|
1131
|
-
throw error;
|
|
1132
|
-
}
|
|
1133
|
-
if (error.message.includes('Unexpected token')) {
|
|
1134
|
-
return false;
|
|
1135
|
-
}
|
|
1153
|
+
if (email.split('\n').length > 1) {
|
|
1136
1154
|
return false;
|
|
1137
1155
|
}
|
|
1156
|
+
return /^.+@.+\..+$/.test(email);
|
|
1138
1157
|
}
|
|
1139
1158
|
|
|
1140
1159
|
/**
|
|
@@ -1156,6 +1175,27 @@
|
|
|
1156
1175
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1157
1176
|
*/
|
|
1158
1177
|
|
|
1178
|
+
/**
|
|
1179
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1180
|
+
*
|
|
1181
|
+
* @public exported from `@promptbook/utils`
|
|
1182
|
+
*/
|
|
1183
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1184
|
+
try {
|
|
1185
|
+
JSON.parse(value);
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
catch (error) {
|
|
1189
|
+
if (!(error instanceof Error)) {
|
|
1190
|
+
throw error;
|
|
1191
|
+
}
|
|
1192
|
+
if (error.message.includes('Unexpected token')) {
|
|
1193
|
+
return false;
|
|
1194
|
+
}
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1159
1199
|
/**
|
|
1160
1200
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1161
1201
|
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
@@ -1169,6 +1209,15 @@
|
|
|
1169
1209
|
if (isValidJsonString(pipelineString)) {
|
|
1170
1210
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1171
1211
|
}
|
|
1212
|
+
else if (isValidUrl(pipelineString)) {
|
|
1213
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1214
|
+
}
|
|
1215
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1216
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1217
|
+
}
|
|
1218
|
+
else if (isValidEmail(pipelineString)) {
|
|
1219
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1220
|
+
}
|
|
1172
1221
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1173
1222
|
return pipelineString;
|
|
1174
1223
|
}
|
|
@@ -2353,6 +2402,58 @@
|
|
|
2353
2402
|
return PipelineExecutionError;
|
|
2354
2403
|
}(Error));
|
|
2355
2404
|
|
|
2405
|
+
/**
|
|
2406
|
+
* Determine if the pipeline is fully prepared
|
|
2407
|
+
*
|
|
2408
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2409
|
+
*
|
|
2410
|
+
* @public exported from `@promptbook/core`
|
|
2411
|
+
*/
|
|
2412
|
+
function isPipelinePrepared(pipeline) {
|
|
2413
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2414
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2415
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2416
|
+
return false;
|
|
2417
|
+
}
|
|
2418
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2419
|
+
return false;
|
|
2420
|
+
}
|
|
2421
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2422
|
+
return false;
|
|
2423
|
+
}
|
|
2424
|
+
/*
|
|
2425
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2426
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2427
|
+
> return false;
|
|
2428
|
+
> }
|
|
2429
|
+
*/
|
|
2430
|
+
return true;
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2434
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2435
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2436
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2437
|
+
* - [🏍] ? Is context in each task
|
|
2438
|
+
* - [♨] Are examples prepared
|
|
2439
|
+
* - [♨] Are tasks prepared
|
|
2440
|
+
*/
|
|
2441
|
+
|
|
2442
|
+
/**
|
|
2443
|
+
* Generates random token
|
|
2444
|
+
*
|
|
2445
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2446
|
+
*
|
|
2447
|
+
* @private internal helper function
|
|
2448
|
+
* @returns secure random token
|
|
2449
|
+
*/
|
|
2450
|
+
function $randomToken(randomness) {
|
|
2451
|
+
return crypto.randomBytes(randomness).toString('hex');
|
|
2452
|
+
}
|
|
2453
|
+
/**
|
|
2454
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2455
|
+
*/
|
|
2456
|
+
|
|
2356
2457
|
/**
|
|
2357
2458
|
* This error indicates problems parsing the format value
|
|
2358
2459
|
*
|
|
@@ -2534,12 +2635,28 @@
|
|
|
2534
2635
|
/**
|
|
2535
2636
|
* Asserts that the execution of a Promptbook is successful
|
|
2536
2637
|
*
|
|
2638
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2639
|
+
*
|
|
2537
2640
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2538
2641
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2539
|
-
* @
|
|
2642
|
+
* @private internal helper function of `asPromise` method of `ExecutionTask`
|
|
2540
2643
|
*/
|
|
2541
|
-
function
|
|
2542
|
-
var
|
|
2644
|
+
function assertsTaskSuccessful(executionResult) {
|
|
2645
|
+
var e_1, _a;
|
|
2646
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2647
|
+
try {
|
|
2648
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2649
|
+
var warning = warnings_1_1.value;
|
|
2650
|
+
console.warn(warning.message);
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2654
|
+
finally {
|
|
2655
|
+
try {
|
|
2656
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2657
|
+
}
|
|
2658
|
+
finally { if (e_1) throw e_1.error; }
|
|
2659
|
+
}
|
|
2543
2660
|
if (isSuccessful === true) {
|
|
2544
2661
|
return;
|
|
2545
2662
|
}
|
|
@@ -2559,122 +2676,55 @@
|
|
|
2559
2676
|
}
|
|
2560
2677
|
}
|
|
2561
2678
|
/**
|
|
2562
|
-
* TODO: [🐚] This function should be removed OR changed OR be completely rewritten
|
|
2563
2679
|
* TODO: [🧠] Can this return type be better typed than void
|
|
2564
2680
|
*/
|
|
2565
2681
|
|
|
2566
2682
|
/**
|
|
2567
|
-
*
|
|
2568
|
-
*
|
|
2569
|
-
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2683
|
+
* Helper to create a new task
|
|
2570
2684
|
*
|
|
2571
|
-
* @
|
|
2685
|
+
* @private internal helper function
|
|
2572
2686
|
*/
|
|
2573
|
-
function
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2687
|
+
function createTask(options) {
|
|
2688
|
+
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2689
|
+
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
|
|
2690
|
+
var resultSubject = new rxjs.BehaviorSubject({});
|
|
2691
|
+
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2692
|
+
resultSubject.next(newOngoingResult);
|
|
2693
|
+
});
|
|
2694
|
+
function asPromise(options) {
|
|
2695
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2696
|
+
var _a, isCrashedOnError, finalResult;
|
|
2697
|
+
return __generator(this, function (_b) {
|
|
2698
|
+
switch (_b.label) {
|
|
2699
|
+
case 0:
|
|
2700
|
+
_a = (options || {}).isCrashedOnError, isCrashedOnError = _a === void 0 ? true : _a;
|
|
2701
|
+
return [4 /*yield*/, finalResultPromise];
|
|
2702
|
+
case 1:
|
|
2703
|
+
finalResult = _b.sent();
|
|
2704
|
+
if (isCrashedOnError) {
|
|
2705
|
+
assertsTaskSuccessful(finalResult);
|
|
2706
|
+
}
|
|
2707
|
+
return [2 /*return*/, finalResult];
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
});
|
|
2584
2711
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2712
|
+
return {
|
|
2713
|
+
taskType: taskType,
|
|
2714
|
+
taskId: taskId,
|
|
2715
|
+
asPromise: asPromise,
|
|
2716
|
+
asObservable: function () {
|
|
2717
|
+
return rxjs.concat(resultSubject.asObservable(), rxjs.from(asPromise({
|
|
2718
|
+
isCrashedOnError: true,
|
|
2719
|
+
})));
|
|
2720
|
+
},
|
|
2721
|
+
};
|
|
2592
2722
|
}
|
|
2593
2723
|
/**
|
|
2594
|
-
* TODO:
|
|
2595
|
-
* TODO: [
|
|
2596
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2597
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2598
|
-
* - [🏍] ? Is context in each task
|
|
2599
|
-
* - [♨] Are examples prepared
|
|
2600
|
-
* - [♨] Are tasks prepared
|
|
2724
|
+
* TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
|
|
2725
|
+
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2601
2726
|
*/
|
|
2602
2727
|
|
|
2603
|
-
/**
|
|
2604
|
-
* Format either small or big number
|
|
2605
|
-
*
|
|
2606
|
-
* @public exported from `@promptbook/utils`
|
|
2607
|
-
*/
|
|
2608
|
-
function numberToString(value) {
|
|
2609
|
-
if (value === 0) {
|
|
2610
|
-
return '0';
|
|
2611
|
-
}
|
|
2612
|
-
else if (Number.isNaN(value)) {
|
|
2613
|
-
return VALUE_STRINGS.nan;
|
|
2614
|
-
}
|
|
2615
|
-
else if (value === Infinity) {
|
|
2616
|
-
return VALUE_STRINGS.infinity;
|
|
2617
|
-
}
|
|
2618
|
-
else if (value === -Infinity) {
|
|
2619
|
-
return VALUE_STRINGS.negativeInfinity;
|
|
2620
|
-
}
|
|
2621
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
2622
|
-
var factor = Math.pow(10, exponent);
|
|
2623
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
2624
|
-
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
2625
|
-
return valueRounded.toFixed(exponent);
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
return value.toString();
|
|
2629
|
-
}
|
|
2630
|
-
|
|
2631
|
-
/**
|
|
2632
|
-
* Function `valueToString` will convert the given value to string
|
|
2633
|
-
* This is useful and used in the `templateParameters` function
|
|
2634
|
-
*
|
|
2635
|
-
* Note: This function is not just calling `toString` method
|
|
2636
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
2637
|
-
* See `VALUE_STRINGS`
|
|
2638
|
-
*
|
|
2639
|
-
* Note: There are 2 similar functions
|
|
2640
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
2641
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
2642
|
-
*
|
|
2643
|
-
* @public exported from `@promptbook/utils`
|
|
2644
|
-
*/
|
|
2645
|
-
function valueToString(value) {
|
|
2646
|
-
try {
|
|
2647
|
-
if (value === '') {
|
|
2648
|
-
return VALUE_STRINGS.empty;
|
|
2649
|
-
}
|
|
2650
|
-
else if (value === null) {
|
|
2651
|
-
return VALUE_STRINGS.null;
|
|
2652
|
-
}
|
|
2653
|
-
else if (value === undefined) {
|
|
2654
|
-
return VALUE_STRINGS.undefined;
|
|
2655
|
-
}
|
|
2656
|
-
else if (typeof value === 'string') {
|
|
2657
|
-
return value;
|
|
2658
|
-
}
|
|
2659
|
-
else if (typeof value === 'number') {
|
|
2660
|
-
return numberToString(value);
|
|
2661
|
-
}
|
|
2662
|
-
else if (value instanceof Date) {
|
|
2663
|
-
return value.toISOString();
|
|
2664
|
-
}
|
|
2665
|
-
else {
|
|
2666
|
-
return JSON.stringify(value);
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
catch (error) {
|
|
2670
|
-
if (!(error instanceof Error)) {
|
|
2671
|
-
throw error;
|
|
2672
|
-
}
|
|
2673
|
-
console.error(error);
|
|
2674
|
-
return VALUE_STRINGS.unserializable;
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
|
|
2678
2728
|
/**
|
|
2679
2729
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
2680
2730
|
*
|
|
@@ -3176,7 +3226,7 @@
|
|
|
3176
3226
|
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
3177
3227
|
throw error_1;
|
|
3178
3228
|
}
|
|
3179
|
-
errors.push(error_1);
|
|
3229
|
+
errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
|
|
3180
3230
|
return [3 /*break*/, 13];
|
|
3181
3231
|
case 13:
|
|
3182
3232
|
_b = _a.next();
|
|
@@ -3203,7 +3253,10 @@
|
|
|
3203
3253
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3204
3254
|
// 3) ...
|
|
3205
3255
|
spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
3206
|
-
.map(function (
|
|
3256
|
+
.map(function (_a, i) {
|
|
3257
|
+
var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
|
|
3258
|
+
return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
|
|
3259
|
+
})
|
|
3207
3260
|
.join('\n')), "\n\n "); }));
|
|
3208
3261
|
}
|
|
3209
3262
|
else if (this.llmExecutionTools.length === 0) {
|
|
@@ -3334,10 +3387,9 @@
|
|
|
3334
3387
|
return modelName;
|
|
3335
3388
|
})
|
|
3336
3389
|
.join(',');
|
|
3337
|
-
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
3390
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
|
|
3338
3391
|
case 3:
|
|
3339
3392
|
result = _d.sent();
|
|
3340
|
-
assertsExecutionSuccessful(result);
|
|
3341
3393
|
outputParameters = result.outputParameters;
|
|
3342
3394
|
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
3343
3395
|
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
@@ -3675,6 +3727,17 @@
|
|
|
3675
3727
|
return mimeTypes.lookup(value) || 'application/octet-stream';
|
|
3676
3728
|
}
|
|
3677
3729
|
|
|
3730
|
+
/**
|
|
3731
|
+
* Convert mime type to file extension
|
|
3732
|
+
*
|
|
3733
|
+
* Note: If the mime type is invalid, `null` is returned
|
|
3734
|
+
*
|
|
3735
|
+
* @private within the repository
|
|
3736
|
+
*/
|
|
3737
|
+
function mimeTypeToExtension(value) {
|
|
3738
|
+
return mimeTypes.extension(value) || null;
|
|
3739
|
+
}
|
|
3740
|
+
|
|
3678
3741
|
/**
|
|
3679
3742
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3680
3743
|
*
|
|
@@ -3710,9 +3773,9 @@
|
|
|
3710
3773
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3711
3774
|
var _a;
|
|
3712
3775
|
return __awaiter(this, void 0, void 0, function () {
|
|
3713
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3714
|
-
return __generator(this, function (
|
|
3715
|
-
switch (
|
|
3776
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
|
|
3777
|
+
return __generator(this, function (_h) {
|
|
3778
|
+
switch (_h.label) {
|
|
3716
3779
|
case 0:
|
|
3717
3780
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3718
3781
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -3721,54 +3784,76 @@
|
|
|
3721
3784
|
if (!name) {
|
|
3722
3785
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3723
3786
|
}
|
|
3724
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3787
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3725
3788
|
url = knowledgeSourceContent;
|
|
3726
3789
|
return [4 /*yield*/, fetch(url)];
|
|
3727
3790
|
case 1:
|
|
3728
|
-
response_1 =
|
|
3791
|
+
response_1 = _h.sent();
|
|
3729
3792
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3793
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
3794
|
+
return [2 /*return*/, {
|
|
3795
|
+
source: name,
|
|
3796
|
+
filename: null,
|
|
3797
|
+
url: url,
|
|
3798
|
+
mimeType: mimeType,
|
|
3799
|
+
/*
|
|
3800
|
+
TODO: [🥽]
|
|
3801
|
+
> async asBlob() {
|
|
3802
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3803
|
+
> const content = await response.blob();
|
|
3804
|
+
> return content;
|
|
3805
|
+
> },
|
|
3806
|
+
*/
|
|
3807
|
+
asJson: function () {
|
|
3808
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3809
|
+
var content;
|
|
3810
|
+
return __generator(this, function (_a) {
|
|
3811
|
+
switch (_a.label) {
|
|
3812
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3813
|
+
case 1:
|
|
3814
|
+
content = _a.sent();
|
|
3815
|
+
return [2 /*return*/, content];
|
|
3816
|
+
}
|
|
3817
|
+
});
|
|
3753
3818
|
});
|
|
3754
|
-
}
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
}
|
|
3819
|
+
},
|
|
3820
|
+
asText: function () {
|
|
3821
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3822
|
+
var content;
|
|
3823
|
+
return __generator(this, function (_a) {
|
|
3824
|
+
switch (_a.label) {
|
|
3825
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3826
|
+
case 1:
|
|
3827
|
+
content = _a.sent();
|
|
3828
|
+
return [2 /*return*/, content];
|
|
3829
|
+
}
|
|
3830
|
+
});
|
|
3766
3831
|
});
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3832
|
+
},
|
|
3833
|
+
}];
|
|
3834
|
+
}
|
|
3835
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
3836
|
+
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
3837
|
+
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3838
|
+
filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
|
|
3839
|
+
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
3770
3840
|
case 2:
|
|
3771
|
-
|
|
3841
|
+
_h.sent();
|
|
3842
|
+
_g = (_f = Buffer).from;
|
|
3843
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3844
|
+
case 3:
|
|
3845
|
+
fileContent = _g.apply(_f, [_h.sent()]);
|
|
3846
|
+
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3847
|
+
throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
|
|
3848
|
+
}
|
|
3849
|
+
return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
|
|
3850
|
+
case 4:
|
|
3851
|
+
_h.sent();
|
|
3852
|
+
// TODO: [💵] Check the file security
|
|
3853
|
+
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3854
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3855
|
+
case 5:
|
|
3856
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3772
3857
|
if (tools.fs === undefined) {
|
|
3773
3858
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3774
3859
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3781,8 +3866,8 @@
|
|
|
3781
3866
|
fileExtension = getFileExtension(filename_1);
|
|
3782
3867
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3783
3868
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3784
|
-
case
|
|
3785
|
-
if (!(
|
|
3869
|
+
case 6:
|
|
3870
|
+
if (!(_h.sent())) {
|
|
3786
3871
|
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(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
3787
3872
|
}
|
|
3788
3873
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3828,7 +3913,7 @@
|
|
|
3828
3913
|
});
|
|
3829
3914
|
},
|
|
3830
3915
|
}];
|
|
3831
|
-
case
|
|
3916
|
+
case 7: return [2 /*return*/, {
|
|
3832
3917
|
source: name,
|
|
3833
3918
|
filename: null,
|
|
3834
3919
|
url: null,
|
|
@@ -4092,10 +4177,9 @@
|
|
|
4092
4177
|
var content = _a.content;
|
|
4093
4178
|
return content;
|
|
4094
4179
|
}).join('\n\n'),
|
|
4095
|
-
})];
|
|
4180
|
+
}).asPromise()];
|
|
4096
4181
|
case 2:
|
|
4097
4182
|
result = _e.sent();
|
|
4098
|
-
assertsExecutionSuccessful(result);
|
|
4099
4183
|
outputParameters = result.outputParameters;
|
|
4100
4184
|
titleRaw = outputParameters.title;
|
|
4101
4185
|
if (isVerbose) {
|
|
@@ -4167,6 +4251,81 @@
|
|
|
4167
4251
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
4168
4252
|
*/
|
|
4169
4253
|
|
|
4254
|
+
/**
|
|
4255
|
+
* Format either small or big number
|
|
4256
|
+
*
|
|
4257
|
+
* @public exported from `@promptbook/utils`
|
|
4258
|
+
*/
|
|
4259
|
+
function numberToString(value) {
|
|
4260
|
+
if (value === 0) {
|
|
4261
|
+
return '0';
|
|
4262
|
+
}
|
|
4263
|
+
else if (Number.isNaN(value)) {
|
|
4264
|
+
return VALUE_STRINGS.nan;
|
|
4265
|
+
}
|
|
4266
|
+
else if (value === Infinity) {
|
|
4267
|
+
return VALUE_STRINGS.infinity;
|
|
4268
|
+
}
|
|
4269
|
+
else if (value === -Infinity) {
|
|
4270
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4271
|
+
}
|
|
4272
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4273
|
+
var factor = Math.pow(10, exponent);
|
|
4274
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4275
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4276
|
+
return valueRounded.toFixed(exponent);
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
return value.toString();
|
|
4280
|
+
}
|
|
4281
|
+
|
|
4282
|
+
/**
|
|
4283
|
+
* Function `valueToString` will convert the given value to string
|
|
4284
|
+
* This is useful and used in the `templateParameters` function
|
|
4285
|
+
*
|
|
4286
|
+
* Note: This function is not just calling `toString` method
|
|
4287
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4288
|
+
* See `VALUE_STRINGS`
|
|
4289
|
+
*
|
|
4290
|
+
* Note: There are 2 similar functions
|
|
4291
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4292
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4293
|
+
*
|
|
4294
|
+
* @public exported from `@promptbook/utils`
|
|
4295
|
+
*/
|
|
4296
|
+
function valueToString(value) {
|
|
4297
|
+
try {
|
|
4298
|
+
if (value === '') {
|
|
4299
|
+
return VALUE_STRINGS.empty;
|
|
4300
|
+
}
|
|
4301
|
+
else if (value === null) {
|
|
4302
|
+
return VALUE_STRINGS.null;
|
|
4303
|
+
}
|
|
4304
|
+
else if (value === undefined) {
|
|
4305
|
+
return VALUE_STRINGS.undefined;
|
|
4306
|
+
}
|
|
4307
|
+
else if (typeof value === 'string') {
|
|
4308
|
+
return value;
|
|
4309
|
+
}
|
|
4310
|
+
else if (typeof value === 'number') {
|
|
4311
|
+
return numberToString(value);
|
|
4312
|
+
}
|
|
4313
|
+
else if (value instanceof Date) {
|
|
4314
|
+
return value.toISOString();
|
|
4315
|
+
}
|
|
4316
|
+
else {
|
|
4317
|
+
return JSON.stringify(value);
|
|
4318
|
+
}
|
|
4319
|
+
}
|
|
4320
|
+
catch (error) {
|
|
4321
|
+
if (!(error instanceof Error)) {
|
|
4322
|
+
throw error;
|
|
4323
|
+
}
|
|
4324
|
+
console.error(error);
|
|
4325
|
+
return VALUE_STRINGS.unserializable;
|
|
4326
|
+
}
|
|
4327
|
+
}
|
|
4328
|
+
|
|
4170
4329
|
/**
|
|
4171
4330
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4172
4331
|
*
|
|
@@ -5611,27 +5770,20 @@
|
|
|
5611
5770
|
*/
|
|
5612
5771
|
function executeTask(options) {
|
|
5613
5772
|
return __awaiter(this, void 0, void 0, function () {
|
|
5614
|
-
var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed,
|
|
5615
|
-
var e_1,
|
|
5616
|
-
return __generator(this, function (
|
|
5617
|
-
switch (
|
|
5773
|
+
var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
|
|
5774
|
+
var _f, e_1, _g, _h, _j;
|
|
5775
|
+
return __generator(this, function (_k) {
|
|
5776
|
+
switch (_k.label) {
|
|
5618
5777
|
case 0:
|
|
5619
5778
|
currentTask = options.currentTask, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts, maxParallelCount = options.maxParallelCount, csvSettings = options.csvSettings, isVerbose = options.isVerbose, rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, isAutoInstalled = options.isAutoInstalled, isNotPreparedWarningSupressed = options.isNotPreparedWarningSupressed;
|
|
5620
|
-
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
5621
|
-
title = currentTask.title;
|
|
5622
5779
|
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5623
5780
|
return [4 /*yield*/, onProgress({
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
isDone: false,
|
|
5628
|
-
taskType: currentTask.taskType,
|
|
5629
|
-
parameterName: currentTask.resultingParameterName,
|
|
5630
|
-
parameterValue: null,
|
|
5631
|
-
// <- [🍸]
|
|
5781
|
+
outputParameters: (_f = {},
|
|
5782
|
+
_f[currentTask.resultingParameterName] = '',
|
|
5783
|
+
_f),
|
|
5632
5784
|
})];
|
|
5633
5785
|
case 1:
|
|
5634
|
-
|
|
5786
|
+
_k.sent();
|
|
5635
5787
|
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5636
5788
|
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5637
5789
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
@@ -5650,7 +5802,7 @@
|
|
|
5650
5802
|
pipelineIdentification: pipelineIdentification,
|
|
5651
5803
|
})];
|
|
5652
5804
|
case 2:
|
|
5653
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
5805
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_k.sent())])), parametersToPass])]);
|
|
5654
5806
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
5655
5807
|
parameters = {};
|
|
5656
5808
|
_loop_1 = function (parameterName) {
|
|
@@ -5678,7 +5830,7 @@
|
|
|
5678
5830
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5679
5831
|
finally {
|
|
5680
5832
|
try {
|
|
5681
|
-
if (_e && !_e.done && (
|
|
5833
|
+
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
5682
5834
|
}
|
|
5683
5835
|
finally { if (e_1) throw e_1.error; }
|
|
5684
5836
|
}
|
|
@@ -5709,24 +5861,19 @@
|
|
|
5709
5861
|
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5710
5862
|
})];
|
|
5711
5863
|
case 3:
|
|
5712
|
-
resultString =
|
|
5864
|
+
resultString = _k.sent();
|
|
5713
5865
|
return [4 /*yield*/, onProgress({
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
isDone: true,
|
|
5718
|
-
taskType: currentTask.taskType,
|
|
5719
|
-
parameterName: currentTask.resultingParameterName,
|
|
5720
|
-
parameterValue: resultString,
|
|
5721
|
-
// <- [🍸]
|
|
5866
|
+
outputParameters: (_h = {},
|
|
5867
|
+
_h[currentTask.resultingParameterName] = resultString,
|
|
5868
|
+
_h),
|
|
5722
5869
|
})];
|
|
5723
5870
|
case 4:
|
|
5724
|
-
|
|
5725
|
-
return [2 /*return*/, Object.freeze((
|
|
5726
|
-
|
|
5871
|
+
_k.sent();
|
|
5872
|
+
return [2 /*return*/, Object.freeze((_j = {},
|
|
5873
|
+
_j[currentTask.resultingParameterName] =
|
|
5727
5874
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5728
5875
|
resultString,
|
|
5729
|
-
|
|
5876
|
+
_j))];
|
|
5730
5877
|
}
|
|
5731
5878
|
});
|
|
5732
5879
|
});
|
|
@@ -5734,9 +5881,6 @@
|
|
|
5734
5881
|
/**
|
|
5735
5882
|
* TODO: [🤹♂️]
|
|
5736
5883
|
*/
|
|
5737
|
-
/**
|
|
5738
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5739
|
-
*/
|
|
5740
5884
|
|
|
5741
5885
|
/**
|
|
5742
5886
|
* @@@
|
|
@@ -5998,15 +6142,15 @@
|
|
|
5998
6142
|
return [3 /*break*/, 4];
|
|
5999
6143
|
case 3:
|
|
6000
6144
|
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
6001
|
-
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (
|
|
6145
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (newOngoingResult) {
|
|
6002
6146
|
if (isReturned) {
|
|
6003
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(
|
|
6147
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(newOngoingResult, null, 4)
|
|
6004
6148
|
.split('\n')
|
|
6005
6149
|
.map(function (line) { return "> ".concat(line); })
|
|
6006
6150
|
.join('\n')), "\n "); }));
|
|
6007
6151
|
}
|
|
6008
6152
|
if (onProgress) {
|
|
6009
|
-
onProgress(
|
|
6153
|
+
onProgress(newOngoingResult);
|
|
6010
6154
|
}
|
|
6011
6155
|
}, $executionReport: executionReport, pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
6012
6156
|
.then(function (newParametersToPass) {
|
|
@@ -6109,9 +6253,6 @@
|
|
|
6109
6253
|
});
|
|
6110
6254
|
});
|
|
6111
6255
|
}
|
|
6112
|
-
/**
|
|
6113
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6114
|
-
*/
|
|
6115
6256
|
|
|
6116
6257
|
/**
|
|
6117
6258
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -6143,7 +6284,7 @@
|
|
|
6143
6284
|
console.warn(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
6144
6285
|
}
|
|
6145
6286
|
var runCount = 0;
|
|
6146
|
-
var
|
|
6287
|
+
var pipelineExecutorWithCallback = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
6147
6288
|
return __generator(this, function (_a) {
|
|
6148
6289
|
runCount++;
|
|
6149
6290
|
return [2 /*return*/, /* not await */ executePipeline({
|
|
@@ -6168,11 +6309,23 @@
|
|
|
6168
6309
|
})];
|
|
6169
6310
|
});
|
|
6170
6311
|
}); };
|
|
6312
|
+
var pipelineExecutor = function (inputParameters) {
|
|
6313
|
+
return createTask({
|
|
6314
|
+
taskType: 'EXECUTION',
|
|
6315
|
+
taskProcessCallback: function (updateOngoingResult) {
|
|
6316
|
+
var _this = this;
|
|
6317
|
+
return pipelineExecutorWithCallback(inputParameters, function (newOngoingResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
6318
|
+
return __generator(this, function (_a) {
|
|
6319
|
+
updateOngoingResult(newOngoingResult);
|
|
6320
|
+
return [2 /*return*/];
|
|
6321
|
+
});
|
|
6322
|
+
}); });
|
|
6323
|
+
},
|
|
6324
|
+
});
|
|
6325
|
+
};
|
|
6326
|
+
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6171
6327
|
return pipelineExecutor;
|
|
6172
6328
|
}
|
|
6173
|
-
/**
|
|
6174
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6175
|
-
*/
|
|
6176
6329
|
|
|
6177
6330
|
/**
|
|
6178
6331
|
* Metadata of the scraper
|
|
@@ -6274,10 +6427,9 @@
|
|
|
6274
6427
|
return [4 /*yield*/, source.asText()];
|
|
6275
6428
|
case 4:
|
|
6276
6429
|
knowledgeContent = _k.sent();
|
|
6277
|
-
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
6430
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
|
|
6278
6431
|
case 5:
|
|
6279
6432
|
result = _k.sent();
|
|
6280
|
-
assertsExecutionSuccessful(result);
|
|
6281
6433
|
outputParameters = result.outputParameters;
|
|
6282
6434
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
6283
6435
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
@@ -6300,13 +6452,13 @@
|
|
|
6300
6452
|
_c.label = 1;
|
|
6301
6453
|
case 1:
|
|
6302
6454
|
_c.trys.push([1, 7, , 8]);
|
|
6303
|
-
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6455
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6304
6456
|
case 2:
|
|
6305
6457
|
titleResult = _c.sent();
|
|
6306
6458
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
6307
6459
|
title = spaceTrim__default["default"](titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
6308
6460
|
name = titleToName(title);
|
|
6309
|
-
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6461
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6310
6462
|
case 3:
|
|
6311
6463
|
keywordsResult = _c.sent();
|
|
6312
6464
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|