@promptbook/openai 0.23.1 → 0.24.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/esm/typings/_packages/types.index.d.ts +2 -2
  2. package/esm/typings/_packages/utils.index.d.ts +11 -1
  3. package/esm/typings/conversion/parseCommand.d.ts +2 -2
  4. package/esm/typings/execution/PromptResult.d.ts +1 -1
  5. package/esm/typings/types/Command.d.ts +17 -4
  6. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
  7. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +19 -0
  8. package/esm/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  9. package/esm/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
  10. package/esm/typings/types/typeAliases.d.ts +3 -1
  11. package/esm/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  12. package/esm/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  13. package/esm/typings/utils/expectation-counters/countLines.d.ts +5 -0
  14. package/esm/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  15. package/esm/typings/utils/expectation-counters/countPages.d.ts +5 -0
  16. package/esm/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  17. package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  18. package/esm/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  19. package/esm/typings/utils/expectation-counters/countSentences.d.ts +5 -0
  20. package/esm/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  21. package/esm/typings/utils/expectation-counters/countWords.d.ts +5 -0
  22. package/esm/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  23. package/esm/typings/utils/expectation-counters/index.d.ts +5 -0
  24. package/esm/typings/utils/parseNumber.d.ts +10 -0
  25. package/esm/typings/utils/parseNumber.test.d.ts +1 -0
  26. package/esm/typings/utils/trimCodeBlock.d.ts +8 -0
  27. package/esm/typings/utils/trimCodeBlock.test.d.ts +1 -0
  28. package/esm/typings/utils/trimEndOfCodeBlock.d.ts +2 -1
  29. package/package.json +2 -2
  30. package/umd/typings/_packages/types.index.d.ts +2 -2
  31. package/umd/typings/_packages/utils.index.d.ts +11 -1
  32. package/umd/typings/conversion/parseCommand.d.ts +2 -2
  33. package/umd/typings/execution/PromptResult.d.ts +1 -1
  34. package/umd/typings/types/Command.d.ts +17 -4
  35. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
  36. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +19 -0
  37. package/umd/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  38. package/umd/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
  39. package/umd/typings/types/typeAliases.d.ts +3 -1
  40. package/umd/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  41. package/umd/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  42. package/umd/typings/utils/expectation-counters/countLines.d.ts +5 -0
  43. package/umd/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  44. package/umd/typings/utils/expectation-counters/countPages.d.ts +5 -0
  45. package/umd/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  46. package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  47. package/umd/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  48. package/umd/typings/utils/expectation-counters/countSentences.d.ts +5 -0
  49. package/umd/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  50. package/umd/typings/utils/expectation-counters/countWords.d.ts +5 -0
  51. package/umd/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  52. package/umd/typings/utils/expectation-counters/index.d.ts +5 -0
  53. package/umd/typings/utils/parseNumber.d.ts +10 -0
  54. package/umd/typings/utils/parseNumber.test.d.ts +1 -0
  55. package/umd/typings/utils/trimCodeBlock.d.ts +8 -0
  56. package/umd/typings/utils/trimCodeBlock.test.d.ts +1 -0
  57. 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,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,4 +1,4 @@
1
- import { string_model_name } from '.././types/typeAliases';
1
+ import type { string_model_name } from '.././types/typeAliases';
2
2
  /**
3
3
  * Prompt result is the simplest concept of execution.
4
4
  * It is the result of executing one prompt _(NOT a template)_.
@@ -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,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,19 @@
1
+ import type { PromptResult } from '../../execution/PromptResult';
2
+ import { Prompt } from '../Prompt';
3
+ /**
4
+ * ExecutionReport is result of executing one promptbook
5
+ * It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
6
+ *
7
+ * It can have 2 formats:
8
+ * - **.md file** created from the **JSON** format
9
+ * - _(this)_ **JSON** format
10
+ *
11
+ * @see https://github.com/webgptorg/promptbook#execution-report
12
+ */
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
+ */
@@ -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 = number_positive & number_integer;
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,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of characters in the text
4
+ */
5
+ export declare function countCharacters(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of lines in the text
4
+ */
5
+ export declare function countLines(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of pages in the text
4
+ */
5
+ export declare function countPages(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of paragraphs in the text
4
+ */
5
+ export declare function countParagraphs(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of sentences in the text
4
+ */
5
+ export declare function countSentences(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of words in the text
4
+ */
5
+ export declare function countWords(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount, ExpectationUnit } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Index of all counter functions
4
+ */
5
+ export declare const CountUtils: Record<ExpectationUnit, (text: string) => ExpectationAmount>;
@@ -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 if you want to start code block in the prompt but you don't want to end it in the result.
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.23.1",
3
+ "version": "0.24.0-0",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -37,7 +37,7 @@
37
37
  "openai": "4.2.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "@promptbook/core": "0.23.1"
40
+ "@promptbook/core": "0.24.0-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,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,4 +1,4 @@
1
- import { string_model_name } from '.././types/typeAliases';
1
+ import type { string_model_name } from '.././types/typeAliases';
2
2
  /**
3
3
  * Prompt result is the simplest concept of execution.
4
4
  * It is the result of executing one prompt _(NOT a template)_.
@@ -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,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,19 @@
1
+ import type { PromptResult } from '../../execution/PromptResult';
2
+ import { Prompt } from '../Prompt';
3
+ /**
4
+ * ExecutionReport is result of executing one promptbook
5
+ * It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
6
+ *
7
+ * It can have 2 formats:
8
+ * - **.md file** created from the **JSON** format
9
+ * - _(this)_ **JSON** format
10
+ *
11
+ * @see https://github.com/webgptorg/promptbook#execution-report
12
+ */
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
+ */
@@ -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 = number_positive & number_integer;
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,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of characters in the text
4
+ */
5
+ export declare function countCharacters(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of lines in the text
4
+ */
5
+ export declare function countLines(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of pages in the text
4
+ */
5
+ export declare function countPages(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of paragraphs in the text
4
+ */
5
+ export declare function countParagraphs(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of sentences in the text
4
+ */
5
+ export declare function countSentences(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Counts number of words in the text
4
+ */
5
+ export declare function countWords(text: string): ExpectationAmount;
@@ -0,0 +1,5 @@
1
+ import type { ExpectationAmount, ExpectationUnit } from '../../types/PromptTemplatePipelineJson/PromptTemplateJson';
2
+ /**
3
+ * Index of all counter functions
4
+ */
5
+ export declare const CountUtils: Record<ExpectationUnit, (text: string) => ExpectationAmount>;
@@ -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 if you want to start code block in the prompt but you don't want to end it in the result.
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;