@promptbook/remote-server 0.44.0-9 โ†’ 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +740 -2
  2. package/esm/index.es.js +2 -2
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/utils.index.d.ts +4 -2
  5. package/esm/typings/conversion/promptbookStringToJson.d.ts +2 -2
  6. package/esm/typings/execution/ExecutionTools.d.ts +3 -3
  7. package/esm/typings/execution/NaturalExecutionTools.d.ts +2 -2
  8. package/esm/typings/execution/ScriptExecutionTools.d.ts +2 -2
  9. package/esm/typings/execution/UserInterfaceTools.d.ts +1 -1
  10. package/esm/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionTools.d.ts +10 -0
  11. package/esm/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +6 -2
  12. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -0
  13. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +7 -7
  14. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  15. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +5 -1
  16. package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/unknownToString.d.ts +7 -0
  17. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
  18. package/esm/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +1 -1
  19. package/esm/typings/library/PromptbookLibrary.d.ts +1 -1
  20. package/esm/typings/types/ExecutionTypes.d.ts +1 -1
  21. package/esm/typings/types/ModelRequirements.d.ts +1 -1
  22. package/esm/typings/types/Prompt.d.ts +5 -0
  23. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +6 -5
  24. package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +1 -1
  25. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -3
  26. package/esm/typings/types/ScriptLanguage.d.ts +1 -1
  27. package/esm/typings/types/TaskProgress.d.ts +2 -2
  28. package/esm/typings/types/execution-report/ExecutionReportStringOptions.d.ts +1 -1
  29. package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
  30. package/package.json +4 -4
  31. package/umd/index.umd.js +4 -5
  32. package/umd/index.umd.js.map +1 -1
  33. package/umd/typings/_packages/utils.index.d.ts +4 -2
  34. package/umd/typings/conversion/promptbookStringToJson.d.ts +2 -2
  35. package/umd/typings/execution/ExecutionTools.d.ts +3 -3
  36. package/umd/typings/execution/NaturalExecutionTools.d.ts +2 -2
  37. package/umd/typings/execution/ScriptExecutionTools.d.ts +2 -2
  38. package/umd/typings/execution/UserInterfaceTools.d.ts +1 -1
  39. package/umd/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionTools.d.ts +10 -0
  40. package/umd/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +6 -2
  41. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -0
  42. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +7 -7
  43. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  44. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +5 -1
  45. package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/unknownToString.d.ts +7 -0
  46. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
  47. package/umd/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +1 -1
  48. package/umd/typings/library/PromptbookLibrary.d.ts +1 -1
  49. package/umd/typings/types/ExecutionTypes.d.ts +1 -1
  50. package/umd/typings/types/ModelRequirements.d.ts +1 -1
  51. package/umd/typings/types/Prompt.d.ts +5 -0
  52. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +6 -5
  53. package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +1 -1
  54. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -3
  55. package/umd/typings/types/ScriptLanguage.d.ts +1 -1
  56. package/umd/typings/types/TaskProgress.d.ts +2 -2
  57. package/umd/typings/types/execution-report/ExecutionReportStringOptions.d.ts +1 -1
  58. package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
package/README.md CHANGED
@@ -1,5 +1,743 @@
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/remote-server)](https://socket.dev/npm/package/@promptbook/remote-server)
12
+
13
+ <!--/Badges-->
14
+
15
+ ## ๐Ÿ“ฆ Package `@promptbook/remote-server`
16
+
17
+ - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
18
+ - This package `@promptbook/remote-server` is one part of the promptbook ecosystem.
19
+
20
+ To install this package, run:
21
+
22
+ ```bash
23
+ npm i @promptbook/remote-server
24
+ ```
25
+
26
+ <!-- TODO: Sample of use + interlink server and client -->
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
+ 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.
427
+
428
+ ### Prompt Result
429
+
430
+ Prompt result is the simplest concept of execution.
431
+ It is the result of executing one prompt _(NOT a template)_.
432
+
433
+ For example:
434
+
435
+ ```json
436
+ {
437
+ "response": "Meow!",
438
+ "model": "chatgpt-3.5-turbo"
439
+ }
440
+ ```
441
+
442
+ ### Execution Tools
443
+
444
+ `ExecutionTools` is an interface which contains all the tools needed to execute prompts.
445
+ It contais 3 subtools:
446
+
447
+ - `NaturalExecutionTools`
448
+ - `ScriptExecutionTools`
449
+ - `UserInterfaceTools`
450
+
451
+ Which are described below:
452
+
453
+ #### Natural Execution Tools
454
+
455
+ `NaturalExecutionTools` is a container for all the tools needed to execute prompts to large language models like GPT-4.
456
+ On its interface it exposes common methods for prompt execution.
457
+ Internally it calls OpenAI, Azure, GPU, proxy, cache, logging,...
458
+
459
+ `NaturalExecutionTools` an abstract interface that is implemented by concrete execution tools:
460
+
461
+ - `OpenAiExecutionTools`
462
+ - _(Not implemented yet)_ `AnthropicClaudeExecutionTools`
463
+ - _(Not implemented yet)_ `AzureOpenAiExecutionTools`
464
+ - _(Not implemented yet)_ `BardExecutionTools`
465
+ - _(Not implemented yet)_ `LamaExecutionTools`
466
+ - _(Not implemented yet)_ `GpuExecutionTools`
467
+ - And a special case are `RemoteNaturalExecutionTools` that connect to a remote server and run one of the above execution tools on that server.
468
+ - The second special case is `MockedEchoNaturalExecutionTools` that is used for testing and mocking.
469
+ - 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.
470
+
471
+ #### Script Execution Tools
472
+
473
+ `ScriptExecutionTools` is an abstract container that represents all the tools needed to EXECUTE SCRIPTs. It is implemented by concrete execution tools:
474
+
475
+ - `JavascriptExecutionTools` is a wrapper around `vm2` module that executes javascript code in a sandbox.
476
+ - `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.
477
+ - _(Not implemented yet)_ `TypescriptExecutionTools` executes typescript code in a sandbox.
478
+ - _(Not implemented yet)_ `PythonExecutionTools` executes python code in a sandbox.
479
+
480
+ There are [postprocessing functions](#postprocessing-functions) that can be used to postprocess the result.
481
+
482
+ #### User Interface Tools
483
+
484
+ `UserInterfaceTools` is an abstract container that represents all the tools needed to interact with the user. It is implemented by concrete execution tools:
485
+
486
+ - _(Not implemented yet)_ `ConsoleInterfaceTools` is a wrapper around `readline` module that interacts with the user via console.
487
+ - `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.
488
+ - `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 -->
489
+
490
+ ### Executor
491
+
492
+ Executor is a simple async function that takes **input parameters** and returns **output parameters**.
493
+ It is constructed by combining execution tools and promptbook to execute together.
494
+
495
+ ### ๐Ÿƒ Jokers
496
+
497
+ Joker is a previously defined parameter that is used to bypass some parts of the pipeline.
498
+ 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.
499
+
500
+ If none of the jokers meet the requirements, the prompt template is executed as usual.
501
+
502
+ 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.
503
+
504
+ 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.
505
+
506
+ Look at [jokers.ptbk.md](samples/templates/41-jokers.ptbk.md) sample.
507
+
508
+ ### Postprocessing functions
509
+
510
+ You can define postprocessing functions when creating `JavascriptEvalExecutionTools`:
511
+
512
+ ```
513
+
514
+ ```
515
+
516
+ Additionally there are some usefull string-manipulation build-in functions, which are [listed here](src/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.ts).
517
+
518
+ ### Expectations
519
+
520
+ `Expect` command describes the desired output of the prompt template (after post-processing)
521
+ It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs,...
522
+
523
+ _Note: LLMs work with tokens, not characters, but in Promptbooks we want to use some human-recognisable and cross-model interoperable units._
524
+
525
+ ```markdown
526
+ # โœจ Sample: Expectations
527
+
528
+ - PROMPTBOOK URL https://promptbook.example.com/samples/postprocessing-2.ptbk.md@v1
529
+ - PROMPTBOOK VERSION 1.0.0
530
+ - INPUTโ€ฏโ€ฏPARAMETER {yourName} Name of the hero
531
+
532
+ ## ๐Ÿ’ฌ Question
533
+
534
+ - EXPECT MAX 30 CHARACTERS
535
+ - EXPECT MIN 2 CHARACTERS
536
+ - EXPECT MAX 3 WORDS
537
+ - EXPECT EXACTLY 1 SENTENCE
538
+ - EXPECT EXACTLY 1 LINE
539
+
540
+ ...
541
+ ```
542
+
543
+ There are two types of expectations which are not strictly symmetrical:
544
+
545
+ #### Minimal expectations
546
+
547
+ - `EXPECT MIN 0 ...` is not valid minimal expectation. It makes no sense.
548
+ - `EXPECT JSON` is both minimal and maximal expectation
549
+ - When you are using `JOKER` in same prompt template, you need to have at least one minimal expectation
550
+
551
+ #### Maximal expectations
552
+
553
+ - `EXPECT MAX 0 ...` is valid maximal expectation. For example, you can expect 0 pages and 2 sentences.
554
+ - `EXPECT JSON` is both minimal and maximal expectation
555
+
556
+ 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.
557
+
558
+ <!--
559
+ ### New
560
+ [๐Ÿฅป] Insert here when making new command
561
+ -->
562
+
563
+ ### Execution report
564
+
565
+ Execution report is a simple object or markdown that contains information about the execution of the promptbook.
566
+
567
+ [See the example of such a report](/samples/templates/50-advanced.report.md)
568
+
569
+ <!-- TODO: Write more -->
570
+
571
+ ### Remote server
572
+
573
+ Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
574
+
575
+ You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
576
+ This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
577
+
578
+ ## ๐Ÿ‘จโ€๐Ÿ’ป Usage and integration _(for developers)_
579
+
580
+ <!--
581
+
582
+ TODO: [๐Ÿง™โ€โ™‚๏ธ]
583
+
584
+ ### ๐Ÿง™โ€โ™‚๏ธ Using wizzard
585
+
586
+ First you need to install this library:
587
+
588
+ ```bash
589
+ npm install --save @promptbook/wizzard
590
+ ```
591
+
592
+ > TODO: !! Write the Wizzard sample
593
+
594
+ [Usage samples](./samples/usage/)
595
+
596
+ -->
597
+
598
+ ### ๐Ÿ”Œ Usage in Typescript / Javascript
599
+
600
+ - [Simple usage](./samples/usage/simple-script)
601
+ - [Usage with client and remote server](./samples/usage/remote)
602
+
603
+ ## โž•โž– When to use Promptbook?
604
+
605
+ ### โž• When to use
606
+
607
+ - When you are writing app that generates complex things via LLM - like **websites, articles, presentations, code, stories, songs**,...
608
+ - When you want to **separate code from text prompts**
609
+ - When you want to describe **complex prompt pipelines** and don't want to do it in the code
610
+ - When you want to **orchestrate multiple prompts** together
611
+ - When you want to **reuse** parts of prompts in multiple places
612
+ - When you want to **version** your prompts and **test multiple versions**
613
+ - When you want to **log** the execution of prompts and backtrace the issues
614
+
615
+ ### โž– When not to use
616
+
617
+ - When you are writing just a simple chatbot without any extra logic, just system messages
618
+
619
+ ## ๐Ÿœ Known issues
620
+
621
+ <!-- TODO: -->
622
+
623
+ ## ๐Ÿงผ Intentionally not implemented features
624
+
625
+ <!-- TODO: -->
626
+
627
+ ## โ” FAQ
628
+
629
+ 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).
630
+
631
+ ### Why not just use the OpenAI SDK / Anthropic Claude SDK / ...?
632
+
633
+ 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.
634
+
635
+ ### How is it different from the Langchain library?
636
+
637
+ 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.
638
+
639
+ We are considering creating a bridge/converter between these two libraries.
640
+
641
+ <!--
642
+
643
+ ==========
644
+ Include:
645
+ - Langchain is the python library and JavaScript is on second place
646
+ - Langchain primarily focused on making templates, not on combining templates into larger structures
647
+ - at the language level it distinguishes between chat and completion, I need to mix the two into one template pipeline
648
+ - 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)
649
+ - The focus of promptbooks is primarily on building user applications, not the data processing, training or autogpt.
650
+ -->
651
+
652
+ ### Promptbooks vs. OpenAI`s GPTs
653
+
654
+ 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.
655
+
656
+ <!--
657
+ TODO:
658
+ ### Promptbooks vs. Semantic Kernel
659
+
660
+
661
+ -->
662
+
663
+ <!--
664
+ TODO: !
665
+ ### Promptbooks vs. Langtail
666
+
667
+
668
+ -->
669
+
670
+ <!--
671
+ TODO:
672
+ ### Promptbooks vs. Evidentally AI
673
+
674
+ Logging and monitoring
675
+
676
+ -->
677
+
678
+ ### Where should I store my promptbooks?
679
+
680
+ If you use raw SDKs, you just put prompts in the sourcecode, mixed in with typescript, javascript, python or whatever programming language you use.
681
+
682
+ If you use promptbooks, you can store them in several places, each with its own advantages and disadvantages:
683
+
684
+ 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.
685
+
686
+ 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)_.
687
+
688
+ 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.
689
+
690
+ ### What should I do when I need same promptbook in multiple human languages?
691
+
692
+ A single promptbook can be written for several _(human)_ languages at once. However, we recommend that you have separate promptbooks for each language.
693
+
694
+ In large language models, you will get better results if you have prompts in the same language as the user input.
695
+
696
+ 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.
697
+
698
+ <!--
699
+ TODO: (Maybe)
700
+ ### Why you need to explicitly specify input and output parameters?
701
+ -->
702
+
703
+ <!--
704
+
705
+
706
+
707
+ !
708
+
709
+
710
+
711
+ unit testing
712
+
713
+ escaping
714
+
715
+ how i get block into prompt
716
+
717
+
718
+ ## ๐Ÿšท Limitations
719
+
720
+ function calling
721
+ system message
722
+ iterations
723
+
724
+ -->
725
+
726
+ ## โŒš Changelog
727
+
728
+ See [CHANGELOG.md](./CHANGELOG.md)
729
+
730
+ ## ๐Ÿ“œ License
731
+
732
+ <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>
733
+
734
+ <!--Contributing-->
735
+ <!--โš ๏ธ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.-->
736
+
737
+ ## ๐Ÿ–‹๏ธ Contributing
738
+
739
+ 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).
740
+
741
+ 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/).
742
+
743
+ <!--/Contributing-->