@promptbook/core 0.44.0-2 → 0.44.0-21

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