@promptbook/openai 0.24.0 → 0.26.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/typings/classes/PromptTemplatePipelineLibrary.d.ts +12 -2
- package/esm/typings/execution/createPtpExecutor.d.ts +14 -2
- package/esm/typings/types/Command.d.ts +14 -2
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +10 -3
- package/package.json +2 -2
- package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +12 -2
- package/umd/typings/execution/createPtpExecutor.d.ts +14 -2
- package/umd/typings/types/Command.d.ts +14 -2
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +10 -3
|
@@ -6,9 +6,18 @@ import { Prompt } from '../types/Prompt';
|
|
|
6
6
|
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
7
7
|
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
8
8
|
import { PromptTemplatePipeline } from './PromptTemplatePipeline';
|
|
9
|
+
/**
|
|
10
|
+
* Options for PromptTemplatePipelineLibrary
|
|
11
|
+
*/
|
|
9
12
|
type PromptTemplatePipelineLibraryOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The library of prompt template pipelines
|
|
15
|
+
*/
|
|
10
16
|
readonly library: Record<string_name, PromptTemplatePipeline>;
|
|
11
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Optional settings for creating a PromptTemplatePipelineExecutor
|
|
19
|
+
*/
|
|
20
|
+
readonly settings?: Partial<CreatePtpExecutorSettings>;
|
|
12
21
|
};
|
|
13
22
|
/**
|
|
14
23
|
* Library of prompt template pipelines that groups together prompt template pipelines for an application. This is a very thin wrapper around the Array / Set of prompt template pipelines.
|
|
@@ -28,9 +37,10 @@ export declare class PromptTemplatePipelineLibrary {
|
|
|
28
37
|
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
29
38
|
*
|
|
30
39
|
* @param ptbkSources contents of .ptbk.md or .ptbk.json files
|
|
40
|
+
* @param settings settings for creating executor functions
|
|
31
41
|
* @returns PromptTemplatePipelineLibrary
|
|
32
42
|
*/
|
|
33
|
-
static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>, settings
|
|
43
|
+
static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>, settings?: Partial<CreatePtpExecutorSettings>): PromptTemplatePipelineLibrary;
|
|
34
44
|
private constructor();
|
|
35
45
|
/**
|
|
36
46
|
* Gets prompt template pipeline by name
|
|
@@ -5,14 +5,26 @@ export interface CreatePtpExecutorSettings {
|
|
|
5
5
|
/**
|
|
6
6
|
* When executor does not satisfy expectations it will be retried this amount of times
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* @default 3
|
|
9
9
|
*/
|
|
10
10
|
readonly maxNaturalExecutionAttempts: number;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Options for creating a PTP (Prompt Template Pipeline) executor
|
|
14
|
+
*/
|
|
12
15
|
interface CreatePtpExecutorOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The Prompt Template Pipeline (PTP) to be executed
|
|
18
|
+
*/
|
|
13
19
|
readonly ptp: PromptTemplatePipeline;
|
|
20
|
+
/**
|
|
21
|
+
* The execution tools to be used during the execution of the PTP
|
|
22
|
+
*/
|
|
14
23
|
readonly tools: ExecutionTools;
|
|
15
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Optional settings for the PTP executor
|
|
26
|
+
*/
|
|
27
|
+
readonly settings?: Partial<CreatePtpExecutorSettings>;
|
|
16
28
|
}
|
|
17
29
|
/**
|
|
18
30
|
* Creates executor function from prompt template pipeline and execution tools.
|
|
@@ -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
|
|
74
|
-
readonly type: '
|
|
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
1
|
import { number_integer, number_positive_or_zero, string_javascript, 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';
|
|
@@ -12,12 +13,18 @@ export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | Scri
|
|
|
12
13
|
export interface NaturalTemplateJson extends PromptTemplateJsonCommon {
|
|
13
14
|
readonly executionType: 'PROMPT_TEMPLATE';
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* Expect this amount of each unit in the answer
|
|
17
|
+
*
|
|
18
|
+
* For example 5 words, 3 sentences, 2 paragraphs, ...
|
|
16
19
|
*/
|
|
17
|
-
readonly
|
|
20
|
+
readonly expectAmount?: Partial<Record<Lowercase<ExpectationUnit>, {
|
|
18
21
|
min?: ExpectationAmount;
|
|
19
22
|
max?: ExpectationAmount;
|
|
20
23
|
}>>;
|
|
24
|
+
/**
|
|
25
|
+
* Expect this format of the answer
|
|
26
|
+
*/
|
|
27
|
+
readonly expectFormat?: ExpectFormatCommand['format'];
|
|
21
28
|
/**
|
|
22
29
|
* Requirements for the model
|
|
23
30
|
* - This is required only for executionType PROMPT_TEMPLATE
|
|
@@ -31,7 +38,7 @@ export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTEN
|
|
|
31
38
|
/**
|
|
32
39
|
* Unit of text measurement
|
|
33
40
|
*/
|
|
34
|
-
export type ExpectationUnit =
|
|
41
|
+
export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
|
|
35
42
|
/**
|
|
36
43
|
* Amount of text measurement
|
|
37
44
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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.
|
|
40
|
+
"@promptbook/core": "0.26.0"
|
|
41
41
|
},
|
|
42
42
|
"main": "./umd/index.umd.js",
|
|
43
43
|
"module": "./esm/index.es.js",
|
|
@@ -6,9 +6,18 @@ import { Prompt } from '../types/Prompt';
|
|
|
6
6
|
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
7
7
|
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
8
8
|
import { PromptTemplatePipeline } from './PromptTemplatePipeline';
|
|
9
|
+
/**
|
|
10
|
+
* Options for PromptTemplatePipelineLibrary
|
|
11
|
+
*/
|
|
9
12
|
type PromptTemplatePipelineLibraryOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The library of prompt template pipelines
|
|
15
|
+
*/
|
|
10
16
|
readonly library: Record<string_name, PromptTemplatePipeline>;
|
|
11
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Optional settings for creating a PromptTemplatePipelineExecutor
|
|
19
|
+
*/
|
|
20
|
+
readonly settings?: Partial<CreatePtpExecutorSettings>;
|
|
12
21
|
};
|
|
13
22
|
/**
|
|
14
23
|
* Library of prompt template pipelines that groups together prompt template pipelines for an application. This is a very thin wrapper around the Array / Set of prompt template pipelines.
|
|
@@ -28,9 +37,10 @@ export declare class PromptTemplatePipelineLibrary {
|
|
|
28
37
|
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
29
38
|
*
|
|
30
39
|
* @param ptbkSources contents of .ptbk.md or .ptbk.json files
|
|
40
|
+
* @param settings settings for creating executor functions
|
|
31
41
|
* @returns PromptTemplatePipelineLibrary
|
|
32
42
|
*/
|
|
33
|
-
static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>, settings
|
|
43
|
+
static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>, settings?: Partial<CreatePtpExecutorSettings>): PromptTemplatePipelineLibrary;
|
|
34
44
|
private constructor();
|
|
35
45
|
/**
|
|
36
46
|
* Gets prompt template pipeline by name
|
|
@@ -5,14 +5,26 @@ export interface CreatePtpExecutorSettings {
|
|
|
5
5
|
/**
|
|
6
6
|
* When executor does not satisfy expectations it will be retried this amount of times
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* @default 3
|
|
9
9
|
*/
|
|
10
10
|
readonly maxNaturalExecutionAttempts: number;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Options for creating a PTP (Prompt Template Pipeline) executor
|
|
14
|
+
*/
|
|
12
15
|
interface CreatePtpExecutorOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The Prompt Template Pipeline (PTP) to be executed
|
|
18
|
+
*/
|
|
13
19
|
readonly ptp: PromptTemplatePipeline;
|
|
20
|
+
/**
|
|
21
|
+
* The execution tools to be used during the execution of the PTP
|
|
22
|
+
*/
|
|
14
23
|
readonly tools: ExecutionTools;
|
|
15
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Optional settings for the PTP executor
|
|
26
|
+
*/
|
|
27
|
+
readonly settings?: Partial<CreatePtpExecutorSettings>;
|
|
16
28
|
}
|
|
17
29
|
/**
|
|
18
30
|
* Creates executor function from prompt template pipeline and execution tools.
|
|
@@ -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
|
|
74
|
-
readonly type: '
|
|
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
1
|
import { number_integer, number_positive_or_zero, string_javascript, 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';
|
|
@@ -12,12 +13,18 @@ export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | Scri
|
|
|
12
13
|
export interface NaturalTemplateJson extends PromptTemplateJsonCommon {
|
|
13
14
|
readonly executionType: 'PROMPT_TEMPLATE';
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* Expect this amount of each unit in the answer
|
|
17
|
+
*
|
|
18
|
+
* For example 5 words, 3 sentences, 2 paragraphs, ...
|
|
16
19
|
*/
|
|
17
|
-
readonly
|
|
20
|
+
readonly expectAmount?: Partial<Record<Lowercase<ExpectationUnit>, {
|
|
18
21
|
min?: ExpectationAmount;
|
|
19
22
|
max?: ExpectationAmount;
|
|
20
23
|
}>>;
|
|
24
|
+
/**
|
|
25
|
+
* Expect this format of the answer
|
|
26
|
+
*/
|
|
27
|
+
readonly expectFormat?: ExpectFormatCommand['format'];
|
|
21
28
|
/**
|
|
22
29
|
* Requirements for the model
|
|
23
30
|
* - This is required only for executionType PROMPT_TEMPLATE
|
|
@@ -31,7 +38,7 @@ export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTEN
|
|
|
31
38
|
/**
|
|
32
39
|
* Unit of text measurement
|
|
33
40
|
*/
|
|
34
|
-
export type ExpectationUnit =
|
|
41
|
+
export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
|
|
35
42
|
/**
|
|
36
43
|
* Amount of text measurement
|
|
37
44
|
*/
|