@promptbook/markitdown 0.84.0-9 → 0.84.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 -9
- package/esm/index.es.js +173 -71
- 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 -2
- package/esm/typings/src/_packages/deepseek.index.d.ts +8 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +4 -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/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/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
- 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/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/wizzard/wizzard.d.ts +7 -1
- package/package.json +9 -16
- package/umd/index.umd.js +176 -74
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten -->
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# ✨ Promptbook
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -14,19 +14,16 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## 🌟 New Features
|
|
18
18
|
|
|
19
|
+
- 💫 Support of [`o3-mini` model by OpenAI](https://openai.com/index/openai-o3-mini/)
|
|
20
|
+
- 🐋 **Support of [DeepSeek models](https://www.npmjs.com/package/@promptbook/deepseek)**
|
|
19
21
|
- 💙 Working [the **Book** language v1.0.0](https://github.com/webgptorg/book)
|
|
20
22
|
- 🖤 Run books from CLI - `npx ptbk run path/to/your/book`
|
|
21
|
-
- 📚 Support of `.docx`, `.doc` and `.pdf` documents
|
|
22
|
-
- ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
|
|
23
|
+
- 📚 Support of `.docx`, `.doc` and `.pdf` documents as knowledge
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
<blockquote style="color: #ff8811">
|
|
27
|
-
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
-
</blockquote>
|
|
29
|
-
|
|
30
27
|
## 📦 Package `@promptbook/markitdown`
|
|
31
28
|
|
|
32
29
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -263,8 +260,9 @@ Or you can install them separately:
|
|
|
263
260
|
- **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
|
|
264
261
|
- **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
|
|
265
262
|
- **[@promptbook/google](https://www.npmjs.com/package/@promptbook/google)** - Integration with Google's Gemini API
|
|
263
|
+
- **[@promptbook/deepseek](https://www.npmjs.com/package/@promptbook/deepseek)** - Integration with [DeepSeek API](https://www.deepseek.com/)
|
|
266
264
|
- **[@promptbook/azure-openai](https://www.npmjs.com/package/@promptbook/azure-openai)** - Execution tools for Azure OpenAI API
|
|
267
|
-
|
|
265
|
+
|
|
268
266
|
- **[@promptbook/fake-llm](https://www.npmjs.com/package/@promptbook/fake-llm)** - Mocked execution tools for testing the library and saving the tokens
|
|
269
267
|
- **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
|
|
270
268
|
- **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
|
|
@@ -434,6 +432,20 @@ See [TODO.md](./TODO.md)
|
|
|
434
432
|
|
|
435
433
|
|
|
436
434
|
|
|
435
|
+
## 🤝 Partners
|
|
436
|
+
|
|
437
|
+
<div style="display: flex; align-items: center; gap: 20px;">
|
|
438
|
+
|
|
439
|
+
<a href="https://promptbook.studio/">
|
|
440
|
+
<img src="./other/design/promptbook-studio-logo.png" alt="Partner 3" height="100">
|
|
441
|
+
</a>
|
|
442
|
+
|
|
443
|
+
<a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
|
|
444
|
+
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
|
|
445
|
+
</a>
|
|
446
|
+
|
|
447
|
+
</div>
|
|
448
|
+
|
|
437
449
|
## 🖋️ Contributing
|
|
438
450
|
|
|
439
451
|
I am open to pull requests, feedback, and suggestions. Or if you like this utility, you can [☕ buy me a coffee](https://www.buymeacoffee.com/hejny) or [donate via cryptocurrencies](https://github.com/hejny/hejny/blob/main/documents/crypto.md).
|
package/esm/index.es.js
CHANGED
|
@@ -6,7 +6,8 @@ import { basename, join, dirname } from 'path';
|
|
|
6
6
|
import { format } from 'prettier';
|
|
7
7
|
import parserHtml from 'prettier/parser-html';
|
|
8
8
|
import { forTime } from 'waitasecond';
|
|
9
|
-
import
|
|
9
|
+
import sha256 from 'crypto-js/sha256';
|
|
10
|
+
import { lookup, extension } from 'mime-types';
|
|
10
11
|
import { unparse, parse } from 'papaparse';
|
|
11
12
|
|
|
12
13
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
@@ -23,7 +24,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
23
24
|
* @generated
|
|
24
25
|
* @see https://github.com/webgptorg/promptbook
|
|
25
26
|
*/
|
|
26
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
27
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
|
|
27
28
|
/**
|
|
28
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -194,6 +195,12 @@ var ADMIN_GITHUB_NAME = 'hejny';
|
|
|
194
195
|
* @public exported from `@promptbook/core`
|
|
195
196
|
*/
|
|
196
197
|
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
198
|
+
/**
|
|
199
|
+
* Maximum file size limit
|
|
200
|
+
*
|
|
201
|
+
* @public exported from `@promptbook/core`
|
|
202
|
+
*/
|
|
203
|
+
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
197
204
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
198
205
|
/**
|
|
199
206
|
* The maximum number of iterations for a loops
|
|
@@ -227,6 +234,12 @@ var SMALL_NUMBER = 0.001;
|
|
|
227
234
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
228
235
|
*/
|
|
229
236
|
var IMMEDIATE_TIME = 10;
|
|
237
|
+
/**
|
|
238
|
+
* The maximum length of the (generated) filename
|
|
239
|
+
*
|
|
240
|
+
* @public exported from `@promptbook/core`
|
|
241
|
+
*/
|
|
242
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
230
243
|
/**
|
|
231
244
|
* Strategy for caching the intermediate results for knowledge sources
|
|
232
245
|
*
|
|
@@ -246,6 +259,15 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
246
259
|
* @public exported from `@promptbook/core`
|
|
247
260
|
*/
|
|
248
261
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
262
|
+
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
263
|
+
/**
|
|
264
|
+
* Where to store the temporary downloads
|
|
265
|
+
*
|
|
266
|
+
* Note: When the folder does not exist, it is created recursively
|
|
267
|
+
*
|
|
268
|
+
* @public exported from `@promptbook/core`
|
|
269
|
+
*/
|
|
270
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
249
271
|
/**
|
|
250
272
|
* Where to store the scrape cache
|
|
251
273
|
*
|
|
@@ -366,6 +388,9 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
366
388
|
* @public exported from `@promptbook/utils`
|
|
367
389
|
*/
|
|
368
390
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
391
|
+
/**
|
|
392
|
+
* TODO: [☑]
|
|
393
|
+
*/
|
|
369
394
|
|
|
370
395
|
/**
|
|
371
396
|
* Checks if the file exists
|
|
@@ -927,24 +952,18 @@ function getScraperIntermediateSource(source, options) {
|
|
|
927
952
|
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"}];
|
|
928
953
|
|
|
929
954
|
/**
|
|
930
|
-
*
|
|
955
|
+
* Checks if value is valid email
|
|
931
956
|
*
|
|
932
957
|
* @public exported from `@promptbook/utils`
|
|
933
958
|
*/
|
|
934
|
-
function
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
return true;
|
|
959
|
+
function isValidEmail(email) {
|
|
960
|
+
if (typeof email !== 'string') {
|
|
961
|
+
return false;
|
|
938
962
|
}
|
|
939
|
-
|
|
940
|
-
if (!(error instanceof Error)) {
|
|
941
|
-
throw error;
|
|
942
|
-
}
|
|
943
|
-
if (error.message.includes('Unexpected token')) {
|
|
944
|
-
return false;
|
|
945
|
-
}
|
|
963
|
+
if (email.split('\n').length > 1) {
|
|
946
964
|
return false;
|
|
947
965
|
}
|
|
966
|
+
return /^.+@.+\..+$/.test(email);
|
|
948
967
|
}
|
|
949
968
|
|
|
950
969
|
/**
|
|
@@ -966,6 +985,27 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
966
985
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
967
986
|
*/
|
|
968
987
|
|
|
988
|
+
/**
|
|
989
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
990
|
+
*
|
|
991
|
+
* @public exported from `@promptbook/utils`
|
|
992
|
+
*/
|
|
993
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
994
|
+
try {
|
|
995
|
+
JSON.parse(value);
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
catch (error) {
|
|
999
|
+
if (!(error instanceof Error)) {
|
|
1000
|
+
throw error;
|
|
1001
|
+
}
|
|
1002
|
+
if (error.message.includes('Unexpected token')) {
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
969
1009
|
/**
|
|
970
1010
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
971
1011
|
* 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.
|
|
@@ -979,6 +1019,15 @@ function validatePipelineString(pipelineString) {
|
|
|
979
1019
|
if (isValidJsonString(pipelineString)) {
|
|
980
1020
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
981
1021
|
}
|
|
1022
|
+
else if (isValidUrl(pipelineString)) {
|
|
1023
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1024
|
+
}
|
|
1025
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1026
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1027
|
+
}
|
|
1028
|
+
else if (isValidEmail(pipelineString)) {
|
|
1029
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1030
|
+
}
|
|
982
1031
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
983
1032
|
return pipelineString;
|
|
984
1033
|
}
|
|
@@ -2360,12 +2409,28 @@ function deserializeError(error) {
|
|
|
2360
2409
|
/**
|
|
2361
2410
|
* Asserts that the execution of a Promptbook is successful
|
|
2362
2411
|
*
|
|
2412
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2413
|
+
*
|
|
2363
2414
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2364
2415
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2365
2416
|
* @public exported from `@promptbook/core`
|
|
2366
2417
|
*/
|
|
2367
2418
|
function assertsExecutionSuccessful(executionResult) {
|
|
2368
|
-
var
|
|
2419
|
+
var e_1, _a;
|
|
2420
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2421
|
+
try {
|
|
2422
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2423
|
+
var warning = warnings_1_1.value;
|
|
2424
|
+
console.warn(warning.message);
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2428
|
+
finally {
|
|
2429
|
+
try {
|
|
2430
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2431
|
+
}
|
|
2432
|
+
finally { if (e_1) throw e_1.error; }
|
|
2433
|
+
}
|
|
2369
2434
|
if (isSuccessful === true) {
|
|
2370
2435
|
return;
|
|
2371
2436
|
}
|
|
@@ -3002,7 +3067,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3002
3067
|
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
3003
3068
|
throw error_1;
|
|
3004
3069
|
}
|
|
3005
|
-
errors.push(error_1);
|
|
3070
|
+
errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
|
|
3006
3071
|
return [3 /*break*/, 13];
|
|
3007
3072
|
case 13:
|
|
3008
3073
|
_b = _a.next();
|
|
@@ -3029,7 +3094,10 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3029
3094
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3030
3095
|
// 3) ...
|
|
3031
3096
|
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
3032
|
-
.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
|
+
})
|
|
3033
3101
|
.join('\n')), "\n\n "); }));
|
|
3034
3102
|
}
|
|
3035
3103
|
else if (this.llmExecutionTools.length === 0) {
|
|
@@ -3511,6 +3579,17 @@ function getFileExtension(value) {
|
|
|
3511
3579
|
return match ? match[1].toLowerCase() : null;
|
|
3512
3580
|
}
|
|
3513
3581
|
|
|
3582
|
+
/**
|
|
3583
|
+
* Convert mime type to file extension
|
|
3584
|
+
*
|
|
3585
|
+
* Note: If the mime type is invalid, `null` is returned
|
|
3586
|
+
*
|
|
3587
|
+
* @private within the repository
|
|
3588
|
+
*/
|
|
3589
|
+
function mimeTypeToExtension(value) {
|
|
3590
|
+
return extension(value) || null;
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3514
3593
|
/**
|
|
3515
3594
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3516
3595
|
*
|
|
@@ -3546,9 +3625,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3546
3625
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3547
3626
|
var _a;
|
|
3548
3627
|
return __awaiter(this, void 0, void 0, function () {
|
|
3549
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3550
|
-
return __generator(this, function (
|
|
3551
|
-
switch (
|
|
3628
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
|
|
3629
|
+
return __generator(this, function (_h) {
|
|
3630
|
+
switch (_h.label) {
|
|
3552
3631
|
case 0:
|
|
3553
3632
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3554
3633
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -3557,54 +3636,76 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3557
3636
|
if (!name) {
|
|
3558
3637
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3559
3638
|
}
|
|
3560
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3639
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3561
3640
|
url = knowledgeSourceContent;
|
|
3562
3641
|
return [4 /*yield*/, fetch(url)];
|
|
3563
3642
|
case 1:
|
|
3564
|
-
response_1 =
|
|
3643
|
+
response_1 = _h.sent();
|
|
3565
3644
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3645
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
3646
|
+
return [2 /*return*/, {
|
|
3647
|
+
source: name,
|
|
3648
|
+
filename: null,
|
|
3649
|
+
url: url,
|
|
3650
|
+
mimeType: mimeType,
|
|
3651
|
+
/*
|
|
3652
|
+
TODO: [🥽]
|
|
3653
|
+
> async asBlob() {
|
|
3654
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3655
|
+
> const content = await response.blob();
|
|
3656
|
+
> return content;
|
|
3657
|
+
> },
|
|
3658
|
+
*/
|
|
3659
|
+
asJson: function () {
|
|
3660
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3661
|
+
var content;
|
|
3662
|
+
return __generator(this, function (_a) {
|
|
3663
|
+
switch (_a.label) {
|
|
3664
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3665
|
+
case 1:
|
|
3666
|
+
content = _a.sent();
|
|
3667
|
+
return [2 /*return*/, content];
|
|
3668
|
+
}
|
|
3669
|
+
});
|
|
3589
3670
|
});
|
|
3590
|
-
}
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
}
|
|
3671
|
+
},
|
|
3672
|
+
asText: function () {
|
|
3673
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3674
|
+
var content;
|
|
3675
|
+
return __generator(this, function (_a) {
|
|
3676
|
+
switch (_a.label) {
|
|
3677
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3678
|
+
case 1:
|
|
3679
|
+
content = _a.sent();
|
|
3680
|
+
return [2 /*return*/, content];
|
|
3681
|
+
}
|
|
3682
|
+
});
|
|
3602
3683
|
});
|
|
3603
|
-
}
|
|
3604
|
-
}
|
|
3605
|
-
|
|
3684
|
+
},
|
|
3685
|
+
}];
|
|
3686
|
+
}
|
|
3687
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
3688
|
+
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3689
|
+
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3690
|
+
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));
|
|
3691
|
+
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3606
3692
|
case 2:
|
|
3607
|
-
|
|
3693
|
+
_h.sent();
|
|
3694
|
+
_g = (_f = Buffer).from;
|
|
3695
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3696
|
+
case 3:
|
|
3697
|
+
fileContent = _g.apply(_f, [_h.sent()]);
|
|
3698
|
+
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3699
|
+
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."));
|
|
3700
|
+
}
|
|
3701
|
+
return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
|
|
3702
|
+
case 4:
|
|
3703
|
+
_h.sent();
|
|
3704
|
+
// TODO: [💵] Check the file security
|
|
3705
|
+
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3706
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3707
|
+
case 5:
|
|
3708
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3608
3709
|
if (tools.fs === undefined) {
|
|
3609
3710
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3610
3711
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3617,8 +3718,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3617
3718
|
fileExtension = getFileExtension(filename_1);
|
|
3618
3719
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3619
3720
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3620
|
-
case
|
|
3621
|
-
if (!(
|
|
3721
|
+
case 6:
|
|
3722
|
+
if (!(_h.sent())) {
|
|
3622
3723
|
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 "); }));
|
|
3623
3724
|
}
|
|
3624
3725
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3664,7 +3765,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3664
3765
|
});
|
|
3665
3766
|
},
|
|
3666
3767
|
}];
|
|
3667
|
-
case
|
|
3768
|
+
case 7: return [2 /*return*/, {
|
|
3668
3769
|
source: name,
|
|
3669
3770
|
filename: null,
|
|
3670
3771
|
url: null,
|
|
@@ -6220,7 +6321,7 @@ var markitdownScraperMetadata = $deepFreeze({
|
|
|
6220
6321
|
className: 'MarkitdownScraper',
|
|
6221
6322
|
mimeTypes: [
|
|
6222
6323
|
'application/pdf',
|
|
6223
|
-
// TODO: Make priority for scrapers and than allow all mime types here:
|
|
6324
|
+
// TODO: [💵] Make priority for scrapers and than analyze which mime-types can Markitdown scrape and allow all mime types here:
|
|
6224
6325
|
// 'text/html',
|
|
6225
6326
|
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
6226
6327
|
],
|
|
@@ -6256,10 +6357,10 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
6256
6357
|
this.tools = tools;
|
|
6257
6358
|
this.options = options;
|
|
6258
6359
|
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
6360
|
+
// Note: Module `markitdown-ts` has no types available, so it is imported using `require`
|
|
6259
6361
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6260
6362
|
var MarkItDown = require('markitdown-ts').MarkItDown;
|
|
6261
|
-
// <- TODO:
|
|
6262
|
-
// <- Note: !!!!!!!
|
|
6363
|
+
// <- TODO: [🍀] Use Markitdown directly not through this package
|
|
6263
6364
|
this.markitdown = new MarkItDown();
|
|
6264
6365
|
}
|
|
6265
6366
|
Object.defineProperty(MarkitdownScraper.prototype, "metadata", {
|
|
@@ -6304,12 +6405,12 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
6304
6405
|
case 2:
|
|
6305
6406
|
if (!!(_f.sent())) return [3 /*break*/, 5];
|
|
6306
6407
|
src = source.filename || source.url || null;
|
|
6307
|
-
console.log('
|
|
6408
|
+
// console.log('!!', { src, source, cacheFilehandler });
|
|
6308
6409
|
if (src === null) {
|
|
6309
6410
|
throw new UnexpectedError('Source has no filename or url');
|
|
6310
6411
|
}
|
|
6311
6412
|
return [4 /*yield*/, this.markitdown.convert(src, {
|
|
6312
|
-
// TODO:
|
|
6413
|
+
// TODO: Pass when sacraping Youtube
|
|
6313
6414
|
// enableYoutubeTranscript: true,
|
|
6314
6415
|
// youtubeTranscriptLanguage: 'en',
|
|
6315
6416
|
})];
|
|
@@ -6317,11 +6418,12 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
6317
6418
|
result = _f.sent();
|
|
6318
6419
|
if (result === null || result === undefined) {
|
|
6319
6420
|
throw new Error("Markitdown could not convert the \"".concat(source.source, "\""));
|
|
6320
|
-
// <- TODO:
|
|
6421
|
+
// <- TODO: [🍀] Make MarkitdownError
|
|
6321
6422
|
}
|
|
6322
|
-
console.log('
|
|
6423
|
+
// console.log('!!', { result, cacheFilehandler });
|
|
6323
6424
|
return [4 /*yield*/, this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content)];
|
|
6324
6425
|
case 4:
|
|
6426
|
+
// console.log('!!', { result, cacheFilehandler });
|
|
6325
6427
|
_f.sent();
|
|
6326
6428
|
_f.label = 5;
|
|
6327
6429
|
case 5: return [2 /*return*/, cacheFilehandler];
|