@promptbook/openai 0.29.0 → 0.30.0-1

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.
@@ -1,4 +1,3 @@
1
- import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
2
1
  import { PromptTemplatePipelineLibrary } from '../classes/PromptTemplatePipelineLibrary';
3
2
  import { PTBK_VERSION } from '../config';
4
3
  import { promptTemplatePipelineStringToJson } from '../conversion/promptTemplatePipelineStringToJson';
@@ -9,7 +8,7 @@ import { CallbackInterfaceTools } from '../execution/plugins/user-interface-exec
9
8
  import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions';
10
9
  import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
11
10
  import { ExecutionTypes } from '../types/ExecutionTypes';
12
- export { ExecutionTypes, PTBK_VERSION, PromptTemplatePipeline, PromptTemplatePipelineLibrary };
11
+ export { ExecutionTypes, PTBK_VERSION, PromptTemplatePipelineLibrary };
13
12
  export { SimplePromptInterfaceTools };
14
13
  export { promptTemplatePipelineStringToJson, validatePromptTemplatePipelineJson };
15
14
  export { MockedEchoNaturalExecutionTools };
@@ -5,7 +5,6 @@ import { PtpExecutor } from '../execution/PtpExecutor';
5
5
  import { Prompt } from '../types/Prompt';
6
6
  import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
7
7
  import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
8
- import { PromptTemplatePipeline } from './PromptTemplatePipeline';
9
8
  /**
10
9
  * Options for PromptTemplatePipelineLibrary
11
10
  */
@@ -13,7 +12,7 @@ type PromptTemplatePipelineLibraryOptions = {
13
12
  /**
14
13
  * The library of prompt template pipelines
15
14
  */
16
- readonly library: Record<string_name, PromptTemplatePipeline>;
15
+ readonly library: Record<string_name, PromptTemplatePipelineJson>;
17
16
  /**
18
17
  * Optional settings for creating a PromptTemplatePipelineExecutor
19
18
  */
@@ -45,7 +44,7 @@ export declare class PromptTemplatePipelineLibrary {
45
44
  /**
46
45
  * Gets prompt template pipeline by name
47
46
  */
48
- getPtp(name: string_name): PromptTemplatePipeline;
47
+ getPtp(name: string_name): PromptTemplatePipelineJson;
49
48
  /**
50
49
  * Checks whether prompt is in the library
51
50
  */
@@ -1,4 +1,4 @@
1
- import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
1
+ import type { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
2
2
  /**
3
3
  * Validates PromptTemplatePipelineJson if it is logically valid.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
1
+ import { PromptTemplatePipelineJson } from '../_packages/types.index';
2
2
  import { ExecutionTools } from './ExecutionTools';
3
3
  import { PtpExecutor } from './PtpExecutor';
4
4
  export interface CreatePtpExecutorSettings {
@@ -16,7 +16,7 @@ interface CreatePtpExecutorOptions {
16
16
  /**
17
17
  * The Prompt Template Pipeline (PTP) to be executed
18
18
  */
19
- readonly ptp: PromptTemplatePipeline;
19
+ readonly ptp: PromptTemplatePipelineJson;
20
20
  /**
21
21
  * The execution tools to be used during the execution of the PTP
22
22
  */
@@ -75,6 +75,12 @@ interface PromptTemplateJsonCommon {
75
75
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
76
76
  */
77
77
  readonly description?: string;
78
+ /**
79
+ * List of parameter names that are used in the prompt template and must be defined before the prompt template is executed
80
+ *
81
+ * Note: Joker is one of the dependent parameters
82
+ */
83
+ readonly dependentParameterNames: Array<string_name>;
78
84
  /**
79
85
  * If theese parameters meet the expectations requirements, they are used instead of executing this prompt template
80
86
  */
@@ -112,7 +118,7 @@ interface PromptTemplateJsonCommon {
112
118
  /**
113
119
  * Name of the parameter that is the result of the prompt template
114
120
  */
115
- readonly resultingParameterName: string;
121
+ readonly resultingParameterName: string_name;
116
122
  }
117
123
  export {};
118
124
  /**
@@ -8,7 +8,6 @@ import { PromptTemplateParameterJson } from './PromptTemplateParameterJson';
8
8
  * It can have 3 formats:
9
9
  * - **.ptbk.md file** in custom markdown format described above
10
10
  * - _(this)_ **JSON** format, parsed from the .ptbk.md file
11
- * - **Object** which is created from JSON format and bound with tools around (but not the execution logic)
12
11
  *
13
12
  * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
14
13
  */
@@ -5,7 +5,6 @@
5
5
  * It can have 3 formats:
6
6
  * - _(this)_ **.ptbk.md file** in custom markdown format described above
7
7
  * - **JSON** format, parsed from the .ptbk.md file
8
- * - **Object** which is created from JSON format and bound with tools around (but not the execution logic)
9
8
  *
10
9
  * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
11
10
  */
@@ -0,0 +1,8 @@
1
+ import { string_name, string_template } from '../types/typeAliases';
2
+ /**
3
+ * Parses the template and returns the list of all parameter names
4
+ *
5
+ * @param template the template with parameters in {curly} braces
6
+ * @returns the list of parameter names
7
+ */
8
+ export declare function extractParameters(template: string_template): Array<string_name>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.29.0",
3
+ "version": "0.30.0-1",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -37,7 +37,7 @@
37
37
  "openai": "4.2.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "@promptbook/core": "0.29.0"
40
+ "@promptbook/core": "0.30.0-1"
41
41
  },
42
42
  "main": "./umd/index.umd.js",
43
43
  "module": "./esm/index.es.js",
@@ -1,4 +1,3 @@
1
- import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
2
1
  import { PromptTemplatePipelineLibrary } from '../classes/PromptTemplatePipelineLibrary';
3
2
  import { PTBK_VERSION } from '../config';
4
3
  import { promptTemplatePipelineStringToJson } from '../conversion/promptTemplatePipelineStringToJson';
@@ -9,7 +8,7 @@ import { CallbackInterfaceTools } from '../execution/plugins/user-interface-exec
9
8
  import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions';
10
9
  import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
11
10
  import { ExecutionTypes } from '../types/ExecutionTypes';
12
- export { ExecutionTypes, PTBK_VERSION, PromptTemplatePipeline, PromptTemplatePipelineLibrary };
11
+ export { ExecutionTypes, PTBK_VERSION, PromptTemplatePipelineLibrary };
13
12
  export { SimplePromptInterfaceTools };
14
13
  export { promptTemplatePipelineStringToJson, validatePromptTemplatePipelineJson };
15
14
  export { MockedEchoNaturalExecutionTools };
@@ -5,7 +5,6 @@ import { PtpExecutor } from '../execution/PtpExecutor';
5
5
  import { Prompt } from '../types/Prompt';
6
6
  import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
7
7
  import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
8
- import { PromptTemplatePipeline } from './PromptTemplatePipeline';
9
8
  /**
10
9
  * Options for PromptTemplatePipelineLibrary
11
10
  */
@@ -13,7 +12,7 @@ type PromptTemplatePipelineLibraryOptions = {
13
12
  /**
14
13
  * The library of prompt template pipelines
15
14
  */
16
- readonly library: Record<string_name, PromptTemplatePipeline>;
15
+ readonly library: Record<string_name, PromptTemplatePipelineJson>;
17
16
  /**
18
17
  * Optional settings for creating a PromptTemplatePipelineExecutor
19
18
  */
@@ -45,7 +44,7 @@ export declare class PromptTemplatePipelineLibrary {
45
44
  /**
46
45
  * Gets prompt template pipeline by name
47
46
  */
48
- getPtp(name: string_name): PromptTemplatePipeline;
47
+ getPtp(name: string_name): PromptTemplatePipelineJson;
49
48
  /**
50
49
  * Checks whether prompt is in the library
51
50
  */
@@ -1,4 +1,4 @@
1
- import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
1
+ import type { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
2
2
  /**
3
3
  * Validates PromptTemplatePipelineJson if it is logically valid.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
1
+ import { PromptTemplatePipelineJson } from '../_packages/types.index';
2
2
  import { ExecutionTools } from './ExecutionTools';
3
3
  import { PtpExecutor } from './PtpExecutor';
4
4
  export interface CreatePtpExecutorSettings {
@@ -16,7 +16,7 @@ interface CreatePtpExecutorOptions {
16
16
  /**
17
17
  * The Prompt Template Pipeline (PTP) to be executed
18
18
  */
19
- readonly ptp: PromptTemplatePipeline;
19
+ readonly ptp: PromptTemplatePipelineJson;
20
20
  /**
21
21
  * The execution tools to be used during the execution of the PTP
22
22
  */
@@ -75,6 +75,12 @@ interface PromptTemplateJsonCommon {
75
75
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
76
76
  */
77
77
  readonly description?: string;
78
+ /**
79
+ * List of parameter names that are used in the prompt template and must be defined before the prompt template is executed
80
+ *
81
+ * Note: Joker is one of the dependent parameters
82
+ */
83
+ readonly dependentParameterNames: Array<string_name>;
78
84
  /**
79
85
  * If theese parameters meet the expectations requirements, they are used instead of executing this prompt template
80
86
  */
@@ -112,7 +118,7 @@ interface PromptTemplateJsonCommon {
112
118
  /**
113
119
  * Name of the parameter that is the result of the prompt template
114
120
  */
115
- readonly resultingParameterName: string;
121
+ readonly resultingParameterName: string_name;
116
122
  }
117
123
  export {};
118
124
  /**
@@ -8,7 +8,6 @@ import { PromptTemplateParameterJson } from './PromptTemplateParameterJson';
8
8
  * It can have 3 formats:
9
9
  * - **.ptbk.md file** in custom markdown format described above
10
10
  * - _(this)_ **JSON** format, parsed from the .ptbk.md file
11
- * - **Object** which is created from JSON format and bound with tools around (but not the execution logic)
12
11
  *
13
12
  * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
14
13
  */
@@ -5,7 +5,6 @@
5
5
  * It can have 3 formats:
6
6
  * - _(this)_ **.ptbk.md file** in custom markdown format described above
7
7
  * - **JSON** format, parsed from the .ptbk.md file
8
- * - **Object** which is created from JSON format and bound with tools around (but not the execution logic)
9
8
  *
10
9
  * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
11
10
  */
@@ -0,0 +1,8 @@
1
+ import { string_name, string_template } from '../types/typeAliases';
2
+ /**
3
+ * Parses the template and returns the list of all parameter names
4
+ *
5
+ * @param template the template with parameters in {curly} braces
6
+ * @returns the list of parameter names
7
+ */
8
+ export declare function extractParameters(template: string_template): Array<string_name>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,71 +0,0 @@
1
- import { string_name, string_version } from '.././types/typeAliases';
2
- import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
3
- import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
4
- import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
5
- import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
6
- /**
7
- * Prompt template pipeline is the **core concept of this library**.
8
- * It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
9
- *
10
- * It can have 3 formats:
11
- * - **.ptbk.md file** in custom markdown format described above
12
- * - **JSON** format, parsed from the .ptbk.md file
13
- * - _(this)_ **Object** which is created from JSON format and bound with tools around (but not the execution logic)
14
- *
15
- * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
16
- */
17
- export declare class PromptTemplatePipeline {
18
- readonly ptbkUrl: URL | null;
19
- readonly title: string | null;
20
- readonly ptbkVersion: string_version | null;
21
- readonly description: string | null;
22
- readonly parameters: Record<string_name, PromptTemplateParameterJson>;
23
- readonly promptTemplates: Array<PromptTemplateJson>;
24
- /**
25
- * Constructs PromptTemplatePipeline from any source
26
- *
27
- * Note: During the construction syntax and logic of source is validated
28
- *
29
- * @param source content of .ptbk.md or .ptbk.json file
30
- * @returns PromptTemplatePipeline
31
- */
32
- static fromSource(ptbkSource: PromptTemplatePipelineString | PromptTemplatePipelineJson): PromptTemplatePipeline;
33
- /**
34
- * Constructs PromptTemplatePipeline from markdown source
35
- *
36
- * Note: During the construction syntax and logic of source is validated
37
- *
38
- * @param ptbkString content of .ptbk.md file
39
- * @returns PromptTemplatePipeline
40
- */
41
- static fromString(ptbkString: PromptTemplatePipelineString): PromptTemplatePipeline;
42
- /**
43
- * Constructs PromptTemplatePipeline from JSON source
44
- *
45
- * Note: During the construction the source is logic validated
46
- *
47
- * @param ptbkjson content of .ptbk.json file parsed into JSON
48
- * @returns PromptTemplatePipeline
49
- */
50
- static fromJson(ptbkjson: PromptTemplatePipelineJson): PromptTemplatePipeline;
51
- private constructor();
52
- /**
53
- * Returns the first prompt template in the pipeline
54
- */
55
- get entryPromptTemplate(): PromptTemplateJson;
56
- /**
57
- * Gets the parameter that is the result of given prompt template
58
- */
59
- getResultingParameter(promptTemplateName: string_name): PromptTemplateParameterJson;
60
- /**
61
- * Gets the following prompt template in the pipeline or null if there is no following prompt template and this is the last one
62
- */
63
- getFollowingPromptTemplate(promptTemplateName: string_name): PromptTemplateJson | null;
64
- }
65
- /**
66
- * TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
67
- * TODO: !! [👐] Make parameters and promptTemplates private WHEN split between interface and class
68
- * TODO: !! Add generic type for entry and result parameters
69
- * TODO: Can be Array elegantly typed such as it must have at least one element?
70
- * TODO: [🧠] Each PromptTemplatePipeline should have its unique hash to be able to compare them and execute on server ONLY the desired ones
71
- */
@@ -1,71 +0,0 @@
1
- import { string_name, string_version } from '.././types/typeAliases';
2
- import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
3
- import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
4
- import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
5
- import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
6
- /**
7
- * Prompt template pipeline is the **core concept of this library**.
8
- * It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
9
- *
10
- * It can have 3 formats:
11
- * - **.ptbk.md file** in custom markdown format described above
12
- * - **JSON** format, parsed from the .ptbk.md file
13
- * - _(this)_ **Object** which is created from JSON format and bound with tools around (but not the execution logic)
14
- *
15
- * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
16
- */
17
- export declare class PromptTemplatePipeline {
18
- readonly ptbkUrl: URL | null;
19
- readonly title: string | null;
20
- readonly ptbkVersion: string_version | null;
21
- readonly description: string | null;
22
- readonly parameters: Record<string_name, PromptTemplateParameterJson>;
23
- readonly promptTemplates: Array<PromptTemplateJson>;
24
- /**
25
- * Constructs PromptTemplatePipeline from any source
26
- *
27
- * Note: During the construction syntax and logic of source is validated
28
- *
29
- * @param source content of .ptbk.md or .ptbk.json file
30
- * @returns PromptTemplatePipeline
31
- */
32
- static fromSource(ptbkSource: PromptTemplatePipelineString | PromptTemplatePipelineJson): PromptTemplatePipeline;
33
- /**
34
- * Constructs PromptTemplatePipeline from markdown source
35
- *
36
- * Note: During the construction syntax and logic of source is validated
37
- *
38
- * @param ptbkString content of .ptbk.md file
39
- * @returns PromptTemplatePipeline
40
- */
41
- static fromString(ptbkString: PromptTemplatePipelineString): PromptTemplatePipeline;
42
- /**
43
- * Constructs PromptTemplatePipeline from JSON source
44
- *
45
- * Note: During the construction the source is logic validated
46
- *
47
- * @param ptbkjson content of .ptbk.json file parsed into JSON
48
- * @returns PromptTemplatePipeline
49
- */
50
- static fromJson(ptbkjson: PromptTemplatePipelineJson): PromptTemplatePipeline;
51
- private constructor();
52
- /**
53
- * Returns the first prompt template in the pipeline
54
- */
55
- get entryPromptTemplate(): PromptTemplateJson;
56
- /**
57
- * Gets the parameter that is the result of given prompt template
58
- */
59
- getResultingParameter(promptTemplateName: string_name): PromptTemplateParameterJson;
60
- /**
61
- * Gets the following prompt template in the pipeline or null if there is no following prompt template and this is the last one
62
- */
63
- getFollowingPromptTemplate(promptTemplateName: string_name): PromptTemplateJson | null;
64
- }
65
- /**
66
- * TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
67
- * TODO: !! [👐] Make parameters and promptTemplates private WHEN split between interface and class
68
- * TODO: !! Add generic type for entry and result parameters
69
- * TODO: Can be Array elegantly typed such as it must have at least one element?
70
- * TODO: [🧠] Each PromptTemplatePipeline should have its unique hash to be able to compare them and execute on server ONLY the desired ones
71
- */