@promptbook/pdf 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 +384 -229
- 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 +385 -232
- 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
|
@@ -5,8 +5,11 @@ import hexEncoder from 'crypto-js/enc-hex';
|
|
|
5
5
|
import { basename, join, dirname } from 'path';
|
|
6
6
|
import { format } from 'prettier';
|
|
7
7
|
import parserHtml from 'prettier/parser-html';
|
|
8
|
+
import { BehaviorSubject, concat, from } from 'rxjs';
|
|
9
|
+
import { randomBytes } from 'crypto';
|
|
8
10
|
import { forTime } from 'waitasecond';
|
|
9
|
-
import
|
|
11
|
+
import sha256 from 'crypto-js/sha256';
|
|
12
|
+
import { lookup, extension } from 'mime-types';
|
|
10
13
|
import { unparse, parse } from 'papaparse';
|
|
11
14
|
|
|
12
15
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
@@ -23,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
23
26
|
* @generated
|
|
24
27
|
* @see https://github.com/webgptorg/promptbook
|
|
25
28
|
*/
|
|
26
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0';
|
|
27
30
|
/**
|
|
28
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -194,6 +197,12 @@ var ADMIN_GITHUB_NAME = 'hejny';
|
|
|
194
197
|
* @public exported from `@promptbook/core`
|
|
195
198
|
*/
|
|
196
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
|
|
197
206
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
198
207
|
/**
|
|
199
208
|
* The maximum number of iterations for a loops
|
|
@@ -227,6 +236,12 @@ var SMALL_NUMBER = 0.001;
|
|
|
227
236
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
228
237
|
*/
|
|
229
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;
|
|
230
245
|
/**
|
|
231
246
|
* Strategy for caching the intermediate results for knowledge sources
|
|
232
247
|
*
|
|
@@ -246,6 +261,15 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
246
261
|
* @public exported from `@promptbook/core`
|
|
247
262
|
*/
|
|
248
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';
|
|
249
273
|
/**
|
|
250
274
|
* Where to store the scrape cache
|
|
251
275
|
*
|
|
@@ -366,6 +390,9 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
366
390
|
* @public exported from `@promptbook/utils`
|
|
367
391
|
*/
|
|
368
392
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
393
|
+
/**
|
|
394
|
+
* TODO: [🎺]
|
|
395
|
+
*/
|
|
369
396
|
|
|
370
397
|
/**
|
|
371
398
|
* Checks if the file exists
|
|
@@ -940,24 +967,18 @@ function getScraperIntermediateSource(source, options) {
|
|
|
940
967
|
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"}];
|
|
941
968
|
|
|
942
969
|
/**
|
|
943
|
-
*
|
|
970
|
+
* Checks if value is valid email
|
|
944
971
|
*
|
|
945
972
|
* @public exported from `@promptbook/utils`
|
|
946
973
|
*/
|
|
947
|
-
function
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
return true;
|
|
974
|
+
function isValidEmail(email) {
|
|
975
|
+
if (typeof email !== 'string') {
|
|
976
|
+
return false;
|
|
951
977
|
}
|
|
952
|
-
|
|
953
|
-
if (!(error instanceof Error)) {
|
|
954
|
-
throw error;
|
|
955
|
-
}
|
|
956
|
-
if (error.message.includes('Unexpected token')) {
|
|
957
|
-
return false;
|
|
958
|
-
}
|
|
978
|
+
if (email.split('\n').length > 1) {
|
|
959
979
|
return false;
|
|
960
980
|
}
|
|
981
|
+
return /^.+@.+\..+$/.test(email);
|
|
961
982
|
}
|
|
962
983
|
|
|
963
984
|
/**
|
|
@@ -979,6 +1000,27 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
979
1000
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
980
1001
|
*/
|
|
981
1002
|
|
|
1003
|
+
/**
|
|
1004
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1005
|
+
*
|
|
1006
|
+
* @public exported from `@promptbook/utils`
|
|
1007
|
+
*/
|
|
1008
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1009
|
+
try {
|
|
1010
|
+
JSON.parse(value);
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
catch (error) {
|
|
1014
|
+
if (!(error instanceof Error)) {
|
|
1015
|
+
throw error;
|
|
1016
|
+
}
|
|
1017
|
+
if (error.message.includes('Unexpected token')) {
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
return false;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
982
1024
|
/**
|
|
983
1025
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
984
1026
|
* 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.
|
|
@@ -992,6 +1034,15 @@ function validatePipelineString(pipelineString) {
|
|
|
992
1034
|
if (isValidJsonString(pipelineString)) {
|
|
993
1035
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
994
1036
|
}
|
|
1037
|
+
else if (isValidUrl(pipelineString)) {
|
|
1038
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1039
|
+
}
|
|
1040
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1041
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1042
|
+
}
|
|
1043
|
+
else if (isValidEmail(pipelineString)) {
|
|
1044
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1045
|
+
}
|
|
995
1046
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
996
1047
|
return pipelineString;
|
|
997
1048
|
}
|
|
@@ -2192,6 +2243,58 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
2192
2243
|
return PipelineExecutionError;
|
|
2193
2244
|
}(Error));
|
|
2194
2245
|
|
|
2246
|
+
/**
|
|
2247
|
+
* Determine if the pipeline is fully prepared
|
|
2248
|
+
*
|
|
2249
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2250
|
+
*
|
|
2251
|
+
* @public exported from `@promptbook/core`
|
|
2252
|
+
*/
|
|
2253
|
+
function isPipelinePrepared(pipeline) {
|
|
2254
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2255
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2256
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2257
|
+
return false;
|
|
2258
|
+
}
|
|
2259
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2260
|
+
return false;
|
|
2261
|
+
}
|
|
2262
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2263
|
+
return false;
|
|
2264
|
+
}
|
|
2265
|
+
/*
|
|
2266
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2267
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2268
|
+
> return false;
|
|
2269
|
+
> }
|
|
2270
|
+
*/
|
|
2271
|
+
return true;
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2275
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2276
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2277
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2278
|
+
* - [🏍] ? Is context in each task
|
|
2279
|
+
* - [♨] Are examples prepared
|
|
2280
|
+
* - [♨] Are tasks prepared
|
|
2281
|
+
*/
|
|
2282
|
+
|
|
2283
|
+
/**
|
|
2284
|
+
* Generates random token
|
|
2285
|
+
*
|
|
2286
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2287
|
+
*
|
|
2288
|
+
* @private internal helper function
|
|
2289
|
+
* @returns secure random token
|
|
2290
|
+
*/
|
|
2291
|
+
function $randomToken(randomness) {
|
|
2292
|
+
return randomBytes(randomness).toString('hex');
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2296
|
+
*/
|
|
2297
|
+
|
|
2195
2298
|
/**
|
|
2196
2299
|
* This error indicates problems parsing the format value
|
|
2197
2300
|
*
|
|
@@ -2373,12 +2476,28 @@ function deserializeError(error) {
|
|
|
2373
2476
|
/**
|
|
2374
2477
|
* Asserts that the execution of a Promptbook is successful
|
|
2375
2478
|
*
|
|
2479
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2480
|
+
*
|
|
2376
2481
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2377
2482
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2378
|
-
* @
|
|
2483
|
+
* @private internal helper function of `asPromise` method of `ExecutionTask`
|
|
2379
2484
|
*/
|
|
2380
|
-
function
|
|
2381
|
-
var
|
|
2485
|
+
function assertsTaskSuccessful(executionResult) {
|
|
2486
|
+
var e_1, _a;
|
|
2487
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2488
|
+
try {
|
|
2489
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2490
|
+
var warning = warnings_1_1.value;
|
|
2491
|
+
console.warn(warning.message);
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2495
|
+
finally {
|
|
2496
|
+
try {
|
|
2497
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2498
|
+
}
|
|
2499
|
+
finally { if (e_1) throw e_1.error; }
|
|
2500
|
+
}
|
|
2382
2501
|
if (isSuccessful === true) {
|
|
2383
2502
|
return;
|
|
2384
2503
|
}
|
|
@@ -2398,122 +2517,55 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2398
2517
|
}
|
|
2399
2518
|
}
|
|
2400
2519
|
/**
|
|
2401
|
-
* TODO: [🐚] This function should be removed OR changed OR be completely rewritten
|
|
2402
2520
|
* TODO: [🧠] Can this return type be better typed than void
|
|
2403
2521
|
*/
|
|
2404
2522
|
|
|
2405
2523
|
/**
|
|
2406
|
-
*
|
|
2407
|
-
*
|
|
2408
|
-
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2524
|
+
* Helper to create a new task
|
|
2409
2525
|
*
|
|
2410
|
-
* @
|
|
2526
|
+
* @private internal helper function
|
|
2411
2527
|
*/
|
|
2412
|
-
function
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2528
|
+
function createTask(options) {
|
|
2529
|
+
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2530
|
+
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
|
|
2531
|
+
var resultSubject = new BehaviorSubject({});
|
|
2532
|
+
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2533
|
+
resultSubject.next(newOngoingResult);
|
|
2534
|
+
});
|
|
2535
|
+
function asPromise(options) {
|
|
2536
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2537
|
+
var _a, isCrashedOnError, finalResult;
|
|
2538
|
+
return __generator(this, function (_b) {
|
|
2539
|
+
switch (_b.label) {
|
|
2540
|
+
case 0:
|
|
2541
|
+
_a = (options || {}).isCrashedOnError, isCrashedOnError = _a === void 0 ? true : _a;
|
|
2542
|
+
return [4 /*yield*/, finalResultPromise];
|
|
2543
|
+
case 1:
|
|
2544
|
+
finalResult = _b.sent();
|
|
2545
|
+
if (isCrashedOnError) {
|
|
2546
|
+
assertsTaskSuccessful(finalResult);
|
|
2547
|
+
}
|
|
2548
|
+
return [2 /*return*/, finalResult];
|
|
2549
|
+
}
|
|
2550
|
+
});
|
|
2551
|
+
});
|
|
2423
2552
|
}
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2553
|
+
return {
|
|
2554
|
+
taskType: taskType,
|
|
2555
|
+
taskId: taskId,
|
|
2556
|
+
asPromise: asPromise,
|
|
2557
|
+
asObservable: function () {
|
|
2558
|
+
return concat(resultSubject.asObservable(), from(asPromise({
|
|
2559
|
+
isCrashedOnError: true,
|
|
2560
|
+
})));
|
|
2561
|
+
},
|
|
2562
|
+
};
|
|
2431
2563
|
}
|
|
2432
2564
|
/**
|
|
2433
|
-
* TODO:
|
|
2434
|
-
* TODO: [
|
|
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
|
|
2565
|
+
* TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
|
|
2566
|
+
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2440
2567
|
*/
|
|
2441
2568
|
|
|
2442
|
-
/**
|
|
2443
|
-
* Format either small or big number
|
|
2444
|
-
*
|
|
2445
|
-
* @public exported from `@promptbook/utils`
|
|
2446
|
-
*/
|
|
2447
|
-
function numberToString(value) {
|
|
2448
|
-
if (value === 0) {
|
|
2449
|
-
return '0';
|
|
2450
|
-
}
|
|
2451
|
-
else if (Number.isNaN(value)) {
|
|
2452
|
-
return VALUE_STRINGS.nan;
|
|
2453
|
-
}
|
|
2454
|
-
else if (value === Infinity) {
|
|
2455
|
-
return VALUE_STRINGS.infinity;
|
|
2456
|
-
}
|
|
2457
|
-
else if (value === -Infinity) {
|
|
2458
|
-
return VALUE_STRINGS.negativeInfinity;
|
|
2459
|
-
}
|
|
2460
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
2461
|
-
var factor = Math.pow(10, exponent);
|
|
2462
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
2463
|
-
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
2464
|
-
return valueRounded.toFixed(exponent);
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
return value.toString();
|
|
2468
|
-
}
|
|
2469
|
-
|
|
2470
|
-
/**
|
|
2471
|
-
* Function `valueToString` will convert the given value to string
|
|
2472
|
-
* This is useful and used in the `templateParameters` function
|
|
2473
|
-
*
|
|
2474
|
-
* Note: This function is not just calling `toString` method
|
|
2475
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
2476
|
-
* See `VALUE_STRINGS`
|
|
2477
|
-
*
|
|
2478
|
-
* Note: There are 2 similar functions
|
|
2479
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
2480
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
2481
|
-
*
|
|
2482
|
-
* @public exported from `@promptbook/utils`
|
|
2483
|
-
*/
|
|
2484
|
-
function valueToString(value) {
|
|
2485
|
-
try {
|
|
2486
|
-
if (value === '') {
|
|
2487
|
-
return VALUE_STRINGS.empty;
|
|
2488
|
-
}
|
|
2489
|
-
else if (value === null) {
|
|
2490
|
-
return VALUE_STRINGS.null;
|
|
2491
|
-
}
|
|
2492
|
-
else if (value === undefined) {
|
|
2493
|
-
return VALUE_STRINGS.undefined;
|
|
2494
|
-
}
|
|
2495
|
-
else if (typeof value === 'string') {
|
|
2496
|
-
return value;
|
|
2497
|
-
}
|
|
2498
|
-
else if (typeof value === 'number') {
|
|
2499
|
-
return numberToString(value);
|
|
2500
|
-
}
|
|
2501
|
-
else if (value instanceof Date) {
|
|
2502
|
-
return value.toISOString();
|
|
2503
|
-
}
|
|
2504
|
-
else {
|
|
2505
|
-
return JSON.stringify(value);
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
catch (error) {
|
|
2509
|
-
if (!(error instanceof Error)) {
|
|
2510
|
-
throw error;
|
|
2511
|
-
}
|
|
2512
|
-
console.error(error);
|
|
2513
|
-
return VALUE_STRINGS.unserializable;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
|
|
2517
2569
|
/**
|
|
2518
2570
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
2519
2571
|
*
|
|
@@ -3015,7 +3067,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3015
3067
|
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
3016
3068
|
throw error_1;
|
|
3017
3069
|
}
|
|
3018
|
-
errors.push(error_1);
|
|
3070
|
+
errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
|
|
3019
3071
|
return [3 /*break*/, 13];
|
|
3020
3072
|
case 13:
|
|
3021
3073
|
_b = _a.next();
|
|
@@ -3042,7 +3094,10 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3042
3094
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3043
3095
|
// 3) ...
|
|
3044
3096
|
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
3045
|
-
.map(function (
|
|
3097
|
+
.map(function (_a, i) {
|
|
3098
|
+
var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
|
|
3099
|
+
return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
|
|
3100
|
+
})
|
|
3046
3101
|
.join('\n')), "\n\n "); }));
|
|
3047
3102
|
}
|
|
3048
3103
|
else if (this.llmExecutionTools.length === 0) {
|
|
@@ -3173,10 +3228,9 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
3173
3228
|
return modelName;
|
|
3174
3229
|
})
|
|
3175
3230
|
.join(',');
|
|
3176
|
-
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
3231
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
|
|
3177
3232
|
case 3:
|
|
3178
3233
|
result = _d.sent();
|
|
3179
|
-
assertsExecutionSuccessful(result);
|
|
3180
3234
|
outputParameters = result.outputParameters;
|
|
3181
3235
|
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
3182
3236
|
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
@@ -3524,6 +3578,17 @@ function getFileExtension(value) {
|
|
|
3524
3578
|
return match ? match[1].toLowerCase() : null;
|
|
3525
3579
|
}
|
|
3526
3580
|
|
|
3581
|
+
/**
|
|
3582
|
+
* Convert mime type to file extension
|
|
3583
|
+
*
|
|
3584
|
+
* Note: If the mime type is invalid, `null` is returned
|
|
3585
|
+
*
|
|
3586
|
+
* @private within the repository
|
|
3587
|
+
*/
|
|
3588
|
+
function mimeTypeToExtension(value) {
|
|
3589
|
+
return extension(value) || null;
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3527
3592
|
/**
|
|
3528
3593
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3529
3594
|
*
|
|
@@ -3559,9 +3624,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3559
3624
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3560
3625
|
var _a;
|
|
3561
3626
|
return __awaiter(this, void 0, void 0, function () {
|
|
3562
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3563
|
-
return __generator(this, function (
|
|
3564
|
-
switch (
|
|
3627
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
|
|
3628
|
+
return __generator(this, function (_h) {
|
|
3629
|
+
switch (_h.label) {
|
|
3565
3630
|
case 0:
|
|
3566
3631
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3567
3632
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -3570,54 +3635,76 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3570
3635
|
if (!name) {
|
|
3571
3636
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3572
3637
|
}
|
|
3573
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3638
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3574
3639
|
url = knowledgeSourceContent;
|
|
3575
3640
|
return [4 /*yield*/, fetch(url)];
|
|
3576
3641
|
case 1:
|
|
3577
|
-
response_1 =
|
|
3642
|
+
response_1 = _h.sent();
|
|
3578
3643
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3644
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
3645
|
+
return [2 /*return*/, {
|
|
3646
|
+
source: name,
|
|
3647
|
+
filename: null,
|
|
3648
|
+
url: url,
|
|
3649
|
+
mimeType: mimeType,
|
|
3650
|
+
/*
|
|
3651
|
+
TODO: [🥽]
|
|
3652
|
+
> async asBlob() {
|
|
3653
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3654
|
+
> const content = await response.blob();
|
|
3655
|
+
> return content;
|
|
3656
|
+
> },
|
|
3657
|
+
*/
|
|
3658
|
+
asJson: function () {
|
|
3659
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3660
|
+
var content;
|
|
3661
|
+
return __generator(this, function (_a) {
|
|
3662
|
+
switch (_a.label) {
|
|
3663
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3664
|
+
case 1:
|
|
3665
|
+
content = _a.sent();
|
|
3666
|
+
return [2 /*return*/, content];
|
|
3667
|
+
}
|
|
3668
|
+
});
|
|
3602
3669
|
});
|
|
3603
|
-
}
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
}
|
|
3670
|
+
},
|
|
3671
|
+
asText: function () {
|
|
3672
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3673
|
+
var content;
|
|
3674
|
+
return __generator(this, function (_a) {
|
|
3675
|
+
switch (_a.label) {
|
|
3676
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3677
|
+
case 1:
|
|
3678
|
+
content = _a.sent();
|
|
3679
|
+
return [2 /*return*/, content];
|
|
3680
|
+
}
|
|
3681
|
+
});
|
|
3615
3682
|
});
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
|
-
|
|
3683
|
+
},
|
|
3684
|
+
}];
|
|
3685
|
+
}
|
|
3686
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
3687
|
+
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3688
|
+
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3689
|
+
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));
|
|
3690
|
+
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3619
3691
|
case 2:
|
|
3620
|
-
|
|
3692
|
+
_h.sent();
|
|
3693
|
+
_g = (_f = Buffer).from;
|
|
3694
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3695
|
+
case 3:
|
|
3696
|
+
fileContent = _g.apply(_f, [_h.sent()]);
|
|
3697
|
+
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3698
|
+
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."));
|
|
3699
|
+
}
|
|
3700
|
+
return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
|
|
3701
|
+
case 4:
|
|
3702
|
+
_h.sent();
|
|
3703
|
+
// TODO: [💵] Check the file security
|
|
3704
|
+
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3705
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3706
|
+
case 5:
|
|
3707
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3621
3708
|
if (tools.fs === undefined) {
|
|
3622
3709
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3623
3710
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3630,8 +3717,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3630
3717
|
fileExtension = getFileExtension(filename_1);
|
|
3631
3718
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3632
3719
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3633
|
-
case
|
|
3634
|
-
if (!(
|
|
3720
|
+
case 6:
|
|
3721
|
+
if (!(_h.sent())) {
|
|
3635
3722
|
throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
3636
3723
|
}
|
|
3637
3724
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3677,7 +3764,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3677
3764
|
});
|
|
3678
3765
|
},
|
|
3679
3766
|
}];
|
|
3680
|
-
case
|
|
3767
|
+
case 7: return [2 /*return*/, {
|
|
3681
3768
|
source: name,
|
|
3682
3769
|
filename: null,
|
|
3683
3770
|
url: null,
|
|
@@ -3941,10 +4028,9 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3941
4028
|
var content = _a.content;
|
|
3942
4029
|
return content;
|
|
3943
4030
|
}).join('\n\n'),
|
|
3944
|
-
})];
|
|
4031
|
+
}).asPromise()];
|
|
3945
4032
|
case 2:
|
|
3946
4033
|
result = _e.sent();
|
|
3947
|
-
assertsExecutionSuccessful(result);
|
|
3948
4034
|
outputParameters = result.outputParameters;
|
|
3949
4035
|
titleRaw = outputParameters.title;
|
|
3950
4036
|
if (isVerbose) {
|
|
@@ -4016,6 +4102,81 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
4016
4102
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
4017
4103
|
*/
|
|
4018
4104
|
|
|
4105
|
+
/**
|
|
4106
|
+
* Format either small or big number
|
|
4107
|
+
*
|
|
4108
|
+
* @public exported from `@promptbook/utils`
|
|
4109
|
+
*/
|
|
4110
|
+
function numberToString(value) {
|
|
4111
|
+
if (value === 0) {
|
|
4112
|
+
return '0';
|
|
4113
|
+
}
|
|
4114
|
+
else if (Number.isNaN(value)) {
|
|
4115
|
+
return VALUE_STRINGS.nan;
|
|
4116
|
+
}
|
|
4117
|
+
else if (value === Infinity) {
|
|
4118
|
+
return VALUE_STRINGS.infinity;
|
|
4119
|
+
}
|
|
4120
|
+
else if (value === -Infinity) {
|
|
4121
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4122
|
+
}
|
|
4123
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4124
|
+
var factor = Math.pow(10, exponent);
|
|
4125
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4126
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4127
|
+
return valueRounded.toFixed(exponent);
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
return value.toString();
|
|
4131
|
+
}
|
|
4132
|
+
|
|
4133
|
+
/**
|
|
4134
|
+
* Function `valueToString` will convert the given value to string
|
|
4135
|
+
* This is useful and used in the `templateParameters` function
|
|
4136
|
+
*
|
|
4137
|
+
* Note: This function is not just calling `toString` method
|
|
4138
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4139
|
+
* See `VALUE_STRINGS`
|
|
4140
|
+
*
|
|
4141
|
+
* Note: There are 2 similar functions
|
|
4142
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4143
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4144
|
+
*
|
|
4145
|
+
* @public exported from `@promptbook/utils`
|
|
4146
|
+
*/
|
|
4147
|
+
function valueToString(value) {
|
|
4148
|
+
try {
|
|
4149
|
+
if (value === '') {
|
|
4150
|
+
return VALUE_STRINGS.empty;
|
|
4151
|
+
}
|
|
4152
|
+
else if (value === null) {
|
|
4153
|
+
return VALUE_STRINGS.null;
|
|
4154
|
+
}
|
|
4155
|
+
else if (value === undefined) {
|
|
4156
|
+
return VALUE_STRINGS.undefined;
|
|
4157
|
+
}
|
|
4158
|
+
else if (typeof value === 'string') {
|
|
4159
|
+
return value;
|
|
4160
|
+
}
|
|
4161
|
+
else if (typeof value === 'number') {
|
|
4162
|
+
return numberToString(value);
|
|
4163
|
+
}
|
|
4164
|
+
else if (value instanceof Date) {
|
|
4165
|
+
return value.toISOString();
|
|
4166
|
+
}
|
|
4167
|
+
else {
|
|
4168
|
+
return JSON.stringify(value);
|
|
4169
|
+
}
|
|
4170
|
+
}
|
|
4171
|
+
catch (error) {
|
|
4172
|
+
if (!(error instanceof Error)) {
|
|
4173
|
+
throw error;
|
|
4174
|
+
}
|
|
4175
|
+
console.error(error);
|
|
4176
|
+
return VALUE_STRINGS.unserializable;
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4019
4180
|
/**
|
|
4020
4181
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4021
4182
|
*
|
|
@@ -5460,27 +5621,20 @@ function getReservedParametersForTask(options) {
|
|
|
5460
5621
|
*/
|
|
5461
5622
|
function executeTask(options) {
|
|
5462
5623
|
return __awaiter(this, void 0, void 0, function () {
|
|
5463
|
-
var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed,
|
|
5464
|
-
var e_1,
|
|
5465
|
-
return __generator(this, function (
|
|
5466
|
-
switch (
|
|
5624
|
+
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;
|
|
5625
|
+
var _f, e_1, _g, _h, _j;
|
|
5626
|
+
return __generator(this, function (_k) {
|
|
5627
|
+
switch (_k.label) {
|
|
5467
5628
|
case 0:
|
|
5468
5629
|
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;
|
|
5469
|
-
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
5470
|
-
title = currentTask.title;
|
|
5471
5630
|
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5472
5631
|
return [4 /*yield*/, onProgress({
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
isDone: false,
|
|
5477
|
-
taskType: currentTask.taskType,
|
|
5478
|
-
parameterName: currentTask.resultingParameterName,
|
|
5479
|
-
parameterValue: null,
|
|
5480
|
-
// <- [🍸]
|
|
5632
|
+
outputParameters: (_f = {},
|
|
5633
|
+
_f[currentTask.resultingParameterName] = '',
|
|
5634
|
+
_f),
|
|
5481
5635
|
})];
|
|
5482
5636
|
case 1:
|
|
5483
|
-
|
|
5637
|
+
_k.sent();
|
|
5484
5638
|
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5485
5639
|
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5486
5640
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
@@ -5499,7 +5653,7 @@ function executeTask(options) {
|
|
|
5499
5653
|
pipelineIdentification: pipelineIdentification,
|
|
5500
5654
|
})];
|
|
5501
5655
|
case 2:
|
|
5502
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
5656
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_k.sent())])), parametersToPass])]);
|
|
5503
5657
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
5504
5658
|
parameters = {};
|
|
5505
5659
|
_loop_1 = function (parameterName) {
|
|
@@ -5527,7 +5681,7 @@ function executeTask(options) {
|
|
|
5527
5681
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5528
5682
|
finally {
|
|
5529
5683
|
try {
|
|
5530
|
-
if (_e && !_e.done && (
|
|
5684
|
+
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
5531
5685
|
}
|
|
5532
5686
|
finally { if (e_1) throw e_1.error; }
|
|
5533
5687
|
}
|
|
@@ -5558,24 +5712,19 @@ function executeTask(options) {
|
|
|
5558
5712
|
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5559
5713
|
})];
|
|
5560
5714
|
case 3:
|
|
5561
|
-
resultString =
|
|
5715
|
+
resultString = _k.sent();
|
|
5562
5716
|
return [4 /*yield*/, onProgress({
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
isDone: true,
|
|
5567
|
-
taskType: currentTask.taskType,
|
|
5568
|
-
parameterName: currentTask.resultingParameterName,
|
|
5569
|
-
parameterValue: resultString,
|
|
5570
|
-
// <- [🍸]
|
|
5717
|
+
outputParameters: (_h = {},
|
|
5718
|
+
_h[currentTask.resultingParameterName] = resultString,
|
|
5719
|
+
_h),
|
|
5571
5720
|
})];
|
|
5572
5721
|
case 4:
|
|
5573
|
-
|
|
5574
|
-
return [2 /*return*/, Object.freeze((
|
|
5575
|
-
|
|
5722
|
+
_k.sent();
|
|
5723
|
+
return [2 /*return*/, Object.freeze((_j = {},
|
|
5724
|
+
_j[currentTask.resultingParameterName] =
|
|
5576
5725
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5577
5726
|
resultString,
|
|
5578
|
-
|
|
5727
|
+
_j))];
|
|
5579
5728
|
}
|
|
5580
5729
|
});
|
|
5581
5730
|
});
|
|
@@ -5583,9 +5732,6 @@ function executeTask(options) {
|
|
|
5583
5732
|
/**
|
|
5584
5733
|
* TODO: [🤹♂️]
|
|
5585
5734
|
*/
|
|
5586
|
-
/**
|
|
5587
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5588
|
-
*/
|
|
5589
5735
|
|
|
5590
5736
|
/**
|
|
5591
5737
|
* @@@
|
|
@@ -5847,15 +5993,15 @@ function executePipeline(options) {
|
|
|
5847
5993
|
return [3 /*break*/, 4];
|
|
5848
5994
|
case 3:
|
|
5849
5995
|
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
5850
|
-
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (
|
|
5996
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (newOngoingResult) {
|
|
5851
5997
|
if (isReturned) {
|
|
5852
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(
|
|
5998
|
+
throw new UnexpectedError(spaceTrim$1(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)
|
|
5853
5999
|
.split('\n')
|
|
5854
6000
|
.map(function (line) { return "> ".concat(line); })
|
|
5855
6001
|
.join('\n')), "\n "); }));
|
|
5856
6002
|
}
|
|
5857
6003
|
if (onProgress) {
|
|
5858
|
-
onProgress(
|
|
6004
|
+
onProgress(newOngoingResult);
|
|
5859
6005
|
}
|
|
5860
6006
|
}, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
5861
6007
|
.then(function (newParametersToPass) {
|
|
@@ -5958,9 +6104,6 @@ function executePipeline(options) {
|
|
|
5958
6104
|
});
|
|
5959
6105
|
});
|
|
5960
6106
|
}
|
|
5961
|
-
/**
|
|
5962
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5963
|
-
*/
|
|
5964
6107
|
|
|
5965
6108
|
/**
|
|
5966
6109
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -5992,7 +6135,7 @@ function createPipelineExecutor(options) {
|
|
|
5992
6135
|
console.warn(spaceTrim$1(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 "); }));
|
|
5993
6136
|
}
|
|
5994
6137
|
var runCount = 0;
|
|
5995
|
-
var
|
|
6138
|
+
var pipelineExecutorWithCallback = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
5996
6139
|
return __generator(this, function (_a) {
|
|
5997
6140
|
runCount++;
|
|
5998
6141
|
return [2 /*return*/, /* not await */ executePipeline({
|
|
@@ -6017,11 +6160,23 @@ function createPipelineExecutor(options) {
|
|
|
6017
6160
|
})];
|
|
6018
6161
|
});
|
|
6019
6162
|
}); };
|
|
6163
|
+
var pipelineExecutor = function (inputParameters) {
|
|
6164
|
+
return createTask({
|
|
6165
|
+
taskType: 'EXECUTION',
|
|
6166
|
+
taskProcessCallback: function (updateOngoingResult) {
|
|
6167
|
+
var _this = this;
|
|
6168
|
+
return pipelineExecutorWithCallback(inputParameters, function (newOngoingResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
6169
|
+
return __generator(this, function (_a) {
|
|
6170
|
+
updateOngoingResult(newOngoingResult);
|
|
6171
|
+
return [2 /*return*/];
|
|
6172
|
+
});
|
|
6173
|
+
}); });
|
|
6174
|
+
},
|
|
6175
|
+
});
|
|
6176
|
+
};
|
|
6177
|
+
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6020
6178
|
return pipelineExecutor;
|
|
6021
6179
|
}
|
|
6022
|
-
/**
|
|
6023
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6024
|
-
*/
|
|
6025
6180
|
|
|
6026
6181
|
/**
|
|
6027
6182
|
* Metadata of the scraper
|
|
@@ -6123,10 +6278,9 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
6123
6278
|
return [4 /*yield*/, source.asText()];
|
|
6124
6279
|
case 4:
|
|
6125
6280
|
knowledgeContent = _k.sent();
|
|
6126
|
-
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
6281
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
|
|
6127
6282
|
case 5:
|
|
6128
6283
|
result = _k.sent();
|
|
6129
|
-
assertsExecutionSuccessful(result);
|
|
6130
6284
|
outputParameters = result.outputParameters;
|
|
6131
6285
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
6132
6286
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
@@ -6149,13 +6303,13 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
6149
6303
|
_c.label = 1;
|
|
6150
6304
|
case 1:
|
|
6151
6305
|
_c.trys.push([1, 7, , 8]);
|
|
6152
|
-
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6306
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6153
6307
|
case 2:
|
|
6154
6308
|
titleResult = _c.sent();
|
|
6155
6309
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
6156
6310
|
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
6157
6311
|
name = titleToName(title);
|
|
6158
|
-
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6312
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6159
6313
|
case 3:
|
|
6160
6314
|
keywordsResult = _c.sent();
|
|
6161
6315
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|
|
@@ -6233,7 +6387,7 @@ var markitdownScraperMetadata = $deepFreeze({
|
|
|
6233
6387
|
className: 'MarkitdownScraper',
|
|
6234
6388
|
mimeTypes: [
|
|
6235
6389
|
'application/pdf',
|
|
6236
|
-
// TODO: Make priority for scrapers and than allow all mime types here:
|
|
6390
|
+
// TODO: [💵] Make priority for scrapers and than analyze which mime-types can Markitdown scrape and allow all mime types here:
|
|
6237
6391
|
// 'text/html',
|
|
6238
6392
|
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
6239
6393
|
],
|
|
@@ -6269,10 +6423,10 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
6269
6423
|
this.tools = tools;
|
|
6270
6424
|
this.options = options;
|
|
6271
6425
|
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
6426
|
+
// Note: Module `markitdown-ts` has no types available, so it is imported using `require`
|
|
6272
6427
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6273
6428
|
var MarkItDown = require('markitdown-ts').MarkItDown;
|
|
6274
|
-
// <- TODO:
|
|
6275
|
-
// <- Note: !!!!!!!
|
|
6429
|
+
// <- TODO: [🍀] Use Markitdown directly not through this package
|
|
6276
6430
|
this.markitdown = new MarkItDown();
|
|
6277
6431
|
}
|
|
6278
6432
|
Object.defineProperty(MarkitdownScraper.prototype, "metadata", {
|
|
@@ -6317,12 +6471,12 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
6317
6471
|
case 2:
|
|
6318
6472
|
if (!!(_f.sent())) return [3 /*break*/, 5];
|
|
6319
6473
|
src = source.filename || source.url || null;
|
|
6320
|
-
console.log('
|
|
6474
|
+
// console.log('!!', { src, source, cacheFilehandler });
|
|
6321
6475
|
if (src === null) {
|
|
6322
6476
|
throw new UnexpectedError('Source has no filename or url');
|
|
6323
6477
|
}
|
|
6324
6478
|
return [4 /*yield*/, this.markitdown.convert(src, {
|
|
6325
|
-
// TODO:
|
|
6479
|
+
// TODO: Pass when sacraping Youtube
|
|
6326
6480
|
// enableYoutubeTranscript: true,
|
|
6327
6481
|
// youtubeTranscriptLanguage: 'en',
|
|
6328
6482
|
})];
|
|
@@ -6330,11 +6484,12 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
6330
6484
|
result = _f.sent();
|
|
6331
6485
|
if (result === null || result === undefined) {
|
|
6332
6486
|
throw new Error("Markitdown could not convert the \"".concat(source.source, "\""));
|
|
6333
|
-
// <- TODO:
|
|
6487
|
+
// <- TODO: [🍀] Make MarkitdownError
|
|
6334
6488
|
}
|
|
6335
|
-
console.log('
|
|
6489
|
+
// console.log('!!', { result, cacheFilehandler });
|
|
6336
6490
|
return [4 /*yield*/, this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content)];
|
|
6337
6491
|
case 4:
|
|
6492
|
+
// console.log('!!', { result, cacheFilehandler });
|
|
6338
6493
|
_f.sent();
|
|
6339
6494
|
_f.label = 5;
|
|
6340
6495
|
case 5: return [2 /*return*/, cacheFilehandler];
|