@promptbook/legacy-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/esm/index.es.js
CHANGED
|
@@ -8,7 +8,10 @@ import { SHA256 } from 'crypto-js';
|
|
|
8
8
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
9
9
|
import { format } from 'prettier';
|
|
10
10
|
import parserHtml from 'prettier/parser-html';
|
|
11
|
-
import {
|
|
11
|
+
import { BehaviorSubject, concat, from } from 'rxjs';
|
|
12
|
+
import { randomBytes } from 'crypto';
|
|
13
|
+
import sha256 from 'crypto-js/sha256';
|
|
14
|
+
import { lookup, extension } from 'mime-types';
|
|
12
15
|
import { unparse, parse } from 'papaparse';
|
|
13
16
|
|
|
14
17
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
@@ -25,7 +28,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
28
|
* @generated
|
|
26
29
|
* @see https://github.com/webgptorg/promptbook
|
|
27
30
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0
|
|
31
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0';
|
|
29
32
|
/**
|
|
30
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -196,6 +199,12 @@ var ADMIN_GITHUB_NAME = 'hejny';
|
|
|
196
199
|
* @public exported from `@promptbook/core`
|
|
197
200
|
*/
|
|
198
201
|
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
202
|
+
/**
|
|
203
|
+
* Maximum file size limit
|
|
204
|
+
*
|
|
205
|
+
* @public exported from `@promptbook/core`
|
|
206
|
+
*/
|
|
207
|
+
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
199
208
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
200
209
|
/**
|
|
201
210
|
* The maximum number of iterations for a loops
|
|
@@ -229,6 +238,12 @@ var SMALL_NUMBER = 0.001;
|
|
|
229
238
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
230
239
|
*/
|
|
231
240
|
var IMMEDIATE_TIME = 10;
|
|
241
|
+
/**
|
|
242
|
+
* The maximum length of the (generated) filename
|
|
243
|
+
*
|
|
244
|
+
* @public exported from `@promptbook/core`
|
|
245
|
+
*/
|
|
246
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
232
247
|
/**
|
|
233
248
|
* Strategy for caching the intermediate results for knowledge sources
|
|
234
249
|
*
|
|
@@ -248,6 +263,15 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
248
263
|
* @public exported from `@promptbook/core`
|
|
249
264
|
*/
|
|
250
265
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
266
|
+
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
267
|
+
/**
|
|
268
|
+
* Where to store the temporary downloads
|
|
269
|
+
*
|
|
270
|
+
* Note: When the folder does not exist, it is created recursively
|
|
271
|
+
*
|
|
272
|
+
* @public exported from `@promptbook/core`
|
|
273
|
+
*/
|
|
274
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
251
275
|
/**
|
|
252
276
|
* Where to store the scrape cache
|
|
253
277
|
*
|
|
@@ -384,6 +408,9 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
384
408
|
* @public exported from `@promptbook/utils`
|
|
385
409
|
*/
|
|
386
410
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
411
|
+
/**
|
|
412
|
+
* TODO: [🎺]
|
|
413
|
+
*/
|
|
387
414
|
|
|
388
415
|
/**
|
|
389
416
|
* Normalize options for `execCommand` and `execCommands`
|
|
@@ -1117,24 +1144,18 @@ function getScraperIntermediateSource(source, options) {
|
|
|
1117
1144
|
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
1145
|
|
|
1119
1146
|
/**
|
|
1120
|
-
*
|
|
1147
|
+
* Checks if value is valid email
|
|
1121
1148
|
*
|
|
1122
1149
|
* @public exported from `@promptbook/utils`
|
|
1123
1150
|
*/
|
|
1124
|
-
function
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
return true;
|
|
1151
|
+
function isValidEmail(email) {
|
|
1152
|
+
if (typeof email !== 'string') {
|
|
1153
|
+
return false;
|
|
1128
1154
|
}
|
|
1129
|
-
|
|
1130
|
-
if (!(error instanceof Error)) {
|
|
1131
|
-
throw error;
|
|
1132
|
-
}
|
|
1133
|
-
if (error.message.includes('Unexpected token')) {
|
|
1134
|
-
return false;
|
|
1135
|
-
}
|
|
1155
|
+
if (email.split('\n').length > 1) {
|
|
1136
1156
|
return false;
|
|
1137
1157
|
}
|
|
1158
|
+
return /^.+@.+\..+$/.test(email);
|
|
1138
1159
|
}
|
|
1139
1160
|
|
|
1140
1161
|
/**
|
|
@@ -1156,6 +1177,27 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
1156
1177
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1157
1178
|
*/
|
|
1158
1179
|
|
|
1180
|
+
/**
|
|
1181
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1182
|
+
*
|
|
1183
|
+
* @public exported from `@promptbook/utils`
|
|
1184
|
+
*/
|
|
1185
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1186
|
+
try {
|
|
1187
|
+
JSON.parse(value);
|
|
1188
|
+
return true;
|
|
1189
|
+
}
|
|
1190
|
+
catch (error) {
|
|
1191
|
+
if (!(error instanceof Error)) {
|
|
1192
|
+
throw error;
|
|
1193
|
+
}
|
|
1194
|
+
if (error.message.includes('Unexpected token')) {
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
return false;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1159
1201
|
/**
|
|
1160
1202
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1161
1203
|
* 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 +1211,15 @@ function validatePipelineString(pipelineString) {
|
|
|
1169
1211
|
if (isValidJsonString(pipelineString)) {
|
|
1170
1212
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1171
1213
|
}
|
|
1214
|
+
else if (isValidUrl(pipelineString)) {
|
|
1215
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1216
|
+
}
|
|
1217
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1218
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1219
|
+
}
|
|
1220
|
+
else if (isValidEmail(pipelineString)) {
|
|
1221
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1222
|
+
}
|
|
1172
1223
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1173
1224
|
return pipelineString;
|
|
1174
1225
|
}
|
|
@@ -2353,6 +2404,58 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
2353
2404
|
return PipelineExecutionError;
|
|
2354
2405
|
}(Error));
|
|
2355
2406
|
|
|
2407
|
+
/**
|
|
2408
|
+
* Determine if the pipeline is fully prepared
|
|
2409
|
+
*
|
|
2410
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2411
|
+
*
|
|
2412
|
+
* @public exported from `@promptbook/core`
|
|
2413
|
+
*/
|
|
2414
|
+
function isPipelinePrepared(pipeline) {
|
|
2415
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2416
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2417
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2418
|
+
return false;
|
|
2419
|
+
}
|
|
2420
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2421
|
+
return false;
|
|
2422
|
+
}
|
|
2423
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
/*
|
|
2427
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2428
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2429
|
+
> return false;
|
|
2430
|
+
> }
|
|
2431
|
+
*/
|
|
2432
|
+
return true;
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2436
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2437
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2438
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2439
|
+
* - [🏍] ? Is context in each task
|
|
2440
|
+
* - [♨] Are examples prepared
|
|
2441
|
+
* - [♨] Are tasks prepared
|
|
2442
|
+
*/
|
|
2443
|
+
|
|
2444
|
+
/**
|
|
2445
|
+
* Generates random token
|
|
2446
|
+
*
|
|
2447
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2448
|
+
*
|
|
2449
|
+
* @private internal helper function
|
|
2450
|
+
* @returns secure random token
|
|
2451
|
+
*/
|
|
2452
|
+
function $randomToken(randomness) {
|
|
2453
|
+
return randomBytes(randomness).toString('hex');
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2457
|
+
*/
|
|
2458
|
+
|
|
2356
2459
|
/**
|
|
2357
2460
|
* This error indicates problems parsing the format value
|
|
2358
2461
|
*
|
|
@@ -2534,12 +2637,28 @@ function deserializeError(error) {
|
|
|
2534
2637
|
/**
|
|
2535
2638
|
* Asserts that the execution of a Promptbook is successful
|
|
2536
2639
|
*
|
|
2640
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2641
|
+
*
|
|
2537
2642
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2538
2643
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2539
|
-
* @
|
|
2644
|
+
* @private internal helper function of `asPromise` method of `ExecutionTask`
|
|
2540
2645
|
*/
|
|
2541
|
-
function
|
|
2542
|
-
var
|
|
2646
|
+
function assertsTaskSuccessful(executionResult) {
|
|
2647
|
+
var e_1, _a;
|
|
2648
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2649
|
+
try {
|
|
2650
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2651
|
+
var warning = warnings_1_1.value;
|
|
2652
|
+
console.warn(warning.message);
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2656
|
+
finally {
|
|
2657
|
+
try {
|
|
2658
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2659
|
+
}
|
|
2660
|
+
finally { if (e_1) throw e_1.error; }
|
|
2661
|
+
}
|
|
2543
2662
|
if (isSuccessful === true) {
|
|
2544
2663
|
return;
|
|
2545
2664
|
}
|
|
@@ -2559,122 +2678,55 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2559
2678
|
}
|
|
2560
2679
|
}
|
|
2561
2680
|
/**
|
|
2562
|
-
* TODO: [🐚] This function should be removed OR changed OR be completely rewritten
|
|
2563
2681
|
* TODO: [🧠] Can this return type be better typed than void
|
|
2564
2682
|
*/
|
|
2565
2683
|
|
|
2566
2684
|
/**
|
|
2567
|
-
*
|
|
2568
|
-
*
|
|
2569
|
-
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2685
|
+
* Helper to create a new task
|
|
2570
2686
|
*
|
|
2571
|
-
* @
|
|
2687
|
+
* @private internal helper function
|
|
2572
2688
|
*/
|
|
2573
|
-
function
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2689
|
+
function createTask(options) {
|
|
2690
|
+
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2691
|
+
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
|
|
2692
|
+
var resultSubject = new BehaviorSubject({});
|
|
2693
|
+
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2694
|
+
resultSubject.next(newOngoingResult);
|
|
2695
|
+
});
|
|
2696
|
+
function asPromise(options) {
|
|
2697
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2698
|
+
var _a, isCrashedOnError, finalResult;
|
|
2699
|
+
return __generator(this, function (_b) {
|
|
2700
|
+
switch (_b.label) {
|
|
2701
|
+
case 0:
|
|
2702
|
+
_a = (options || {}).isCrashedOnError, isCrashedOnError = _a === void 0 ? true : _a;
|
|
2703
|
+
return [4 /*yield*/, finalResultPromise];
|
|
2704
|
+
case 1:
|
|
2705
|
+
finalResult = _b.sent();
|
|
2706
|
+
if (isCrashedOnError) {
|
|
2707
|
+
assertsTaskSuccessful(finalResult);
|
|
2708
|
+
}
|
|
2709
|
+
return [2 /*return*/, finalResult];
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
});
|
|
2584
2713
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2714
|
+
return {
|
|
2715
|
+
taskType: taskType,
|
|
2716
|
+
taskId: taskId,
|
|
2717
|
+
asPromise: asPromise,
|
|
2718
|
+
asObservable: function () {
|
|
2719
|
+
return concat(resultSubject.asObservable(), from(asPromise({
|
|
2720
|
+
isCrashedOnError: true,
|
|
2721
|
+
})));
|
|
2722
|
+
},
|
|
2723
|
+
};
|
|
2592
2724
|
}
|
|
2593
2725
|
/**
|
|
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
|
|
2726
|
+
* TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
|
|
2727
|
+
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2601
2728
|
*/
|
|
2602
2729
|
|
|
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
2730
|
/**
|
|
2679
2731
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
2680
2732
|
*
|
|
@@ -3176,7 +3228,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3176
3228
|
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
3177
3229
|
throw error_1;
|
|
3178
3230
|
}
|
|
3179
|
-
errors.push(error_1);
|
|
3231
|
+
errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
|
|
3180
3232
|
return [3 /*break*/, 13];
|
|
3181
3233
|
case 13:
|
|
3182
3234
|
_b = _a.next();
|
|
@@ -3203,7 +3255,10 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3203
3255
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3204
3256
|
// 3) ...
|
|
3205
3257
|
spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
3206
|
-
.map(function (
|
|
3258
|
+
.map(function (_a, i) {
|
|
3259
|
+
var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
|
|
3260
|
+
return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
|
|
3261
|
+
})
|
|
3207
3262
|
.join('\n')), "\n\n "); }));
|
|
3208
3263
|
}
|
|
3209
3264
|
else if (this.llmExecutionTools.length === 0) {
|
|
@@ -3334,10 +3389,9 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
3334
3389
|
return modelName;
|
|
3335
3390
|
})
|
|
3336
3391
|
.join(',');
|
|
3337
|
-
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
3392
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
|
|
3338
3393
|
case 3:
|
|
3339
3394
|
result = _d.sent();
|
|
3340
|
-
assertsExecutionSuccessful(result);
|
|
3341
3395
|
outputParameters = result.outputParameters;
|
|
3342
3396
|
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
3343
3397
|
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
@@ -3675,6 +3729,17 @@ function extensionToMimeType(value) {
|
|
|
3675
3729
|
return lookup(value) || 'application/octet-stream';
|
|
3676
3730
|
}
|
|
3677
3731
|
|
|
3732
|
+
/**
|
|
3733
|
+
* Convert mime type to file extension
|
|
3734
|
+
*
|
|
3735
|
+
* Note: If the mime type is invalid, `null` is returned
|
|
3736
|
+
*
|
|
3737
|
+
* @private within the repository
|
|
3738
|
+
*/
|
|
3739
|
+
function mimeTypeToExtension(value) {
|
|
3740
|
+
return extension(value) || null;
|
|
3741
|
+
}
|
|
3742
|
+
|
|
3678
3743
|
/**
|
|
3679
3744
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3680
3745
|
*
|
|
@@ -3710,9 +3775,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3710
3775
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3711
3776
|
var _a;
|
|
3712
3777
|
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 (
|
|
3778
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
|
|
3779
|
+
return __generator(this, function (_h) {
|
|
3780
|
+
switch (_h.label) {
|
|
3716
3781
|
case 0:
|
|
3717
3782
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3718
3783
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -3721,54 +3786,76 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3721
3786
|
if (!name) {
|
|
3722
3787
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3723
3788
|
}
|
|
3724
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3789
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3725
3790
|
url = knowledgeSourceContent;
|
|
3726
3791
|
return [4 /*yield*/, fetch(url)];
|
|
3727
3792
|
case 1:
|
|
3728
|
-
response_1 =
|
|
3793
|
+
response_1 = _h.sent();
|
|
3729
3794
|
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
|
-
|
|
3795
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
3796
|
+
return [2 /*return*/, {
|
|
3797
|
+
source: name,
|
|
3798
|
+
filename: null,
|
|
3799
|
+
url: url,
|
|
3800
|
+
mimeType: mimeType,
|
|
3801
|
+
/*
|
|
3802
|
+
TODO: [🥽]
|
|
3803
|
+
> async asBlob() {
|
|
3804
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3805
|
+
> const content = await response.blob();
|
|
3806
|
+
> return content;
|
|
3807
|
+
> },
|
|
3808
|
+
*/
|
|
3809
|
+
asJson: function () {
|
|
3810
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3811
|
+
var content;
|
|
3812
|
+
return __generator(this, function (_a) {
|
|
3813
|
+
switch (_a.label) {
|
|
3814
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3815
|
+
case 1:
|
|
3816
|
+
content = _a.sent();
|
|
3817
|
+
return [2 /*return*/, content];
|
|
3818
|
+
}
|
|
3819
|
+
});
|
|
3753
3820
|
});
|
|
3754
|
-
}
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
}
|
|
3821
|
+
},
|
|
3822
|
+
asText: function () {
|
|
3823
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3824
|
+
var content;
|
|
3825
|
+
return __generator(this, function (_a) {
|
|
3826
|
+
switch (_a.label) {
|
|
3827
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3828
|
+
case 1:
|
|
3829
|
+
content = _a.sent();
|
|
3830
|
+
return [2 /*return*/, content];
|
|
3831
|
+
}
|
|
3832
|
+
});
|
|
3766
3833
|
});
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3834
|
+
},
|
|
3835
|
+
}];
|
|
3836
|
+
}
|
|
3837
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
3838
|
+
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3839
|
+
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3840
|
+
filepath = 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));
|
|
3841
|
+
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3770
3842
|
case 2:
|
|
3771
|
-
|
|
3843
|
+
_h.sent();
|
|
3844
|
+
_g = (_f = Buffer).from;
|
|
3845
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3846
|
+
case 3:
|
|
3847
|
+
fileContent = _g.apply(_f, [_h.sent()]);
|
|
3848
|
+
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3849
|
+
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."));
|
|
3850
|
+
}
|
|
3851
|
+
return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
|
|
3852
|
+
case 4:
|
|
3853
|
+
_h.sent();
|
|
3854
|
+
// TODO: [💵] Check the file security
|
|
3855
|
+
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3856
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3857
|
+
case 5:
|
|
3858
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3772
3859
|
if (tools.fs === undefined) {
|
|
3773
3860
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3774
3861
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3781,8 +3868,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3781
3868
|
fileExtension = getFileExtension(filename_1);
|
|
3782
3869
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3783
3870
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3784
|
-
case
|
|
3785
|
-
if (!(
|
|
3871
|
+
case 6:
|
|
3872
|
+
if (!(_h.sent())) {
|
|
3786
3873
|
throw new NotFoundError(spaceTrim$1(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
3874
|
}
|
|
3788
3875
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3828,7 +3915,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3828
3915
|
});
|
|
3829
3916
|
},
|
|
3830
3917
|
}];
|
|
3831
|
-
case
|
|
3918
|
+
case 7: return [2 /*return*/, {
|
|
3832
3919
|
source: name,
|
|
3833
3920
|
filename: null,
|
|
3834
3921
|
url: null,
|
|
@@ -4092,10 +4179,9 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
4092
4179
|
var content = _a.content;
|
|
4093
4180
|
return content;
|
|
4094
4181
|
}).join('\n\n'),
|
|
4095
|
-
})];
|
|
4182
|
+
}).asPromise()];
|
|
4096
4183
|
case 2:
|
|
4097
4184
|
result = _e.sent();
|
|
4098
|
-
assertsExecutionSuccessful(result);
|
|
4099
4185
|
outputParameters = result.outputParameters;
|
|
4100
4186
|
titleRaw = outputParameters.title;
|
|
4101
4187
|
if (isVerbose) {
|
|
@@ -4167,6 +4253,81 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
4167
4253
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
4168
4254
|
*/
|
|
4169
4255
|
|
|
4256
|
+
/**
|
|
4257
|
+
* Format either small or big number
|
|
4258
|
+
*
|
|
4259
|
+
* @public exported from `@promptbook/utils`
|
|
4260
|
+
*/
|
|
4261
|
+
function numberToString(value) {
|
|
4262
|
+
if (value === 0) {
|
|
4263
|
+
return '0';
|
|
4264
|
+
}
|
|
4265
|
+
else if (Number.isNaN(value)) {
|
|
4266
|
+
return VALUE_STRINGS.nan;
|
|
4267
|
+
}
|
|
4268
|
+
else if (value === Infinity) {
|
|
4269
|
+
return VALUE_STRINGS.infinity;
|
|
4270
|
+
}
|
|
4271
|
+
else if (value === -Infinity) {
|
|
4272
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4273
|
+
}
|
|
4274
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4275
|
+
var factor = Math.pow(10, exponent);
|
|
4276
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4277
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4278
|
+
return valueRounded.toFixed(exponent);
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
return value.toString();
|
|
4282
|
+
}
|
|
4283
|
+
|
|
4284
|
+
/**
|
|
4285
|
+
* Function `valueToString` will convert the given value to string
|
|
4286
|
+
* This is useful and used in the `templateParameters` function
|
|
4287
|
+
*
|
|
4288
|
+
* Note: This function is not just calling `toString` method
|
|
4289
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4290
|
+
* See `VALUE_STRINGS`
|
|
4291
|
+
*
|
|
4292
|
+
* Note: There are 2 similar functions
|
|
4293
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4294
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4295
|
+
*
|
|
4296
|
+
* @public exported from `@promptbook/utils`
|
|
4297
|
+
*/
|
|
4298
|
+
function valueToString(value) {
|
|
4299
|
+
try {
|
|
4300
|
+
if (value === '') {
|
|
4301
|
+
return VALUE_STRINGS.empty;
|
|
4302
|
+
}
|
|
4303
|
+
else if (value === null) {
|
|
4304
|
+
return VALUE_STRINGS.null;
|
|
4305
|
+
}
|
|
4306
|
+
else if (value === undefined) {
|
|
4307
|
+
return VALUE_STRINGS.undefined;
|
|
4308
|
+
}
|
|
4309
|
+
else if (typeof value === 'string') {
|
|
4310
|
+
return value;
|
|
4311
|
+
}
|
|
4312
|
+
else if (typeof value === 'number') {
|
|
4313
|
+
return numberToString(value);
|
|
4314
|
+
}
|
|
4315
|
+
else if (value instanceof Date) {
|
|
4316
|
+
return value.toISOString();
|
|
4317
|
+
}
|
|
4318
|
+
else {
|
|
4319
|
+
return JSON.stringify(value);
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
catch (error) {
|
|
4323
|
+
if (!(error instanceof Error)) {
|
|
4324
|
+
throw error;
|
|
4325
|
+
}
|
|
4326
|
+
console.error(error);
|
|
4327
|
+
return VALUE_STRINGS.unserializable;
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
|
|
4170
4331
|
/**
|
|
4171
4332
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4172
4333
|
*
|
|
@@ -5611,27 +5772,20 @@ function getReservedParametersForTask(options) {
|
|
|
5611
5772
|
*/
|
|
5612
5773
|
function executeTask(options) {
|
|
5613
5774
|
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 (
|
|
5775
|
+
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;
|
|
5776
|
+
var _f, e_1, _g, _h, _j;
|
|
5777
|
+
return __generator(this, function (_k) {
|
|
5778
|
+
switch (_k.label) {
|
|
5618
5779
|
case 0:
|
|
5619
5780
|
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
5781
|
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5623
5782
|
return [4 /*yield*/, onProgress({
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
isDone: false,
|
|
5628
|
-
taskType: currentTask.taskType,
|
|
5629
|
-
parameterName: currentTask.resultingParameterName,
|
|
5630
|
-
parameterValue: null,
|
|
5631
|
-
// <- [🍸]
|
|
5783
|
+
outputParameters: (_f = {},
|
|
5784
|
+
_f[currentTask.resultingParameterName] = '',
|
|
5785
|
+
_f),
|
|
5632
5786
|
})];
|
|
5633
5787
|
case 1:
|
|
5634
|
-
|
|
5788
|
+
_k.sent();
|
|
5635
5789
|
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5636
5790
|
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5637
5791
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
@@ -5650,7 +5804,7 @@ function executeTask(options) {
|
|
|
5650
5804
|
pipelineIdentification: pipelineIdentification,
|
|
5651
5805
|
})];
|
|
5652
5806
|
case 2:
|
|
5653
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
5807
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_k.sent())])), parametersToPass])]);
|
|
5654
5808
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
5655
5809
|
parameters = {};
|
|
5656
5810
|
_loop_1 = function (parameterName) {
|
|
@@ -5678,7 +5832,7 @@ function executeTask(options) {
|
|
|
5678
5832
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5679
5833
|
finally {
|
|
5680
5834
|
try {
|
|
5681
|
-
if (_e && !_e.done && (
|
|
5835
|
+
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
5682
5836
|
}
|
|
5683
5837
|
finally { if (e_1) throw e_1.error; }
|
|
5684
5838
|
}
|
|
@@ -5709,24 +5863,19 @@ function executeTask(options) {
|
|
|
5709
5863
|
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5710
5864
|
})];
|
|
5711
5865
|
case 3:
|
|
5712
|
-
resultString =
|
|
5866
|
+
resultString = _k.sent();
|
|
5713
5867
|
return [4 /*yield*/, onProgress({
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
isDone: true,
|
|
5718
|
-
taskType: currentTask.taskType,
|
|
5719
|
-
parameterName: currentTask.resultingParameterName,
|
|
5720
|
-
parameterValue: resultString,
|
|
5721
|
-
// <- [🍸]
|
|
5868
|
+
outputParameters: (_h = {},
|
|
5869
|
+
_h[currentTask.resultingParameterName] = resultString,
|
|
5870
|
+
_h),
|
|
5722
5871
|
})];
|
|
5723
5872
|
case 4:
|
|
5724
|
-
|
|
5725
|
-
return [2 /*return*/, Object.freeze((
|
|
5726
|
-
|
|
5873
|
+
_k.sent();
|
|
5874
|
+
return [2 /*return*/, Object.freeze((_j = {},
|
|
5875
|
+
_j[currentTask.resultingParameterName] =
|
|
5727
5876
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5728
5877
|
resultString,
|
|
5729
|
-
|
|
5878
|
+
_j))];
|
|
5730
5879
|
}
|
|
5731
5880
|
});
|
|
5732
5881
|
});
|
|
@@ -5734,9 +5883,6 @@ function executeTask(options) {
|
|
|
5734
5883
|
/**
|
|
5735
5884
|
* TODO: [🤹♂️]
|
|
5736
5885
|
*/
|
|
5737
|
-
/**
|
|
5738
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5739
|
-
*/
|
|
5740
5886
|
|
|
5741
5887
|
/**
|
|
5742
5888
|
* @@@
|
|
@@ -5998,15 +6144,15 @@ function executePipeline(options) {
|
|
|
5998
6144
|
return [3 /*break*/, 4];
|
|
5999
6145
|
case 3:
|
|
6000
6146
|
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 (
|
|
6147
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (newOngoingResult) {
|
|
6002
6148
|
if (isReturned) {
|
|
6003
|
-
throw new UnexpectedError(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(
|
|
6149
|
+
throw new UnexpectedError(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
6150
|
.split('\n')
|
|
6005
6151
|
.map(function (line) { return "> ".concat(line); })
|
|
6006
6152
|
.join('\n')), "\n "); }));
|
|
6007
6153
|
}
|
|
6008
6154
|
if (onProgress) {
|
|
6009
|
-
onProgress(
|
|
6155
|
+
onProgress(newOngoingResult);
|
|
6010
6156
|
}
|
|
6011
6157
|
}, $executionReport: executionReport, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
6012
6158
|
.then(function (newParametersToPass) {
|
|
@@ -6109,9 +6255,6 @@ function executePipeline(options) {
|
|
|
6109
6255
|
});
|
|
6110
6256
|
});
|
|
6111
6257
|
}
|
|
6112
|
-
/**
|
|
6113
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6114
|
-
*/
|
|
6115
6258
|
|
|
6116
6259
|
/**
|
|
6117
6260
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -6143,7 +6286,7 @@ function createPipelineExecutor(options) {
|
|
|
6143
6286
|
console.warn(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
6287
|
}
|
|
6145
6288
|
var runCount = 0;
|
|
6146
|
-
var
|
|
6289
|
+
var pipelineExecutorWithCallback = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
6147
6290
|
return __generator(this, function (_a) {
|
|
6148
6291
|
runCount++;
|
|
6149
6292
|
return [2 /*return*/, /* not await */ executePipeline({
|
|
@@ -6168,11 +6311,23 @@ function createPipelineExecutor(options) {
|
|
|
6168
6311
|
})];
|
|
6169
6312
|
});
|
|
6170
6313
|
}); };
|
|
6314
|
+
var pipelineExecutor = function (inputParameters) {
|
|
6315
|
+
return createTask({
|
|
6316
|
+
taskType: 'EXECUTION',
|
|
6317
|
+
taskProcessCallback: function (updateOngoingResult) {
|
|
6318
|
+
var _this = this;
|
|
6319
|
+
return pipelineExecutorWithCallback(inputParameters, function (newOngoingResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
6320
|
+
return __generator(this, function (_a) {
|
|
6321
|
+
updateOngoingResult(newOngoingResult);
|
|
6322
|
+
return [2 /*return*/];
|
|
6323
|
+
});
|
|
6324
|
+
}); });
|
|
6325
|
+
},
|
|
6326
|
+
});
|
|
6327
|
+
};
|
|
6328
|
+
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6171
6329
|
return pipelineExecutor;
|
|
6172
6330
|
}
|
|
6173
|
-
/**
|
|
6174
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6175
|
-
*/
|
|
6176
6331
|
|
|
6177
6332
|
/**
|
|
6178
6333
|
* Metadata of the scraper
|
|
@@ -6274,10 +6429,9 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
6274
6429
|
return [4 /*yield*/, source.asText()];
|
|
6275
6430
|
case 4:
|
|
6276
6431
|
knowledgeContent = _k.sent();
|
|
6277
|
-
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
6432
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
|
|
6278
6433
|
case 5:
|
|
6279
6434
|
result = _k.sent();
|
|
6280
|
-
assertsExecutionSuccessful(result);
|
|
6281
6435
|
outputParameters = result.outputParameters;
|
|
6282
6436
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
6283
6437
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
@@ -6300,13 +6454,13 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
6300
6454
|
_c.label = 1;
|
|
6301
6455
|
case 1:
|
|
6302
6456
|
_c.trys.push([1, 7, , 8]);
|
|
6303
|
-
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6457
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6304
6458
|
case 2:
|
|
6305
6459
|
titleResult = _c.sent();
|
|
6306
6460
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
6307
6461
|
title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
6308
6462
|
name = titleToName(title);
|
|
6309
|
-
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6463
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6310
6464
|
case 3:
|
|
6311
6465
|
keywordsResult = _c.sent();
|
|
6312
6466
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|