@promptbook/openai 0.23.2 → 0.24.0-1.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/_packages/types.index.d.ts +2 -2
- package/esm/typings/_packages/utils.index.d.ts +11 -1
- package/esm/typings/classes/PromptTemplatePipeline.d.ts +4 -1
- package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +8 -2
- package/esm/typings/conversion/parseCommand.d.ts +2 -2
- package/esm/typings/execution/PromptResult.d.ts +1 -1
- package/esm/typings/execution/PtpExecutor.d.ts +24 -4
- package/esm/typings/execution/createPtpExecutor.d.ts +9 -0
- package/esm/typings/types/Command.d.ts +17 -4
- package/esm/typings/types/Prompt.d.ts +8 -2
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
- package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +56 -0
- package/esm/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
- package/esm/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
- package/esm/typings/types/typeAliases.d.ts +3 -1
- package/esm/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countLines.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countPages.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countSentences.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/countWords.d.ts +5 -0
- package/esm/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
- package/esm/typings/utils/expectation-counters/index.d.ts +5 -0
- package/esm/typings/utils/markdown/prettifyMarkdown.d.ts +8 -0
- package/esm/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
- package/esm/typings/utils/parseNumber.d.ts +10 -0
- package/esm/typings/utils/parseNumber.test.d.ts +1 -0
- package/esm/typings/utils/trimCodeBlock.d.ts +8 -0
- package/esm/typings/utils/trimCodeBlock.test.d.ts +1 -0
- package/esm/typings/utils/trimEndOfCodeBlock.d.ts +2 -1
- package/package.json +2 -2
- package/umd/typings/_packages/types.index.d.ts +2 -2
- package/umd/typings/_packages/utils.index.d.ts +11 -1
- package/umd/typings/classes/PromptTemplatePipeline.d.ts +4 -1
- package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +8 -2
- package/umd/typings/conversion/parseCommand.d.ts +2 -2
- package/umd/typings/execution/PromptResult.d.ts +1 -1
- package/umd/typings/execution/PtpExecutor.d.ts +24 -4
- package/umd/typings/execution/createPtpExecutor.d.ts +9 -0
- package/umd/typings/types/Command.d.ts +17 -4
- package/umd/typings/types/Prompt.d.ts +8 -2
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
- package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +56 -0
- package/umd/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
- package/umd/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
- package/umd/typings/types/typeAliases.d.ts +3 -1
- package/umd/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countLines.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countPages.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countSentences.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/countWords.d.ts +5 -0
- package/umd/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
- package/umd/typings/utils/expectation-counters/index.d.ts +5 -0
- package/umd/typings/utils/markdown/prettifyMarkdown.d.ts +8 -0
- package/umd/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
- package/umd/typings/utils/parseNumber.d.ts +10 -0
- package/umd/typings/utils/parseNumber.test.d.ts +1 -0
- package/umd/typings/utils/trimCodeBlock.d.ts +8 -0
- package/umd/typings/utils/trimCodeBlock.test.d.ts +1 -0
- package/umd/typings/utils/trimEndOfCodeBlock.d.ts +2 -1
|
@@ -9,7 +9,7 @@ import { ExecutionType } from '../types/ExecutionTypes';
|
|
|
9
9
|
import { ModelRequirements, ModelVariant } from '../types/ModelRequirements';
|
|
10
10
|
import { Parameters } from '../types/Parameters';
|
|
11
11
|
import { Prompt } from '../types/Prompt';
|
|
12
|
-
import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
|
|
12
|
+
import { EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
|
|
13
13
|
import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
|
|
14
14
|
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
15
15
|
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
@@ -17,7 +17,7 @@ import { ScriptLanguage } from '../types/ScriptLanguage';
|
|
|
17
17
|
import { TaskProgress } from '../types/TaskProgress';
|
|
18
18
|
import { string_char_emoji } from '../types/typeAliasEmoji';
|
|
19
19
|
import { ILicense, IPersonProfile, IRepository, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml } from '../types/typeAliases';
|
|
20
|
-
export { CommonExecutionToolsOptions, ExecutionTools, ExecutionType, ILicense, IPersonProfile, IRepository, ModelRequirements, ModelVariant, NaturalExecutionTools, Parameters, Prompt, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, PromptTemplatePipelineJson, PromptTemplatePipelineString, PtpExecutor, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_char_emoji, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml, };
|
|
20
|
+
export { CommonExecutionToolsOptions, EXPECTATION_UNITS, ExecutionTools, ExecutionType, ExpectationAmount, ExpectationUnit, ILicense, IPersonProfile, IRepository, ModelRequirements, ModelVariant, NaturalExecutionTools, Parameters, Prompt, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, PromptTemplatePipelineJson, PromptTemplatePipelineString, PtpExecutor, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_char_emoji, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml, };
|
|
21
21
|
/**
|
|
22
22
|
* TODO: !!! Filter out all the types that are not used in the library
|
|
23
23
|
*/
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
1
2
|
import { EMOJIS, EMOJIS_IN_CATEGORIES } from '../utils/emojis';
|
|
3
|
+
import { CountUtils } from '../utils/expectation-counters';
|
|
4
|
+
import { countCharacters } from '../utils/expectation-counters/countCharacters';
|
|
5
|
+
import { countLines } from '../utils/expectation-counters/countLines';
|
|
6
|
+
import { countPages } from '../utils/expectation-counters/countPages';
|
|
7
|
+
import { countParagraphs } from '../utils/expectation-counters/countParagraphs';
|
|
8
|
+
import { countSentences } from '../utils/expectation-counters/countSentences';
|
|
9
|
+
import { countWords } from '../utils/expectation-counters/countWords';
|
|
2
10
|
import { isValidJsonString } from '../utils/isValidJsonString';
|
|
3
11
|
import { extractAllBlocksFromMarkdown } from '../utils/markdown/extractAllBlocksFromMarkdown';
|
|
4
12
|
import { extractAllListItemsFromMarkdown } from '../utils/markdown/extractAllListItemsFromMarkdown';
|
|
5
13
|
import { extractOneBlockFromMarkdown } from '../utils/markdown/extractOneBlockFromMarkdown';
|
|
6
14
|
import { removeContentComments } from '../utils/markdown/removeContentComments';
|
|
7
15
|
import { removeMarkdownFormatting } from '../utils/markdown/removeMarkdownFormatting';
|
|
16
|
+
import { parseNumber } from '../utils/parseNumber';
|
|
8
17
|
import { removeEmojis } from '../utils/removeEmojis';
|
|
9
18
|
import { removeQuotes } from '../utils/removeQuotes';
|
|
10
19
|
import { replaceParameters } from '../utils/replaceParameters';
|
|
20
|
+
import { trimCodeBlock } from '../utils/trimCodeBlock';
|
|
11
21
|
import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
|
|
12
22
|
import { unwrapResult } from '../utils/unwrapResult';
|
|
13
|
-
export { EMOJIS, EMOJIS_IN_CATEGORIES, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractOneBlockFromMarkdown, isValidJsonString, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, trimEndOfCodeBlock, unwrapResult, };
|
|
23
|
+
export { CountUtils, EMOJIS, EMOJIS_IN_CATEGORIES, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, executionReportJsonToString, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractOneBlockFromMarkdown, isValidJsonString, parseNumber, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
|
|
@@ -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
|
|
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
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { string_markdown_text } from '.././types/typeAliases';
|
|
2
|
-
import { Command } from '../types/Command';
|
|
1
|
+
import type { string_markdown_text } from '.././types/typeAliases';
|
|
2
|
+
import type { Command } from '../types/Command';
|
|
3
3
|
/**
|
|
4
4
|
* Parses one line of ul/ol to command
|
|
5
5
|
*/
|
|
@@ -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<
|
|
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,12 @@
|
|
|
1
|
-
import { string_markdown_text, string_name, string_version } from '.././types/typeAliases';
|
|
2
|
-
import { ExecutionType } from './ExecutionTypes';
|
|
3
|
-
import { ModelRequirements } from './ModelRequirements';
|
|
1
|
+
import type { string_markdown_text, string_name, string_version } from '.././types/typeAliases';
|
|
2
|
+
import type { ExecutionType } from './ExecutionTypes';
|
|
3
|
+
import type { ModelRequirements } from './ModelRequirements';
|
|
4
|
+
import type { ExpectationAmount, ExpectationUnit } from './PromptTemplatePipelineJson/PromptTemplateJson';
|
|
4
5
|
/**
|
|
5
6
|
* Command is one piece of the prompt template which adds some logic to the prompt template or the whole pipeline.
|
|
6
7
|
* It is parsed from the markdown from ul/ol items - one command per one item.
|
|
7
8
|
*/
|
|
8
|
-
export type Command = PtbkUrlCommand | PtbkVersionCommand | ExecuteCommand | ModelCommand | ParameterCommand | PostprocessCommand;
|
|
9
|
+
export type Command = PtbkUrlCommand | PtbkVersionCommand | ExecuteCommand | ModelCommand | ParameterCommand | PostprocessCommand | ExpectCommand;
|
|
9
10
|
/**
|
|
10
11
|
* PtpVersion command tells which version is .ptp file using
|
|
11
12
|
*
|
|
@@ -63,3 +64,15 @@ export interface PostprocessCommand {
|
|
|
63
64
|
readonly type: 'POSTPROCESS';
|
|
64
65
|
readonly functionName: string_name;
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
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,...
|
|
70
|
+
*
|
|
71
|
+
* Note: LLMs work with tokens, not characters, but in Promptbooks we want to use some human-recognisable and cross-model interoperable units.
|
|
72
|
+
*/
|
|
73
|
+
export interface ExpectCommand {
|
|
74
|
+
readonly type: 'EXPECT';
|
|
75
|
+
readonly sign: 'EXACTLY' | 'MINIMUM' | 'MAXIMUM';
|
|
76
|
+
readonly unit: ExpectationUnit;
|
|
77
|
+
readonly amount: ExpectationAmount;
|
|
78
|
+
}
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { string_javascript, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
|
|
1
|
+
import { number_integer, number_positive_or_zero, string_javascript, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
|
|
2
2
|
import { ExecutionType } from '../ExecutionTypes';
|
|
3
3
|
import { ModelRequirements } from '../ModelRequirements';
|
|
4
4
|
import { ScriptLanguage } from '../ScriptLanguage';
|
|
@@ -9,14 +9,33 @@ export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | Scri
|
|
|
9
9
|
/**
|
|
10
10
|
* Template for prompt to LLM
|
|
11
11
|
*/
|
|
12
|
-
interface NaturalTemplateJson extends PromptTemplateJsonCommon {
|
|
12
|
+
export interface NaturalTemplateJson extends PromptTemplateJsonCommon {
|
|
13
13
|
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
|
+
}>>;
|
|
14
21
|
/**
|
|
15
22
|
* Requirements for the model
|
|
16
23
|
* - This is required only for executionType PROMPT_TEMPLATE
|
|
17
24
|
*/
|
|
18
25
|
readonly modelRequirements?: ModelRequirements;
|
|
19
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Units of text measurement
|
|
29
|
+
*/
|
|
30
|
+
export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "PARAGRAPHS", "LINES", "PAGES"];
|
|
31
|
+
/**
|
|
32
|
+
* Unit of text measurement
|
|
33
|
+
*/
|
|
34
|
+
export type ExpectationUnit = (typeof EXPECTATION_UNITS)[number];
|
|
35
|
+
/**
|
|
36
|
+
* Amount of text measurement
|
|
37
|
+
*/
|
|
38
|
+
export type ExpectationAmount = number_integer & number_positive_or_zero;
|
|
20
39
|
/**
|
|
21
40
|
* Template for simple concatenation of strings
|
|
22
41
|
*/
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { PromptResult } from '../../execution/PromptResult';
|
|
2
|
+
import type { Prompt } from '../Prompt';
|
|
3
|
+
import type { string_ptbk_url, string_version } from '../typeAliases';
|
|
4
|
+
/**
|
|
5
|
+
* ExecutionReport is result of executing one promptbook
|
|
6
|
+
* It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
|
|
7
|
+
*
|
|
8
|
+
* It can have 2 formats:
|
|
9
|
+
* - **.md file** created from the **JSON** format
|
|
10
|
+
* - _(this)_ **JSON** format
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/webgptorg/promptbook#execution-report
|
|
13
|
+
*/
|
|
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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExecutionReport is result of executing one promptbook
|
|
3
|
+
* It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
|
|
4
|
+
*
|
|
5
|
+
* It can have 2 formats:
|
|
6
|
+
* - _(this)_ **.md file** created from the **JSON** format
|
|
7
|
+
* - **JSON** format
|
|
8
|
+
*
|
|
9
|
+
* @see https://github.com/webgptorg/promptbook#execution-report
|
|
10
|
+
*/
|
|
11
|
+
export type ExecutionReportString = string & {
|
|
12
|
+
readonly _type: 'ExecutionReportString';
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* TODO: Better validation or remove branded type and make it just string
|
|
16
|
+
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExecutionReportJson } from './ExecutionReportJson';
|
|
2
|
+
import type { ExecutionReportString } from './ExecutionReportString';
|
|
3
|
+
/**
|
|
4
|
+
* Converts execution report from JSON to string format
|
|
5
|
+
*/
|
|
6
|
+
export declare function executionReportJsonToString(executionReportJson: ExecutionReportJson): ExecutionReportString;
|
|
@@ -406,6 +406,8 @@ export type string_ssh_key = string;
|
|
|
406
406
|
export type string_pgp_key = string;
|
|
407
407
|
export type number_positive = number;
|
|
408
408
|
export type number_negative = number;
|
|
409
|
+
export type number_positive_or_zero = number;
|
|
410
|
+
export type number_negative_or_zero = number;
|
|
409
411
|
export type number_integer = number;
|
|
410
412
|
/**
|
|
411
413
|
* Semantic helper;
|
|
@@ -429,7 +431,7 @@ export type number_days = number;
|
|
|
429
431
|
export type number_weeks = number;
|
|
430
432
|
export type number_months = number;
|
|
431
433
|
export type number_years = number;
|
|
432
|
-
export type number_bytes =
|
|
434
|
+
export type number_bytes = number_integer & number_positive;
|
|
433
435
|
export type number_kilobytes = number_positive;
|
|
434
436
|
export type number_megabytes = number_positive;
|
|
435
437
|
export type number_gigabytes = number_positive;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function parseNumber will parse number from string
|
|
3
|
+
*
|
|
4
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
5
|
+
* Note: it also works only with decimal numbers
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseNumber(value: string | number): number;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
10
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
|
3
|
+
*
|
|
4
|
+
* Note: This is usefull for post-processing of the result of the chat LLM model
|
|
5
|
+
* when the model wraps the result in the (markdown) code block.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare function trimCodeBlock(value: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
|
|
3
3
|
*
|
|
4
|
-
* This is usefull for post-processing of the result of the completion LLM model
|
|
4
|
+
* Note: This is usefull for post-processing of the result of the completion LLM model
|
|
5
|
+
* if you want to start code block in the prompt but you don't want to end it in the result.
|
|
5
6
|
*/
|
|
6
7
|
export declare function trimEndOfCodeBlock(value: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0-1.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.24.0-1.0"
|
|
41
41
|
},
|
|
42
42
|
"main": "./umd/index.umd.js",
|
|
43
43
|
"module": "./esm/index.es.js",
|
|
@@ -9,7 +9,7 @@ import { ExecutionType } from '../types/ExecutionTypes';
|
|
|
9
9
|
import { ModelRequirements, ModelVariant } from '../types/ModelRequirements';
|
|
10
10
|
import { Parameters } from '../types/Parameters';
|
|
11
11
|
import { Prompt } from '../types/Prompt';
|
|
12
|
-
import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
|
|
12
|
+
import { EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
|
|
13
13
|
import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
|
|
14
14
|
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
15
15
|
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
@@ -17,7 +17,7 @@ import { ScriptLanguage } from '../types/ScriptLanguage';
|
|
|
17
17
|
import { TaskProgress } from '../types/TaskProgress';
|
|
18
18
|
import { string_char_emoji } from '../types/typeAliasEmoji';
|
|
19
19
|
import { ILicense, IPersonProfile, IRepository, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml } from '../types/typeAliases';
|
|
20
|
-
export { CommonExecutionToolsOptions, ExecutionTools, ExecutionType, ILicense, IPersonProfile, IRepository, ModelRequirements, ModelVariant, NaturalExecutionTools, Parameters, Prompt, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, PromptTemplatePipelineJson, PromptTemplatePipelineString, PtpExecutor, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_char_emoji, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml, };
|
|
20
|
+
export { CommonExecutionToolsOptions, EXPECTATION_UNITS, ExecutionTools, ExecutionType, ExpectationAmount, ExpectationUnit, ILicense, IPersonProfile, IRepository, ModelRequirements, ModelVariant, NaturalExecutionTools, Parameters, Prompt, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, PromptTemplatePipelineJson, PromptTemplatePipelineString, PtpExecutor, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_char_emoji, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml, };
|
|
21
21
|
/**
|
|
22
22
|
* TODO: !!! Filter out all the types that are not used in the library
|
|
23
23
|
*/
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
1
2
|
import { EMOJIS, EMOJIS_IN_CATEGORIES } from '../utils/emojis';
|
|
3
|
+
import { CountUtils } from '../utils/expectation-counters';
|
|
4
|
+
import { countCharacters } from '../utils/expectation-counters/countCharacters';
|
|
5
|
+
import { countLines } from '../utils/expectation-counters/countLines';
|
|
6
|
+
import { countPages } from '../utils/expectation-counters/countPages';
|
|
7
|
+
import { countParagraphs } from '../utils/expectation-counters/countParagraphs';
|
|
8
|
+
import { countSentences } from '../utils/expectation-counters/countSentences';
|
|
9
|
+
import { countWords } from '../utils/expectation-counters/countWords';
|
|
2
10
|
import { isValidJsonString } from '../utils/isValidJsonString';
|
|
3
11
|
import { extractAllBlocksFromMarkdown } from '../utils/markdown/extractAllBlocksFromMarkdown';
|
|
4
12
|
import { extractAllListItemsFromMarkdown } from '../utils/markdown/extractAllListItemsFromMarkdown';
|
|
5
13
|
import { extractOneBlockFromMarkdown } from '../utils/markdown/extractOneBlockFromMarkdown';
|
|
6
14
|
import { removeContentComments } from '../utils/markdown/removeContentComments';
|
|
7
15
|
import { removeMarkdownFormatting } from '../utils/markdown/removeMarkdownFormatting';
|
|
16
|
+
import { parseNumber } from '../utils/parseNumber';
|
|
8
17
|
import { removeEmojis } from '../utils/removeEmojis';
|
|
9
18
|
import { removeQuotes } from '../utils/removeQuotes';
|
|
10
19
|
import { replaceParameters } from '../utils/replaceParameters';
|
|
20
|
+
import { trimCodeBlock } from '../utils/trimCodeBlock';
|
|
11
21
|
import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
|
|
12
22
|
import { unwrapResult } from '../utils/unwrapResult';
|
|
13
|
-
export { EMOJIS, EMOJIS_IN_CATEGORIES, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractOneBlockFromMarkdown, isValidJsonString, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, trimEndOfCodeBlock, unwrapResult, };
|
|
23
|
+
export { CountUtils, EMOJIS, EMOJIS_IN_CATEGORIES, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, executionReportJsonToString, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractOneBlockFromMarkdown, isValidJsonString, parseNumber, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
|
|
@@ -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
|
|
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
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { string_markdown_text } from '.././types/typeAliases';
|
|
2
|
-
import { Command } from '../types/Command';
|
|
1
|
+
import type { string_markdown_text } from '.././types/typeAliases';
|
|
2
|
+
import type { Command } from '../types/Command';
|
|
3
3
|
/**
|
|
4
4
|
* Parses one line of ul/ol to command
|
|
5
5
|
*/
|
|
@@ -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<
|
|
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,12 @@
|
|
|
1
|
-
import { string_markdown_text, string_name, string_version } from '.././types/typeAliases';
|
|
2
|
-
import { ExecutionType } from './ExecutionTypes';
|
|
3
|
-
import { ModelRequirements } from './ModelRequirements';
|
|
1
|
+
import type { string_markdown_text, string_name, string_version } from '.././types/typeAliases';
|
|
2
|
+
import type { ExecutionType } from './ExecutionTypes';
|
|
3
|
+
import type { ModelRequirements } from './ModelRequirements';
|
|
4
|
+
import type { ExpectationAmount, ExpectationUnit } from './PromptTemplatePipelineJson/PromptTemplateJson';
|
|
4
5
|
/**
|
|
5
6
|
* Command is one piece of the prompt template which adds some logic to the prompt template or the whole pipeline.
|
|
6
7
|
* It is parsed from the markdown from ul/ol items - one command per one item.
|
|
7
8
|
*/
|
|
8
|
-
export type Command = PtbkUrlCommand | PtbkVersionCommand | ExecuteCommand | ModelCommand | ParameterCommand | PostprocessCommand;
|
|
9
|
+
export type Command = PtbkUrlCommand | PtbkVersionCommand | ExecuteCommand | ModelCommand | ParameterCommand | PostprocessCommand | ExpectCommand;
|
|
9
10
|
/**
|
|
10
11
|
* PtpVersion command tells which version is .ptp file using
|
|
11
12
|
*
|
|
@@ -63,3 +64,15 @@ export interface PostprocessCommand {
|
|
|
63
64
|
readonly type: 'POSTPROCESS';
|
|
64
65
|
readonly functionName: string_name;
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
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,...
|
|
70
|
+
*
|
|
71
|
+
* Note: LLMs work with tokens, not characters, but in Promptbooks we want to use some human-recognisable and cross-model interoperable units.
|
|
72
|
+
*/
|
|
73
|
+
export interface ExpectCommand {
|
|
74
|
+
readonly type: 'EXPECT';
|
|
75
|
+
readonly sign: 'EXACTLY' | 'MINIMUM' | 'MAXIMUM';
|
|
76
|
+
readonly unit: ExpectationUnit;
|
|
77
|
+
readonly amount: ExpectationAmount;
|
|
78
|
+
}
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { string_javascript, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
|
|
1
|
+
import { number_integer, number_positive_or_zero, string_javascript, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
|
|
2
2
|
import { ExecutionType } from '../ExecutionTypes';
|
|
3
3
|
import { ModelRequirements } from '../ModelRequirements';
|
|
4
4
|
import { ScriptLanguage } from '../ScriptLanguage';
|
|
@@ -9,14 +9,33 @@ export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | Scri
|
|
|
9
9
|
/**
|
|
10
10
|
* Template for prompt to LLM
|
|
11
11
|
*/
|
|
12
|
-
interface NaturalTemplateJson extends PromptTemplateJsonCommon {
|
|
12
|
+
export interface NaturalTemplateJson extends PromptTemplateJsonCommon {
|
|
13
13
|
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
|
+
}>>;
|
|
14
21
|
/**
|
|
15
22
|
* Requirements for the model
|
|
16
23
|
* - This is required only for executionType PROMPT_TEMPLATE
|
|
17
24
|
*/
|
|
18
25
|
readonly modelRequirements?: ModelRequirements;
|
|
19
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Units of text measurement
|
|
29
|
+
*/
|
|
30
|
+
export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "PARAGRAPHS", "LINES", "PAGES"];
|
|
31
|
+
/**
|
|
32
|
+
* Unit of text measurement
|
|
33
|
+
*/
|
|
34
|
+
export type ExpectationUnit = (typeof EXPECTATION_UNITS)[number];
|
|
35
|
+
/**
|
|
36
|
+
* Amount of text measurement
|
|
37
|
+
*/
|
|
38
|
+
export type ExpectationAmount = number_integer & number_positive_or_zero;
|
|
20
39
|
/**
|
|
21
40
|
* Template for simple concatenation of strings
|
|
22
41
|
*/
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { PromptResult } from '../../execution/PromptResult';
|
|
2
|
+
import type { Prompt } from '../Prompt';
|
|
3
|
+
import type { string_ptbk_url, string_version } from '../typeAliases';
|
|
4
|
+
/**
|
|
5
|
+
* ExecutionReport is result of executing one promptbook
|
|
6
|
+
* It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
|
|
7
|
+
*
|
|
8
|
+
* It can have 2 formats:
|
|
9
|
+
* - **.md file** created from the **JSON** format
|
|
10
|
+
* - _(this)_ **JSON** format
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/webgptorg/promptbook#execution-report
|
|
13
|
+
*/
|
|
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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExecutionReport is result of executing one promptbook
|
|
3
|
+
* It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
|
|
4
|
+
*
|
|
5
|
+
* It can have 2 formats:
|
|
6
|
+
* - _(this)_ **.md file** created from the **JSON** format
|
|
7
|
+
* - **JSON** format
|
|
8
|
+
*
|
|
9
|
+
* @see https://github.com/webgptorg/promptbook#execution-report
|
|
10
|
+
*/
|
|
11
|
+
export type ExecutionReportString = string & {
|
|
12
|
+
readonly _type: 'ExecutionReportString';
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* TODO: Better validation or remove branded type and make it just string
|
|
16
|
+
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExecutionReportJson } from './ExecutionReportJson';
|
|
2
|
+
import type { ExecutionReportString } from './ExecutionReportString';
|
|
3
|
+
/**
|
|
4
|
+
* Converts execution report from JSON to string format
|
|
5
|
+
*/
|
|
6
|
+
export declare function executionReportJsonToString(executionReportJson: ExecutionReportJson): ExecutionReportString;
|
|
@@ -406,6 +406,8 @@ export type string_ssh_key = string;
|
|
|
406
406
|
export type string_pgp_key = string;
|
|
407
407
|
export type number_positive = number;
|
|
408
408
|
export type number_negative = number;
|
|
409
|
+
export type number_positive_or_zero = number;
|
|
410
|
+
export type number_negative_or_zero = number;
|
|
409
411
|
export type number_integer = number;
|
|
410
412
|
/**
|
|
411
413
|
* Semantic helper;
|
|
@@ -429,7 +431,7 @@ export type number_days = number;
|
|
|
429
431
|
export type number_weeks = number;
|
|
430
432
|
export type number_months = number;
|
|
431
433
|
export type number_years = number;
|
|
432
|
-
export type number_bytes =
|
|
434
|
+
export type number_bytes = number_integer & number_positive;
|
|
433
435
|
export type number_kilobytes = number_positive;
|
|
434
436
|
export type number_megabytes = number_positive;
|
|
435
437
|
export type number_gigabytes = number_positive;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function parseNumber will parse number from string
|
|
3
|
+
*
|
|
4
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
5
|
+
* Note: it also works only with decimal numbers
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseNumber(value: string | number): number;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
10
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
|
3
|
+
*
|
|
4
|
+
* Note: This is usefull for post-processing of the result of the chat LLM model
|
|
5
|
+
* when the model wraps the result in the (markdown) code block.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare function trimCodeBlock(value: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
|
|
3
3
|
*
|
|
4
|
-
* This is usefull for post-processing of the result of the completion LLM model
|
|
4
|
+
* Note: This is usefull for post-processing of the result of the completion LLM model
|
|
5
|
+
* if you want to start code block in the prompt but you don't want to end it in the result.
|
|
5
6
|
*/
|
|
6
7
|
export declare function trimEndOfCodeBlock(value: string): string;
|