@promptbook/openai 0.25.0 → 0.27.0-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/esm/index.es.js CHANGED
@@ -191,7 +191,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
191
191
  return OpenAiExecutionTools;
192
192
  }());
193
193
  /**
194
- * TODO: !!!! Allow to use other models - List all from openai
194
+
195
195
  * TODO: Maybe Create some common util for gptChat and gptComplete
196
196
  * TODO: Maybe make custom OpenaiError
197
197
  */
@@ -1,6 +1,5 @@
1
1
  export {};
2
2
  /**
3
3
  * TODO: [🧠] Probbably change syntax MODEL VARIANT -> MODEL
4
- * TODO: !!!! Allow to skip segments SKIP IF {foo} NOT DEFINED
5
- * TODO: !!! Allow to EXPECT 3 words
4
+ * TODO: !!! Allow to skip segments SKIP IF {foo} NOT DEFINED
6
5
  */
@@ -9,7 +9,5 @@ export declare function promptTemplatePipelineStringToJson(promptTemplatePipelin
9
9
  /**
10
10
  * TODO: Report here line/column of error
11
11
  * TODO: Use spaceTrim more effectively
12
- * TODO: !!!! Parameter flags - isInput, isOutput, isInternal, isBeforePostprocessing, isBeforeFinal, canonicalName
13
- * TODO: !!!! Allow to have non-immutable parameters - suffix them with fooPrevious3 -> fooPrevious2 -> fooPrevious1 -> foo
14
- * This must work with other technial parameters
12
+ * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
15
13
  */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This error occurs when some expectation is not met in the execution of the pipeline
3
+ */
4
+ export declare class ExpectError extends Error {
5
+ readonly name = "ExpectError";
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * TODO: [🧠] Should be this exported from the library
10
+ */
@@ -1,4 +1,4 @@
1
- import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
1
+ import type { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
2
2
  import { ExecutionTools } from './ExecutionTools';
3
3
  import { PtpExecutor } from './PtpExecutor';
4
4
  export interface CreatePtpExecutorSettings {
@@ -7,7 +7,7 @@ export interface CreatePtpExecutorSettings {
7
7
  *
8
8
  * @default 3
9
9
  */
10
- readonly maxNaturalExecutionAttempts: number;
10
+ readonly maxExecutionAttempts: number;
11
11
  }
12
12
  /**
13
13
  * Options for creating a PTP (Prompt Template Pipeline) executor
@@ -22,7 +22,7 @@ export declare class OpenAiExecutionTools implements NaturalExecutionTools {
22
22
  gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
23
23
  }
24
24
  /**
25
- * TODO: !!!! Allow to use other models - List all from openai
25
+
26
26
  * TODO: Maybe Create some common util for gptChat and gptComplete
27
27
  * TODO: Maybe make custom OpenaiError
28
28
  */
@@ -66,13 +66,25 @@ export interface PostprocessCommand {
66
66
  }
67
67
  /**
68
68
  * Expect command describes the desired output of the prompt template (after post-processing)
69
+ * It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
70
+ */
71
+ export type ExpectCommand = ExpectAmountCommand | ExpectFormatCommand;
72
+ /**
73
+ * Expect amount command describes the desired output of the prompt template (after post-processing)
69
74
  * It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs,...
70
75
  *
71
76
  * Note: LLMs work with tokens, not characters, but in Promptbooks we want to use some human-recognisable and cross-model interoperable units.
72
77
  */
73
- export interface ExpectCommand {
74
- readonly type: 'EXPECT';
78
+ export interface ExpectAmountCommand {
79
+ readonly type: 'EXPECT_AMOUNT';
75
80
  readonly sign: 'EXACTLY' | 'MINIMUM' | 'MAXIMUM';
76
81
  readonly unit: ExpectationUnit;
77
82
  readonly amount: ExpectationAmount;
78
83
  }
84
+ /**
85
+ * Represents a command that expects a specific format.
86
+ */
87
+ export interface ExpectFormatCommand {
88
+ readonly type: 'EXPECT_FORMAT';
89
+ readonly format: 'JSON';
90
+ }
@@ -1,4 +1,5 @@
1
- import { number_integer, number_positive_or_zero, string_javascript, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
1
+ import { number_integer, number_positive_or_zero, string_javascript, string_javascript_name, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
2
+ import { ExpectFormatCommand } from '../Command';
2
3
  import { ExecutionType } from '../ExecutionTypes';
3
4
  import { ModelRequirements } from '../ModelRequirements';
4
5
  import { ScriptLanguage } from '../ScriptLanguage';
@@ -11,13 +12,6 @@ export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | Scri
11
12
  */
12
13
  export interface NaturalTemplateJson extends PromptTemplateJsonCommon {
13
14
  readonly executionType: 'PROMPT_TEMPLATE';
14
- /**
15
- * Expectations for the answer
16
- */
17
- readonly expectations: Partial<Record<Lowercase<ExpectationUnit>, {
18
- min?: ExpectationAmount;
19
- max?: ExpectationAmount;
20
- }>>;
21
15
  /**
22
16
  * Requirements for the model
23
17
  * - This is required only for executionType PROMPT_TEMPLATE
@@ -31,7 +25,7 @@ export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTEN
31
25
  /**
32
26
  * Unit of text measurement
33
27
  */
34
- export type ExpectationUnit = (typeof EXPECTATION_UNITS)[number];
28
+ export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
35
29
  /**
36
30
  * Amount of text measurement
37
31
  */
@@ -90,6 +84,27 @@ interface PromptTemplateJsonCommon {
90
84
  * Content of the template with {placeholders} for parameters
91
85
  */
92
86
  readonly content: (string_prompt | string_javascript | string_markdown) & string_template;
87
+ /**
88
+ * List of postprocessing steps that are executed after the prompt template
89
+ */
90
+ readonly postprocessing?: Array<string_javascript_name>;
91
+ /**
92
+ * Expect this amount of each unit in the answer
93
+ *
94
+ * For example 5 words, 3 sentences, 2 paragraphs, ...
95
+ *
96
+ * Note: Expectations are performed after all postprocessing steps
97
+ */
98
+ readonly expectAmount?: Partial<Record<Lowercase<ExpectationUnit>, {
99
+ min?: ExpectationAmount;
100
+ max?: ExpectationAmount;
101
+ }>>;
102
+ /**
103
+ * Expect this format of the answer
104
+ *
105
+ * Note: Expectations are performed after all postprocessing steps
106
+ */
107
+ readonly expectFormat?: ExpectFormatCommand['format'];
93
108
  /**
94
109
  * Name of the parameter that is the result of the prompt template
95
110
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.25.0",
3
+ "version": "0.27.0-0",
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.25.0"
40
+ "@promptbook/core": "0.27.0-0"
41
41
  },
42
42
  "main": "./umd/index.umd.js",
43
43
  "module": "./esm/index.es.js",
package/umd/index.umd.js CHANGED
@@ -199,7 +199,7 @@
199
199
  return OpenAiExecutionTools;
200
200
  }());
201
201
  /**
202
- * TODO: !!!! Allow to use other models - List all from openai
202
+
203
203
  * TODO: Maybe Create some common util for gptChat and gptComplete
204
204
  * TODO: Maybe make custom OpenaiError
205
205
  */
@@ -1,6 +1,5 @@
1
1
  export {};
2
2
  /**
3
3
  * TODO: [🧠] Probbably change syntax MODEL VARIANT -> MODEL
4
- * TODO: !!!! Allow to skip segments SKIP IF {foo} NOT DEFINED
5
- * TODO: !!! Allow to EXPECT 3 words
4
+ * TODO: !!! Allow to skip segments SKIP IF {foo} NOT DEFINED
6
5
  */
@@ -9,7 +9,5 @@ export declare function promptTemplatePipelineStringToJson(promptTemplatePipelin
9
9
  /**
10
10
  * TODO: Report here line/column of error
11
11
  * TODO: Use spaceTrim more effectively
12
- * TODO: !!!! Parameter flags - isInput, isOutput, isInternal, isBeforePostprocessing, isBeforeFinal, canonicalName
13
- * TODO: !!!! Allow to have non-immutable parameters - suffix them with fooPrevious3 -> fooPrevious2 -> fooPrevious1 -> foo
14
- * This must work with other technial parameters
12
+ * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
15
13
  */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This error occurs when some expectation is not met in the execution of the pipeline
3
+ */
4
+ export declare class ExpectError extends Error {
5
+ readonly name = "ExpectError";
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * TODO: [🧠] Should be this exported from the library
10
+ */
@@ -1,4 +1,4 @@
1
- import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
1
+ import type { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
2
2
  import { ExecutionTools } from './ExecutionTools';
3
3
  import { PtpExecutor } from './PtpExecutor';
4
4
  export interface CreatePtpExecutorSettings {
@@ -7,7 +7,7 @@ export interface CreatePtpExecutorSettings {
7
7
  *
8
8
  * @default 3
9
9
  */
10
- readonly maxNaturalExecutionAttempts: number;
10
+ readonly maxExecutionAttempts: number;
11
11
  }
12
12
  /**
13
13
  * Options for creating a PTP (Prompt Template Pipeline) executor
@@ -22,7 +22,7 @@ export declare class OpenAiExecutionTools implements NaturalExecutionTools {
22
22
  gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
23
23
  }
24
24
  /**
25
- * TODO: !!!! Allow to use other models - List all from openai
25
+
26
26
  * TODO: Maybe Create some common util for gptChat and gptComplete
27
27
  * TODO: Maybe make custom OpenaiError
28
28
  */
@@ -66,13 +66,25 @@ export interface PostprocessCommand {
66
66
  }
67
67
  /**
68
68
  * Expect command describes the desired output of the prompt template (after post-processing)
69
+ * It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
70
+ */
71
+ export type ExpectCommand = ExpectAmountCommand | ExpectFormatCommand;
72
+ /**
73
+ * Expect amount command describes the desired output of the prompt template (after post-processing)
69
74
  * It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs,...
70
75
  *
71
76
  * Note: LLMs work with tokens, not characters, but in Promptbooks we want to use some human-recognisable and cross-model interoperable units.
72
77
  */
73
- export interface ExpectCommand {
74
- readonly type: 'EXPECT';
78
+ export interface ExpectAmountCommand {
79
+ readonly type: 'EXPECT_AMOUNT';
75
80
  readonly sign: 'EXACTLY' | 'MINIMUM' | 'MAXIMUM';
76
81
  readonly unit: ExpectationUnit;
77
82
  readonly amount: ExpectationAmount;
78
83
  }
84
+ /**
85
+ * Represents a command that expects a specific format.
86
+ */
87
+ export interface ExpectFormatCommand {
88
+ readonly type: 'EXPECT_FORMAT';
89
+ readonly format: 'JSON';
90
+ }
@@ -1,4 +1,5 @@
1
- import { number_integer, number_positive_or_zero, string_javascript, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
1
+ import { number_integer, number_positive_or_zero, string_javascript, string_javascript_name, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
2
+ import { ExpectFormatCommand } from '../Command';
2
3
  import { ExecutionType } from '../ExecutionTypes';
3
4
  import { ModelRequirements } from '../ModelRequirements';
4
5
  import { ScriptLanguage } from '../ScriptLanguage';
@@ -11,13 +12,6 @@ export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | Scri
11
12
  */
12
13
  export interface NaturalTemplateJson extends PromptTemplateJsonCommon {
13
14
  readonly executionType: 'PROMPT_TEMPLATE';
14
- /**
15
- * Expectations for the answer
16
- */
17
- readonly expectations: Partial<Record<Lowercase<ExpectationUnit>, {
18
- min?: ExpectationAmount;
19
- max?: ExpectationAmount;
20
- }>>;
21
15
  /**
22
16
  * Requirements for the model
23
17
  * - This is required only for executionType PROMPT_TEMPLATE
@@ -31,7 +25,7 @@ export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTEN
31
25
  /**
32
26
  * Unit of text measurement
33
27
  */
34
- export type ExpectationUnit = (typeof EXPECTATION_UNITS)[number];
28
+ export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
35
29
  /**
36
30
  * Amount of text measurement
37
31
  */
@@ -90,6 +84,27 @@ interface PromptTemplateJsonCommon {
90
84
  * Content of the template with {placeholders} for parameters
91
85
  */
92
86
  readonly content: (string_prompt | string_javascript | string_markdown) & string_template;
87
+ /**
88
+ * List of postprocessing steps that are executed after the prompt template
89
+ */
90
+ readonly postprocessing?: Array<string_javascript_name>;
91
+ /**
92
+ * Expect this amount of each unit in the answer
93
+ *
94
+ * For example 5 words, 3 sentences, 2 paragraphs, ...
95
+ *
96
+ * Note: Expectations are performed after all postprocessing steps
97
+ */
98
+ readonly expectAmount?: Partial<Record<Lowercase<ExpectationUnit>, {
99
+ min?: ExpectationAmount;
100
+ max?: ExpectationAmount;
101
+ }>>;
102
+ /**
103
+ * Expect this format of the answer
104
+ *
105
+ * Note: Expectations are performed after all postprocessing steps
106
+ */
107
+ readonly expectFormat?: ExpectFormatCommand['format'];
93
108
  /**
94
109
  * Name of the parameter that is the result of the prompt template
95
110
  */