ptbk 0.44.0-22

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