@promptbook/browser 0.72.0-9 → 0.73.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 (146) hide show
  1. package/README.md +36 -252
  2. package/esm/index.es.js +227 -30
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +24 -18
  5. package/esm/typings/src/_packages/node.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +18 -12
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  8. package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
  9. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +2 -2
  10. package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
  11. package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
  12. package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
  13. package/esm/typings/src/commands/TEMPLATE/TemplateTypes.d.ts +1 -1
  14. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -5
  15. package/esm/typings/src/config.d.ts +22 -15
  16. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
  17. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
  18. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +1 -1
  19. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +2 -2
  20. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
  21. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
  22. package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
  23. package/esm/typings/src/executables/locateApp.d.ts +33 -0
  24. package/esm/typings/src/executables/locateApp.test.d.ts +1 -0
  25. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
  26. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
  27. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
  28. package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
  29. package/esm/typings/src/execution/Executables.d.ts +18 -0
  30. package/esm/typings/src/execution/ExecutionTools.d.ts +9 -3
  31. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  32. package/esm/typings/src/execution/LlmExecutionTools.d.ts +2 -2
  33. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  34. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -2
  35. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +29 -6
  36. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -11
  37. package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -13
  38. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +9 -14
  39. package/esm/typings/src/execution/createPipelineExecutor/{getSamplesForTemplate.d.ts → getExamplesForTemplate.d.ts} +1 -1
  40. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -3
  41. package/esm/typings/src/execution/utils/addUsage.d.ts +1 -1
  42. package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  43. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +4 -4
  44. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +3 -3
  45. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForCli.d.ts +2 -2
  46. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +1 -1
  47. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +7 -0
  48. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +4 -1
  49. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  50. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
  51. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  52. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  53. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  54. package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +1 -1
  55. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
  56. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  57. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  58. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +4 -5
  59. package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
  60. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +0 -1
  61. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -2
  62. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
  63. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  64. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +4 -4
  65. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +15 -6
  66. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Response.d.ts +4 -4
  67. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +6 -12
  68. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Response.d.ts +3 -3
  69. package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +9 -14
  70. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +23 -8
  71. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  72. package/esm/typings/src/personas/preparePersona.d.ts +1 -1
  73. package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +4 -23
  74. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +2 -2
  75. package/esm/typings/src/prepare/prepareTemplates.d.ts +2 -2
  76. package/esm/typings/src/scrapers/_common/Scraper.d.ts +2 -9
  77. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
  78. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +2 -2
  79. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +2 -2
  80. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -2
  81. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +2 -2
  82. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
  83. package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +2 -2
  84. package/esm/typings/src/scrapers/document/DocumentScraper.test.d.ts +1 -1
  85. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  86. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -1
  87. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +3 -3
  88. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.test.d.ts +1 -1
  89. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +1 -1
  90. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -1
  91. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -1
  92. package/esm/typings/src/scrapers/markdown/MarkdownScraper.test.d.ts +1 -1
  93. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +1 -1
  94. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -1
  95. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +2 -2
  96. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
  97. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -1
  98. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +6 -3
  99. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +1 -1
  100. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -1
  101. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
  102. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.test.d.ts +1 -0
  103. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  104. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +1 -1
  105. package/esm/typings/src/types/Arrayable.d.ts +1 -1
  106. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
  107. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +4 -4
  108. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
  109. package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +2 -2
  110. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
  111. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
  112. package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +2 -2
  113. package/esm/typings/src/types/Prompt.d.ts +2 -1
  114. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +1 -1
  115. package/esm/typings/src/types/typeAliases.d.ts +11 -8
  116. package/esm/typings/src/utils/$Register.d.ts +1 -1
  117. package/esm/typings/src/utils/FromtoItems.d.ts +1 -1
  118. package/esm/typings/src/utils/arrayableToArray.d.ts +1 -1
  119. package/esm/typings/src/utils/emojis.d.ts +1 -1
  120. package/esm/typings/src/utils/execCommand/$execCommand.d.ts +4 -2
  121. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
  122. package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -0
  123. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
  124. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
  125. package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
  126. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
  127. package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +1 -1
  128. package/esm/typings/src/utils/normalization/IKeywords.d.ts +2 -2
  129. package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -2
  130. package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +2 -2
  131. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +2 -2
  132. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
  133. package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
  134. package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
  135. package/esm/typings/src/utils/sets/intersection.d.ts +1 -1
  136. package/esm/typings/src/utils/sets/union.d.ts +1 -1
  137. package/esm/typings/src/utils/unwrapResult.d.ts +4 -4
  138. package/package.json +6 -4
  139. package/umd/index.umd.js +227 -30
  140. package/umd/index.umd.js.map +1 -1
  141. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +0 -29
  142. package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +0 -12
  143. package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +0 -23
  144. package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +0 -10
  145. /package/esm/typings/src/{scrapers/website/WebsiteScraper.test.d.ts → executables/apps/locateLibreoffice.test.d.ts} +0 -0
  146. /package/esm/typings/src/{scrapers/website/utils/markdownConverter.test.d.ts → executables/apps/locatePandoc.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
 
@@ -18,12 +18,10 @@ Supercharge your use of large language models
18
18
 
19
19
  ## ✨ New Features
20
20
 
21
+ - 💙 Working on [the **Book** language v1](https://github.com/webgptorg/book)
22
+ - 📚 Support of `.docx`, `.doc` and `.pdf` documents
21
23
  - ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
22
24
 
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
25
 
28
26
 
29
27
  ## 📦 Package `@promptbook/browser`
@@ -54,260 +52,48 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
54
52
 
55
53
  ## 🤍 The Promptbook Whitepaper
56
54
 
55
+ 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.
57
56
 
58
-
59
- 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.
60
-
61
- 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:
57
+ 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 resp0nses**. When this happens, you generally have three options:
62
58
 
63
59
  1. **Fine-tune** the model to your specifications or even train your own.
64
60
  2. **Prompt-engineer** the prompt to the best shape you can achieve.
65
61
  3. Orchestrate **multiple prompts** in a [pipeline](https://github.com/webgptorg/promptbook/discussions/64) to get the best result.
66
62
 
67
- In all of these situations, but especially in 3., the Promptbook library can make your life easier.
63
+ In all of these situations, but especially in 3., the **✨ Promptbook can make your life waaaaaaaaaay easier**.
68
64
 
69
- - [**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.
70
- - 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.
71
- - **Forget** about **low-level details** like choosing the right model, tokens, context size, temperature, top-k, top-p, or kernel sampling. **Just write your intent** and [**persona**](https://github.com/webgptorg/promptbook/discussions/22) who should be responsible for the task and let the library do the rest.
72
- - Has built-in **orchestration** of [pipeline](https://github.com/webgptorg/promptbook/discussions/64) execution and many tools to make the process easier, more reliable, and more efficient, such as caching, [compilation+preparation](https://github.com/webgptorg/promptbook/discussions/78), [just-in-time fine-tuning](https://github.com/webgptorg/promptbook/discussions/33), [expectation-aware generation](https://github.com/webgptorg/promptbook/discussions/37), [agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39), and more.
65
+ - [**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. For this purpose, it introduces a new language called [the **💙 Book**](https://github.com/webgptorg/book).
66
+ - Book allows you to **focus on the business** logic without having to write code or deal with the technicalities of LLMs.
67
+ - **Forget** about **low-level details** like choosing the right model, tokens, context size, `temperature`, `top-k`, `top-p`, or kernel sampling. **Just write your intent** and [**persona**](https://github.com/webgptorg/promptbook/discussions/22) who should be responsible for the task and let the library do the rest.
68
+ - We have built-in **orchestration** of [pipeline](https://github.com/webgptorg/promptbook/discussions/64) execution and many tools to make the process easier, more reliable, and more efficient, such as caching, [compilation+preparation](https://github.com/webgptorg/promptbook/discussions/78), [just-in-time fine-tuning](https://github.com/webgptorg/promptbook/discussions/33), [expectation-aware generation](https://github.com/webgptorg/promptbook/discussions/37), [agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39), and more.
73
69
  - Sometimes even the best prompts with the best framework like Promptbook `:)` can't avoid the problems. In this case, the library has built-in **[anomaly detection](https://github.com/webgptorg/promptbook/discussions/40) and logging** to help you find and fix the problems.
74
- - Promptbook has built in versioning. You can test multiple **A/B versions** of pipelines and see which one works best.
75
- - Promptbook is designed to do [**RAG** (Retrieval-Augmented Generation)](https://github.com/webgptorg/promptbook/discussions/41) and other advanced techniques. You can use **knowledge** to improve the quality of the output.
76
-
77
-
78
-
79
- ## 🧔 Pipeline _(for prompt-engeneers)_
80
-
81
- **P**romp**t** **b**oo**k** markdown file (or `.ptbk.md` file) is document that describes a **pipeline** - a series of prompts that are chained together to form somewhat reciepe for transforming natural language input.
82
-
83
- - Multiple pipelines forms a **collection** which will handle core **know-how of your LLM application**.
84
- - Theese pipelines are designed such as they **can be written by non-programmers**.
85
-
86
-
87
-
88
- ### Sample:
89
-
90
- File `write-website-content.ptbk.md`:
91
-
92
-
93
-
94
-
95
-
96
- > # 🌍 Create website content
97
- >
98
- > Instructions for creating web page content.
99
- >
100
- > - PIPELINE URL https://promptbook.studio/webgpt/write-website-content.ptbk.md
101
- > - INPUT  PARAM `{rawTitle}` Automatically suggested a site name or empty text
102
- > - INPUT  PARAM `{rawAssigment}` Automatically generated site entry from image recognition
103
- > - OUTPUT PARAM `{websiteContent}` Web content
104
- > - OUTPUT PARAM `{keywords}` Keywords
105
- >
106
- > ## 👤 Specifying the assigment
107
- >
108
- > What is your web about?
109
- >
110
- > - DIALOG TEMPLATE
111
- >
112
- > ```
113
- > {rawAssigment}
114
- > ```
115
- >
116
- > `-> {assigment}` Website assignment and specification
117
- >
118
- > ## ✨ Improving the title
119
- >
120
- > - PERSONA Jane, Copywriter and Marketing Specialist.
121
- >
122
- > ```
123
- > As an experienced marketing specialist, you have been entrusted with improving the name of your client's business.
124
- >
125
- > A suggested name from a client:
126
- > "{rawTitle}"
127
- >
128
- > Assignment from customer:
129
- >
130
- > > {assigment}
131
- >
132
- > ## Instructions:
133
- >
134
- > - Write only one name suggestion
135
- > - The name will be used on the website, business cards, visuals, etc.
136
- > ```
137
- >
138
- > `-> {enhancedTitle}` Enhanced title
139
- >
140
- > ## 👤 Website title approval
141
- >
142
- > Is the title for your website okay?
143
- >
144
- > - DIALOG TEMPLATE
145
- >
146
- > ```
147
- > {enhancedTitle}
148
- > ```
149
- >
150
- > `-> {title}` Title for the website
151
- >
152
- > ## 🐰 Cunning subtitle
153
- >
154
- > - PERSONA Josh, a copywriter, tasked with creating a claim for the website.
155
- >
156
- > ```
157
- > As an experienced copywriter, you have been entrusted with creating a claim for the "{title}" web page.
158
- >
159
- > A website assignment from a customer:
160
- >
161
- > > {assigment}
162
- >
163
- > ## Instructions:
164
- >
165
- > - Write only one name suggestion
166
- > - Claim will be used on website, business cards, visuals, etc.
167
- > - Claim should be punchy, funny, original
168
- > ```
169
- >
170
- > `-> {claim}` Claim for the web
171
- >
172
- > ## 🚦 Keyword analysis
173
- >
174
- > - PERSONA Paul, extremely creative SEO specialist.
175
- >
176
- > ```
177
- > As an experienced SEO specialist, you have been entrusted with creating keywords for the website "{title}".
178
- >
179
- > Website assignment from the customer:
180
- >
181
- > > {assigment}
182
- >
183
- > ## Instructions:
184
- >
185
- > - Write a list of keywords
186
- > - Keywords are in basic form
187
- >
188
- > ## Example:
189
- >
190
- > - Ice cream
191
- > - Olomouc
192
- > - Quality
193
- > - Family
194
- > - Tradition
195
- > - Italy
196
- > - Craft
197
- >
198
- > ```
199
- >
200
- > `-> {keywords}` Keywords
201
- >
202
- > ## 🔗 Combine the beginning
203
- >
204
- > - SIMPLE TEMPLATE
205
- >
206
- > ```
207
- >
208
- > # {title}
209
- >
210
- > > {claim}
211
- >
212
- > ```
213
- >
214
- > `-> {contentBeginning}` Beginning of web content
215
- >
216
- > ## 🖋 Write the content
217
- >
218
- > - PERSONA Jane
219
- >
220
- > ```
221
- > As an experienced copywriter and web designer, you have been entrusted with creating text for a new website {title}.
222
- >
223
- > A website assignment from a customer:
224
- >
225
- > > {assigment}
226
- >
227
- > ## Instructions:
228
- >
229
- > - Text formatting is in Markdown
230
- > - Be concise and to the point
231
- > - Use keywords, but they should be naturally in the text
232
- > - This is the complete content of the page, so don't forget all the important information and elements the page should contain
233
- > - Use headings, bullets, text formatting
234
- >
235
- > ## Keywords:
236
- >
237
- > {keywords}
238
- >
239
- > ## Web Content:
240
- >
241
- > {contentBeginning}
242
- > ```
243
- >
244
- > `-> {contentBody}` Middle of the web content
245
- >
246
- > ## 🔗 Combine the content
247
- >
248
- > - SIMPLE TEMPLATE
249
- >
250
- > ```markdown
251
- > {contentBeginning}
252
- >
253
- > {contentBody}
254
- > ```
255
- >
256
- > `-> {websiteContent}`
257
-
258
-
259
-
260
- Following is the scheme how the promptbook above is executed:
261
-
262
- ```mermaid
263
- %% 🔮 Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually
264
-
265
- flowchart LR
266
- subgraph "🌍 Create website content"
267
-
268
- direction TB
269
-
270
- input((Input)):::input
271
- templateSpecifyingTheAssigment(👤 Specifying the assigment)
272
- input--"{rawAssigment}"-->templateSpecifyingTheAssigment
273
- templateImprovingTheTitle(✨ Improving the title)
274
- input--"{rawTitle}"-->templateImprovingTheTitle
275
- templateSpecifyingTheAssigment--"{assigment}"-->templateImprovingTheTitle
276
- templateWebsiteTitleApproval(👤 Website title approval)
277
- templateImprovingTheTitle--"{enhancedTitle}"-->templateWebsiteTitleApproval
278
- templateCunningSubtitle(🐰 Cunning subtitle)
279
- templateWebsiteTitleApproval--"{title}"-->templateCunningSubtitle
280
- templateSpecifyingTheAssigment--"{assigment}"-->templateCunningSubtitle
281
- templateKeywordAnalysis(🚦 Keyword analysis)
282
- templateWebsiteTitleApproval--"{title}"-->templateKeywordAnalysis
283
- templateSpecifyingTheAssigment--"{assigment}"-->templateKeywordAnalysis
284
- templateCombineTheBeginning(🔗 Combine the beginning)
285
- templateWebsiteTitleApproval--"{title}"-->templateCombineTheBeginning
286
- templateCunningSubtitle--"{claim}"-->templateCombineTheBeginning
287
- templateWriteTheContent(🖋 Write the content)
288
- templateWebsiteTitleApproval--"{title}"-->templateWriteTheContent
289
- templateSpecifyingTheAssigment--"{assigment}"-->templateWriteTheContent
290
- templateKeywordAnalysis--"{keywords}"-->templateWriteTheContent
291
- templateCombineTheBeginning--"{contentBeginning}"-->templateWriteTheContent
292
- templateCombineTheContent(🔗 Combine the content)
293
- templateCombineTheBeginning--"{contentBeginning}"-->templateCombineTheContent
294
- templateWriteTheContent--"{contentBody}"-->templateCombineTheContent
295
-
296
- templateCombineTheContent--"{websiteContent}"-->output
297
- output((Output)):::output
298
-
299
- classDef input color: grey;
300
- classDef output color: grey;
301
-
302
- end;
303
- ```
70
+ - Versioning is build in. You can test multiple **A/B versions** of pipelines and see which one works best.
71
+ - Promptbook is designed to use [**RAG** (Retrieval-Augmented Generation)](https://github.com/webgptorg/promptbook/discussions/41) and other advanced techniques to bring the context of your business to generic LLM. You can use **knowledge** to improve the quality of the output.
72
+
73
+
74
+
75
+ ## 💙 Book language _(for prompt-engineer)_
76
+
77
+ Promptbook [pipelines](https://github.com/webgptorg/promptbook/discussions/64) are written in markdown-like language called [Book](https://github.com/webgptorg/book). It is designed to be understandable by non-programmers and non-technical people.
304
78
 
305
- - [More template samples](./samples/pipelines/)
306
- - [Read more about `.ptbk.md` file format here](https://github.com/webgptorg/promptbook/discussions/categories/concepts?discussions_q=is%3Aopen+label%3A.ptbk.md+category%3AConcepts)
307
79
 
308
- _Note: We are using [postprocessing functions](#postprocessing-functions) like `unwrapResult` that can be used to postprocess the result._
309
80
 
310
- ## 📦 Packages
81
+ ```markdown
82
+ # 🌟 My first Book
83
+
84
+ - PERSONA Jane, marketing specialist with prior experience in writing articles about technology and artificial intelligence
85
+ - KNOWLEDGE https://ptbk.io
86
+ - KNOWLEDGE ./promptbook.pdf
87
+ - EXPECT MIN 1 Sentence
88
+ - EXPECT MAX 1 Paragraph
89
+
90
+ > Write an article about the future of artificial intelligence in the next 10 years and how metalanguages will change the way AI is used in the world.
91
+ > Look specifically at the impact of Promptbook on the AI industry.
92
+
93
+ -> {article}
94
+ ```
95
+
96
+ ## 📦 Packages _(for developers)_
311
97
 
312
98
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
313
99
  You can install all of them at once:
@@ -349,8 +135,6 @@ Or you can install them separately:
349
135
 
350
136
  The following glossary is used to clarify certain concepts:
351
137
 
352
-
353
-
354
138
  ### Core concepts
355
139
 
356
140
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
@@ -381,8 +165,8 @@ The following glossary is used to clarify certain concepts:
381
165
 
382
166
  ## 🔌 Usage in Typescript / Javascript
383
167
 
384
- - [Simple usage](./samples/usage/simple-script)
385
- - [Usage with client and remote server](./samples/usage/remote)
168
+ - [Simple usage](./examples/usage/simple-script)
169
+ - [Usage with client and remote server](./examples/usage/remote)
386
170
 
387
171
  ## ➕➖ When to use Promptbook?
388
172
 
package/esm/index.es.js CHANGED
@@ -5,7 +5,7 @@ import { isRunningInBrowser } from 'openai/core';
5
5
  /**
6
6
  * The version of the Promptbook library
7
7
  */
8
- var PROMPTBOOK_VERSION = '0.72.0-8';
8
+ var PROMPTBOOK_VERSION = '0.72.0';
9
9
  // TODO: [main] !!!! List here all the versions and annotate + put into script
10
10
 
11
11
  /*! *****************************************************************************
@@ -193,32 +193,6 @@ var $isRunningInBrowser = new Function("\n try {\n return this === win
193
193
  */
194
194
  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");
195
195
 
196
- /**
197
- * @@@!!!!!!
198
- *
199
- * 1) @@@
200
- * 2) @@@
201
- *
202
- * @public exported from `@promptbook/browser`
203
- */
204
- function $provideScrapersForBrowser(tools, options) {
205
- return __awaiter(this, void 0, void 0, function () {
206
- var isAutoInstalled /* Note: [0] Intentionally not assigning a default value = IS_AUTO_INSTALLED */;
207
- return __generator(this, function (_a) {
208
- if (!$isRunningInBrowser() || $isRunningInWebWorker()) {
209
- throw new EnvironmentMismatchError('Function `$provideScrapersForBrowser` works only in browser environment');
210
- }
211
- isAutoInstalled = (options || {}).isAutoInstalled;
212
- if (isAutoInstalled === true /* <- Note: [0] Ignoring undefined, just checking EXPLICIT requirement for install */) {
213
- throw new EnvironmentMismatchError('Auto-installing is not supported in browser environment');
214
- }
215
- return [2 /*return*/, [
216
- // TODO: !!!!!!! Implement
217
- ]];
218
- });
219
- });
220
- }
221
-
222
196
  /**
223
197
  * @@@
224
198
  *
@@ -434,10 +408,10 @@ $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
434
408
  'content',
435
409
  'context',
436
410
  'knowledge',
437
- 'samples',
411
+ 'examples',
438
412
  'modelName',
439
413
  'currentDate',
440
- // <- TODO: !!!!! list here all command names
414
+ // <- TODO: list here all command names
441
415
  // <- TODO: Add more like 'date', 'modelName',...
442
416
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
443
417
  ]);
@@ -457,6 +431,229 @@ Object.freeze({
457
431
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
458
432
  */
459
433
 
434
+ /**
435
+ * This error type indicates that some part of the code is not implemented yet
436
+ *
437
+ * @public exported from `@promptbook/core`
438
+ */
439
+ var NotYetImplementedError = /** @class */ (function (_super) {
440
+ __extends(NotYetImplementedError, _super);
441
+ function NotYetImplementedError(message) {
442
+ 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;
443
+ _this.name = 'NotYetImplementedError';
444
+ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
445
+ return _this;
446
+ }
447
+ return NotYetImplementedError;
448
+ }(Error));
449
+
450
+ /**
451
+ * @@@
452
+ *
453
+ * Note: `$` is used to indicate that this function is not a pure function - it access global scope
454
+ *
455
+ * @private internal function of `$Register`
456
+ */
457
+ function $getGlobalScope() {
458
+ return Function('return this')();
459
+ }
460
+
461
+ /**
462
+ * @@@
463
+ *
464
+ * @param text @@@
465
+ * @returns @@@
466
+ * @example 'HELLO_WORLD'
467
+ * @example 'I_LOVE_PROMPTBOOK'
468
+ * @public exported from `@promptbook/utils`
469
+ */
470
+ function normalizeTo_SCREAMING_CASE(text) {
471
+ var e_1, _a;
472
+ var charType;
473
+ var lastCharType = 'OTHER';
474
+ var normalizedName = '';
475
+ try {
476
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
477
+ var char = text_1_1.value;
478
+ var normalizedChar = void 0;
479
+ if (/^[a-z]$/.test(char)) {
480
+ charType = 'LOWERCASE';
481
+ normalizedChar = char.toUpperCase();
482
+ }
483
+ else if (/^[A-Z]$/.test(char)) {
484
+ charType = 'UPPERCASE';
485
+ normalizedChar = char;
486
+ }
487
+ else if (/^[0-9]$/.test(char)) {
488
+ charType = 'NUMBER';
489
+ normalizedChar = char;
490
+ }
491
+ else {
492
+ charType = 'OTHER';
493
+ normalizedChar = '_';
494
+ }
495
+ if (charType !== lastCharType &&
496
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
497
+ !(lastCharType === 'NUMBER') &&
498
+ !(charType === 'NUMBER')) {
499
+ normalizedName += '_';
500
+ }
501
+ normalizedName += normalizedChar;
502
+ lastCharType = charType;
503
+ }
504
+ }
505
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
506
+ finally {
507
+ try {
508
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
509
+ }
510
+ finally { if (e_1) throw e_1.error; }
511
+ }
512
+ normalizedName = normalizedName.replace(/_+/g, '_');
513
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
514
+ normalizedName = normalizedName.replace(/^_/, '');
515
+ normalizedName = normalizedName.replace(/_$/, '');
516
+ return normalizedName;
517
+ }
518
+ /**
519
+ * TODO: Tests
520
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
521
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
522
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
523
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
524
+ * TODO: [🌺] Use some intermediate util splitWords
525
+ */
526
+
527
+ /**
528
+ * @@@
529
+ *
530
+ * @param text @@@
531
+ * @returns @@@
532
+ * @example 'hello_world'
533
+ * @example 'i_love_promptbook'
534
+ * @public exported from `@promptbook/utils`
535
+ */
536
+ function normalizeTo_snake_case(text) {
537
+ return normalizeTo_SCREAMING_CASE(text).toLowerCase();
538
+ }
539
+
540
+ /**
541
+ * Register is @@@
542
+ *
543
+ * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
544
+ *
545
+ * @private internal utility, exported are only signleton instances of this class
546
+ */
547
+ var $Register = /** @class */ (function () {
548
+ function $Register(registerName) {
549
+ this.registerName = registerName;
550
+ var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
551
+ var globalScope = $getGlobalScope();
552
+ if (globalScope[storageName] === undefined) {
553
+ globalScope[storageName] = [];
554
+ }
555
+ else if (!Array.isArray(globalScope[storageName])) {
556
+ throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
557
+ }
558
+ this.storage = globalScope[storageName];
559
+ }
560
+ $Register.prototype.list = function () {
561
+ // <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
562
+ return this.storage;
563
+ };
564
+ $Register.prototype.register = function (registered) {
565
+ var packageName = registered.packageName, className = registered.className;
566
+ var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
567
+ var existingRegistration = this.storage[existingRegistrationIndex];
568
+ if (!existingRegistration) {
569
+ this.storage.push(registered);
570
+ }
571
+ else {
572
+ this.storage[existingRegistrationIndex] = registered;
573
+ }
574
+ return {
575
+ registerName: this.registerName,
576
+ packageName: packageName,
577
+ className: className,
578
+ get isDestroyed() {
579
+ return false;
580
+ },
581
+ destroy: function () {
582
+ throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
583
+ },
584
+ };
585
+ };
586
+ return $Register;
587
+ }());
588
+
589
+ /**
590
+ * @@@
591
+ *
592
+ * Note: `$` is used to indicate that this interacts with the global scope
593
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
594
+ * @public exported from `@promptbook/core`
595
+ */
596
+ var $scrapersRegister = new $Register('scraper_constructors');
597
+ /**
598
+ * TODO: [®] DRY Register logic
599
+ */
600
+
601
+ /**
602
+ * @@@
603
+ *
604
+ * 1) @@@
605
+ * 2) @@@
606
+ *
607
+ * @public exported from `@promptbook/browser`
608
+ */
609
+ function $provideScrapersForBrowser(tools, options) {
610
+ return __awaiter(this, void 0, void 0, function () {
611
+ var isAutoInstalled /* Note: [0] Intentionally not assigning a default value = IS_AUTO_INSTALLED */, scrapers, _a, _b, scraperFactory, scraper, e_1_1;
612
+ var e_1, _c;
613
+ return __generator(this, function (_d) {
614
+ switch (_d.label) {
615
+ case 0:
616
+ if (!$isRunningInBrowser() || $isRunningInWebWorker()) {
617
+ throw new EnvironmentMismatchError('Function `$provideScrapersForBrowser` works only in browser environment');
618
+ }
619
+ isAutoInstalled = (options || {}).isAutoInstalled;
620
+ if (isAutoInstalled === true /* <- Note: [0] Ignoring undefined, just checking EXPLICIT requirement for install */) {
621
+ throw new EnvironmentMismatchError('Auto-installing is not supported in browser environment');
622
+ }
623
+ scrapers = [];
624
+ _d.label = 1;
625
+ case 1:
626
+ _d.trys.push([1, 6, 7, 8]);
627
+ _a = __values($scrapersRegister.list()), _b = _a.next();
628
+ _d.label = 2;
629
+ case 2:
630
+ if (!!_b.done) return [3 /*break*/, 5];
631
+ scraperFactory = _b.value;
632
+ return [4 /*yield*/, scraperFactory(tools, options || {})];
633
+ case 3:
634
+ scraper = _d.sent();
635
+ scrapers.push(scraper);
636
+ _d.label = 4;
637
+ case 4:
638
+ _b = _a.next();
639
+ return [3 /*break*/, 2];
640
+ case 5: return [3 /*break*/, 8];
641
+ case 6:
642
+ e_1_1 = _d.sent();
643
+ e_1 = { error: e_1_1 };
644
+ return [3 /*break*/, 8];
645
+ case 7:
646
+ try {
647
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
648
+ }
649
+ finally { if (e_1) throw e_1.error; }
650
+ return [7 /*endfinally*/];
651
+ case 8: return [2 /*return*/, scrapers];
652
+ }
653
+ });
654
+ });
655
+ }
656
+
460
657
  /**
461
658
  * Tests if the value is [🚉] serializable as JSON
462
659
  *
@@ -511,7 +708,7 @@ function stringifyPipelineJson(pipeline) {
511
708
  return pipelineJsonStringified;
512
709
  }
513
710
  /**
514
- * TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
711
+ * TODO: [🐝] Not Working propperly @see https://promptbook.studio/examples/mixed-knowledge.ptbk.md
515
712
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
516
713
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
517
714
  * TODO: [🍙] Make some standard order of json properties