@promptbook/anthropic-claude 0.72.0-8 → 0.72.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 (196) hide show
  1. package/README.md +75 -71
  2. package/esm/index.es.js +110 -12
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/browser.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/cli.index.d.ts +20 -0
  6. package/esm/typings/src/_packages/core.index.d.ts +42 -30
  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 +12 -4
  11. package/esm/typings/src/_packages/pdf.index.d.ts +8 -0
  12. package/esm/typings/src/_packages/types.index.d.ts +33 -17
  13. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  14. package/esm/typings/src/_packages/website-crawler.index.d.ts +8 -0
  15. package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
  16. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +2 -2
  17. package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
  18. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +5 -3
  19. package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
  20. package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
  21. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -5
  22. package/esm/typings/src/config.d.ts +26 -13
  23. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +3 -1
  24. package/esm/typings/src/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +2 -2
  25. package/esm/typings/src/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -3
  26. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
  27. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
  28. package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
  29. package/esm/typings/src/executables/locateApp.d.ts +33 -0
  30. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
  31. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
  32. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
  33. package/esm/typings/src/execution/{CommonExecutionToolsOptions.d.ts → CommonToolsOptions.d.ts} +1 -1
  34. package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
  35. package/esm/typings/src/execution/Executables.d.ts +18 -0
  36. package/esm/typings/src/execution/ExecutionTools.d.ts +32 -6
  37. package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
  38. package/esm/typings/src/execution/LlmExecutionTools.d.ts +2 -2
  39. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  40. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -2
  41. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +29 -6
  42. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +3 -12
  43. package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -18
  44. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +9 -19
  45. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -3
  46. package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +1 -0
  47. package/esm/typings/src/execution/utils/$provideExecutionToolsForNode.d.ts +13 -0
  48. package/esm/typings/src/execution/utils/addUsage.d.ts +1 -1
  49. package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  50. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +2 -2
  51. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -2
  52. package/esm/typings/src/llm-providers/_common/{$llmToolsMetadataRegister.d.ts → register/$llmToolsMetadataRegister.d.ts} +4 -1
  53. package/esm/typings/src/llm-providers/_common/{$llmToolsRegister.d.ts → register/$llmToolsRegister.d.ts} +5 -2
  54. package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfigurationFromEnv.d.ts → register/$provideLlmToolsConfigurationFromEnv.d.ts} +3 -3
  55. package/esm/typings/src/llm-providers/_common/{getLlmToolsForCli.d.ts → register/$provideLlmToolsForCli.d.ts} +4 -11
  56. package/esm/typings/src/llm-providers/_common/{getLlmToolsForTestingAndScriptsAndPlayground.d.ts → register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts} +4 -3
  57. package/esm/typings/src/llm-providers/_common/{createLlmToolsFromEnv.d.ts → register/$provideLlmToolsFromEnv.d.ts} +6 -5
  58. package/esm/typings/src/llm-providers/_common/{$registeredLlmToolsMessage.d.ts → register/$registeredLlmToolsMessage.d.ts} +5 -2
  59. package/esm/typings/src/llm-providers/_common/{LlmToolsConfiguration.d.ts → register/LlmToolsConfiguration.d.ts} +6 -5
  60. package/esm/typings/src/llm-providers/_common/{LlmToolsMetadata.d.ts → register/LlmToolsMetadata.d.ts} +5 -4
  61. package/esm/typings/src/llm-providers/_common/{LlmToolsOptions.d.ts → register/LlmToolsOptions.d.ts} +4 -1
  62. package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfiguration.d.ts → register/createLlmToolsFromConfiguration.d.ts} +12 -4
  63. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +4 -1
  64. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  65. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +5 -5
  66. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  67. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +4 -3
  68. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +4 -3
  69. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  70. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +4 -3
  71. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +4 -3
  72. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +4 -3
  73. package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +1 -1
  74. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
  75. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +4 -4
  76. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +4 -4
  77. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +4 -4
  78. package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
  79. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +0 -1
  80. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -2
  81. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +4 -4
  82. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  83. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +5 -4
  84. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +5 -4
  85. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +4 -4
  86. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +16 -7
  87. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Response.d.ts +4 -4
  88. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +7 -13
  89. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Response.d.ts +3 -3
  90. package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +11 -16
  91. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +24 -9
  92. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  93. package/esm/typings/src/personas/preparePersona.d.ts +2 -1
  94. package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +10 -28
  95. package/esm/typings/src/prepare/preparePipeline.d.ts +2 -1
  96. package/esm/typings/src/prepare/prepareTemplates.d.ts +3 -2
  97. package/esm/typings/src/scrapers/_common/Converter.d.ts +4 -10
  98. package/esm/typings/src/scrapers/_common/Scraper.d.ts +5 -17
  99. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -1
  100. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
  101. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +12 -0
  102. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +15 -0
  103. package/esm/typings/src/scrapers/_common/register/$registeredScrapersMessage.d.ts +12 -0
  104. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +13 -0
  105. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +13 -0
  106. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +41 -0
  107. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +12 -0
  108. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +3 -2
  109. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -2
  110. package/esm/typings/src/scrapers/document/{documentScraper.d.ts → DocumentScraper.d.ts} +18 -12
  111. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +20 -0
  112. package/esm/typings/src/scrapers/document/register-constructor.d.ts +13 -0
  113. package/esm/typings/src/scrapers/document/register-metadata.d.ts +24 -0
  114. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +43 -0
  115. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +20 -0
  116. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +13 -0
  117. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +24 -0
  118. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +29 -0
  119. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +20 -0
  120. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +13 -0
  121. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +24 -0
  122. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +40 -0
  123. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +20 -0
  124. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +13 -0
  125. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +24 -0
  126. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +50 -0
  127. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +20 -0
  128. package/esm/typings/src/scrapers/website/register-constructor.d.ts +13 -0
  129. package/esm/typings/src/scrapers/website/register-metadata.d.ts +24 -0
  130. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
  131. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
  132. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  133. package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +3 -3
  134. package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +3 -3
  135. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +5 -3
  136. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +1 -1
  137. package/esm/typings/src/storage/{utils → memory/utils}/PrefixStorage.d.ts +1 -1
  138. package/esm/typings/src/storage/{utils → memory/utils}/makePromptbookStorageFromWebStorage.d.ts +1 -1
  139. package/esm/typings/src/types/Arrayable.d.ts +1 -1
  140. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
  141. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +4 -4
  142. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
  143. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
  144. package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +2 -2
  145. package/esm/typings/src/types/Prompt.d.ts +2 -1
  146. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +1 -1
  147. package/esm/typings/src/types/typeAliases.d.ts +18 -8
  148. package/esm/typings/src/utils/$Register.d.ts +20 -7
  149. package/esm/typings/src/utils/FromtoItems.d.ts +1 -1
  150. package/esm/typings/src/utils/arrayableToArray.d.ts +1 -1
  151. package/esm/typings/src/utils/emojis.d.ts +1 -1
  152. package/esm/typings/src/utils/execCommand/$execCommand.d.ts +5 -3
  153. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
  154. package/esm/typings/src/utils/execCommand/$execCommands.d.ts +2 -1
  155. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
  156. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
  157. package/esm/typings/src/utils/files/isDirectoryExisting.d.ts +14 -0
  158. package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
  159. package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
  160. package/esm/typings/src/utils/files/isFileExisting.test.d.ts +1 -0
  161. package/esm/typings/src/utils/files/{$listAllFiles.d.ts → listAllFiles.d.ts} +3 -4
  162. package/esm/typings/src/utils/files/listAllFiles.test.d.ts +1 -0
  163. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
  164. package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +1 -1
  165. package/esm/typings/src/utils/normalization/IKeywords.d.ts +2 -2
  166. package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -2
  167. package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +2 -2
  168. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +2 -2
  169. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
  170. package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
  171. package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
  172. package/esm/typings/src/utils/sets/intersection.d.ts +1 -1
  173. package/esm/typings/src/utils/sets/union.d.ts +1 -1
  174. package/esm/typings/src/utils/unwrapResult.d.ts +4 -4
  175. package/package.json +4 -3
  176. package/umd/index.umd.js +110 -12
  177. package/umd/index.umd.js.map +1 -1
  178. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +0 -29
  179. package/esm/typings/src/scrapers/document-legacy/legacyDocumentScraper.d.ts +0 -37
  180. package/esm/typings/src/scrapers/index.d.ts +0 -8
  181. package/esm/typings/src/scrapers/markdown/markdownScraper.d.ts +0 -29
  182. package/esm/typings/src/scrapers/pdf/pdfScraper.d.ts +0 -35
  183. package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +0 -12
  184. package/esm/typings/src/scrapers/website/websiteScraper.d.ts +0 -43
  185. package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +0 -23
  186. package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +0 -10
  187. package/esm/typings/src/utils/files/$isDirectoryExisting.d.ts +0 -15
  188. package/esm/typings/src/utils/files/$isFileExisting.d.ts +0 -14
  189. /package/esm/typings/src/{scrapers/website/utils/markdownConverter.test.d.ts → executables/apps/locateLibreoffice.test.d.ts} +0 -0
  190. /package/esm/typings/src/{scrapers/website/websiteScraper.test.d.ts → executables/apps/locatePandoc.test.d.ts} +0 -0
  191. /package/esm/typings/src/{utils/files/$isDirectoryExisting.test.d.ts → executables/locateApp.test.d.ts} +0 -0
  192. /package/esm/typings/src/scrapers/document/{documentScraper.test.d.ts → DocumentScraper.test.d.ts} +0 -0
  193. /package/esm/typings/src/scrapers/document-legacy/{legacyDocumentScraper.test.d.ts → LegacyDocumentScraper.test.d.ts} +0 -0
  194. /package/esm/typings/src/scrapers/markdown/{markdownScraper.test.d.ts → MarkdownScraper.test.d.ts} +0 -0
  195. /package/esm/typings/src/{utils/files/$isFileExisting.test.d.ts → scrapers/website/utils/createShowdownConverter.test.d.ts} +0 -0
  196. /package/esm/typings/src/utils/files/{$listAllFiles.test.d.ts → isDirectoryExisting.test.d.ts} +0 -0
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # ![Promptbook logo - cube with letters P and B](./other/design/logo-h1.png) Promptbook
4
4
 
5
- Supercharge your use of large language models
5
+ Build responsible, controlled and transparent applications on top of LLM models!
6
6
 
7
7
 
8
8
 
@@ -20,10 +20,6 @@ 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
23
 
28
24
 
29
25
  ## 📦 Package `@promptbook/anthropic-claude`
@@ -47,31 +43,37 @@ npm install @promptbook/anthropic-claude
47
43
 
48
44
  ```typescript
49
45
  import { createPipelineExecutor, createCollectionFromDirectory, assertsExecutionSuccessful } from '@promptbook/core';
50
- import { createCollectionFromDirectory } from '@promptbook/node';
46
+ import {
47
+ createCollectionFromDirectory,
48
+ $provideExecutionToolsForNode,
49
+ $provideFilesystemForNode,
50
+ } from '@promptbook/node';
51
51
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
52
52
  import { AnthropicClaudeExecutionTools } from '@promptbook/anthropic-claude';
53
53
 
54
+ // ▶ Prepare tools
55
+ const fs = $provideFilesystemForNode();
56
+ const llm = new AnthropicClaudeExecutionTools(
57
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
58
+ {
59
+ isVerbose: true,
60
+ apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
61
+ },
62
+ );
63
+ const executables = await $provideExecutablesForNode();
64
+ const tools = {
65
+ llm,
66
+ fs,
67
+ scrapers: await $provideScrapersForNode({ fs, llm, executables }),
68
+ script: [new JavascriptExecutionTools()],
69
+ };
70
+
54
71
  // ▶ Create whole pipeline collection
55
- const collection = await createCollectionFromDirectory('./promptbook-collection');
72
+ const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
56
73
 
57
74
  // ▶ Get single Pipeline
58
75
  const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
59
76
 
60
- // ▶ Prepare tools
61
- const tools = {
62
- llm: new AnthropicClaudeExecutionTools(
63
- // <- TODO: [🧱] Implement in a functional (not new Class) way
64
- {
65
- isVerbose: true,
66
- apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
67
- },
68
- ),
69
- script: [
70
- new JavascriptExecutionTools(),
71
- // <- TODO: [🧱] Implement in a functional (not new Class) way
72
- ],
73
- };
74
-
75
77
  // ▶ Create executor - the function that will execute the Pipeline
76
78
  const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
77
79
 
@@ -91,29 +93,23 @@ console.info(outputParameters);
91
93
 
92
94
  ## 🧙‍♂️ Connect to LLM providers automatically
93
95
 
94
- You can just use `createLlmToolsFromEnv` function to create LLM tools from environment variables like `ANTHROPIC_CLAUDE_API_KEY` and `OPENAI_API_KEY` automatically.
96
+ You can just use `$provideExecutionToolsForNode` function to create all required tools from environment variables like `ANTHROPIC_CLAUDE_API_KEY` and `OPENAI_API_KEY` automatically.
95
97
 
96
98
  ```typescript
97
99
  import { createPipelineExecutor, createCollectionFromDirectory, assertsExecutionSuccessful } from '@promptbook/core';
98
100
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
99
- import { createLlmToolsFromEnv } from '@promptbook/node';
101
+ import { $provideExecutionToolsForNode } from '@promptbook/node';
102
+ import { $provideFilesystemForNode } from '@promptbook/node';
103
+
104
+ // ▶ Prepare tools
105
+ const tools = await $provideExecutionToolsForNode();
100
106
 
101
107
  // ▶ Create whole pipeline collection
102
- const collection = await createCollectionFromDirectory('./promptbook-collection');
108
+ const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
103
109
 
104
110
  // ▶ Get single Pipeline
105
111
  const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
106
112
 
107
- // ▶ Prepare multiple tools
108
- const tools = {
109
- // Note: 🧙‍♂️ Just call `createLlmToolsFromEnv` to automatically connect to all configured providers
110
- llm: createLlmToolsFromEnv(),
111
- script: [
112
- new JavascriptExecutionTools(),
113
- // <- TODO: [🧱] Implement in a functional (not new Class) way
114
- ],
115
- };
116
-
117
113
  // ▶ Create executor - the function that will execute the Pipeline
118
114
  const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
119
115
 
@@ -137,47 +133,51 @@ You can use multiple LLM providers in one Promptbook execution. The best model w
137
133
 
138
134
  ```typescript
139
135
  import { createPipelineExecutor, createCollectionFromDirectory, assertsExecutionSuccessful } from '@promptbook/core';
136
+ import { $provideExecutionToolsForNode } from '@promptbook/node';
137
+ import { $provideFilesystemForNode } from '@promptbook/node';
140
138
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
141
139
  import { OpenAiExecutionTools } from '@promptbook/openai';
142
140
 
141
+ // ▶ Prepare multiple tools
142
+ const fs = $provideFilesystemForNode();
143
+ const llm = [
144
+ // Note: 💕 You can use multiple LLM providers in one Promptbook execution.
145
+ // The best model will be chosen automatically according to the prompt and the model's capabilities.
146
+ new AnthropicClaudeExecutionTools(
147
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
148
+ {
149
+ apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
150
+ },
151
+ ),
152
+ new OpenAiExecutionTools(
153
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
154
+ {
155
+ apiKey: process.env.OPENAI_API_KEY,
156
+ },
157
+ ),
158
+ new AzureOpenAiExecutionTools(
159
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
160
+ {
161
+ resourceName: process.env.AZUREOPENAI_RESOURCE_NAME,
162
+ deploymentName: process.env.AZUREOPENAI_DEPLOYMENT_NAME,
163
+ apiKey: process.env.AZUREOPENAI_API_KEY,
164
+ },
165
+ ),
166
+ ];
167
+ const executables = await $provideExecutablesForNode();
168
+ const tools = {
169
+ llm,
170
+ fs,
171
+ scrapers: await $provideScrapersForNode({ fs, llm, executables }),
172
+ script: [new JavascriptExecutionTools()],
173
+ };
174
+
143
175
  // ▶ Create whole pipeline collection
144
- const collection = await createCollectionFromDirectory('./promptbook-collection');
176
+ const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
145
177
 
146
178
  // ▶ Get single Pipeline
147
179
  const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
148
180
 
149
- // ▶ Prepare multiple tools
150
- const tools = {
151
- llm: [
152
- // Note: 💕 You can use multiple LLM providers in one Promptbook execution.
153
- // The best model will be chosen automatically according to the prompt and the model's capabilities.
154
- new AnthropicClaudeExecutionTools(
155
- // <- TODO: [🧱] Implement in a functional (not new Class) way
156
- {
157
- apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
158
- },
159
- ),
160
- new OpenAiExecutionTools(
161
- // <- TODO: [🧱] Implement in a functional (not new Class) way
162
- {
163
- apiKey: process.env.OPENAI_API_KEY,
164
- },
165
- ),
166
- new AzureOpenAiExecutionTools(
167
- // <- TODO: [🧱] Implement in a functional (not new Class) way
168
- {
169
- resourceName: process.env.AZUREOPENAI_RESOURCE_NAME,
170
- deploymentName: process.env.AZUREOPENAI_DEPLOYMENT_NAME,
171
- apiKey: process.env.AZUREOPENAI_API_KEY,
172
- },
173
- ),
174
- ],
175
- script: [
176
- new JavascriptExecutionTools(),
177
- // <- TODO: [🧱] Implement in a functional (not new Class) way
178
- ],
179
- };
180
-
181
181
  // ▶ Create executor - the function that will execute the Pipeline
182
182
  const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
183
183
 
@@ -213,15 +213,15 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
213
213
 
214
214
 
215
215
 
216
- If you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama 2, or whatever, it doesn't matter how you integrate it. Whether it's calling a REST API directly, using the SDK, hardcoding the prompt into the source code, or importing a text file, the process remains the same.
216
+ If you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama 3, or whatever, it doesn't matter how you integrate it. Whether it's calling a REST API directly, using the SDK, hardcoding the prompt into the source code, or importing a text file, the process remains the same.
217
217
 
218
- But often you will struggle with the limitations of LLMs, such as hallucinations, off-topic responses, poor quality output, language drift, word repetition repetition repetition repetition or misuse, lack of context, or just plain w𝒆𝐢rd responses. When this happens, you generally have three options:
218
+ But often you will struggle with the **limitations of LLMs**, such as **hallucinations, off-topic responses, poor quality output, language and prompt drift, word repetition repetition repetition repetition or misuse, lack of context, or just plain w𝒆𝐢rd responses**. When this happens, you generally have three options:
219
219
 
220
220
  1. **Fine-tune** the model to your specifications or even train your own.
221
221
  2. **Prompt-engineer** the prompt to the best shape you can achieve.
222
222
  3. Orchestrate **multiple prompts** in a [pipeline](https://github.com/webgptorg/promptbook/discussions/64) to get the best result.
223
223
 
224
- In all of these situations, but especially in 3., the Promptbook library can make your life easier.
224
+ In all of these situations, but especially in 3., the **✨ Promptbook can make your life waaaaaaaaaay easier**.
225
225
 
226
226
  - [**Separates concerns**](https://github.com/webgptorg/promptbook/discussions/32) between prompt-engineer and programmer, between code files and prompt files, and between prompts and their execution logic.
227
227
  - Establishes a [**common format `.ptbk.md`**](https://github.com/webgptorg/promptbook/discussions/85) that can be used to describe your prompt business logic without having to write code or deal with the technicalities of LLMs.
@@ -493,6 +493,10 @@ Or you can install them separately:
493
493
  - **[@promptbook/fake-llm](https://www.npmjs.com/package/@promptbook/fake-llm)** - Mocked execution tools for testing the library and saving the tokens
494
494
  - **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
495
495
  - **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
496
+ - **[@promptbook/pdf](https://www.npmjs.com/package/@promptbook/pdf)** - Read knowledge from `.pdf` documents
497
+ - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
498
+ - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
499
+ - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
496
500
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
497
501
  - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
498
502
 
package/esm/index.es.js CHANGED
@@ -7,7 +7,7 @@ import { io } from 'socket.io-client';
7
7
  /**
8
8
  * The version of the Promptbook library
9
9
  */
10
- var PROMPTBOOK_VERSION = '0.72.0-7';
10
+ var PROMPTBOOK_VERSION = '0.72.0-34';
11
11
  // TODO: [main] !!!! List here all the versions and annotate + put into script
12
12
 
13
13
  /*! *****************************************************************************
@@ -442,6 +442,7 @@ var LOOP_LIMIT = 1000;
442
442
  * @private within the repository - too low-level in comparison with other `MAX_...`
443
443
  */
444
444
  var CONNECTION_TIMEOUT_MS = 7 * 1000;
445
+ // <- TODO: [⏳] Standartize timeouts, Make DEFAULT_TIMEOUT_MS as global constant
445
446
  /**
446
447
  * How many times to retry the connections
447
448
  *
@@ -1448,6 +1449,7 @@ function deserializeError(error) {
1448
1449
  * @public exported from `@promptbook/remote-client`
1449
1450
  */
1450
1451
  var RemoteLlmExecutionTools = /** @class */ (function () {
1452
+ /* <- TODO: [🍚] `, Destroyable` */
1451
1453
  function RemoteLlmExecutionTools(options) {
1452
1454
  this.options = options;
1453
1455
  }
@@ -1497,12 +1499,16 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
1497
1499
  if (this.options.isAnonymous) {
1498
1500
  socket.emit('listModels-request', {
1499
1501
  isAnonymous: true,
1502
+ userId: this.options.userId,
1500
1503
  llmToolsConfiguration: this.options.llmToolsConfiguration,
1501
1504
  } /* <- TODO: [🤛] */);
1502
1505
  }
1503
1506
  else {
1504
1507
  socket.emit('listModels-request', {
1505
1508
  isAnonymous: false,
1509
+ appId: this.options.appId,
1510
+ userId: this.options.userId,
1511
+ customOptions: this.options.customOptions,
1506
1512
  } /* <- TODO: [🤛] */);
1507
1513
  }
1508
1514
  return [4 /*yield*/, new Promise(function (resolve, reject) {
@@ -1528,9 +1534,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
1528
1534
  */
1529
1535
  RemoteLlmExecutionTools.prototype.makeConnection = function () {
1530
1536
  var _this = this;
1531
- return new Promise(
1532
- // <- TODO: [🧱] Implement in a functional (not new Class) way
1533
- function (resolve, reject) {
1537
+ return new Promise(function (resolve, reject) {
1534
1538
  var socket = io(_this.options.remoteUrl, {
1535
1539
  retries: CONNECTION_RETRIES_LIMIT,
1536
1540
  timeout: CONNECTION_TIMEOUT_MS,
@@ -1598,7 +1602,9 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
1598
1602
  else {
1599
1603
  socket.emit('prompt-request', {
1600
1604
  isAnonymous: false,
1605
+ appId: this.options.appId,
1601
1606
  userId: this.options.userId,
1607
+ customOptions: this.options.customOptions,
1602
1608
  prompt: prompt,
1603
1609
  } /* <- TODO: [🤛] */);
1604
1610
  }
@@ -1638,7 +1644,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
1638
1644
  */
1639
1645
  var createAnthropicClaudeExecutionTools = Object.assign(function (options) {
1640
1646
  if (options.isProxied) {
1641
- return new RemoteLlmExecutionTools(__assign(__assign({}, options), { isAnonymous: true, llmToolsConfiguration: [
1647
+ return new RemoteLlmExecutionTools(__assign(__assign({}, options), { userId: null, isAnonymous: true, llmToolsConfiguration: [
1642
1648
  {
1643
1649
  title: 'Anthropic Claude (proxied)',
1644
1650
  packageName: '@promptbook/anthropic-claude',
@@ -1671,6 +1677,85 @@ function $getGlobalScope() {
1671
1677
  return Function('return this')();
1672
1678
  }
1673
1679
 
1680
+ /**
1681
+ * @@@
1682
+ *
1683
+ * @param text @@@
1684
+ * @returns @@@
1685
+ * @example 'HELLO_WORLD'
1686
+ * @example 'I_LOVE_PROMPTBOOK'
1687
+ * @public exported from `@promptbook/utils`
1688
+ */
1689
+ function normalizeTo_SCREAMING_CASE(text) {
1690
+ var e_1, _a;
1691
+ var charType;
1692
+ var lastCharType = 'OTHER';
1693
+ var normalizedName = '';
1694
+ try {
1695
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
1696
+ var char = text_1_1.value;
1697
+ var normalizedChar = void 0;
1698
+ if (/^[a-z]$/.test(char)) {
1699
+ charType = 'LOWERCASE';
1700
+ normalizedChar = char.toUpperCase();
1701
+ }
1702
+ else if (/^[A-Z]$/.test(char)) {
1703
+ charType = 'UPPERCASE';
1704
+ normalizedChar = char;
1705
+ }
1706
+ else if (/^[0-9]$/.test(char)) {
1707
+ charType = 'NUMBER';
1708
+ normalizedChar = char;
1709
+ }
1710
+ else {
1711
+ charType = 'OTHER';
1712
+ normalizedChar = '_';
1713
+ }
1714
+ if (charType !== lastCharType &&
1715
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1716
+ !(lastCharType === 'NUMBER') &&
1717
+ !(charType === 'NUMBER')) {
1718
+ normalizedName += '_';
1719
+ }
1720
+ normalizedName += normalizedChar;
1721
+ lastCharType = charType;
1722
+ }
1723
+ }
1724
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1725
+ finally {
1726
+ try {
1727
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
1728
+ }
1729
+ finally { if (e_1) throw e_1.error; }
1730
+ }
1731
+ normalizedName = normalizedName.replace(/_+/g, '_');
1732
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1733
+ normalizedName = normalizedName.replace(/^_/, '');
1734
+ normalizedName = normalizedName.replace(/_$/, '');
1735
+ return normalizedName;
1736
+ }
1737
+ /**
1738
+ * TODO: Tests
1739
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1740
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1741
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1742
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1743
+ * TODO: [🌺] Use some intermediate util splitWords
1744
+ */
1745
+
1746
+ /**
1747
+ * @@@
1748
+ *
1749
+ * @param text @@@
1750
+ * @returns @@@
1751
+ * @example 'hello_world'
1752
+ * @example 'i_love_promptbook'
1753
+ * @public exported from `@promptbook/utils`
1754
+ */
1755
+ function normalizeTo_snake_case(text) {
1756
+ return normalizeTo_SCREAMING_CASE(text).toLowerCase();
1757
+ }
1758
+
1674
1759
  /**
1675
1760
  * Register is @@@
1676
1761
  *
@@ -1679,9 +1764,9 @@ function $getGlobalScope() {
1679
1764
  * @private internal utility, exported are only signleton instances of this class
1680
1765
  */
1681
1766
  var $Register = /** @class */ (function () {
1682
- function $Register(storageName) {
1683
- this.storageName = storageName;
1684
- storageName = "_promptbook_".concat(storageName);
1767
+ function $Register(registerName) {
1768
+ this.registerName = registerName;
1769
+ var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
1685
1770
  var globalScope = $getGlobalScope();
1686
1771
  if (globalScope[storageName] === undefined) {
1687
1772
  globalScope[storageName] = [];
@@ -1692,11 +1777,10 @@ var $Register = /** @class */ (function () {
1692
1777
  this.storage = globalScope[storageName];
1693
1778
  }
1694
1779
  $Register.prototype.list = function () {
1695
- // <- TODO: ReadonlyDeep<Array<TRegistered>>
1780
+ // <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
1696
1781
  return this.storage;
1697
1782
  };
1698
1783
  $Register.prototype.register = function (registered) {
1699
- // <- TODO: What to return here
1700
1784
  var packageName = registered.packageName, className = registered.className;
1701
1785
  var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
1702
1786
  var existingRegistration = this.storage[existingRegistrationIndex];
@@ -1706,6 +1790,17 @@ var $Register = /** @class */ (function () {
1706
1790
  else {
1707
1791
  this.storage[existingRegistrationIndex] = registered;
1708
1792
  }
1793
+ return {
1794
+ registerName: this.registerName,
1795
+ packageName: packageName,
1796
+ className: className,
1797
+ get isDestroyed() {
1798
+ return false;
1799
+ },
1800
+ destroy: function () {
1801
+ throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
1802
+ },
1803
+ };
1709
1804
  };
1710
1805
  return $Register;
1711
1806
  }());
@@ -1718,11 +1813,14 @@ var $Register = /** @class */ (function () {
1718
1813
  * @public exported from `@promptbook/core`
1719
1814
  */
1720
1815
  var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
1816
+ /**
1817
+ * TODO: [®] DRY Register logic
1818
+ */
1721
1819
 
1722
1820
  /**
1723
- * @@@ registration2
1821
+ * Registration of LLM provider
1724
1822
  *
1725
- * Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
1823
+ * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
1726
1824
  *
1727
1825
  * @public exported from `@promptbook/anthropic-claude`
1728
1826
  * @public exported from `@promptbook/cli`