@promptbook/openai 0.71.0-0 → 0.71.0-13

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 (195) hide show
  1. package/README.md +65 -62
  2. package/esm/index.es.js +139 -13
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/browser.index.d.ts +3 -1
  5. package/esm/typings/src/_packages/cli.index.d.ts +20 -0
  6. package/esm/typings/src/_packages/core.index.d.ts +36 -14
  7. package/esm/typings/src/_packages/documents.index.d.ts +8 -0
  8. package/esm/typings/src/_packages/legacy-documents.index.d.ts +8 -0
  9. package/esm/typings/src/_packages/markdown-utils.index.d.ts +6 -0
  10. package/esm/typings/src/_packages/node.index.d.ts +14 -6
  11. package/esm/typings/src/_packages/pdf.index.d.ts +8 -0
  12. package/esm/typings/src/_packages/types.index.d.ts +41 -25
  13. package/esm/typings/src/_packages/website-crawler.index.d.ts +8 -0
  14. package/esm/typings/src/cli/cli-commands/about.d.ts +1 -1
  15. package/esm/typings/src/cli/cli-commands/hello.d.ts +2 -1
  16. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  17. package/esm/typings/src/cli/cli-commands/prettify.d.ts +2 -1
  18. package/esm/typings/src/cli/cli-commands/test-command.d.ts +13 -0
  19. package/esm/typings/src/cli/main.d.ts +1 -1
  20. package/esm/typings/src/cli/promptbookCli.d.ts +1 -1
  21. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -6
  22. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
  23. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +1 -1
  24. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +5 -1
  25. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
  26. package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +1 -1
  27. package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +1 -1
  28. package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +1 -1
  29. package/esm/typings/src/commands/KNOWLEDGE/utils/sourceContentToName.d.ts +11 -0
  30. package/esm/typings/src/commands/KNOWLEDGE/utils/sourceContentToName.test.d.ts +4 -0
  31. package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +1 -1
  32. package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +1 -1
  33. package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +1 -1
  34. package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +1 -1
  35. package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +1 -1
  36. package/esm/typings/src/commands/TEMPLATE/templateCommandParser.d.ts +1 -1
  37. package/esm/typings/src/commands/URL/urlCommandParser.d.ts +1 -1
  38. package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +1 -1
  39. package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +1 -1
  40. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
  41. package/esm/typings/src/config.d.ts +16 -0
  42. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +4 -15
  43. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -1
  44. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +1 -1
  45. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +5 -5
  46. package/esm/typings/src/{knowledge/dialogs → dialogs}/callback/CallbackInterfaceTools.d.ts +2 -2
  47. package/esm/typings/src/{knowledge/dialogs → dialogs}/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
  48. package/esm/typings/src/{knowledge/dialogs → dialogs}/simple-prompt/SimplePromptInterfaceTools.d.ts +5 -5
  49. package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
  50. package/esm/typings/src/errors/KnowledgeScrapeError.d.ts +9 -0
  51. package/esm/typings/src/errors/MissingToolsError.d.ts +9 -0
  52. package/esm/typings/src/execution/{CommonExecutionToolsOptions.d.ts → CommonToolsOptions.d.ts} +1 -1
  53. package/esm/typings/src/execution/ExecutionTools.d.ts +20 -8
  54. package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -0
  55. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +5 -2
  56. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +2 -13
  57. package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +3 -0
  58. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +5 -2
  59. package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -6
  60. package/esm/typings/src/execution/createPipelineExecutor/{30-executeFormatCells.d.ts → 30-executeFormatSubvalues.d.ts} +2 -6
  61. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -6
  62. package/esm/typings/src/execution/embeddingVectorToString.d.ts +1 -1
  63. package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +3 -0
  64. package/esm/typings/src/execution/utils/$provideExecutionToolsForNode.d.ts +13 -0
  65. package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -0
  66. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -1
  67. package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
  68. package/esm/typings/src/llm-providers/_common/{$llmToolsMetadataRegister.d.ts → register/$llmToolsMetadataRegister.d.ts} +4 -1
  69. package/esm/typings/src/llm-providers/_common/{$llmToolsRegister.d.ts → register/$llmToolsRegister.d.ts} +5 -2
  70. package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfigurationFromEnv.d.ts → register/$provideLlmToolsConfigurationFromEnv.d.ts} +3 -3
  71. package/esm/typings/src/llm-providers/_common/{getLlmToolsForCli.d.ts → register/$provideLlmToolsForCli.d.ts} +4 -3
  72. package/esm/typings/src/llm-providers/_common/{getLlmToolsForTestingAndScriptsAndPlayground.d.ts → register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts} +4 -3
  73. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +27 -0
  74. package/esm/typings/src/llm-providers/_common/{$registeredLlmToolsMessage.d.ts → register/$registeredLlmToolsMessage.d.ts} +5 -2
  75. package/esm/typings/src/llm-providers/_common/{LlmToolsConfiguration.d.ts → register/LlmToolsConfiguration.d.ts} +5 -4
  76. package/esm/typings/src/llm-providers/_common/{LlmToolsMetadata.d.ts → register/LlmToolsMetadata.d.ts} +5 -4
  77. package/esm/typings/src/llm-providers/_common/{LlmToolsOptions.d.ts → register/LlmToolsOptions.d.ts} +4 -1
  78. package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfiguration.d.ts → register/createLlmToolsFromConfiguration.d.ts} +5 -4
  79. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
  80. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -3
  81. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -2
  82. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +4 -3
  83. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +4 -3
  84. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +8 -1
  85. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -2
  86. package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +1 -0
  87. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +4 -3
  88. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +4 -3
  89. package/esm/typings/src/llm-providers/langtail/playground/playground.d.ts +3 -0
  90. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
  91. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +2 -2
  92. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +1 -0
  93. package/esm/typings/src/llm-providers/multiple/playground/playground.d.ts +3 -0
  94. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -1
  95. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
  96. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +2 -1
  97. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +4 -3
  98. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +4 -3
  99. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +1 -1
  100. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +1 -1
  101. package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +3 -3
  102. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +2 -2
  103. package/esm/typings/src/llm-providers/remote/playground/playground.d.ts +3 -0
  104. package/esm/typings/src/personas/preparePersona.d.ts +3 -2
  105. package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +68 -0
  106. package/esm/typings/src/prepare/preparePipeline.d.ts +3 -2
  107. package/esm/typings/src/prepare/prepareTemplates.d.ts +3 -2
  108. package/esm/typings/src/scrapers/_common/Converter.d.ts +22 -0
  109. package/esm/typings/src/scrapers/_common/Scraper.d.ts +66 -0
  110. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +11 -0
  111. package/esm/typings/src/{knowledge/prepare-knowledge → scrapers}/_common/prepareKnowledgePieces.d.ts +5 -4
  112. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +12 -0
  113. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +15 -0
  114. package/esm/typings/src/scrapers/_common/register/$registeredScrapersMessage.d.ts +12 -0
  115. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +13 -0
  116. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +13 -0
  117. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +41 -0
  118. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +12 -0
  119. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +33 -0
  120. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.test.d.ts +4 -0
  121. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +13 -0
  122. package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +43 -0
  123. package/esm/typings/src/scrapers/document/DocumentScraper.test.d.ts +4 -0
  124. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +20 -0
  125. package/esm/typings/src/scrapers/document/playground/document-scraper-playground.d.ts +5 -0
  126. package/esm/typings/src/scrapers/document/register-constructor.d.ts +13 -0
  127. package/esm/typings/src/scrapers/document/register-metadata.d.ts +24 -0
  128. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +43 -0
  129. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.test.d.ts +4 -0
  130. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +20 -0
  131. package/esm/typings/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.d.ts +5 -0
  132. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +13 -0
  133. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +24 -0
  134. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +29 -0
  135. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +20 -0
  136. package/esm/typings/src/scrapers/markdown/playground/markdown-scraper-playground.d.ts +5 -0
  137. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +13 -0
  138. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +24 -0
  139. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +40 -0
  140. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +20 -0
  141. package/esm/typings/src/scrapers/pdf/playground/pdf-scraper-playground.d.ts +5 -0
  142. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +13 -0
  143. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +24 -0
  144. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +47 -0
  145. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +20 -0
  146. package/esm/typings/src/scrapers/website/playground/website-scraper-playground.d.ts +5 -0
  147. package/esm/typings/src/scrapers/website/register-constructor.d.ts +13 -0
  148. package/esm/typings/src/scrapers/website/register-metadata.d.ts +24 -0
  149. package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +12 -0
  150. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
  151. package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +2 -2
  152. package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +2 -2
  153. package/esm/typings/src/storage/{files-storage/FilesStorage.d.ts → file-cache-storage/FileCacheStorage.d.ts} +4 -4
  154. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +10 -0
  155. package/esm/typings/src/storage/{files-storage → file-cache-storage}/utils/nameToSubfolderPath.d.ts +1 -1
  156. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  157. package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +1 -1
  158. package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +1 -1
  159. package/esm/typings/src/storage/{utils → memory/utils}/PrefixStorage.d.ts +1 -1
  160. package/esm/typings/src/storage/{utils → memory/utils}/makePromptbookStorageFromWebStorage.d.ts +1 -1
  161. package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -1
  162. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -2
  163. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +0 -3
  164. package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -1
  165. package/esm/typings/src/types/typeAliases.d.ts +16 -12
  166. package/esm/typings/src/utils/$Register.d.ts +19 -6
  167. package/esm/typings/src/utils/execCommand/$execCommand.d.ts +14 -0
  168. package/esm/typings/src/utils/execCommand/$execCommands.d.ts +17 -0
  169. package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +23 -0
  170. package/esm/typings/src/utils/execCommand/execCommand.test.d.ts +1 -0
  171. package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +10 -0
  172. package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.test.d.ts +1 -0
  173. package/esm/typings/src/utils/files/$isDirectoryExisting.d.ts +3 -3
  174. package/esm/typings/src/utils/files/$isFileExisting.d.ts +3 -3
  175. package/esm/typings/src/utils/files/$listAllFiles.d.ts +5 -4
  176. package/esm/typings/src/utils/files/extensionToMimeType.d.ts +8 -0
  177. package/esm/typings/src/utils/files/extensionToMimeType.test.d.ts +1 -0
  178. package/esm/typings/src/utils/files/getFileExtension.d.ts +8 -0
  179. package/esm/typings/src/utils/files/getFileExtension.test.d.ts +1 -0
  180. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -2
  181. package/package.json +2 -2
  182. package/umd/index.umd.js +139 -13
  183. package/umd/index.umd.js.map +1 -1
  184. package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +0 -37
  185. package/esm/typings/src/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +0 -2
  186. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +0 -14
  187. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +0 -15
  188. package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +0 -25
  189. package/esm/typings/src/prepare/PrepareOptions.d.ts +0 -22
  190. package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +0 -10
  191. /package/esm/typings/src/{knowledge/dialogs → dialogs}/user-interface-execution-tools.test.d.ts +0 -0
  192. /package/esm/typings/src/{knowledge/prepare-knowledge → scrapers}/_common/prepareKnowledgePieces.test.d.ts +0 -0
  193. /package/esm/typings/src/{knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts → scrapers/markdown/MarkdownScraper.test.d.ts} +0 -0
  194. /package/esm/typings/src/{knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts → scrapers/website/WebsiteScraper.test.d.ts} +0 -0
  195. /package/esm/typings/src/{storage/files-storage/utils/nameToSubfolderPath.test.d.ts → scrapers/website/utils/markdownConverter.test.d.ts} +0 -0
package/README.md CHANGED
@@ -20,6 +20,12 @@ Supercharge your use of large language models
20
20
 
21
21
  - ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
22
22
 
23
+ <blockquote style="color: #ff8811">
24
+ <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>.
25
+ </blockquote>
26
+
27
+
28
+
23
29
  ## 📦 Package `@promptbook/openai`
24
30
 
25
31
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -42,30 +48,30 @@ npm install @promptbook/openai
42
48
  ```typescript
43
49
  import { createPipelineExecutor, assertsExecutionSuccessful } from '@promptbook/core';
44
50
  import { createCollectionFromDirectory } from '@promptbook/node';
51
+ import { $provideExecutionToolsForNode } from '@promptbook/node';
45
52
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
46
53
  import { OpenAiExecutionTools } from '@promptbook/openai';
47
54
 
55
+ // ▶ Prepare tools
56
+ const llm = new OpenAiExecutionTools(
57
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
58
+ {
59
+ isVerbose: true,
60
+ apiKey: process.env.OPENAI_API_KEY,
61
+ },
62
+ );
63
+ const tools = {
64
+ llm,
65
+ scrapers: await $provideScrapersForNode({ llm }),
66
+ script: [new JavascriptExecutionTools()],
67
+ };
68
+
48
69
  // ▶ Create whole pipeline collection
49
- const collection = await createCollectionFromDirectory('./promptbook-collection');
70
+ const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
50
71
 
51
72
  // ▶ Get single Pipeline
52
73
  const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
53
74
 
54
- // ▶ Prepare tools
55
- const tools = {
56
- llm: new OpenAiExecutionTools(
57
- // <- TODO: [🧱] Implement in a functional (not new Class) way
58
- {
59
- isVerbose: true,
60
- apiKey: process.env.OPENAI_API_KEY,
61
- },
62
- ),
63
- script: [
64
- new JavascriptExecutionTools(),
65
- // <- TODO: [🧱] Implement in a functional (not new Class) way
66
- ],
67
- };
68
-
69
75
  // ▶ Create executor - the function that will execute the Pipeline
70
76
  const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
71
77
 
@@ -85,29 +91,22 @@ console.info(outputParameters);
85
91
 
86
92
  ## 🧙‍♂️ Connect to LLM providers automatically
87
93
 
88
- You can just use `createLlmToolsFromEnv` function to create LLM tools from environment variables like `OPENAI_API_KEY` and `ANTHROPIC_CLAUDE_API_KEY` automatically.
94
+ You can just use `$provideExecutionToolsForNode` function to create all required tools from environment variables like `OPENAI_API_KEY` and `ANTHROPIC_CLAUDE_API_KEY` automatically.
89
95
 
90
96
  ```typescript
91
97
  import { createPipelineExecutor, createCollectionFromDirectory, assertsExecutionSuccessful } from '@promptbook/core';
92
98
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
93
- import { createLlmToolsFromEnv } from '@promptbook/node';
99
+ import { $provideExecutionToolsForNode } from '@promptbook/node';
100
+
101
+ // ▶ Prepare tools
102
+ const tools = await $provideExecutionToolsForNode();
94
103
 
95
104
  // ▶ Create whole pipeline collection
96
- const collection = await createCollectionFromDirectory('./promptbook-collection');
105
+ const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
97
106
 
98
107
  // ▶ Get single Pipeline
99
108
  const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
100
109
 
101
- // ▶ Prepare multiple tools
102
- const tools = {
103
- // Note: 🧙‍♂️ Just call `createLlmToolsFromEnv` to automatically connect to all configured providers
104
- llm: createLlmToolsFromEnv(),
105
- script: [
106
- new JavascriptExecutionTools(),
107
- // <- TODO: [🧱] Implement in a functional (not new Class) way
108
- ],
109
- };
110
-
111
110
  // ▶ Create executor - the function that will execute the Pipeline
112
111
  const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
113
112
 
@@ -132,49 +131,49 @@ You can use multiple LLM providers in one Promptbook execution. The best model w
132
131
  ```typescript
133
132
  import { createPipelineExecutor, assertsExecutionSuccessful } from '@promptbook/core';
134
133
  import { createCollectionFromDirectory } from '@promptbook/node';
134
+ import { $provideExecutionToolsForNode } from '@promptbook/node';
135
135
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
136
136
  import { OpenAiExecutionTools } from '@promptbook/openai';
137
137
  import { AnthropicClaudeExecutionTools } from '@promptbook/anthropic-claude';
138
138
  import { AzureOpenAiExecutionTools } from '@promptbook/azure-openai';
139
139
 
140
+ // ▶ Prepare multiple tools
141
+ const llm = [
142
+ // Note: You can use multiple LLM providers in one Promptbook execution.
143
+ // The best model will be chosen automatically according to the prompt and the model's capabilities.
144
+ new OpenAiExecutionTools(
145
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
146
+ {
147
+ apiKey: process.env.OPENAI_API_KEY,
148
+ },
149
+ ),
150
+ new AnthropicClaudeExecutionTools(
151
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
152
+ {
153
+ apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
154
+ },
155
+ ),
156
+ new AzureOpenAiExecutionTools(
157
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
158
+ {
159
+ resourceName: process.env.AZUREOPENAI_RESOURCE_NAME,
160
+ deploymentName: process.env.AZUREOPENAI_DEPLOYMENT_NAME,
161
+ apiKey: process.env.AZUREOPENAI_API_KEY,
162
+ },
163
+ ),
164
+ ];
165
+ const tools = {
166
+ llm,
167
+ scrapers: await $provideScrapersForNode({ llm }),
168
+ script: [new JavascriptExecutionTools()],
169
+ };
170
+
140
171
  // ▶ Create whole pipeline collection
141
- const collection = await createCollectionFromDirectory('./promptbook-collection');
172
+ const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
142
173
 
143
174
  // ▶ Get single Pipeline
144
175
  const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
145
176
 
146
- // ▶ Prepare multiple tools
147
- const tools = {
148
- llm: [
149
- // Note: You can use multiple LLM providers in one Promptbook execution.
150
- // The best model will be chosen automatically according to the prompt and the model's capabilities.
151
- new OpenAiExecutionTools(
152
- // <- TODO: [🧱] Implement in a functional (not new Class) way
153
- {
154
- apiKey: process.env.OPENAI_API_KEY,
155
- },
156
- ),
157
- new AnthropicClaudeExecutionTools(
158
- // <- TODO: [🧱] Implement in a functional (not new Class) way
159
- {
160
- apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
161
- },
162
- ),
163
- new AzureOpenAiExecutionTools(
164
- // <- TODO: [🧱] Implement in a functional (not new Class) way
165
- {
166
- resourceName: process.env.AZUREOPENAI_RESOURCE_NAME,
167
- deploymentName: process.env.AZUREOPENAI_DEPLOYMENT_NAME,
168
- apiKey: process.env.AZUREOPENAI_API_KEY,
169
- },
170
- ),
171
- ],
172
- script: [
173
- new JavascriptExecutionTools(),
174
- // <- TODO: [🧱] Implement in a functional (not new Class) way
175
- ],
176
- };
177
-
178
177
  // ▶ Create executor - the function that will execute the Pipeline
179
178
  const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
180
179
 
@@ -490,6 +489,10 @@ Or you can install them separately:
490
489
  - **[@promptbook/fake-llm](https://www.npmjs.com/package/@promptbook/fake-llm)** - Mocked execution tools for testing the library and saving the tokens
491
490
  - **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
492
491
  - **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
492
+ - **[@promptbook/pdf](https://www.npmjs.com/package/@promptbook/pdf)** - Read knowledge from `.pdf` documents
493
+ - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
494
+ - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
495
+ - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
493
496
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
494
497
  - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
495
498
 
package/esm/index.es.js CHANGED
@@ -6,8 +6,8 @@ import spaceTrim$1, { spaceTrim } from 'spacetrim';
6
6
  /**
7
7
  * The version of the Promptbook library
8
8
  */
9
- var PROMPTBOOK_VERSION = '0.70.0-1';
10
- // TODO:[main] !!!! List here all the versions and annotate + put into script
9
+ var PROMPTBOOK_VERSION = '0.71.0-12';
10
+ // TODO: [main] !!!! List here all the versions and annotate + put into script
11
11
 
12
12
  /*! *****************************************************************************
13
13
  Copyright (c) Microsoft Corporation.
@@ -1209,7 +1209,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
1209
1209
  prompt: computeUsage("$5.00 / 1M tokens"),
1210
1210
  output: computeUsage("$15.00 / 1M tokens"),
1211
1211
  },
1212
- //TODO:[main] !!!!!! Add gpt-4o-mini-2024-07-18 and all others to be up to date
1212
+ //TODO: [main] !!! Add gpt-4o-mini-2024-07-18 and all others to be up to date
1213
1213
  },
1214
1214
  /**/
1215
1215
  /**/
@@ -1239,7 +1239,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
1239
1239
  modelVariant: 'CHAT',
1240
1240
  modelTitle: 'o1-preview-2024-09-12',
1241
1241
  modelName: 'o1-preview-2024-09-12',
1242
- // <- TODO:[main] !!!!!! Some better system to organize theese date suffixes and versions
1242
+ // <- TODO: [main] !!! Some better system to organize theese date suffixes and versions
1243
1243
  pricing: {
1244
1244
  prompt: computeUsage("$15.00 / 1M tokens"),
1245
1245
  output: computeUsage("$60.00 / 1M tokens"),
@@ -1413,6 +1413,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
1413
1413
  OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
1414
1414
  return __awaiter(this, void 0, void 0, function () {
1415
1415
  var content, parameters, modelRequirements, format, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
1416
+ var _this = this;
1416
1417
  return __generator(this, function (_a) {
1417
1418
  switch (_a.label) {
1418
1419
  case 0:
@@ -1459,7 +1460,12 @@ var OpenAiExecutionTools = /** @class */ (function () {
1459
1460
  if (this.options.isVerbose) {
1460
1461
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1461
1462
  }
1462
- return [4 /*yield*/, client.chat.completions.create(rawRequest)];
1463
+ return [4 /*yield*/, client.chat.completions.create(rawRequest).catch(function (error) {
1464
+ if (_this.options.isVerbose) {
1465
+ console.info(colors.bgRed('error'), error);
1466
+ }
1467
+ throw error;
1468
+ })];
1463
1469
  case 2:
1464
1470
  rawResponse = _a.sent();
1465
1471
  if (this.options.isVerbose) {
@@ -1502,6 +1508,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
1502
1508
  OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
1503
1509
  return __awaiter(this, void 0, void 0, function () {
1504
1510
  var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
1511
+ var _this = this;
1505
1512
  return __generator(this, function (_a) {
1506
1513
  switch (_a.label) {
1507
1514
  case 0:
@@ -1531,7 +1538,12 @@ var OpenAiExecutionTools = /** @class */ (function () {
1531
1538
  if (this.options.isVerbose) {
1532
1539
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1533
1540
  }
1534
- return [4 /*yield*/, client.completions.create(rawRequest)];
1541
+ return [4 /*yield*/, client.completions.create(rawRequest).catch(function (error) {
1542
+ if (_this.options.isVerbose) {
1543
+ console.info(colors.bgRed('error'), error);
1544
+ }
1545
+ throw error;
1546
+ })];
1535
1547
  case 2:
1536
1548
  rawResponse = _a.sent();
1537
1549
  if (this.options.isVerbose) {
@@ -1571,6 +1583,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
1571
1583
  OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
1572
1584
  return __awaiter(this, void 0, void 0, function () {
1573
1585
  var content, parameters, modelRequirements, client, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
1586
+ var _this = this;
1574
1587
  return __generator(this, function (_a) {
1575
1588
  switch (_a.label) {
1576
1589
  case 0:
@@ -1595,7 +1608,12 @@ var OpenAiExecutionTools = /** @class */ (function () {
1595
1608
  if (this.options.isVerbose) {
1596
1609
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1597
1610
  }
1598
- return [4 /*yield*/, client.embeddings.create(rawRequest)];
1611
+ return [4 /*yield*/, client.embeddings.create(rawRequest).catch(function (error) {
1612
+ if (_this.options.isVerbose) {
1613
+ console.info(colors.bgRed('error'), error);
1614
+ }
1615
+ throw error;
1616
+ })];
1599
1617
  case 2:
1600
1618
  rawResponse = _a.sent();
1601
1619
  if (this.options.isVerbose) {
@@ -1694,6 +1712,22 @@ var createOpenAiExecutionTools = Object.assign(function (options) {
1694
1712
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
1695
1713
  */
1696
1714
 
1715
+ /**
1716
+ * This error type indicates that some part of the code is not implemented yet
1717
+ *
1718
+ * @public exported from `@promptbook/core`
1719
+ */
1720
+ var NotYetImplementedError = /** @class */ (function (_super) {
1721
+ __extends(NotYetImplementedError, _super);
1722
+ function NotYetImplementedError(message) {
1723
+ var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
1724
+ _this.name = 'NotYetImplementedError';
1725
+ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
1726
+ return _this;
1727
+ }
1728
+ return NotYetImplementedError;
1729
+ }(Error));
1730
+
1697
1731
  /**
1698
1732
  * @@@
1699
1733
  *
@@ -1705,6 +1739,85 @@ function $getGlobalScope() {
1705
1739
  return Function('return this')();
1706
1740
  }
1707
1741
 
1742
+ /**
1743
+ * @@@
1744
+ *
1745
+ * @param text @@@
1746
+ * @returns @@@
1747
+ * @example 'HELLO_WORLD'
1748
+ * @example 'I_LOVE_PROMPTBOOK'
1749
+ * @public exported from `@promptbook/utils`
1750
+ */
1751
+ function normalizeTo_SCREAMING_CASE(text) {
1752
+ var e_1, _a;
1753
+ var charType;
1754
+ var lastCharType = 'OTHER';
1755
+ var normalizedName = '';
1756
+ try {
1757
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
1758
+ var char = text_1_1.value;
1759
+ var normalizedChar = void 0;
1760
+ if (/^[a-z]$/.test(char)) {
1761
+ charType = 'LOWERCASE';
1762
+ normalizedChar = char.toUpperCase();
1763
+ }
1764
+ else if (/^[A-Z]$/.test(char)) {
1765
+ charType = 'UPPERCASE';
1766
+ normalizedChar = char;
1767
+ }
1768
+ else if (/^[0-9]$/.test(char)) {
1769
+ charType = 'NUMBER';
1770
+ normalizedChar = char;
1771
+ }
1772
+ else {
1773
+ charType = 'OTHER';
1774
+ normalizedChar = '_';
1775
+ }
1776
+ if (charType !== lastCharType &&
1777
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1778
+ !(lastCharType === 'NUMBER') &&
1779
+ !(charType === 'NUMBER')) {
1780
+ normalizedName += '_';
1781
+ }
1782
+ normalizedName += normalizedChar;
1783
+ lastCharType = charType;
1784
+ }
1785
+ }
1786
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1787
+ finally {
1788
+ try {
1789
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
1790
+ }
1791
+ finally { if (e_1) throw e_1.error; }
1792
+ }
1793
+ normalizedName = normalizedName.replace(/_+/g, '_');
1794
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1795
+ normalizedName = normalizedName.replace(/^_/, '');
1796
+ normalizedName = normalizedName.replace(/_$/, '');
1797
+ return normalizedName;
1798
+ }
1799
+ /**
1800
+ * TODO: Tests
1801
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1802
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1803
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1804
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1805
+ * TODO: [🌺] Use some intermediate util splitWords
1806
+ */
1807
+
1808
+ /**
1809
+ * @@@
1810
+ *
1811
+ * @param text @@@
1812
+ * @returns @@@
1813
+ * @example 'hello_world'
1814
+ * @example 'i_love_promptbook'
1815
+ * @public exported from `@promptbook/utils`
1816
+ */
1817
+ function normalizeTo_snake_case(text) {
1818
+ return normalizeTo_SCREAMING_CASE(text).toLowerCase();
1819
+ }
1820
+
1708
1821
  /**
1709
1822
  * Register is @@@
1710
1823
  *
@@ -1713,9 +1826,9 @@ function $getGlobalScope() {
1713
1826
  * @private internal utility, exported are only signleton instances of this class
1714
1827
  */
1715
1828
  var $Register = /** @class */ (function () {
1716
- function $Register(storageName) {
1717
- this.storageName = storageName;
1718
- storageName = "_promptbook_".concat(storageName);
1829
+ function $Register(registerName) {
1830
+ this.registerName = registerName;
1831
+ var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
1719
1832
  var globalScope = $getGlobalScope();
1720
1833
  if (globalScope[storageName] === undefined) {
1721
1834
  globalScope[storageName] = [];
@@ -1730,7 +1843,6 @@ var $Register = /** @class */ (function () {
1730
1843
  return this.storage;
1731
1844
  };
1732
1845
  $Register.prototype.register = function (registered) {
1733
- // <- TODO: What to return here
1734
1846
  var packageName = registered.packageName, className = registered.className;
1735
1847
  var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
1736
1848
  var existingRegistration = this.storage[existingRegistrationIndex];
@@ -1740,6 +1852,17 @@ var $Register = /** @class */ (function () {
1740
1852
  else {
1741
1853
  this.storage[existingRegistrationIndex] = registered;
1742
1854
  }
1855
+ return {
1856
+ registerName: this.registerName,
1857
+ packageName: packageName,
1858
+ className: className,
1859
+ get isDestroyed() {
1860
+ return false;
1861
+ },
1862
+ destroy: function () {
1863
+ throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
1864
+ },
1865
+ };
1743
1866
  };
1744
1867
  return $Register;
1745
1868
  }());
@@ -1752,11 +1875,14 @@ var $Register = /** @class */ (function () {
1752
1875
  * @public exported from `@promptbook/core`
1753
1876
  */
1754
1877
  var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
1878
+ /**
1879
+ * TODO: [®] DRY Register logic
1880
+ */
1755
1881
 
1756
1882
  /**
1757
- * @@@ registration2
1883
+ * Registration of LLM provider
1758
1884
  *
1759
- * Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
1885
+ * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
1760
1886
  *
1761
1887
  * @public exported from `@promptbook/openai`
1762
1888
  * @public exported from `@promptbook/cli`