@promptbook/utils 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.
Files changed (43) hide show
  1. package/README.md +68 -30
  2. package/esm/index.es.js +46 -8
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +12 -2
  6. package/esm/typings/src/_packages/deepseek.index.d.ts +8 -0
  7. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  8. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  9. package/esm/typings/src/_packages/wizzard.index.d.ts +4 -0
  10. package/esm/typings/src/cli/cli-commands/about.d.ts +4 -1
  11. package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -1
  12. package/esm/typings/src/cli/cli-commands/list-models.d.ts +3 -1
  13. package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +13 -0
  14. package/esm/typings/src/cli/cli-commands/make.d.ts +3 -1
  15. package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -1
  16. package/esm/typings/src/cli/cli-commands/run.d.ts +3 -1
  17. package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +1 -1
  18. package/esm/typings/src/cli/cli-commands/test-command.d.ts +3 -1
  19. package/esm/typings/src/config.d.ts +27 -1
  20. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
  21. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  22. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
  23. package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +9 -0
  24. package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +9 -0
  25. package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +14 -0
  26. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +14 -0
  27. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +15 -0
  28. package/esm/typings/src/pipeline/book-notation.d.ts +3 -2
  29. package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -5
  30. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
  31. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +5 -2
  32. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +1 -0
  33. package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +1 -0
  34. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +3 -0
  35. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +3 -0
  36. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +3 -0
  37. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +3 -0
  38. package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +10 -0
  39. package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +1 -0
  40. package/esm/typings/src/wizzard/wizzard.d.ts +7 -1
  41. package/package.json +7 -14
  42. package/umd/index.umd.js +46 -7
  43. 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
- # Promptbook
3
+ # Promptbook
4
4
 
5
5
 
6
6
 
@@ -14,19 +14,16 @@
14
14
 
15
15
 
16
16
 
17
- ## New Features
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/utils`
31
28
 
32
29
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -42,37 +39,37 @@ npm i ptbk
42
39
  npm install @promptbook/utils
43
40
  ```
44
41
 
45
- Utility functions used in the library but also useful for individual use in preprocessing and postprocessing LLM inputs and outputs
42
+ Utility functions used in the library, but also useful for individual use in pre and post-processing of LLM inputs and outputs.
46
43
 
47
- Here is a overview of the functions which are exported from the `@promptbook/utils` package and can be used in your own projects:
44
+ Here is an overview of the functions that can be exported from the `@promptbook/utils` package and used in your own projects:
48
45
 
49
- ## Postprocessing
46
+ ## Simple templating
50
47
 
51
- Sometimes you need to postprocess the output of the LLM model, every postprocessing function that is available through `POSTPROCESS` command in promptbook is exported from `@promptbook/utils`. You can use:
48
+ The `prompt` template tag function helps format prompt strings for LLM interactions. It handles string interpolation and maintains consistent formatting for multiline strings and lists and also handles a security to avoid **prompt injection**.
52
49
 
53
- - `spaceTrim`
54
- - `extractAllBlocksFromMarkdown`, _<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
55
- - `extractAllListItemsFromMarkdown` _<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
56
- - `extractBlock`
57
- - `extractOneBlockFromMarkdown `_<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
58
- - `prettifyPipelineString`
59
- - `removeMarkdownComments`
60
- - `removeEmojis`
61
- - `removeMarkdownFormatting` _<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
62
- - `removeQuotes`
63
- - `trimCodeBlock`
64
- - `trimEndOfCodeBlock`
65
- - `unwrapResult`
50
+ ```typescript
51
+ import { prompt } from '@promptbook/utils';
66
52
 
67
- Very often you will use `unwrapResult`, which is used to extract the result you need from output with some additional information:
53
+ const promptString = prompt`
54
+ Correct the following sentence:
55
+
56
+ > ${unsecureUserInput}
57
+ `;
58
+ ```
59
+
60
+ The `prompt` name could be overloaded by multiple things in your code. If you want to use the `promptTemplate` which is alias for `prompt`:
68
61
 
69
62
  ```typescript
70
- import { unwrapResult } from '@promptbook/utils';
63
+ import { promptTemplate } from '@promptbook/utils';
71
64
 
72
- unwrapResult('Best greeting for the user is "Hi Pavol!"'); // 'Hi Pavol!'
65
+ const promptString = promptTemplate`
66
+ Correct the following sentence:
67
+
68
+ > ${unsecureUserInput}
69
+ `;
73
70
  ```
74
71
 
75
- ## Templating
72
+ ## Advanced templating
76
73
 
77
74
  There is a function `templateParameters` which is used to replace the parameters in given template optimized to LLM prompt templates.
78
75
 
@@ -152,6 +149,32 @@ console.log(normalizeTo['kebab-case']('Hello, world!')); // 'hello-world'
152
149
  - There are more normalization functions like `capitalize`, `decapitalize`, `removeDiacritics`,...
153
150
  - Theese can be also used as postprocessing functions in the `POSTPROCESS` command in promptbook
154
151
 
152
+ ## Postprocessing
153
+
154
+ Sometimes you need to postprocess the output of the LLM model, every postprocessing function that is available through `POSTPROCESS` command in promptbook is exported from `@promptbook/utils`. You can use:
155
+
156
+ - `spaceTrim`
157
+ - `extractAllBlocksFromMarkdown`, _<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
158
+ - `extractAllListItemsFromMarkdown` _<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
159
+ - `extractBlock`
160
+ - `extractOneBlockFromMarkdown `_<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
161
+ - `prettifyPipelineString`
162
+ - `removeMarkdownComments`
163
+ - `removeEmojis`
164
+ - `removeMarkdownFormatting` _<- Note: Exported from [`@promptbook/markdown-utils`](https://www.npmjs.com/package/@promptbook/markdown-utils)_
165
+ - `removeQuotes`
166
+ - `trimCodeBlock`
167
+ - `trimEndOfCodeBlock`
168
+ - `unwrapResult`
169
+
170
+ Very often you will use `unwrapResult`, which is used to extract the result you need from output with some additional information:
171
+
172
+ ```typescript
173
+ import { unwrapResult } from '@promptbook/utils';
174
+
175
+ unwrapResult('Best greeting for the user is "Hi Pavol!"'); // 'Hi Pavol!'
176
+ ```
177
+
155
178
  ## Misc
156
179
 
157
180
  See also the documentation for all the functions in the `@promptbook/utils` package, every function is documented by jsdoc, typed by typescript and tested by jest.
@@ -384,8 +407,9 @@ Or you can install them separately:
384
407
  - **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
385
408
  - **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
386
409
  - **[@promptbook/google](https://www.npmjs.com/package/@promptbook/google)** - Integration with Google's Gemini API
410
+ - **[@promptbook/deepseek](https://www.npmjs.com/package/@promptbook/deepseek)** - Integration with [DeepSeek API](https://www.deepseek.com/)
387
411
  - **[@promptbook/azure-openai](https://www.npmjs.com/package/@promptbook/azure-openai)** - Execution tools for Azure OpenAI API
388
- - **[@promptbook/langtail](https://www.npmjs.com/package/@promptbook/langtail)** - Execution tools for Langtail API, wrapper around Langtail SDK
412
+
389
413
  - **[@promptbook/fake-llm](https://www.npmjs.com/package/@promptbook/fake-llm)** - Mocked execution tools for testing the library and saving the tokens
390
414
  - **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
391
415
  - **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
@@ -555,6 +579,20 @@ See [TODO.md](./TODO.md)
555
579
 
556
580
 
557
581
 
582
+ ## 🤝 Partners
583
+
584
+ <div style="display: flex; align-items: center; gap: 20px;">
585
+
586
+ <a href="https://promptbook.studio/">
587
+ <img src="./other/design/promptbook-studio-logo.png" alt="Partner 3" height="100">
588
+ </a>
589
+
590
+ <a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
591
+ <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
592
+ </a>
593
+
594
+ </div>
595
+
558
596
  ## 🖋️ Contributing
559
597
 
560
598
  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
@@ -15,7 +15,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
15
15
  * @generated
16
16
  * @see https://github.com/webgptorg/promptbook
17
17
  */
18
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
18
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
19
19
  /**
20
20
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
21
21
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1729,13 +1729,14 @@ function templateParameters(template, parameters) {
1729
1729
  /**
1730
1730
  * Tag function for notating a prompt as template literal
1731
1731
  *
1732
- * Note: There are 2 similar functions:
1732
+ * Note: There are 3 similar functions:
1733
1733
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
1734
- * 1) `book` for notating and validating entire books exported from `@promptbook/utils`
1734
+ * 2) `promptTemplate` alias for `prompt`
1735
+ * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
1735
1736
  *
1736
- * @param strings @@@
1737
- * @param values @@@
1738
- * @returns the pipeline string
1737
+ * @param strings
1738
+ * @param values
1739
+ * @returns the prompt string
1739
1740
  * @public exported from `@promptbook/utils`
1740
1741
  */
1741
1742
  function prompt(strings) {
@@ -1746,10 +1747,14 @@ function prompt(strings) {
1746
1747
  if (values.length === 0) {
1747
1748
  return spaceTrim$1(strings.join(''));
1748
1749
  }
1750
+ var stringsWithHiddenParameters = strings.map(function (stringsItem) {
1751
+ // TODO: [0] DRY
1752
+ return stringsItem.split('{').join("".concat(REPLACING_NONCE, "beginbracket")).split('}').join("".concat(REPLACING_NONCE, "endbracket"));
1753
+ });
1749
1754
  var placeholderParameterNames = values.map(function (value, i) { return "".concat(REPLACING_NONCE).concat(i); });
1750
1755
  var parameters = Object.fromEntries(values.map(function (value, i) { return [placeholderParameterNames[i], value]; }));
1751
1756
  // Combine strings and values
1752
- var pipelineString = strings.reduce(function (result, stringsItem, i) {
1757
+ var pipelineString = stringsWithHiddenParameters.reduce(function (result, stringsItem, i) {
1753
1758
  return placeholderParameterNames[i] === undefined
1754
1759
  ? "".concat(result).concat(stringsItem)
1755
1760
  : "".concat(result).concat(stringsItem, "{").concat(placeholderParameterNames[i], "}");
@@ -1765,8 +1770,26 @@ function prompt(strings) {
1765
1770
  console.error({ pipelineString: pipelineString, parameters: parameters, placeholderParameterNames: placeholderParameterNames, error: error });
1766
1771
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Internal error in prompt template literal\n \n ".concat(block(JSON.stringify({ strings: strings, values: values }, null, 4)), "}\n \n "); }));
1767
1772
  }
1773
+ // TODO: [0] DRY
1774
+ pipelineString = pipelineString
1775
+ .split("".concat(REPLACING_NONCE, "beginbracket"))
1776
+ .join('{')
1777
+ .split("".concat(REPLACING_NONCE, "endbracket"))
1778
+ .join('}');
1768
1779
  return pipelineString;
1769
1780
  }
1781
+ /**
1782
+ * Tag function for notating a prompt as template literal
1783
+ *
1784
+ * Note: There are 3 similar functions:
1785
+ * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
1786
+ * 2) `promptTemplate` alias for `prompt`
1787
+ * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
1788
+ *
1789
+ * @alias prompt
1790
+ * @public exported from `@promptbook/utils`
1791
+ */
1792
+ var promptTemplate = prompt;
1770
1793
  /**
1771
1794
  * TODO: [🧠][🈴] Where is the best location for this file
1772
1795
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1792,6 +1815,9 @@ function $getCurrentDate() {
1792
1815
  * @public exported from `@promptbook/utils`
1793
1816
  */
1794
1817
  var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
1818
+ /**
1819
+ * TODO: [☑]
1820
+ */
1795
1821
 
1796
1822
  /**
1797
1823
  * Detects if the code is running in jest environment
@@ -1801,6 +1827,9 @@ var $isRunningInBrowser = new Function("\n try {\n return this === win
1801
1827
  * @public exported from `@promptbook/utils`
1802
1828
  */
1803
1829
  var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
1830
+ /**
1831
+ * TODO: [☑]
1832
+ */
1804
1833
 
1805
1834
  /**
1806
1835
  * Detects if the code is running in a Node.js environment
@@ -1810,6 +1839,9 @@ var $isRunningInJest = new Function("\n try {\n return process.env.JES
1810
1839
  * @public exported from `@promptbook/utils`
1811
1840
  */
1812
1841
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
1842
+ /**
1843
+ * TODO: [☑]
1844
+ */
1813
1845
 
1814
1846
  /**
1815
1847
  * Detects if the code is running in a web worker
@@ -1819,6 +1851,9 @@ var $isRunningInNode = new Function("\n try {\n return this === global
1819
1851
  * @public exported from `@promptbook/utils`
1820
1852
  */
1821
1853
  var $isRunningInWebWorker = new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
1854
+ /**
1855
+ * TODO: [☑]
1856
+ */
1822
1857
 
1823
1858
  /**
1824
1859
  * Number of characters per standard line with 11pt Arial font size.
@@ -2617,6 +2652,9 @@ function isValidEmail(email) {
2617
2652
  if (typeof email !== 'string') {
2618
2653
  return false;
2619
2654
  }
2655
+ if (email.split('\n').length > 1) {
2656
+ return false;
2657
+ }
2620
2658
  return /^.+@.+\..+$/.test(email);
2621
2659
  }
2622
2660
 
@@ -2787,5 +2825,5 @@ function isValidUuid(value) {
2787
2825
  return /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i.test(value);
2788
2826
  }
2789
2827
 
2790
- export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, SMALL_NUMBER, VALUE_STRINGS, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, exportJson, extractParameterNames, extractVariablesFromScript, forEachAsync, intersection, isHostnameOnPrivateNetwork, isRootPath, isSerializableAsJson, isUrlOnPrivateNetwork, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, numberToString, orderJson, parseKeywords, parseKeywordsFromString, parseNumber, prompt, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, searchKeywords, serializeError, spaceTrim, splitIntoSentences, templateParameters, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult, valueToString };
2828
+ export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, SMALL_NUMBER, VALUE_STRINGS, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, exportJson, extractParameterNames, extractVariablesFromScript, forEachAsync, intersection, isHostnameOnPrivateNetwork, isRootPath, isSerializableAsJson, isUrlOnPrivateNetwork, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, numberToString, orderJson, parseKeywords, parseKeywordsFromString, parseNumber, prompt, promptTemplate, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, searchKeywords, serializeError, spaceTrim, splitIntoSentences, templateParameters, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult, valueToString };
2791
2829
  //# sourceMappingURL=index.es.js.map