@promptbook/openai 0.24.0-0 → 0.24.0-2.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.
@@ -1,4 +1,4 @@
1
- import { string_name } from '.././types/typeAliases';
1
+ import { string_name, string_version } from '.././types/typeAliases';
2
2
  import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
3
3
  import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
4
4
  import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
@@ -16,6 +16,9 @@ import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineStr
16
16
  */
17
17
  export declare class PromptTemplatePipeline {
18
18
  readonly ptbkUrl: URL | null;
19
+ readonly title: string | null;
20
+ readonly ptbkVersion: string_version | null;
21
+ readonly description: string | null;
19
22
  readonly parameters: Record<string_name, PromptTemplateParameterJson>;
20
23
  readonly promptTemplates: Array<PromptTemplateJson>;
21
24
  /**
@@ -1,10 +1,15 @@
1
1
  import { string_name } from '.././types/typeAliases';
2
+ import { CreatePtpExecutorSettings } from '../execution/createPtpExecutor';
2
3
  import { ExecutionTools } from '../execution/ExecutionTools';
3
4
  import { PtpExecutor } from '../execution/PtpExecutor';
4
5
  import { Prompt } from '../types/Prompt';
5
6
  import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
6
7
  import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
7
8
  import { PromptTemplatePipeline } from './PromptTemplatePipeline';
9
+ type PromptTemplatePipelineLibraryOptions = {
10
+ readonly library: Record<string_name, PromptTemplatePipeline>;
11
+ readonly settings: CreatePtpExecutorSettings;
12
+ };
8
13
  /**
9
14
  * 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.
10
15
  *
@@ -15,7 +20,7 @@ import { PromptTemplatePipeline } from './PromptTemplatePipeline';
15
20
  * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline-library
16
21
  */
17
22
  export declare class PromptTemplatePipelineLibrary {
18
- readonly promptTemplatePipelines: Record<string_name, PromptTemplatePipeline>;
23
+ readonly options: PromptTemplatePipelineLibraryOptions;
19
24
  /**
20
25
  * Constructs PromptTemplatePipeline from any sources
21
26
  *
@@ -25,7 +30,7 @@ export declare class PromptTemplatePipelineLibrary {
25
30
  * @param ptbkSources contents of .ptbk.md or .ptbk.json files
26
31
  * @returns PromptTemplatePipelineLibrary
27
32
  */
28
- static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>): PromptTemplatePipelineLibrary;
33
+ static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>, settings: CreatePtpExecutorSettings): PromptTemplatePipelineLibrary;
29
34
  private constructor();
30
35
  /**
31
36
  * Gets prompt template pipeline by name
@@ -40,6 +45,7 @@ export declare class PromptTemplatePipelineLibrary {
40
45
  */
41
46
  createExecutor(name: string_name, tools: ExecutionTools): PtpExecutor;
42
47
  }
48
+ export {};
43
49
  /**
44
50
  * TODO: !!! This should be renamed to Promptbook
45
51
  * TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
@@ -1,6 +1,7 @@
1
- import { Promisable } from 'type-fest';
2
- import { string_name } from '.././types/typeAliases';
3
- import { TaskProgress } from '../types/TaskProgress';
1
+ import type { Promisable } from 'type-fest';
2
+ import type { string_name } from '.././types/typeAliases';
3
+ import type { TaskProgress } from '../types/TaskProgress';
4
+ import type { ExecutionReportJson } from '../types/execution-report/ExecutionReportJson';
4
5
  /**
5
6
  * Executor is a simple async function that takes input parameters and returns result parameters _(along with all intermediate parameters and input parameters = it extends input object)_.
6
7
  * Executor is made by combining execution tools and prompt template pipeline library.
@@ -12,7 +13,26 @@ import { TaskProgress } from '../types/TaskProgress';
12
13
  * @see https://github.com/webgptorg/promptbook#executor
13
14
  */
14
15
  export interface PtpExecutor {
15
- (inputParameters: Record<string_name, string>, onProgress: (taskProgress: TaskProgress) => Promisable<void>): Promise<Record<string_name, string>>;
16
+ (inputParameters: Record<string_name, string>, onProgress: (taskProgress: TaskProgress) => Promisable<void>): Promise<{
17
+ /**
18
+ * Whether the execution was successful
19
+ */
20
+ isSuccessful: boolean;
21
+ /**
22
+ * Errors that occured during the execution
23
+ */
24
+ errors: Array<Error>;
25
+ /**
26
+ * The report of the execution
27
+ */
28
+ executionReport: ExecutionReportJson;
29
+ /**
30
+ * Result parameters of the execution
31
+ *
32
+ * Note: If the execution was not successful, there are only some of the result parameters
33
+ */
34
+ outputParameters: Record<string_name, string>;
35
+ }>;
16
36
  }
17
37
  /**
18
38
  * TODO: [🧠] Should this file be in /execution or /types folder?
@@ -1,9 +1,18 @@
1
1
  import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
2
2
  import { ExecutionTools } from './ExecutionTools';
3
3
  import { PtpExecutor } from './PtpExecutor';
4
+ export interface CreatePtpExecutorSettings {
5
+ /**
6
+ * When executor does not satisfy expectations it will be retried this amount of times
7
+ *
8
+ * !!!!!!! Make default in version 24.1.0
9
+ */
10
+ readonly maxNaturalExecutionAttempts: number;
11
+ }
4
12
  interface CreatePtpExecutorOptions {
5
13
  readonly ptp: PromptTemplatePipeline;
6
14
  readonly tools: ExecutionTools;
15
+ readonly settings: CreatePtpExecutorSettings;
7
16
  }
8
17
  /**
9
18
  * Creates executor function from prompt template pipeline and execution tools.
@@ -1,11 +1,17 @@
1
- import { string_name, string_prompt, string_ptbk_url_with_hashtemplate } from '.././types/typeAliases';
2
- import { ModelRequirements } from './ModelRequirements';
1
+ import type { string_name, string_prompt, string_ptbk_url_with_hashtemplate, string_title } from '.././types/typeAliases';
2
+ import type { ModelRequirements } from './ModelRequirements';
3
3
  /**
4
4
  * Prompt in a text along with model requirements, but without any execution or templating logic.
5
5
  *
6
6
  * @see https://github.com/webgptorg/promptbook#prompt
7
7
  */
8
8
  export interface Prompt {
9
+ /**
10
+ * The title of the prompt
11
+ *
12
+ * Note: This has no effect on the model, it is just for the reporting
13
+ */
14
+ readonly title: string_title;
9
15
  /**
10
16
  * The text of the prompt
11
17
  *
@@ -1,5 +1,6 @@
1
1
  import type { PromptResult } from '../../execution/PromptResult';
2
- import { Prompt } from '../Prompt';
2
+ import type { Prompt } from '../Prompt';
3
+ import type { string_ptbk_url, string_version } from '../typeAliases';
3
4
  /**
4
5
  * ExecutionReport is result of executing one promptbook
5
6
  * It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
@@ -10,10 +11,46 @@ import { Prompt } from '../Prompt';
10
11
  *
11
12
  * @see https://github.com/webgptorg/promptbook#execution-report
12
13
  */
13
- export type ExecutionReportJson = Array<{
14
- prompt: Omit<Prompt, 'ptbkUrl' | 'parameters'>;
15
- result: PromptResult;
16
- }>;
17
- /**
18
- * TODO: [🧠] What is the best shape of ExecutionReportJson
19
- */
14
+ export type ExecutionReportJson = {
15
+ /**
16
+ * Unique identifier of the ptp from ptp which was executed
17
+ */
18
+ readonly ptbkUrl?: string_ptbk_url;
19
+ /**
20
+ * Title of from ptp which was executed
21
+ */
22
+ readonly title?: string;
23
+ /**
24
+ * Version from ptp which was executed
25
+ */
26
+ readonly ptbkUsedVersion: string_version;
27
+ /**
28
+ * Version from ptp which was requested by promptbook
29
+ */
30
+ readonly ptbkRequestedVersion?: string_version;
31
+ /**
32
+ * Description of the ptp which was executed
33
+ */
34
+ readonly description?: string;
35
+ /**
36
+ * Sequence of prompt templates in order which were executed
37
+ */
38
+ readonly promptExecutions: Array<{
39
+ /**
40
+ * The prompt wich was executed
41
+ */
42
+ prompt: Omit<Prompt, 'ptbkUrl' | 'parameters'>;
43
+ /**
44
+ * Result of the prompt execution (if not failed during LLM execution)
45
+ */
46
+ result?: PromptResult;
47
+ /**
48
+ * The error which occured during LLM execution or during postprocessing or expectation checking
49
+ *
50
+ * Note: It makes sense to have both error and result defined, for example when the result not pass expectations
51
+ */
52
+ error?: {
53
+ message: string;
54
+ };
55
+ }>;
56
+ };
@@ -0,0 +1,8 @@
1
+ import type { string_html } from '../../types/typeAliases';
2
+ /**
3
+ * Prettify the html code
4
+ *
5
+ * @param html raw html code
6
+ * @returns formatted html code
7
+ */
8
+ export declare function prettifyMarkdown(html: string_html): string_html;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.24.0-0",
3
+ "version": "0.24.0-2.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.24.0-0"
40
+ "@promptbook/core": "0.24.0-2.0"
41
41
  },
42
42
  "main": "./umd/index.umd.js",
43
43
  "module": "./esm/index.es.js",
@@ -1,4 +1,4 @@
1
- import { string_name } from '.././types/typeAliases';
1
+ import { string_name, string_version } from '.././types/typeAliases';
2
2
  import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
3
3
  import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
4
4
  import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
@@ -16,6 +16,9 @@ import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineStr
16
16
  */
17
17
  export declare class PromptTemplatePipeline {
18
18
  readonly ptbkUrl: URL | null;
19
+ readonly title: string | null;
20
+ readonly ptbkVersion: string_version | null;
21
+ readonly description: string | null;
19
22
  readonly parameters: Record<string_name, PromptTemplateParameterJson>;
20
23
  readonly promptTemplates: Array<PromptTemplateJson>;
21
24
  /**
@@ -1,10 +1,15 @@
1
1
  import { string_name } from '.././types/typeAliases';
2
+ import { CreatePtpExecutorSettings } from '../execution/createPtpExecutor';
2
3
  import { ExecutionTools } from '../execution/ExecutionTools';
3
4
  import { PtpExecutor } from '../execution/PtpExecutor';
4
5
  import { Prompt } from '../types/Prompt';
5
6
  import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
6
7
  import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
7
8
  import { PromptTemplatePipeline } from './PromptTemplatePipeline';
9
+ type PromptTemplatePipelineLibraryOptions = {
10
+ readonly library: Record<string_name, PromptTemplatePipeline>;
11
+ readonly settings: CreatePtpExecutorSettings;
12
+ };
8
13
  /**
9
14
  * 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.
10
15
  *
@@ -15,7 +20,7 @@ import { PromptTemplatePipeline } from './PromptTemplatePipeline';
15
20
  * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline-library
16
21
  */
17
22
  export declare class PromptTemplatePipelineLibrary {
18
- readonly promptTemplatePipelines: Record<string_name, PromptTemplatePipeline>;
23
+ readonly options: PromptTemplatePipelineLibraryOptions;
19
24
  /**
20
25
  * Constructs PromptTemplatePipeline from any sources
21
26
  *
@@ -25,7 +30,7 @@ export declare class PromptTemplatePipelineLibrary {
25
30
  * @param ptbkSources contents of .ptbk.md or .ptbk.json files
26
31
  * @returns PromptTemplatePipelineLibrary
27
32
  */
28
- static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>): PromptTemplatePipelineLibrary;
33
+ static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>, settings: CreatePtpExecutorSettings): PromptTemplatePipelineLibrary;
29
34
  private constructor();
30
35
  /**
31
36
  * Gets prompt template pipeline by name
@@ -40,6 +45,7 @@ export declare class PromptTemplatePipelineLibrary {
40
45
  */
41
46
  createExecutor(name: string_name, tools: ExecutionTools): PtpExecutor;
42
47
  }
48
+ export {};
43
49
  /**
44
50
  * TODO: !!! This should be renamed to Promptbook
45
51
  * TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
@@ -1,6 +1,7 @@
1
- import { Promisable } from 'type-fest';
2
- import { string_name } from '.././types/typeAliases';
3
- import { TaskProgress } from '../types/TaskProgress';
1
+ import type { Promisable } from 'type-fest';
2
+ import type { string_name } from '.././types/typeAliases';
3
+ import type { TaskProgress } from '../types/TaskProgress';
4
+ import type { ExecutionReportJson } from '../types/execution-report/ExecutionReportJson';
4
5
  /**
5
6
  * Executor is a simple async function that takes input parameters and returns result parameters _(along with all intermediate parameters and input parameters = it extends input object)_.
6
7
  * Executor is made by combining execution tools and prompt template pipeline library.
@@ -12,7 +13,26 @@ import { TaskProgress } from '../types/TaskProgress';
12
13
  * @see https://github.com/webgptorg/promptbook#executor
13
14
  */
14
15
  export interface PtpExecutor {
15
- (inputParameters: Record<string_name, string>, onProgress: (taskProgress: TaskProgress) => Promisable<void>): Promise<Record<string_name, string>>;
16
+ (inputParameters: Record<string_name, string>, onProgress: (taskProgress: TaskProgress) => Promisable<void>): Promise<{
17
+ /**
18
+ * Whether the execution was successful
19
+ */
20
+ isSuccessful: boolean;
21
+ /**
22
+ * Errors that occured during the execution
23
+ */
24
+ errors: Array<Error>;
25
+ /**
26
+ * The report of the execution
27
+ */
28
+ executionReport: ExecutionReportJson;
29
+ /**
30
+ * Result parameters of the execution
31
+ *
32
+ * Note: If the execution was not successful, there are only some of the result parameters
33
+ */
34
+ outputParameters: Record<string_name, string>;
35
+ }>;
16
36
  }
17
37
  /**
18
38
  * TODO: [🧠] Should this file be in /execution or /types folder?
@@ -1,9 +1,18 @@
1
1
  import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
2
2
  import { ExecutionTools } from './ExecutionTools';
3
3
  import { PtpExecutor } from './PtpExecutor';
4
+ export interface CreatePtpExecutorSettings {
5
+ /**
6
+ * When executor does not satisfy expectations it will be retried this amount of times
7
+ *
8
+ * !!!!!!! Make default in version 24.1.0
9
+ */
10
+ readonly maxNaturalExecutionAttempts: number;
11
+ }
4
12
  interface CreatePtpExecutorOptions {
5
13
  readonly ptp: PromptTemplatePipeline;
6
14
  readonly tools: ExecutionTools;
15
+ readonly settings: CreatePtpExecutorSettings;
7
16
  }
8
17
  /**
9
18
  * Creates executor function from prompt template pipeline and execution tools.
@@ -1,11 +1,17 @@
1
- import { string_name, string_prompt, string_ptbk_url_with_hashtemplate } from '.././types/typeAliases';
2
- import { ModelRequirements } from './ModelRequirements';
1
+ import type { string_name, string_prompt, string_ptbk_url_with_hashtemplate, string_title } from '.././types/typeAliases';
2
+ import type { ModelRequirements } from './ModelRequirements';
3
3
  /**
4
4
  * Prompt in a text along with model requirements, but without any execution or templating logic.
5
5
  *
6
6
  * @see https://github.com/webgptorg/promptbook#prompt
7
7
  */
8
8
  export interface Prompt {
9
+ /**
10
+ * The title of the prompt
11
+ *
12
+ * Note: This has no effect on the model, it is just for the reporting
13
+ */
14
+ readonly title: string_title;
9
15
  /**
10
16
  * The text of the prompt
11
17
  *
@@ -1,5 +1,6 @@
1
1
  import type { PromptResult } from '../../execution/PromptResult';
2
- import { Prompt } from '../Prompt';
2
+ import type { Prompt } from '../Prompt';
3
+ import type { string_ptbk_url, string_version } from '../typeAliases';
3
4
  /**
4
5
  * ExecutionReport is result of executing one promptbook
5
6
  * It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
@@ -10,10 +11,46 @@ import { Prompt } from '../Prompt';
10
11
  *
11
12
  * @see https://github.com/webgptorg/promptbook#execution-report
12
13
  */
13
- export type ExecutionReportJson = Array<{
14
- prompt: Omit<Prompt, 'ptbkUrl' | 'parameters'>;
15
- result: PromptResult;
16
- }>;
17
- /**
18
- * TODO: [🧠] What is the best shape of ExecutionReportJson
19
- */
14
+ export type ExecutionReportJson = {
15
+ /**
16
+ * Unique identifier of the ptp from ptp which was executed
17
+ */
18
+ readonly ptbkUrl?: string_ptbk_url;
19
+ /**
20
+ * Title of from ptp which was executed
21
+ */
22
+ readonly title?: string;
23
+ /**
24
+ * Version from ptp which was executed
25
+ */
26
+ readonly ptbkUsedVersion: string_version;
27
+ /**
28
+ * Version from ptp which was requested by promptbook
29
+ */
30
+ readonly ptbkRequestedVersion?: string_version;
31
+ /**
32
+ * Description of the ptp which was executed
33
+ */
34
+ readonly description?: string;
35
+ /**
36
+ * Sequence of prompt templates in order which were executed
37
+ */
38
+ readonly promptExecutions: Array<{
39
+ /**
40
+ * The prompt wich was executed
41
+ */
42
+ prompt: Omit<Prompt, 'ptbkUrl' | 'parameters'>;
43
+ /**
44
+ * Result of the prompt execution (if not failed during LLM execution)
45
+ */
46
+ result?: PromptResult;
47
+ /**
48
+ * The error which occured during LLM execution or during postprocessing or expectation checking
49
+ *
50
+ * Note: It makes sense to have both error and result defined, for example when the result not pass expectations
51
+ */
52
+ error?: {
53
+ message: string;
54
+ };
55
+ }>;
56
+ };
@@ -0,0 +1,8 @@
1
+ import type { string_html } from '../../types/typeAliases';
2
+ /**
3
+ * Prettify the html code
4
+ *
5
+ * @param html raw html code
6
+ * @returns formatted html code
7
+ */
8
+ export declare function prettifyMarkdown(html: string_html): string_html;