@promptbook/cli 0.44.0-9 → 0.44.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
@@ -1,5 +1,754 @@
1
- # 📖 Promptbook
1
+ # ![Promptbook logo - cube with letters P and B](./other/design/logo-h1.png) Promptbook
2
2
 
3
3
  Library to supercharge your use of large language models
4
4
 
5
- [Read the manual](https://github.com/webgptorg/promptbook)
5
+ <!--Badges-->
6
+ <!--⚠️WARNING: This section was generated by https://github.com/hejny/batch-project-editor/blob/main/src/workflows/800-badges/badges.ts so every manual change will be overwritten.-->
7
+
8
+ [![License of 📖 Prompt book](https://img.shields.io/github/license/webgptorg/promptbook.svg?style=flat)](https://github.com/webgptorg/promptbook/blob/main/LICENSE)
9
+ [![Known Vulnerabilities](https://snyk.io/test/github/webgptorg/promptbook/badge.svg)](https://snyk.io/test/github/webgptorg/promptbook)
10
+ [![Issues](https://img.shields.io/github/issues/webgptorg/promptbook.svg?style=flat)](https://github.com/webgptorg/promptbook/issues)
11
+ [![Socket Badge](https://socket.dev/api/badge/npm/package/@promptbook/cli)](https://socket.dev/npm/package/@promptbook/cli)
12
+
13
+ <!--/Badges-->
14
+
15
+ ## 📦 Package `@promptbook/cli`
16
+
17
+ - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
18
+ - This package `@promptbook/cli` is one part of the promptbook ecosystem.
19
+
20
+ To install this package, run:
21
+
22
+ ```bash
23
+ # Install as dev dependency
24
+ npm i -D @promptbook/cli
25
+
26
+ # Or install globally
27
+ npm i -g @promptbook/cli
28
+ ```
29
+
30
+ CLI utils for Promptbook. After install you can use `promptbook` command in terminal:
31
+
32
+ ```bash
33
+ npx promptbook prettify promptbook/**/*.ptbk.md
34
+ ```
35
+
36
+ This will prettify all promptbooks in `promptbook` directory and adds Mermaid graphs to them.
37
+
38
+
39
+ ---
40
+
41
+ Rest of the documentation is common for **entire promptbook ecosystem**:
42
+
43
+ <!--
44
+ TODO: Probbably remove this section only in packages
45
+ > ⚠ Warning: This library is still in early development.
46
+ -->
47
+
48
+ ## 🤍 Whitepaper
49
+
50
+ When you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama 2, or whatever, it doesn't matter how it is integrated. Whether it's the direct calling of a REST API, using the SDK, hardcoding the prompt in the source code, or importing a text file, the process remains the same.
51
+
52
+ If you need something more advanced or want to extend the capabilities of LLMs, you generally have three ways to proceed:
53
+
54
+ 1. **Fine-tune** the model to your specifications or even train your own.
55
+ 2. **Prompt-engineer** the prompt to the best shape you can achieve.
56
+ 3. Use **multiple prompts** in a pipeline to get the best result.
57
+
58
+ In any of these situations, but especially in (3), the Promptbook library can make your life easier and make **orchestraror for your prompts**.
59
+
60
+ - **Separation of concerns** between prompt engineer and programmer; between code files and prompt files; and between prompts, templates, templating pipelines, and their execution logic.
61
+ - Set up a **common format** for prompts that is interchangeable between projects and language/technology stacks.
62
+ - **Preprocessing** and cleaning the input data from the user.
63
+ - Use default values - **Jokers** to bypass some parts of the pipeline.
64
+ - **Expect** some specific output from the model.
65
+ - **Retry** mismatched outputs.
66
+ - **Combine** multiple models together.
67
+ - Interactive **User interaction** with the model and the user.
68
+ - Leverage **external** sources (like ChatGPT plugins or OpenAI's GPTs).
69
+ - Simplify your code to be **DRY** and not repeat all the boilerplate code for each prompt.
70
+ - **Versioning** of promptbooks
71
+ - **Reuse** parts of promptbooks in/between projects.
72
+ - Run the LLM **optimally** in parallel, with the best _cost/quality_ ratio or _speed/quality_ ratio.
73
+ - **Execution report** to see what happened during the execution.
74
+ - **Logging** the results of the promptbooks.
75
+ - _(Not ready yet)_ **Caching** calls to LLMs to save money and time.
76
+ - _(Not ready yet)_ Extend one prompt book from another one.
77
+ - _(Not ready yet)_ Leverage the **streaming** to make super cool UI/UX.
78
+ - _(Not ready yet)_ **A/B testing** to determine which prompt works best for the job.
79
+
80
+ ![WebGPT](./other/screencasts/screencast-fiabciakcmgepblmdkmemdbbkilneeeh-2023.10.26-21_46_17.gif)
81
+
82
+ ## 🧔 Promptbook _(for prompt-engeneers)_
83
+
84
+ **P**romp**t** **b**oo**k** markdown file (**PTBK** for short, or `.ptbk.md`) is document that describes a series of prompts that are chained together to form somewhat reciepe for transforming natural language input. Inside a PTBK you can use chat prompts, completion prompts, scripting or trigger interaction with user to ask for additional information.
85
+
86
+ - Multiple promptbooks forms a library which will become a **part of your application codebase**.
87
+ - Theese promptbooks are designed such as they **can be written by non-programmers**.
88
+
89
+ <!-- TODO: [🧠] Make some more clear escaping -->
90
+
91
+ ### Sample:
92
+
93
+ File `write-website-content.ptbk.md`:
94
+
95
+ <!------------------------[ Sample: ]------------------------>
96
+
97
+ > # 🌍 Create website content
98
+ >
99
+ > Instructions for creating web page content.
100
+ >
101
+ > - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md@v0.1.0
102
+ > - PROMPTBOOK VERSION 0.0.1
103
+ > - INPUT  PARAM `{rawTitle}` Automatically suggested a site name or empty text
104
+ > - INPUT  PARAM `{rawAssigment}` Automatically generated site entry from image recognition
105
+ > - OUTPUT PARAM `{content}` Web content
106
+ > - OUTPUT PARAM `{keywords}` Keywords
107
+ >
108
+ > ## 👤 Specifying the assigment
109
+ >
110
+ > What is your web about?
111
+ >
112
+ > - PROMPT DIALOG
113
+ >
114
+ > ```
115
+ > {rawAssigment}
116
+ > ```
117
+ >
118
+ > `-> {assigment}` Website assignment and specification
119
+ >
120
+ > ## ✨ Improving the title
121
+ >
122
+ > - MODEL VARIANT Chat
123
+ > - MODEL NAME `gpt-4`
124
+ > - POSTPROCESSING `unwrapResult`
125
+ >
126
+ > ```
127
+ > As an experienced marketing specialist, you have been entrusted with improving the name of your client's business.
128
+ >
129
+ > A suggested name from a client:
130
+ > "{rawTitle}"
131
+ >
132
+ > Assignment from customer:
133
+ >
134
+ > > {assigment}
135
+ >
136
+ > ## Instructions:
137
+ >
138
+ > - Write only one name suggestion
139
+ > - The name will be used on the website, business cards, visuals, etc.
140
+ > ```
141
+ >
142
+ > `-> {enhancedTitle}` Enhanced title
143
+ >
144
+ > ## 👤 Website title approval
145
+ >
146
+ > Is the title for your website okay?
147
+ >
148
+ > - PROMPT DIALOG
149
+ >
150
+ > ```
151
+ > {enhancedTitle}
152
+ > ```
153
+ >
154
+ > `-> {title}` Title for the website
155
+ >
156
+ > ## 🐰 Cunning subtitle
157
+ >
158
+ > - MODEL VARIANT Chat
159
+ > - MODEL NAME `gpt-4`
160
+ > - POSTPROCESSING `unwrapResult`
161
+ >
162
+ > ```
163
+ > As an experienced copywriter, you have been entrusted with creating a claim for the "{title}" web page.
164
+ >
165
+ > A website assignment from a customer:
166
+ >
167
+ > > {assigment}
168
+ >
169
+ > ## Instructions:
170
+ >
171
+ > - Write only one name suggestion
172
+ > - Claim will be used on website, business cards, visuals, etc.
173
+ > - Claim should be punchy, funny, original
174
+ > ```
175
+ >
176
+ > `-> {claim}` Claim for the web
177
+ >
178
+ > ## 🚦 Keyword analysis
179
+ >
180
+ > - MODEL VARIANT Chat
181
+ > - MODEL NAME `gpt-4`
182
+ >
183
+ > ```
184
+ > As an experienced SEO specialist, you have been entrusted with creating keywords for the website "{title}".
185
+ >
186
+ > Website assignment from the customer:
187
+ >
188
+ > > {assigment}
189
+ >
190
+ > ## Instructions:
191
+ >
192
+ > - Write a list of keywords
193
+ > - Keywords are in basic form
194
+ >
195
+ > ## Example:
196
+ >
197
+ > - Ice cream
198
+ > - Olomouc
199
+ > - Quality
200
+ > - Family
201
+ > - Tradition
202
+ > - Italy
203
+ > - Craft
204
+ >
205
+ > ```
206
+ >
207
+ > `-> {keywords}` Keywords
208
+ >
209
+ > ## 🔗 Combine the beginning
210
+ >
211
+ > - SIMPLE TEMPLATE
212
+ >
213
+ > ```
214
+ >
215
+ > # {title}
216
+ >
217
+ > > {claim}
218
+ >
219
+ > ```
220
+ >
221
+ > `-> {contentBeginning}` Beginning of web content
222
+ >
223
+ > ## 🖋 Write the content
224
+ >
225
+ > - MODEL VARIANT Completion
226
+ > - MODEL NAME `gpt-3.5-turbo-instruct`
227
+ >
228
+ > ```
229
+ > As an experienced copywriter and web designer, you have been entrusted with creating text for a new website {title}.
230
+ >
231
+ > A website assignment from a customer:
232
+ >
233
+ > > {assigment}
234
+ >
235
+ > ## Instructions:
236
+ >
237
+ > - Text formatting is in Markdown
238
+ > - Be concise and to the point
239
+ > - Use keywords, but they should be naturally in the text
240
+ > - This is the complete content of the page, so don't forget all the important information and elements the page should contain
241
+ > - Use headings, bullets, text formatting
242
+ >
243
+ > ## Keywords:
244
+ >
245
+ > {keywords}
246
+ >
247
+ > ## Web Content:
248
+ >
249
+ > {contentBeginning}
250
+ > ```
251
+ >
252
+ > `-> {contentBody}` Middle of the web content
253
+ >
254
+ > ## 🔗 Combine the content
255
+ >
256
+ > - SIMPLE TEMPLATE
257
+ >
258
+ > ```markdown
259
+ > {contentBeginning}
260
+ >
261
+ > {contentBody}
262
+ > ```
263
+ >
264
+ > `-> {content}`
265
+
266
+ <!------------------------[ /Sample ]------------------------>
267
+
268
+ Following is the scheme how the promptbook above is executed:
269
+
270
+ ```mermaid
271
+ %% 🔮 Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually
272
+
273
+ flowchart LR
274
+ subgraph "🌍 Create website content"
275
+
276
+ direction TB
277
+
278
+ input((Input)):::input
279
+ templateSpecifyingTheAssigment(👤 Specifying the assigment)
280
+ input--"{rawAssigment}"-->templateSpecifyingTheAssigment
281
+ templateImprovingTheTitle(✨ Improving the title)
282
+ input--"{rawTitle}"-->templateImprovingTheTitle
283
+ templateSpecifyingTheAssigment--"{assigment}"-->templateImprovingTheTitle
284
+ templateWebsiteTitleApproval(👤 Website title approval)
285
+ templateImprovingTheTitle--"{enhancedTitle}"-->templateWebsiteTitleApproval
286
+ templateCunningSubtitle(🐰 Cunning subtitle)
287
+ templateWebsiteTitleApproval--"{title}"-->templateCunningSubtitle
288
+ templateSpecifyingTheAssigment--"{assigment}"-->templateCunningSubtitle
289
+ templateKeywordAnalysis(🚦 Keyword analysis)
290
+ templateWebsiteTitleApproval--"{title}"-->templateKeywordAnalysis
291
+ templateSpecifyingTheAssigment--"{assigment}"-->templateKeywordAnalysis
292
+ templateCombineTheBeginning(🔗 Combine the beginning)
293
+ templateWebsiteTitleApproval--"{title}"-->templateCombineTheBeginning
294
+ templateCunningSubtitle--"{claim}"-->templateCombineTheBeginning
295
+ templateWriteTheContent(🖋 Write the content)
296
+ templateWebsiteTitleApproval--"{title}"-->templateWriteTheContent
297
+ templateSpecifyingTheAssigment--"{assigment}"-->templateWriteTheContent
298
+ templateKeywordAnalysis--"{keywords}"-->templateWriteTheContent
299
+ templateCombineTheBeginning--"{contentBeginning}"-->templateWriteTheContent
300
+ templateCombineTheContent(🔗 Combine the content)
301
+ templateCombineTheBeginning--"{contentBeginning}"-->templateCombineTheContent
302
+ templateWriteTheContent--"{contentBody}"-->templateCombineTheContent
303
+
304
+ templateCombineTheContent--"{content}"-->output
305
+ output((Output)):::output
306
+
307
+ classDef input color: grey;
308
+ classDef output color: grey;
309
+
310
+ end;
311
+ ```
312
+
313
+ [More template samples](./samples/templates/)
314
+
315
+ _Note: We are using [postprocessing functions](#postprocessing-functions) like `unwrapResult` that can be used to postprocess the result._
316
+
317
+ ## 📦 Packages
318
+
319
+ This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook):
320
+
321
+ <!--[🔠]-->
322
+
323
+ - **[@promptbook/core](https://www.npmjs.com/package/@promptbook/core)** - Core of the library, it contains the main logic for promptbooks
324
+ - **[@promptbook/utils](https://www.npmjs.com/package/@promptbook/utils)** - Utility functions used in the library but also useful for individual use in preprocessing and postprocessing LLM inputs and outputs
325
+ - _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
326
+ - **[@promptbook/execute-javascript](https://www.npmjs.com/package/@promptbook/execute-javascript)** - Execution tools for javascript inside promptbooks
327
+ - **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
328
+ - **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
329
+ - **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
330
+ - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
331
+ - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
332
+
333
+ ## 📚 Dictionary
334
+
335
+ The following glossary is used to clarify certain basic concepts:
336
+
337
+ ### Prompt
338
+
339
+ Prompt in a text along with model requirements, but without any execution or templating logic.
340
+
341
+ For example:
342
+
343
+ ```json
344
+ {
345
+ "request": "Which sound does a cat make?",
346
+ "modelRequirements": {
347
+ "variant": "CHAT"
348
+ }
349
+ }
350
+ ```
351
+
352
+ ```json
353
+ {
354
+ "request": "I am a cat.\nI like to eat fish.\nI like to sleep.\nI like to play with a ball.\nI l",
355
+ "modelRequirements": {
356
+ "variant": "COMPLETION"
357
+ }
358
+ }
359
+ ```
360
+
361
+ ### Prompt Template
362
+
363
+ Similar concept to Prompt, but with templating logic.
364
+
365
+ For example:
366
+
367
+ ```json
368
+ {
369
+ "request": "Which sound does a {animalName} make?",
370
+ "modelRequirements": {
371
+ "variant": "CHAT"
372
+ }
373
+ }
374
+ ```
375
+
376
+ ### Model Requirements
377
+
378
+ Abstract way to specify the LLM.
379
+ It does not specify the LLM with concrete version itself, only the requirements for the LLM.
380
+ _NOT chatgpt-3.5-turbo BUT CHAT variant of GPT-3.5._
381
+
382
+ For example:
383
+
384
+ ```json
385
+ {
386
+ "variant": "CHAT",
387
+ "version": "GPT-3.5",
388
+ "temperature": 0.7
389
+ }
390
+ ```
391
+
392
+ ### Execution type
393
+
394
+ Each block of promptbook can have a different execution type.
395
+ It is specified in list of requirements for the block.
396
+ By default, it is `Prompt template`
397
+
398
+ - _(default)_ `Prompt template` The block is a prompt template and is executed by LLM (OpenAI, Azure,...)
399
+ - `SIMPLE TEMPLATE` The block is a simple text template which is just filled with parameters
400
+ - `Script` The block is a script that is executed by some script runtime, the runtime is determined by block type, currently only `javascript` is supported but we plan to add `python` and `typescript` in the future.
401
+ - `PROMPT DIALOG` Ask user for input
402
+
403
+ ### Parameters
404
+
405
+ Parameters that are placed in the prompt template and replaced to create the prompt.
406
+ It is a simple key-value object.
407
+
408
+ ```json
409
+ {
410
+ "animalName": "cat",
411
+ "animalSound": "Meow!"
412
+ }
413
+ ```
414
+
415
+ There are three types of template parameters, depending on how they are used in the promptbook:
416
+
417
+ - **INPUT PARAMETER**s are required to execute the promptbook.
418
+ - **Intermediate parameters** are used internally in the promptbook.
419
+ - **OUTPUT PARAMETER**s are explicitelly marked and they are returned as the result of the promptbook execution.
420
+
421
+ _Note: Parameter can be both intermedite and output at the same time._
422
+
423
+ ### Promptbook
424
+
425
+ Promptbook is **core concept of this library**.
426
+ It represents a series of prompt templates chained together to form a **pipeline** / one big prompt template with input and result parameters.
427
+
428
+ Internally it can have multiple formats:
429
+
430
+ - **.ptbk.md file** in custom markdown format described above
431
+ - _(concept)_ **.ptbk** format, custom fileextension based on markdown
432
+ - _(internal)_ **JSON** format, parsed from the .ptbk.md file
433
+
434
+ ### Promptbook **Library**
435
+
436
+ Library of all promptbooks used in your application.
437
+ Each promptbook is a separate `.ptbk.md` file with unique `PROMPTBOOK URL`. Theese urls are used to reference promptbooks in other promptbooks or in the application code.
438
+
439
+ ### Prompt Result
440
+
441
+ Prompt result is the simplest concept of execution.
442
+ It is the result of executing one prompt _(NOT a template)_.
443
+
444
+ For example:
445
+
446
+ ```json
447
+ {
448
+ "response": "Meow!",
449
+ "model": "chatgpt-3.5-turbo"
450
+ }
451
+ ```
452
+
453
+ ### Execution Tools
454
+
455
+ `ExecutionTools` is an interface which contains all the tools needed to execute prompts.
456
+ It contais 3 subtools:
457
+
458
+ - `NaturalExecutionTools`
459
+ - `ScriptExecutionTools`
460
+ - `UserInterfaceTools`
461
+
462
+ Which are described below:
463
+
464
+ #### Natural Execution Tools
465
+
466
+ `NaturalExecutionTools` is a container for all the tools needed to execute prompts to large language models like GPT-4.
467
+ On its interface it exposes common methods for prompt execution.
468
+ Internally it calls OpenAI, Azure, GPU, proxy, cache, logging,...
469
+
470
+ `NaturalExecutionTools` an abstract interface that is implemented by concrete execution tools:
471
+
472
+ - `OpenAiExecutionTools`
473
+ - _(Not implemented yet)_ `AnthropicClaudeExecutionTools`
474
+ - _(Not implemented yet)_ `AzureOpenAiExecutionTools`
475
+ - _(Not implemented yet)_ `BardExecutionTools`
476
+ - _(Not implemented yet)_ `LamaExecutionTools`
477
+ - _(Not implemented yet)_ `GpuExecutionTools`
478
+ - And a special case are `RemoteNaturalExecutionTools` that connect to a remote server and run one of the above execution tools on that server.
479
+ - The second special case is `MockedEchoNaturalExecutionTools` that is used for testing and mocking.
480
+ - The third special case is `LogNaturalExecutionToolsWrapper` that is technically also an execution tools but it is more proxy wrapper around other execution tools that logs all calls to execution tools.
481
+
482
+ #### Script Execution Tools
483
+
484
+ `ScriptExecutionTools` is an abstract container that represents all the tools needed to EXECUTE SCRIPTs. It is implemented by concrete execution tools:
485
+
486
+ - `JavascriptExecutionTools` is a wrapper around `vm2` module that executes javascript code in a sandbox.
487
+ - `JavascriptEvalExecutionTools` is wrapper around `eval` function that executes javascript. It is used for testing and mocking **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
488
+ - _(Not implemented yet)_ `TypescriptExecutionTools` executes typescript code in a sandbox.
489
+ - _(Not implemented yet)_ `PythonExecutionTools` executes python code in a sandbox.
490
+
491
+ There are [postprocessing functions](#postprocessing-functions) that can be used to postprocess the result.
492
+
493
+ #### User Interface Tools
494
+
495
+ `UserInterfaceTools` is an abstract container that represents all the tools needed to interact with the user. It is implemented by concrete execution tools:
496
+
497
+ - _(Not implemented yet)_ `ConsoleInterfaceTools` is a wrapper around `readline` module that interacts with the user via console.
498
+ - `SimplePromptInterfaceTools` is a wrapper around `window.prompt` synchronous function that interacts with the user via browser prompt. It is used for testing and mocking **NOT intended to use in the production** due to its synchronous nature.
499
+ - `CallbackInterfaceTools` delagates the user interaction to a async callback function. You need to provide your own implementation of this callback function and its bind to UI. <!-- <- TODO: Provide here a way how to do it with some our plugin -->
500
+
501
+ ### Executor
502
+
503
+ Executor is a simple async function that takes **input parameters** and returns **output parameters**.
504
+ It is constructed by combining execution tools and promptbook to execute together.
505
+
506
+ ### 🃏 Jokers
507
+
508
+ Joker is a previously defined parameter that is used to bypass some parts of the pipeline.
509
+ If the joker is present in the template, it is checked to see if it meets the requirements (without postprocessing), and if so, it is used instead of executing that prompt template. There can be multiple wildcards in a prompt template, if so they are checked in order and the first one that meets the requirements is used.
510
+
511
+ If none of the jokers meet the requirements, the prompt template is executed as usual.
512
+
513
+ This can be useful, for example, if you want to use some predefined data, or if you want to use some data from the user, but you are not sure if it is suitable form.
514
+
515
+ When using wildcards, you must have at least one minimum expectation. If you do not have a minimum expectation, the joker will always fulfil the expectation because it has none, so it makes no logical sense.
516
+
517
+ Look at [jokers.ptbk.md](samples/templates/41-jokers.ptbk.md) sample.
518
+
519
+ ### Postprocessing functions
520
+
521
+ You can define postprocessing functions when creating `JavascriptEvalExecutionTools`:
522
+
523
+ ```
524
+
525
+ ```
526
+
527
+ Additionally there are some usefull string-manipulation build-in functions, which are [listed here](src/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.ts).
528
+
529
+ ### Expectations
530
+
531
+ `Expect` command describes the desired output of the prompt template (after post-processing)
532
+ It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs,...
533
+
534
+ _Note: LLMs work with tokens, not characters, but in Promptbooks we want to use some human-recognisable and cross-model interoperable units._
535
+
536
+ ```markdown
537
+ # ✨ Sample: Expectations
538
+
539
+ - PROMPTBOOK URL https://promptbook.example.com/samples/postprocessing-2.ptbk.md@v1
540
+ - PROMPTBOOK VERSION 1.0.0
541
+ - INPUT  PARAMETER {yourName} Name of the hero
542
+
543
+ ## 💬 Question
544
+
545
+ - EXPECT MAX 30 CHARACTERS
546
+ - EXPECT MIN 2 CHARACTERS
547
+ - EXPECT MAX 3 WORDS
548
+ - EXPECT EXACTLY 1 SENTENCE
549
+ - EXPECT EXACTLY 1 LINE
550
+
551
+ ...
552
+ ```
553
+
554
+ There are two types of expectations which are not strictly symmetrical:
555
+
556
+ #### Minimal expectations
557
+
558
+ - `EXPECT MIN 0 ...` is not valid minimal expectation. It makes no sense.
559
+ - `EXPECT JSON` is both minimal and maximal expectation
560
+ - When you are using `JOKER` in same prompt template, you need to have at least one minimal expectation
561
+
562
+ #### Maximal expectations
563
+
564
+ - `EXPECT MAX 0 ...` is valid maximal expectation. For example, you can expect 0 pages and 2 sentences.
565
+ - `EXPECT JSON` is both minimal and maximal expectation
566
+
567
+ Look at [expectations.ptbk.md](samples/templates/45-expectations.ptbk.md) and [expect-json.ptbk.md](samples/templates/45-expect-json.ptbk.md) samples for more.
568
+
569
+ <!--
570
+ ### New
571
+ [🥻] Insert here when making new command
572
+ -->
573
+
574
+ ### Execution report
575
+
576
+ Execution report is a simple object or markdown that contains information about the execution of the promptbook.
577
+
578
+ [See the example of such a report](/samples/templates/50-advanced.report.md)
579
+
580
+ <!-- TODO: Write more -->
581
+
582
+ ### Remote server
583
+
584
+ Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
585
+
586
+ You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
587
+ This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
588
+
589
+ ## 👨‍💻 Usage and integration _(for developers)_
590
+
591
+ <!--
592
+
593
+ TODO: [🧙‍♂️]
594
+
595
+ ### 🧙‍♂️ Using wizzard
596
+
597
+ First you need to install this library:
598
+
599
+ ```bash
600
+ npm install --save @promptbook/wizzard
601
+ ```
602
+
603
+ > TODO: !! Write the Wizzard sample
604
+
605
+ [Usage samples](./samples/usage/)
606
+
607
+ -->
608
+
609
+ ### 🔌 Usage in Typescript / Javascript
610
+
611
+ - [Simple usage](./samples/usage/simple-script)
612
+ - [Usage with client and remote server](./samples/usage/remote)
613
+
614
+ ## ➕➖ When to use Promptbook?
615
+
616
+ ### ➕ When to use
617
+
618
+ - When you are writing app that generates complex things via LLM - like **websites, articles, presentations, code, stories, songs**,...
619
+ - When you want to **separate code from text prompts**
620
+ - When you want to describe **complex prompt pipelines** and don't want to do it in the code
621
+ - When you want to **orchestrate multiple prompts** together
622
+ - When you want to **reuse** parts of prompts in multiple places
623
+ - When you want to **version** your prompts and **test multiple versions**
624
+ - When you want to **log** the execution of prompts and backtrace the issues
625
+
626
+ ### ➖ When not to use
627
+
628
+ - When you are writing just a simple chatbot without any extra logic, just system messages
629
+
630
+ ## 🐜 Known issues
631
+
632
+ <!-- TODO: -->
633
+
634
+ ## 🧼 Intentionally not implemented features
635
+
636
+ <!-- TODO: -->
637
+
638
+ ## ❔ FAQ
639
+
640
+ If you have a question [start a discussion](https://github.com/webgptorg/promptbook/discussions/), [open an issue](https://github.com/webgptorg/promptbook/issues) or [write me an email](https://www.pavolhejny.com/contact).
641
+
642
+ ### Why not just use the OpenAI SDK / Anthropic Claude SDK / ...?
643
+
644
+ Different levels of abstraction. OpenAI library is for direct use of OpenAI API. This library is for a higher level of abstraction. It is for creating prompt templates and promptbooks that are independent of the underlying library, LLM model, or even LLM provider.
645
+
646
+ ### How is it different from the Langchain library?
647
+
648
+ Langchain is primarily aimed at ML developers working in Python. This library is for developers working in javascript/typescript and creating applications for end users.
649
+
650
+ We are considering creating a bridge/converter between these two libraries.
651
+
652
+ <!--
653
+
654
+ ==========
655
+ Include:
656
+ - Langchain is the python library and JavaScript is on second place
657
+ - Langchain primarily focused on making templates, not on combining templates into larger structures
658
+ - at the language level it distinguishes between chat and completion, I need to mix the two into one template pipeline
659
+ - for a non-programmer it's quite hard to work with such a thing and write templates - I would much prefer a system that allows non-technical people to write templates (of which there are many more on the market than free pythonists)
660
+ - The focus of promptbooks is primarily on building user applications, not the data processing, training or autogpt.
661
+ -->
662
+
663
+ ### Promptbooks vs. OpenAI`s GPTs
664
+
665
+ GPTs are chat assistants that can be assigned to specific tasks and materials. But they are still chat assistants. Promptbooks are a way to orchestrate many more predefined tasks to have much tighter control over the process. Promptbooks are not a good technology for creating human-like chatbots, GPTs are not a good technology for creating outputs with specific requirements.
666
+
667
+ <!--
668
+ TODO:
669
+ ### Promptbooks vs. Semantic Kernel
670
+
671
+
672
+ -->
673
+
674
+ <!--
675
+ TODO: !
676
+ ### Promptbooks vs. Langtail
677
+
678
+
679
+ -->
680
+
681
+ <!--
682
+ TODO:
683
+ ### Promptbooks vs. Evidentally AI
684
+
685
+ Logging and monitoring
686
+
687
+ -->
688
+
689
+ ### Where should I store my promptbooks?
690
+
691
+ If you use raw SDKs, you just put prompts in the sourcecode, mixed in with typescript, javascript, python or whatever programming language you use.
692
+
693
+ If you use promptbooks, you can store them in several places, each with its own advantages and disadvantages:
694
+
695
+ 1. As **source code**, typically git-committed. In this case you can use the versioning system and the promptbooks will be tightly coupled with the version of the application. You still get the power of promptbooks, as you separate the concerns of the prompt-engineer and the programmer.
696
+
697
+ 2. As data in a **database** In this case, promptbooks are like posts / articles on the blog. They can be modified independently of the application. You don't need to redeploy the application to change the promptbooks. You can have multiple versions of promptbooks for each user. You can have a web interface for non-programmers to create and modify promptbooks. But you lose the versioning system and you still have to consider the interface between the promptbooks and the application _(= input and output parameters)_.
698
+
699
+ 3. In a **configuration** in environment variables. This is a good way to store promptbooks if you have an application with multiple deployments and you want to have different but simple promptbooks for each deployment and you don't need to change them often.
700
+
701
+ ### What should I do when I need same promptbook in multiple human languages?
702
+
703
+ A single promptbook can be written for several _(human)_ languages at once. However, we recommend that you have separate promptbooks for each language.
704
+
705
+ In large language models, you will get better results if you have prompts in the same language as the user input.
706
+
707
+ The best way to manage this is to have suffixed promptbooks like `write-website-content.en.ptbk.md` and `write-website-content.cs.ptbk.md` for each supported language.
708
+
709
+ <!--
710
+ TODO: (Maybe)
711
+ ### Why you need to explicitly specify input and output parameters?
712
+ -->
713
+
714
+ <!--
715
+
716
+
717
+
718
+ !
719
+
720
+
721
+
722
+ unit testing
723
+
724
+ escaping
725
+
726
+ how i get block into prompt
727
+
728
+
729
+ ## 🚷 Limitations
730
+
731
+ function calling
732
+ system message
733
+ iterations
734
+
735
+ -->
736
+
737
+ ## ⌚ Changelog
738
+
739
+ See [CHANGELOG.md](./CHANGELOG.md)
740
+
741
+ ## 📜 License
742
+
743
+ <p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://github.com/webgptorg/promptbook">Promptbook</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://github.com/hejny/">Pavol Hejný</a> is licensed under <a href="https://creativecommons.org/licenses/by/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY 4.0</a></p>
744
+
745
+ <!--Contributing-->
746
+ <!--⚠️WARNING: This section was generated by https://github.com/hejny/batch-project-editor/blob/main/src/workflows/810-contributing/contributing.ts so every manual change will be overwritten.-->
747
+
748
+ ## 🖋️ Contributing
749
+
750
+ I am open to pull requests, feedback, and suggestions. Or if you like this utility, you can [☕ buy me a coffee](https://www.buymeacoffee.com/hejny) or [donate via cryptocurrencies](https://github.com/hejny/hejny/blob/main/documents/crypto.md).
751
+
752
+ You can also ⭐ star the promptbook package, [follow me on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).
753
+
754
+ <!--/Contributing-->