@promptbook/openai 0.50.0-14 → 0.50.0-16

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 (25) hide show
  1. package/esm/typings/_packages/execute-javascript.index.d.ts +44 -1
  2. package/esm/typings/_packages/utils.index.d.ts +9 -2
  3. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
  4. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
  5. package/esm/typings/conversion/utils/extractVariables.d.ts +4 -3
  6. package/esm/typings/utils/extractParameters.d.ts +1 -3
  7. package/esm/typings/utils/sets/difference.d.ts +4 -0
  8. package/esm/typings/utils/sets/difference.test.d.ts +1 -0
  9. package/esm/typings/utils/sets/intersection.d.ts +4 -0
  10. package/esm/typings/utils/sets/intersection.test.d.ts +1 -0
  11. package/esm/typings/utils/sets/union.d.ts +4 -0
  12. package/esm/typings/utils/sets/union.test.d.ts +1 -0
  13. package/package.json +2 -2
  14. package/umd/typings/_packages/execute-javascript.index.d.ts +44 -1
  15. package/umd/typings/_packages/utils.index.d.ts +9 -2
  16. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
  17. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
  18. package/umd/typings/conversion/utils/extractVariables.d.ts +4 -3
  19. package/umd/typings/utils/extractParameters.d.ts +1 -3
  20. package/umd/typings/utils/sets/difference.d.ts +4 -0
  21. package/umd/typings/utils/sets/difference.test.d.ts +1 -0
  22. package/umd/typings/utils/sets/intersection.d.ts +4 -0
  23. package/umd/typings/utils/sets/intersection.test.d.ts +1 -0
  24. package/umd/typings/utils/sets/union.d.ts +4 -0
  25. package/umd/typings/utils/sets/union.test.d.ts +1 -0
@@ -1,3 +1,46 @@
1
+ import spaceTrim from 'spacetrim';
1
2
  import { JavascriptEvalExecutionTools } from '../execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools';
2
3
  import { JavascriptExecutionTools } from '../execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools';
3
- export { JavascriptEvalExecutionTools, JavascriptExecutionTools };
4
+ import { prettifyMarkdown } from '../utils/markdown/prettifyMarkdown';
5
+ import { capitalize } from '../utils/normalization/capitalize';
6
+ import { decapitalize } from '../utils/normalization/decapitalize';
7
+ import { nameToUriPart } from '../utils/normalization/nameToUriPart';
8
+ import { nameToUriParts } from '../utils/normalization/nameToUriParts';
9
+ import { normalizeToKebabCase } from '../utils/normalization/normalize-to-kebab-case';
10
+ import { normalizeTo_PascalCase } from '../utils/normalization/normalizeTo_PascalCase';
11
+ import { normalizeTo_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
12
+ import { normalizeTo_camelCase } from '../utils/normalization/normalizeTo_camelCase';
13
+ import { normalizeTo_snake_case } from '../utils/normalization/normalizeTo_snake_case';
14
+ import { normalizeWhitespaces } from '../utils/normalization/normalizeWhitespaces';
15
+ import { removeDiacritics } from '../utils/normalization/removeDiacritics';
16
+ import { extractBlock } from '../utils/postprocessing/extractBlock';
17
+ import { removeEmojis } from '../utils/removeEmojis';
18
+ import { removeQuotes } from '../utils/removeQuotes';
19
+ import { trimCodeBlock } from '../utils/trimCodeBlock';
20
+ import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
21
+ import { unwrapResult } from '../utils/unwrapResult';
22
+ declare const POSTPROCESSING_FUNCTIONS: {
23
+ spaceTrim: typeof spaceTrim;
24
+ removeQuotes: typeof removeQuotes;
25
+ unwrapResult: typeof unwrapResult;
26
+ trimEndOfCodeBlock: typeof trimEndOfCodeBlock;
27
+ trimCodeBlock: typeof trimCodeBlock;
28
+ trim: (str: string) => string;
29
+ reverse: (str: string) => string;
30
+ removeEmojis: typeof removeEmojis;
31
+ prettifyMarkdown: typeof prettifyMarkdown;
32
+ capitalize: typeof capitalize;
33
+ decapitalize: typeof decapitalize;
34
+ nameToUriPart: typeof nameToUriPart;
35
+ nameToUriParts: typeof nameToUriParts;
36
+ removeDiacritics: typeof removeDiacritics;
37
+ normalizeWhitespaces: typeof normalizeWhitespaces;
38
+ normalizeToKebabCase: typeof normalizeToKebabCase;
39
+ normalizeTo_camelCase: typeof normalizeTo_camelCase;
40
+ normalizeTo_snake_case: typeof normalizeTo_snake_case;
41
+ normalizeTo_PascalCase: typeof normalizeTo_PascalCase;
42
+ parseKeywords: (input: string) => string;
43
+ normalizeTo_SCREAMING_CASE: typeof normalizeTo_SCREAMING_CASE;
44
+ extractBlock: typeof extractBlock;
45
+ };
46
+ export { JavascriptEvalExecutionTools, JavascriptExecutionTools, POSTPROCESSING_FUNCTIONS };
@@ -1,6 +1,8 @@
1
1
  import { spaceTrim } from 'spacetrim';
2
2
  import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
3
3
  import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid';
4
+ import { extractParametersFromPromptTemplate } from '../conversion/utils/extractParametersFromPromptTemplate';
5
+ import { extractVariables } from '../conversion/utils/extractVariables';
4
6
  import { parseNumber } from '../conversion/utils/parseNumber';
5
7
  import { renameParameter } from '../conversion/utils/renameParameter';
6
8
  import { titleToName } from '../conversion/utils/titleToName';
@@ -16,6 +18,7 @@ import { countPages } from '../utils/expectation-counters/countPages';
16
18
  import { countParagraphs } from '../utils/expectation-counters/countParagraphs';
17
19
  import { countSentences, splitIntoSentences } from '../utils/expectation-counters/countSentences';
18
20
  import { countWords } from '../utils/expectation-counters/countWords';
21
+ import { extractParameters } from '../utils/extractParameters';
19
22
  import { isValidJsonString } from '../utils/isValidJsonString';
20
23
  import { extractAllBlocksFromMarkdown } from '../utils/markdown/extractAllBlocksFromMarkdown';
21
24
  import { extractAllListItemsFromMarkdown } from '../utils/markdown/extractAllListItemsFromMarkdown';
@@ -42,12 +45,15 @@ import { searchKeywords } from '../utils/normalization/searchKeywords';
42
45
  import { extractBlock } from '../utils/postprocessing/extractBlock';
43
46
  import { removeEmojis } from '../utils/removeEmojis';
44
47
  import { removeQuotes } from '../utils/removeQuotes';
48
+ import { difference } from '../utils/sets/difference';
49
+ import { intersection } from '../utils/sets/intersection';
50
+ import { union } from '../utils/sets/union';
45
51
  import { trimCodeBlock } from '../utils/trimCodeBlock';
46
52
  import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
47
53
  import { unwrapResult } from '../utils/unwrapResult';
48
54
  export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, extractAllBlocksFromMarkdown, // <- [🌻]
49
55
  extractAllListItemsFromMarkdown, extractBlock, // <- [🌻]
50
- extractOneBlockFromMarkdown, isPassingExpectations, isValidJsonString, parseNumber, // <- [🌻]
56
+ extractOneBlockFromMarkdown, extractParameters, extractVariables, isPassingExpectations, isValidJsonString, parseNumber, // <- [🌻]
51
57
  prettifyPromptbookString, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, spaceTrim, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
52
58
  export { countCharacters, countLines, countPages, countParagraphs, countSentences, CountUtils, countWords };
53
59
  export { splitIntoSentences };
@@ -59,7 +65,8 @@ export declare const normalizeTo: {
59
65
  'kebab-case': typeof normalizeToKebabCase;
60
66
  };
61
67
  export { capitalize, decapitalize, DIACRITIC_VARIANTS_LETTERS, IKeywords, isValidKeyword, nameToUriPart, nameToUriParts, normalizeTo_camelCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_snake_case, normalizeToKebabCase, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, removeDiacritics, searchKeywords, string_keyword, titleToName, };
62
- export { renameParameter, renderPromptbookMermaid };
68
+ export { extractParametersFromPromptTemplate, renameParameter, renderPromptbookMermaid };
69
+ export { difference, intersection, union };
63
70
  /**
64
71
  * TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
65
72
  * Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
@@ -0,0 +1,13 @@
1
+ import { PromptTemplateJson } from '../../types/PromptbookJson/PromptTemplateJson';
2
+ import { string_name } from '../../types/typeAliases';
3
+ /**
4
+ * Parses the prompt template and returns the set of all used parameters
5
+ *
6
+ * @param promptTemplate the template with used parameters
7
+ * @returns the set of parameter names
8
+ * @throws {PromptbookSyntaxError} if the script is invalid
9
+ */
10
+ export declare function extractParametersFromPromptTemplate(promptTemplate: Pick<PromptTemplateJson, 'title' | 'description' | 'executionType' | 'content'>): Set<string_name>;
11
+ /**
12
+ * TODO: [🔣] If script require contentLanguage
13
+ */
@@ -5,7 +5,8 @@ import { string_javascript, string_javascript_name } from '../../types/typeAlias
5
5
  * @param script from which to extract the variables
6
6
  * @returns the list of variable names
7
7
  * @throws {PromptbookSyntaxError} if the script is invalid
8
- *
9
- * @private within the promptbookStringToJson
10
8
  */
11
- export declare function extractVariables(script: string_javascript): Array<string_javascript_name>;
9
+ export declare function extractVariables(script: string_javascript): Set<string_javascript_name>;
10
+ /**
11
+ * TODO: [🔣] Support for multiple languages - python, java,...
12
+ */
@@ -4,7 +4,5 @@ import { string_name, string_template } from '../types/typeAliases';
4
4
  *
5
5
  * @param template the template with parameters in {curly} braces
6
6
  * @returns the list of parameter names
7
- *
8
- * @private within the library
9
7
  */
10
- export declare function extractParameters(template: string_template): Array<string_name>;
8
+ export declare function extractParameters(template: string_template): Set<string_name>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Create difference set of two sets.
3
+ */
4
+ export declare function difference<TItem>(a: Set<TItem>, b: Set<TItem>, isEqual?: (a: TItem, b: TItem) => boolean): Set<TItem>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Creates a new set with all elements that are present in all sets
3
+ */
4
+ export declare function intersection<TItem>(...sets: Array<Set<TItem>>): Set<TItem>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Creates a new set with all elements that are present in either set
3
+ */
4
+ export declare function union<TItem>(...sets: Array<Set<TItem>>): Set<TItem>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.50.0-14",
3
+ "version": "0.50.0-16",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -48,7 +48,7 @@
48
48
  }
49
49
  ],
50
50
  "peerDependencies": {
51
- "@promptbook/core": "0.50.0-14"
51
+ "@promptbook/core": "0.50.0-16"
52
52
  },
53
53
  "main": "./umd/index.umd.js",
54
54
  "module": "./esm/index.es.js",
@@ -1,3 +1,46 @@
1
+ import spaceTrim from 'spacetrim';
1
2
  import { JavascriptEvalExecutionTools } from '../execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools';
2
3
  import { JavascriptExecutionTools } from '../execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools';
3
- export { JavascriptEvalExecutionTools, JavascriptExecutionTools };
4
+ import { prettifyMarkdown } from '../utils/markdown/prettifyMarkdown';
5
+ import { capitalize } from '../utils/normalization/capitalize';
6
+ import { decapitalize } from '../utils/normalization/decapitalize';
7
+ import { nameToUriPart } from '../utils/normalization/nameToUriPart';
8
+ import { nameToUriParts } from '../utils/normalization/nameToUriParts';
9
+ import { normalizeToKebabCase } from '../utils/normalization/normalize-to-kebab-case';
10
+ import { normalizeTo_PascalCase } from '../utils/normalization/normalizeTo_PascalCase';
11
+ import { normalizeTo_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
12
+ import { normalizeTo_camelCase } from '../utils/normalization/normalizeTo_camelCase';
13
+ import { normalizeTo_snake_case } from '../utils/normalization/normalizeTo_snake_case';
14
+ import { normalizeWhitespaces } from '../utils/normalization/normalizeWhitespaces';
15
+ import { removeDiacritics } from '../utils/normalization/removeDiacritics';
16
+ import { extractBlock } from '../utils/postprocessing/extractBlock';
17
+ import { removeEmojis } from '../utils/removeEmojis';
18
+ import { removeQuotes } from '../utils/removeQuotes';
19
+ import { trimCodeBlock } from '../utils/trimCodeBlock';
20
+ import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
21
+ import { unwrapResult } from '../utils/unwrapResult';
22
+ declare const POSTPROCESSING_FUNCTIONS: {
23
+ spaceTrim: typeof spaceTrim;
24
+ removeQuotes: typeof removeQuotes;
25
+ unwrapResult: typeof unwrapResult;
26
+ trimEndOfCodeBlock: typeof trimEndOfCodeBlock;
27
+ trimCodeBlock: typeof trimCodeBlock;
28
+ trim: (str: string) => string;
29
+ reverse: (str: string) => string;
30
+ removeEmojis: typeof removeEmojis;
31
+ prettifyMarkdown: typeof prettifyMarkdown;
32
+ capitalize: typeof capitalize;
33
+ decapitalize: typeof decapitalize;
34
+ nameToUriPart: typeof nameToUriPart;
35
+ nameToUriParts: typeof nameToUriParts;
36
+ removeDiacritics: typeof removeDiacritics;
37
+ normalizeWhitespaces: typeof normalizeWhitespaces;
38
+ normalizeToKebabCase: typeof normalizeToKebabCase;
39
+ normalizeTo_camelCase: typeof normalizeTo_camelCase;
40
+ normalizeTo_snake_case: typeof normalizeTo_snake_case;
41
+ normalizeTo_PascalCase: typeof normalizeTo_PascalCase;
42
+ parseKeywords: (input: string) => string;
43
+ normalizeTo_SCREAMING_CASE: typeof normalizeTo_SCREAMING_CASE;
44
+ extractBlock: typeof extractBlock;
45
+ };
46
+ export { JavascriptEvalExecutionTools, JavascriptExecutionTools, POSTPROCESSING_FUNCTIONS };
@@ -1,6 +1,8 @@
1
1
  import { spaceTrim } from 'spacetrim';
2
2
  import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
3
3
  import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid';
4
+ import { extractParametersFromPromptTemplate } from '../conversion/utils/extractParametersFromPromptTemplate';
5
+ import { extractVariables } from '../conversion/utils/extractVariables';
4
6
  import { parseNumber } from '../conversion/utils/parseNumber';
5
7
  import { renameParameter } from '../conversion/utils/renameParameter';
6
8
  import { titleToName } from '../conversion/utils/titleToName';
@@ -16,6 +18,7 @@ import { countPages } from '../utils/expectation-counters/countPages';
16
18
  import { countParagraphs } from '../utils/expectation-counters/countParagraphs';
17
19
  import { countSentences, splitIntoSentences } from '../utils/expectation-counters/countSentences';
18
20
  import { countWords } from '../utils/expectation-counters/countWords';
21
+ import { extractParameters } from '../utils/extractParameters';
19
22
  import { isValidJsonString } from '../utils/isValidJsonString';
20
23
  import { extractAllBlocksFromMarkdown } from '../utils/markdown/extractAllBlocksFromMarkdown';
21
24
  import { extractAllListItemsFromMarkdown } from '../utils/markdown/extractAllListItemsFromMarkdown';
@@ -42,12 +45,15 @@ import { searchKeywords } from '../utils/normalization/searchKeywords';
42
45
  import { extractBlock } from '../utils/postprocessing/extractBlock';
43
46
  import { removeEmojis } from '../utils/removeEmojis';
44
47
  import { removeQuotes } from '../utils/removeQuotes';
48
+ import { difference } from '../utils/sets/difference';
49
+ import { intersection } from '../utils/sets/intersection';
50
+ import { union } from '../utils/sets/union';
45
51
  import { trimCodeBlock } from '../utils/trimCodeBlock';
46
52
  import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
47
53
  import { unwrapResult } from '../utils/unwrapResult';
48
54
  export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, extractAllBlocksFromMarkdown, // <- [🌻]
49
55
  extractAllListItemsFromMarkdown, extractBlock, // <- [🌻]
50
- extractOneBlockFromMarkdown, isPassingExpectations, isValidJsonString, parseNumber, // <- [🌻]
56
+ extractOneBlockFromMarkdown, extractParameters, extractVariables, isPassingExpectations, isValidJsonString, parseNumber, // <- [🌻]
51
57
  prettifyPromptbookString, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, spaceTrim, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
52
58
  export { countCharacters, countLines, countPages, countParagraphs, countSentences, CountUtils, countWords };
53
59
  export { splitIntoSentences };
@@ -59,7 +65,8 @@ export declare const normalizeTo: {
59
65
  'kebab-case': typeof normalizeToKebabCase;
60
66
  };
61
67
  export { capitalize, decapitalize, DIACRITIC_VARIANTS_LETTERS, IKeywords, isValidKeyword, nameToUriPart, nameToUriParts, normalizeTo_camelCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_snake_case, normalizeToKebabCase, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, removeDiacritics, searchKeywords, string_keyword, titleToName, };
62
- export { renameParameter, renderPromptbookMermaid };
68
+ export { extractParametersFromPromptTemplate, renameParameter, renderPromptbookMermaid };
69
+ export { difference, intersection, union };
63
70
  /**
64
71
  * TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
65
72
  * Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
@@ -0,0 +1,13 @@
1
+ import { PromptTemplateJson } from '../../types/PromptbookJson/PromptTemplateJson';
2
+ import { string_name } from '../../types/typeAliases';
3
+ /**
4
+ * Parses the prompt template and returns the set of all used parameters
5
+ *
6
+ * @param promptTemplate the template with used parameters
7
+ * @returns the set of parameter names
8
+ * @throws {PromptbookSyntaxError} if the script is invalid
9
+ */
10
+ export declare function extractParametersFromPromptTemplate(promptTemplate: Pick<PromptTemplateJson, 'title' | 'description' | 'executionType' | 'content'>): Set<string_name>;
11
+ /**
12
+ * TODO: [🔣] If script require contentLanguage
13
+ */
@@ -5,7 +5,8 @@ import { string_javascript, string_javascript_name } from '../../types/typeAlias
5
5
  * @param script from which to extract the variables
6
6
  * @returns the list of variable names
7
7
  * @throws {PromptbookSyntaxError} if the script is invalid
8
- *
9
- * @private within the promptbookStringToJson
10
8
  */
11
- export declare function extractVariables(script: string_javascript): Array<string_javascript_name>;
9
+ export declare function extractVariables(script: string_javascript): Set<string_javascript_name>;
10
+ /**
11
+ * TODO: [🔣] Support for multiple languages - python, java,...
12
+ */
@@ -4,7 +4,5 @@ import { string_name, string_template } from '../types/typeAliases';
4
4
  *
5
5
  * @param template the template with parameters in {curly} braces
6
6
  * @returns the list of parameter names
7
- *
8
- * @private within the library
9
7
  */
10
- export declare function extractParameters(template: string_template): Array<string_name>;
8
+ export declare function extractParameters(template: string_template): Set<string_name>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Create difference set of two sets.
3
+ */
4
+ export declare function difference<TItem>(a: Set<TItem>, b: Set<TItem>, isEqual?: (a: TItem, b: TItem) => boolean): Set<TItem>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Creates a new set with all elements that are present in all sets
3
+ */
4
+ export declare function intersection<TItem>(...sets: Array<Set<TItem>>): Set<TItem>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Creates a new set with all elements that are present in either set
3
+ */
4
+ export declare function union<TItem>(...sets: Array<Set<TItem>>): Set<TItem>;
@@ -0,0 +1 @@
1
+ export {};