@promptbook/utils 0.72.0 → 0.74.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,10 +18,16 @@ Build responsible, controlled and transparent applications on top of LLM 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
25
 
24
26
 
27
+ <blockquote style="color: #ff8811">
28
+ <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>.
29
+ </blockquote>
30
+
25
31
  ## 📦 Package `@promptbook/utils`
26
32
 
27
33
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -171,7 +177,7 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
171
177
 
172
178
  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.
173
179
 
174
- 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:
180
+ 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:
175
181
 
176
182
  1. **Fine-tune** the model to your specifications or even train your own.
177
183
  2. **Prompt-engineer** the prompt to the best shape you can achieve.
@@ -179,248 +185,87 @@ But often you will struggle with the **limitations of LLMs**, such as **hallucin
179
185
 
180
186
  In all of these situations, but especially in 3., the **✨ Promptbook can make your life waaaaaaaaaay easier**.
181
187
 
182
- - [**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.
183
- - 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.
184
- - **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.
185
- - 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.
188
+ - [**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).
189
+ - Book allows you to **focus on the business** logic without having to write code or deal with the technicalities of LLMs.
190
+ - **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.
191
+ - 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.
186
192
  - 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.
187
- - Promptbook has built in versioning. You can test multiple **A/B versions** of pipelines and see which one works best.
188
- - 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.
189
-
190
-
191
-
192
- ## 🧔 Pipeline _(for prompt-engeneers)_
193
-
194
- **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.
195
-
196
- - Multiple pipelines forms a **collection** which will handle core **know-how of your LLM application**.
197
- - Theese pipelines are designed such as they **can be written by non-programmers**.
198
-
199
-
200
-
201
- ### Sample:
202
-
203
- File `write-website-content.ptbk.md`:
204
-
205
-
206
-
207
-
208
-
209
- > # 🌍 Create website content
210
- >
211
- > Instructions for creating web page content.
212
- >
213
- > - PIPELINE URL https://promptbook.studio/webgpt/write-website-content.ptbk.md
214
- > - INPUT  PARAM `{rawTitle}` Automatically suggested a site name or empty text
215
- > - INPUT  PARAM `{rawAssigment}` Automatically generated site entry from image recognition
216
- > - OUTPUT PARAM `{websiteContent}` Web content
217
- > - OUTPUT PARAM `{keywords}` Keywords
218
- >
219
- > ## 👤 Specifying the assigment
220
- >
221
- > What is your web about?
222
- >
223
- > - DIALOG TEMPLATE
224
- >
225
- > ```
226
- > {rawAssigment}
227
- > ```
228
- >
229
- > `-> {assigment}` Website assignment and specification
230
- >
231
- > ## ✨ Improving the title
232
- >
233
- > - PERSONA Jane, Copywriter and Marketing Specialist.
234
- >
235
- > ```
236
- > As an experienced marketing specialist, you have been entrusted with improving the name of your client's business.
237
- >
238
- > A suggested name from a client:
239
- > "{rawTitle}"
240
- >
241
- > Assignment from customer:
242
- >
243
- > > {assigment}
244
- >
245
- > ## Instructions:
246
- >
247
- > - Write only one name suggestion
248
- > - The name will be used on the website, business cards, visuals, etc.
249
- > ```
250
- >
251
- > `-> {enhancedTitle}` Enhanced title
252
- >
253
- > ## 👤 Website title approval
254
- >
255
- > Is the title for your website okay?
256
- >
257
- > - DIALOG TEMPLATE
258
- >
259
- > ```
260
- > {enhancedTitle}
261
- > ```
262
- >
263
- > `-> {title}` Title for the website
264
- >
265
- > ## 🐰 Cunning subtitle
266
- >
267
- > - PERSONA Josh, a copywriter, tasked with creating a claim for the website.
268
- >
269
- > ```
270
- > As an experienced copywriter, you have been entrusted with creating a claim for the "{title}" web page.
271
- >
272
- > A website assignment from a customer:
273
- >
274
- > > {assigment}
275
- >
276
- > ## Instructions:
277
- >
278
- > - Write only one name suggestion
279
- > - Claim will be used on website, business cards, visuals, etc.
280
- > - Claim should be punchy, funny, original
281
- > ```
282
- >
283
- > `-> {claim}` Claim for the web
284
- >
285
- > ## 🚦 Keyword analysis
286
- >
287
- > - PERSONA Paul, extremely creative SEO specialist.
288
- >
289
- > ```
290
- > As an experienced SEO specialist, you have been entrusted with creating keywords for the website "{title}".
291
- >
292
- > Website assignment from the customer:
293
- >
294
- > > {assigment}
295
- >
296
- > ## Instructions:
297
- >
298
- > - Write a list of keywords
299
- > - Keywords are in basic form
300
- >
301
- > ## Example:
302
- >
303
- > - Ice cream
304
- > - Olomouc
305
- > - Quality
306
- > - Family
307
- > - Tradition
308
- > - Italy
309
- > - Craft
310
- >
311
- > ```
312
- >
313
- > `-> {keywords}` Keywords
314
- >
315
- > ## 🔗 Combine the beginning
316
- >
317
- > - SIMPLE TEMPLATE
318
- >
319
- > ```
320
- >
321
- > # {title}
322
- >
323
- > > {claim}
324
- >
325
- > ```
326
- >
327
- > `-> {contentBeginning}` Beginning of web content
328
- >
329
- > ## 🖋 Write the content
330
- >
331
- > - PERSONA Jane
332
- >
333
- > ```
334
- > As an experienced copywriter and web designer, you have been entrusted with creating text for a new website {title}.
335
- >
336
- > A website assignment from a customer:
337
- >
338
- > > {assigment}
339
- >
340
- > ## Instructions:
341
- >
342
- > - Text formatting is in Markdown
343
- > - Be concise and to the point
344
- > - Use keywords, but they should be naturally in the text
345
- > - This is the complete content of the page, so don't forget all the important information and elements the page should contain
346
- > - Use headings, bullets, text formatting
347
- >
348
- > ## Keywords:
349
- >
350
- > {keywords}
351
- >
352
- > ## Web Content:
353
- >
354
- > {contentBeginning}
355
- > ```
356
- >
357
- > `-> {contentBody}` Middle of the web content
358
- >
359
- > ## 🔗 Combine the content
360
- >
361
- > - SIMPLE TEMPLATE
362
- >
363
- > ```markdown
364
- > {contentBeginning}
365
- >
366
- > {contentBody}
367
- > ```
368
- >
369
- > `-> {websiteContent}`
370
-
371
-
372
-
373
- Following is the scheme how the promptbook above is executed:
374
-
375
- ```mermaid
376
- %% 🔮 Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually
377
-
378
- flowchart LR
379
- subgraph "🌍 Create website content"
380
-
381
- direction TB
382
-
383
- input((Input)):::input
384
- templateSpecifyingTheAssigment(👤 Specifying the assigment)
385
- input--"{rawAssigment}"-->templateSpecifyingTheAssigment
386
- templateImprovingTheTitle(✨ Improving the title)
387
- input--"{rawTitle}"-->templateImprovingTheTitle
388
- templateSpecifyingTheAssigment--"{assigment}"-->templateImprovingTheTitle
389
- templateWebsiteTitleApproval(👤 Website title approval)
390
- templateImprovingTheTitle--"{enhancedTitle}"-->templateWebsiteTitleApproval
391
- templateCunningSubtitle(🐰 Cunning subtitle)
392
- templateWebsiteTitleApproval--"{title}"-->templateCunningSubtitle
393
- templateSpecifyingTheAssigment--"{assigment}"-->templateCunningSubtitle
394
- templateKeywordAnalysis(🚦 Keyword analysis)
395
- templateWebsiteTitleApproval--"{title}"-->templateKeywordAnalysis
396
- templateSpecifyingTheAssigment--"{assigment}"-->templateKeywordAnalysis
397
- templateCombineTheBeginning(🔗 Combine the beginning)
398
- templateWebsiteTitleApproval--"{title}"-->templateCombineTheBeginning
399
- templateCunningSubtitle--"{claim}"-->templateCombineTheBeginning
400
- templateWriteTheContent(🖋 Write the content)
401
- templateWebsiteTitleApproval--"{title}"-->templateWriteTheContent
402
- templateSpecifyingTheAssigment--"{assigment}"-->templateWriteTheContent
403
- templateKeywordAnalysis--"{keywords}"-->templateWriteTheContent
404
- templateCombineTheBeginning--"{contentBeginning}"-->templateWriteTheContent
405
- templateCombineTheContent(🔗 Combine the content)
406
- templateCombineTheBeginning--"{contentBeginning}"-->templateCombineTheContent
407
- templateWriteTheContent--"{contentBody}"-->templateCombineTheContent
408
-
409
- templateCombineTheContent--"{websiteContent}"-->output
410
- output((Output)):::output
411
-
412
- classDef input color: grey;
413
- classDef output color: grey;
414
-
415
- end;
416
- ```
193
+ - Versioning is build in. You can test multiple **A/B versions** of pipelines and see which one works best.
194
+ - 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.
195
+
196
+
197
+
198
+ ## 💜 The Promptbook Project
199
+
200
+
201
+
202
+ <table>
203
+ <tbody>
204
+ <tr>
205
+ <td>Promptbook whitepaper</td>
206
+ <td>Basic motivations and problems which we are trying to solve</td>
207
+ <td rowspan=3>https://github.com/webgptorg/book</td>
208
+ </tr>
209
+ <tr>
210
+ <td>Promptbook <i>(system)</i></td>
211
+ <td>Promptbook ...</td>
212
+ </tr>
213
+ <tr>
214
+ <td>Book language</td>
215
+ <td>
216
+ Book is a markdown-like language to define projects, pipelines, knowledge,... in the Promptbook system. It is designed to be understandable by non-programmers and non-technical people
217
+ </td>
218
+ </tr>
219
+ <tr>
220
+ <td>Promptbook typescript project</td>
221
+ <td>Implementation of Promptbook in TypeScript published into multiple packages to NPM</td>
222
+ <td>https://github.com/webgptorg/promptbook</td>
223
+ </tr>
224
+ <tr>
225
+ <td>Promptbook studio</td>
226
+ <td>Promptbook studio</td>
227
+ <td rowspan=2>https://github.com/hejny/promptbook-studio</td>
228
+ </tr>
229
+ <tr>
230
+ <td>Promptbook miniapps</td>
231
+ <td>Promptbook miniapps</td>
232
+ </tr>
233
+ </tbody>
234
+ </table>
235
+
236
+ ## 💙 Book language _(for prompt-engineer)_
237
+
238
+ 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.
239
+
417
240
 
418
- - [More template samples](./samples/pipelines/)
419
- - [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)
420
241
 
421
- _Note: We are using [postprocessing functions](#postprocessing-functions) like `unwrapResult` that can be used to postprocess the result._
242
+ ```markdown
243
+ # 🌟 My first Book
422
244
 
423
- ## 📦 Packages
245
+ - INPUT PARAMETER {subject}
246
+ - OUTPUT PARAMETER {article}
247
+
248
+ ## Sample subject
249
+
250
+ > Promptbook
251
+
252
+ -> {subject}
253
+
254
+ ## Write an article
255
+
256
+ - PERSONA Jane, marketing specialist with prior experience in writing articles about technology and artificial intelligence
257
+ - KNOWLEDGE https://ptbk.io
258
+ - KNOWLEDGE ./promptbook.pdf
259
+ - EXPECT MIN 1 Sentence
260
+ - EXPECT MAX 1 Paragraph
261
+
262
+ > 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.
263
+ > Look specifically at the impact of {subject} on the AI industry.
264
+
265
+ -> {article}
266
+ ```
267
+
268
+ ## 📦 Packages _(for developers)_
424
269
 
425
270
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
426
271
  You can install all of them at once:
@@ -462,6 +307,8 @@ Or you can install them separately:
462
307
 
463
308
  The following glossary is used to clarify certain concepts:
464
309
 
310
+ ### Basic terms
311
+
465
312
 
466
313
 
467
314
  ### Core concepts
@@ -494,8 +341,8 @@ The following glossary is used to clarify certain concepts:
494
341
 
495
342
  ## 🔌 Usage in Typescript / Javascript
496
343
 
497
- - [Simple usage](./samples/usage/simple-script)
498
- - [Usage with client and remote server](./samples/usage/remote)
344
+ - [Simple usage](./examples/usage/simple-script)
345
+ - [Usage with client and remote server](./examples/usage/remote)
499
346
 
500
347
  ## ➕➖ When to use Promptbook?
501
348
 
package/esm/index.es.js CHANGED
@@ -5,7 +5,7 @@ import { basename } from 'path';
5
5
  /**
6
6
  * The version of the Promptbook library
7
7
  */
8
- var PROMPTBOOK_VERSION = '0.72.0-34';
8
+ var PROMPTBOOK_VERSION = '0.73.0';
9
9
  // TODO: [main] !!!! List here all the versions and annotate + put into script
10
10
 
11
11
  /*! *****************************************************************************
@@ -678,9 +678,9 @@ function renderPromptbookMermaid(pipelineJson, options) {
678
678
  return promptbookMermaid;
679
679
  }
680
680
  /**
681
- * TODO: !!!!! FOREACH in mermaid graph
682
- * TODO: !!!!! Knowledge in mermaid graph
683
- * TODO: !!!!! Personas in mermaid graph
681
+ * TODO: [🧠] !! FOREACH in mermaid graph
682
+ * TODO: [🧠] !! Knowledge in mermaid graph
683
+ * TODO: [🧠] !! Personas in mermaid graph
684
684
  * TODO: Maybe use some Mermaid package instead of string templating
685
685
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
686
686
  */
@@ -1795,10 +1795,10 @@ $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
1795
1795
  'content',
1796
1796
  'context',
1797
1797
  'knowledge',
1798
- 'samples',
1798
+ 'examples',
1799
1799
  'modelName',
1800
1800
  'currentDate',
1801
- // <- TODO: !!!!! list here all command names
1801
+ // <- TODO: list here all command names
1802
1802
  // <- TODO: Add more like 'date', 'modelName',...
1803
1803
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
1804
1804
  ]);