@promptbook/types 0.63.0-8 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,12 +97,23 @@ In any of these situations, but especially in (3), the Promptbook library can ma
97
97
 
98
98
 
99
99
 
100
+ ## 🧔 Promptbook _(for prompt-engeneers)_
101
+
102
+ **P**romp**t** **b**oo**k** markdown file (or `.ptbk.md` file) is document that describes a **pipeline** - a series of prompts that are chained together to form somewhat reciepe for transforming natural language input.
103
+
104
+ - Multiple pipelines forms a **collection** which will handle core **know-how of your LLM application**.
105
+ - Theese pipelines are designed such as they **can be written by non-programmers**.
106
+
107
+
108
+
100
109
  ### Sample:
101
110
 
102
111
  File `write-website-content.ptbk.md`:
103
112
 
104
113
 
105
114
 
115
+
116
+
106
117
  > # 🌍 Create website content
107
118
  >
108
119
  > Instructions for creating web page content.
@@ -319,7 +330,8 @@ flowchart LR
319
330
  end;
320
331
  ```
321
332
 
322
- [More template samples](./samples/templates/)
333
+ - [More template samples](./samples/templates/)
334
+ - [Read more about `.ptbk.md` file format here](https://github.com/webgptorg/promptbook/discussions/categories/concepts?discussions_q=is%3Aopen+label%3A.ptbk.md+category%3AConcepts)
323
335
 
324
336
  _Note: We are using [postprocessing functions](#postprocessing-functions) like `unwrapResult` that can be used to postprocess the result._
325
337
 
@@ -336,7 +348,6 @@ Or you can install them separately:
336
348
 
337
349
  > ⭐ Marked packages are worth to try first
338
350
 
339
-
340
351
  - ⭐ **[ptbk](https://www.npmjs.com/package/ptbk)** - Bundle of all packages, when you want to install everything and you don't care about the size
341
352
  - **[promptbook](https://www.npmjs.com/package/promptbook)** - Same as `ptbk`
342
353
  - **[@promptbook/core](https://www.npmjs.com/package/@promptbook/core)** - Core of the library, it contains the main logic for promptbooks
@@ -360,263 +371,39 @@ Or you can install them separately:
360
371
 
361
372
  ## 📚 Dictionary
362
373
 
363
- The following glossary is used to clarify certain basic concepts:
364
-
365
- ### Prompt
366
-
367
- Prompt in a text along with model requirements, but without any execution or templating logic.
368
-
369
- For example:
370
-
371
- ```json
372
- {
373
- "request": "Which sound does a cat make?",
374
- "modelRequirements": {
375
- "variant": "CHAT"
376
- }
377
- }
378
- ```
379
-
380
- ```json
381
- {
382
- "request": "I am a cat.\nI like to eat fish.\nI like to sleep.\nI like to play with a ball.\nI l",
383
- "modelRequirements": {
384
- "variant": "COMPLETION"
385
- }
386
- }
387
- ```
388
-
389
- ### Prompt Template
390
-
391
- Similar concept to Prompt, but with templating logic.
392
-
393
- For example:
394
-
395
- ```json
396
- {
397
- "request": "Which sound does a {animalName} make?",
398
- "modelRequirements": {
399
- "variant": "CHAT"
400
- }
401
- }
402
- ```
403
-
404
- ### Model Requirements
405
-
406
- Abstract way to specify the LLM.
407
- It does not specify the LLM with concrete version itself, only the requirements for the LLM.
408
- _NOT chatgpt-3.5-turbo BUT CHAT variant of GPT-3.5._
409
-
410
- For example:
411
-
412
- ```json
413
- {
414
- "variant": "CHAT",
415
- "version": "GPT-3.5",
416
- "temperature": 0.7
417
- }
418
- ```
419
-
420
- ### Block type
421
-
422
- Each block of promptbook can have a different execution type.
423
- It is specified in list of requirements for the block.
424
- By default, it is `Prompt template`
425
-
426
- - _(default)_ `Prompt template` The block is a prompt template and is executed by LLM (OpenAI, Azure,...)
427
- - `SIMPLE TEMPLATE` The block is a simple text template which is just filled with parameters
428
- - `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.
429
- - `PROMPT DIALOG` Ask user for input
430
-
431
- ### Parameters
432
-
433
- Parameters that are placed in the prompt template and replaced to create the prompt.
434
- It is a simple key-value object.
435
-
436
- ```json
437
- {
438
- "animalName": "cat",
439
- "animalSound": "Meow!"
440
- }
441
- ```
442
-
443
- There are three types of template parameters, depending on how they are used in the promptbook:
444
-
445
- - **INPUT PARAMETER**s are required to execute the promptbook.
446
- - **Intermediate parameters** are used internally in the promptbook.
447
- - **OUTPUT PARAMETER**s are explicitelly marked and they are returned as the result of the promptbook execution.
448
-
449
- _Note: Parameter can be both intermedite and output at the same time._
450
-
451
- ### Promptbook
452
-
453
- Promptbook is **core concept of this library**.
454
- It represents a series of prompt templates chained together to form a **pipeline** / one big prompt template with input and result parameters.
455
-
456
- Internally it can have multiple formats:
457
-
458
- - **.ptbk.md file** in custom markdown format described above
459
- - _(concept)_ **.ptbk** format, custom fileextension based on markdown
460
- - _(internal)_ **JSON** format, parsed from the .ptbk.md file
461
-
462
- ### Promptbook **Library**
463
-
464
- Library of all promptbooks used in your application.
465
- Each promptbook is a separate `.ptbk.md` file with unique `PIPELINE URL`. Theese urls are used to reference promptbooks in other promptbooks or in the application code.
466
-
467
- ### Prompt Result
468
-
469
- Prompt result is the simplest concept of execution.
470
- It is the result of executing one prompt _(NOT a template)_.
471
-
472
- For example:
473
-
474
- ```json
475
- {
476
- "response": "Meow!",
477
- "model": "chatgpt-3.5-turbo"
478
- }
479
- ```
480
-
481
- ### Execution Tools
482
-
483
-
484
-
485
- `ExecutionTools` is an interface which contains all the tools needed to execute prompts.
486
- It contais 3 subtools:
487
-
488
- - `LlmExecutionTools`
489
- - `ScriptExecutionTools`
490
- - `UserInterfaceTools`
491
-
492
- Which are described below:
374
+ The following glossary is used to clarify certain concepts:
493
375
 
494
- #### LLM Execution Tools
495
376
 
496
- `LlmExecutionTools` is a container for all the tools needed to execute prompts to large language models like GPT-4.
497
- On its interface it exposes common methods for prompt execution.
498
- Internally it calls OpenAI, Azure, GPU, proxy, cache, logging,...
499
377
 
500
- `LlmExecutionTools` an abstract interface that is implemented by concrete execution tools:
378
+ ### Core concepts
501
379
 
502
- - `OpenAiExecutionTools`
503
- - `AnthropicClaudeExecutionTools`
504
- - `AzureOpenAiExecutionTools`
505
- - `LangtailExecutionTools`
506
- - _(Not implemented yet)_ `BardExecutionTools`
507
- - _(Not implemented yet)_ `LamaExecutionTools`
508
- - _(Not implemented yet)_ `GpuExecutionTools`
509
- - Special case are `RemoteLlmExecutionTools` that connect to a remote server and run one of the above execution tools on that server.
510
- - Another special case is `MockedEchoLlmExecutionTools` that is used for testing and mocking.
511
- - The another special case is `LogLlmExecutionToolsWrapper` that is technically also an execution tools but it is more proxy wrapper around other execution tools that logs all calls to execution tools.
380
+ - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
381
+ - [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
382
+ - [🎺 Pipeline templates](https://github.com/webgptorg/promptbook/discussions/88)
383
+ - [🤼 Personas](https://github.com/webgptorg/promptbook/discussions/22)
384
+ - [⭕ Parameters](https://github.com/webgptorg/promptbook/discussions/83)
385
+ - [🚀 Pipeline execution](https://github.com/webgptorg/promptbook/discussions/84)
386
+ - [🧪 Expectations](https://github.com/webgptorg/promptbook/discussions/30)
387
+ - [✂️ Postprocessing](https://github.com/webgptorg/promptbook/discussions/31)
388
+ - [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
389
+ - [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
512
390
 
513
- #### Script Execution Tools
391
+ ### Advanced concepts
514
392
 
515
- `ScriptExecutionTools` is an abstract container that represents all the tools needed to EXECUTE SCRIPTs. It is implemented by concrete execution tools:
393
+ - [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
394
+ - [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
395
+ - [🃏 Jokers (conditions)](https://github.com/webgptorg/promptbook/discussions/66)
396
+ - [🔳 Metaprompting](https://github.com/webgptorg/promptbook/discussions/35)
397
+ - [🌏 Linguistically typed languages](https://github.com/webgptorg/promptbook/discussions/53)
398
+ - [🌍 Auto-Translations](https://github.com/webgptorg/promptbook/discussions/42)
399
+ - [📽 Images, audio, video, spreadsheets](https://github.com/webgptorg/promptbook/discussions/54)
400
+ - [🔙 Expectation-aware generation](https://github.com/webgptorg/promptbook/discussions/37)
401
+ - [⏳ Just-in-time fine-tuning](https://github.com/webgptorg/promptbook/discussions/33)
402
+ - [🔴 Anomaly detection](https://github.com/webgptorg/promptbook/discussions/40)
403
+ - [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
404
+ - [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
516
405
 
517
- - `JavascriptExecutionTools` is a wrapper around `vm2` module that executes javascript code in a sandbox.
518
- - `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.
519
- - _(Not implemented yet)_ `TypescriptExecutionTools` executes typescript code in a sandbox.
520
- - _(Not implemented yet)_ `PythonExecutionTools` executes python code in a sandbox.
521
-
522
- There are [postprocessing functions](#postprocessing-functions) that can be used to postprocess the result.
523
-
524
- #### User Interface Tools
525
-
526
- `UserInterfaceTools` is an abstract container that represents all the tools needed to interact with the user. It is implemented by concrete execution tools:
527
-
528
- - _(Not implemented yet)_ `ConsoleInterfaceTools` is a wrapper around `readline` module that interacts with the user via console.
529
- - `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.
530
- - `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.
531
-
532
- ### Executor
533
-
534
- Executor is a simple async function that takes **input parameters** and returns **output parameters**.
535
- It is constructed by combining execution tools and promptbook to execute together.
536
-
537
- ### 🃏 Jokers (conditions)
538
-
539
- Joker is a previously defined parameter that is used to bypass some parts of the pipeline.
540
- 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.
541
-
542
- If none of the jokers meet the requirements, the prompt template is executed as usual.
543
-
544
- 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.
545
-
546
- 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.
547
-
548
- Look at [jokers.ptbk.md](samples/templates/41-jokers.ptbk.md) sample.
549
-
550
- ### Postprocessing functions
551
-
552
- You can define postprocessing functions when creating `JavascriptEvalExecutionTools`:
553
-
554
- ```
555
-
556
- ```
557
-
558
- Additionally there are some usefull string-manipulation build-in functions, which are [listed here](src/scripting/javascript/JavascriptEvalExecutionTools.ts).
559
-
560
- ### Expectations
561
-
562
- `Expect` command describes the desired output of the prompt template (after post-processing)
563
- It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs,...
564
-
565
- _Note: LLMs work with tokens, not characters, but in Promptbooks we want to use some human-recognisable and cross-model interoperable units._
566
-
567
- ```markdown
568
- # ✨ Sample: Expectations
569
-
570
- - INPUT  PARAMETER {yourName} Name of the hero
571
-
572
- ## 💬 Question
573
-
574
- - EXPECT MAX 30 CHARACTERS
575
- - EXPECT MIN 2 CHARACTERS
576
- - EXPECT MAX 3 WORDS
577
- - EXPECT EXACTLY 1 SENTENCE
578
- - EXPECT EXACTLY 1 LINE
579
-
580
- ...
581
- ```
582
-
583
- There are two types of expectations which are not strictly symmetrical:
584
-
585
- #### Minimal expectations
586
-
587
- - `EXPECT MIN 0 ...` is not valid minimal expectation. It makes no sense.
588
- - `EXPECT JSON` is both minimal and maximal expectation
589
- - When you are using `JOKER` in same prompt template, you need to have at least one minimal expectation
590
-
591
- #### Maximal expectations
592
-
593
- - `EXPECT MAX 0 ...` is valid maximal expectation. For example, you can expect 0 pages and 2 sentences.
594
- - `EXPECT JSON` is both minimal and maximal expectation
595
-
596
- 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.
597
-
598
- ### Execution report
599
-
600
- Execution report is a simple object or markdown that contains information about the execution of the pipeline.
601
-
602
- [See the example of such a report](/samples/templates/50-advanced.report.md)
603
-
604
-
605
-
606
-
607
-
608
- ### Remote server
609
-
610
- Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
611
-
612
- You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
613
- This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
614
-
615
- ## 👨‍💻 Usage and integration _(for developers)_
616
-
617
-
618
-
619
- ### 🔌 Usage in Typescript / Javascript
406
+ ## 🔌 Usage in Typescript / Javascript
620
407
 
621
408
  - [Simple usage](./samples/usage/simple-script)
622
409
  - [Usage with client and remote server](./samples/usage/remote)
@@ -639,14 +426,19 @@ This is useful to make all logic on browser side but not expose your API keys or
639
426
 
640
427
  ## 🐜 Known issues
641
428
 
642
-
429
+ - [🤸‍♂️ Iterations not working yet](https://github.com/webgptorg/promptbook/discussions/55)
430
+ - [⤵️ Imports not working yet](https://github.com/webgptorg/promptbook/discussions/34)
643
431
 
644
432
  ## 🧼 Intentionally not implemented features
645
433
 
646
434
 
435
+ - [➿ No recursion](https://github.com/webgptorg/promptbook/discussions/38)
436
+ - [🏳 There are no types, just strings](https://github.com/webgptorg/promptbook/discussions/52)
647
437
 
648
438
  ## ❔ FAQ
649
439
 
440
+
441
+
650
442
  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).
651
443
 
652
444
  ### Why not just use the OpenAI SDK / Anthropic Claude SDK / ...?
package/esm/index.es.js CHANGED
@@ -1,9 +1,2 @@
1
- // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
2
- /**
3
- * The version of the Promptbook library
4
- */
5
- var PROMPTBOOK_VERSION = '0.63.0-7';
6
- // TODO: !!!! List here all the versions and annotate + put into script
7
1
 
8
- export { PROMPTBOOK_VERSION };
9
2
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../../../../src/version.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AAIA;;;IAGa,kBAAkB,GAA8B,WAAW;AAGxE;;;;"}
1
+ {"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -59,6 +59,8 @@ import { PrefixStorage } from '../storage/utils/PrefixStorage';
59
59
  import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
60
60
  import type { ExecutionReportStringOptions } from '../types/execution-report/ExecutionReportStringOptions';
61
61
  import { ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
62
+ import { MODEL_VARIANTS } from '../types/ModelVariant';
63
+ import { EXPECTATION_UNITS } from '../types/PipelineJson/Expectations';
62
64
  export { PROMPTBOOK_VERSION };
63
65
  export { collectionToJson };
64
66
  export { createCollectionFromJson };
@@ -120,3 +122,5 @@ export { PrefixStorage };
120
122
  export { executionReportJsonToString };
121
123
  export type { ExecutionReportStringOptions };
122
124
  export { ExecutionReportStringOptionsDefaults };
125
+ export { MODEL_VARIANTS };
126
+ export { EXPECTATION_UNITS };
@@ -1,4 +1,3 @@
1
- import { PROMPTBOOK_VERSION } from '../version';
2
1
  import type { PipelineCollection } from '../collection/PipelineCollection';
3
2
  import type { Command } from '../commands/_common/types/Command';
4
3
  import type { CommandParser } from '../commands/_common/types/CommandParser';
@@ -205,7 +204,6 @@ import type { string_snake_case } from '../utils/normalization/normalizeTo_snake
205
204
  import type { really_any } from '../utils/organization/really_any';
206
205
  import type { TODO_any } from '../utils/organization/TODO_any';
207
206
  import type { string_promptbook_version } from '../version';
208
- export { PROMPTBOOK_VERSION };
209
207
  export type { PipelineCollection };
210
208
  export type { Command };
211
209
  export type { CommandParser };
@@ -6,6 +6,7 @@ import type { Command as Program } from 'commander';
6
6
  */
7
7
  export declare function initializeMakeCommand(program: Program): void;
8
8
  /**
9
+ * TODO: [🥃] !!! Allow `ptbk make` without llm tools
9
10
  * TODO: Maybe remove this command - "about" command should be enough?
10
11
  * TODO: [0] DRY Javascript and typescript - Maybe make ONLY typescript and for javascript just remove types
11
12
  * Note: [🟡] This code should never be published outside of `@promptbook/cli`
@@ -36,4 +36,5 @@ export declare function createLlmToolsFromEnv(options?: CreateLlmToolsFromEnvOpt
36
36
  * TODO: [🧠] Maybe pass env as argument
37
37
  * Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
38
38
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
39
+ * TODO: [🥃] Allow `ptbk make` without llm tools
39
40
  */
@@ -17,4 +17,5 @@ export {};
17
17
  /**
18
18
  * Note: [🟡] This code should never be published outside of `@promptbook/cli`
19
19
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
20
+ * TODO: [🥃] Allow `ptbk make` without llm tools
20
21
  */
@@ -10,6 +10,6 @@ export type ModelVariant = TupleToUnion<typeof MODEL_VARIANTS>;
10
10
  /**
11
11
  * @@@
12
12
  *
13
- * @private internal base for `ModelVariant` and `modelCommandParser`
13
+ * @public exported from `@promptbook/core`
14
14
  */
15
15
  export declare const MODEL_VARIANTS: readonly ["COMPLETION", "CHAT", "EMBEDDING"];
@@ -24,7 +24,7 @@ export type ExpectationUnit = TupleToUnion<typeof EXPECTATION_UNITS>;
24
24
  * Units of text measurement
25
25
  *
26
26
  * @see https://github.com/webgptorg/promptbook/discussions/30
27
- * @private internal base for `ExpectationUnit`
27
+ * @public exported from `@promptbook/core`
28
28
  */
29
29
  export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "LINES", "PARAGRAPHS", "PAGES"];
30
30
  /**
@@ -14,7 +14,7 @@ export type LlmTemplateJson = PromptTemplateJsonCommon & {
14
14
  * Requirements for the model
15
15
  * - This is required only for blockType PROMPT_TEMPLATE
16
16
  */
17
- readonly modelRequirements: ModelRequirements;
17
+ readonly modelRequirements?: Partial<ModelRequirements>;
18
18
  };
19
19
  /**
20
20
  * TODO: [🧠][🥜]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/types",
3
- "version": "0.63.0-8",
3
+ "version": "0.63.0",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -43,10 +43,8 @@
43
43
  "url": "https://github.com/webgptorg/promptbook/blob/main/README.md#%EF%B8%8F-contributing"
44
44
  }
45
45
  ],
46
- "main": "./umd/index.umd.js",
47
- "module": "./esm/index.es.js",
48
46
  "typings": "./esm/typings/src/_packages/types.index.d.ts",
49
47
  "peerDependencies": {
50
- "@promptbook/core": "0.63.0-8"
48
+ "@promptbook/core": "0.63.0"
51
49
  }
52
50
  }
package/umd/index.umd.js CHANGED
@@ -1,19 +1,9 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-types"] = {}));
5
- })(this, (function (exports) { 'use strict';
1
+ (function (factory) {
2
+ typeof define === 'function' && define.amd ? define(factory) :
3
+ factory();
4
+ })((function () { 'use strict';
6
5
 
7
- // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
8
- /**
9
- * The version of the Promptbook library
10
- */
11
- var PROMPTBOOK_VERSION = '0.63.0-7';
12
- // TODO: !!!! List here all the versions and annotate + put into script
13
6
 
14
- exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
15
-
16
- Object.defineProperty(exports, '__esModule', { value: true });
17
7
 
18
8
  }));
19
9
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../../../../src/version.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;CAAA;CAIA;;;KAGa,kBAAkB,GAA8B,WAAW;CAGxE;;;;;;;;;;"}
1
+ {"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}