@promptbook/remote-server 0.50.0 → 0.51.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 (43) hide show
  1. package/esm/index.es.js +1 -1
  2. package/esm/typings/_packages/execute-javascript.index.d.ts +44 -1
  3. package/esm/typings/_packages/openai.index.d.ts +2 -1
  4. package/esm/typings/_packages/types.index.d.ts +3 -2
  5. package/esm/typings/_packages/utils.index.d.ts +9 -2
  6. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
  7. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
  8. package/esm/typings/conversion/utils/extractVariables.d.ts +4 -3
  9. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +0 -3
  10. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +13 -0
  11. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
  12. package/esm/typings/execution/plugins/llm-execution-tools/openai/models.d.ts +25 -0
  13. package/esm/typings/types/ModelRequirements.d.ts +1 -0
  14. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -1
  15. package/esm/typings/utils/extractParameters.d.ts +1 -3
  16. package/esm/typings/utils/sets/difference.d.ts +4 -0
  17. package/esm/typings/utils/sets/difference.test.d.ts +1 -0
  18. package/esm/typings/utils/sets/intersection.d.ts +4 -0
  19. package/esm/typings/utils/sets/intersection.test.d.ts +1 -0
  20. package/esm/typings/utils/sets/union.d.ts +4 -0
  21. package/esm/typings/utils/sets/union.test.d.ts +1 -0
  22. package/package.json +3 -3
  23. package/umd/index.umd.js +1 -1
  24. package/umd/typings/_packages/execute-javascript.index.d.ts +44 -1
  25. package/umd/typings/_packages/openai.index.d.ts +2 -1
  26. package/umd/typings/_packages/types.index.d.ts +3 -2
  27. package/umd/typings/_packages/utils.index.d.ts +9 -2
  28. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
  29. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
  30. package/umd/typings/conversion/utils/extractVariables.d.ts +4 -3
  31. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +0 -3
  32. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +13 -0
  33. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
  34. package/umd/typings/execution/plugins/llm-execution-tools/openai/models.d.ts +25 -0
  35. package/umd/typings/types/ModelRequirements.d.ts +1 -0
  36. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -1
  37. package/umd/typings/utils/extractParameters.d.ts +1 -3
  38. package/umd/typings/utils/sets/difference.d.ts +4 -0
  39. package/umd/typings/utils/sets/difference.test.d.ts +1 -0
  40. package/umd/typings/utils/sets/intersection.d.ts +4 -0
  41. package/umd/typings/utils/sets/intersection.test.d.ts +1 -0
  42. package/umd/typings/utils/sets/union.d.ts +4 -0
  43. package/umd/typings/utils/sets/union.test.d.ts +1 -0
package/esm/index.es.js CHANGED
@@ -89,7 +89,7 @@ var PromptbookExecutionError = /** @class */ (function (_super) {
89
89
  /**
90
90
  * The version of the Promptbook library
91
91
  */
92
- var PROMPTBOOK_VERSION = '0.50.0-10';
92
+ var PROMPTBOOK_VERSION = '0.50.0-19';
93
93
 
94
94
  /**
95
95
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
@@ -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,3 +1,4 @@
1
+ import { OPENAI_MODELS } from '../execution/plugins/llm-execution-tools/openai/models';
1
2
  import { OpenAiExecutionTools } from '../execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools';
2
3
  import { OpenAiExecutionToolsOptions } from '../execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions';
3
- export { OpenAiExecutionTools, OpenAiExecutionToolsOptions };
4
+ export { OPENAI_MODELS, OpenAiExecutionTools, OpenAiExecutionToolsOptions };
@@ -10,7 +10,8 @@ import type { ExecutionType } from '../types/ExecutionTypes';
10
10
  import type { ModelRequirements, ModelVariant } from '../types/ModelRequirements';
11
11
  import type { Parameters } from '../types/Parameters';
12
12
  import type { Prompt } from '../types/Prompt';
13
- import type { EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, LlmTemplateJson, PromptDialogJson, PromptTemplateJson, ScriptJson, SimpleTemplateJson } from '../types/PromptbookJson/PromptTemplateJson';
13
+ import type { ExpectationAmount, Expectations, ExpectationUnit, LlmTemplateJson, PromptDialogJson, PromptTemplateJson, ScriptJson, SimpleTemplateJson } from '../types/PromptbookJson/PromptTemplateJson';
14
+ import { EXPECTATION_UNITS } from '../types/PromptbookJson/PromptTemplateJson';
14
15
  import type { PromptTemplateParameterJson } from '../types/PromptbookJson/PromptTemplateParameterJson';
15
16
  import type { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
16
17
  import type { PromptbookString } from '../types/PromptbookString';
@@ -20,7 +21,7 @@ import type { ExecutionReportJson } from '../types/execution-report/ExecutionRep
20
21
  import type { string_char_emoji } from '../types/typeAliasEmoji';
21
22
  import type { client_id, string_char, string_chat_prompt, string_completion_prompt, 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_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version } from '../types/typeAliases';
22
23
  import { FromtoItems } from '../utils/FromtoItems';
23
- export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, 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_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
24
+ export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, 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_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
24
25
  /**
25
26
  * TODO: [🧠][🆔] Is this the best package to export custom errors from?
26
27
  * TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
@@ -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
+ */
@@ -6,6 +6,3 @@ import type { PromptResult } from '../../../PromptResult';
6
6
  * @throws {PromptbookExecutionError} If the usage is not defined in the response from OpenAI
7
7
  */
8
8
  export declare function computeOpenaiUsage(rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResult['usage'];
9
- /**
10
- * TODO: [🍓] Make better
11
- */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * String value found on openai page
3
+ *
4
+ * @private within the library, used only as internal helper for `OPENAI_MODELS` and `computeUsage`
5
+ */
6
+ type string_openai_price = `$${number}.${number} / ${number}M tokens`;
7
+ /**
8
+ * Function computeUsage will create price per one token based on the string value found on openai page
9
+ *
10
+ * @private within the library, used only as internal helper for `OPENAI_MODELS`
11
+ */
12
+ export declare function computeUsage(value: string_openai_price): number;
13
+ export {};
@@ -0,0 +1,25 @@
1
+ import { number_usd } from '../../../../types/typeAliases';
2
+ import type { AvailableModel } from '../../../LlmExecutionTools';
3
+ /**
4
+ * List of available OpenAI models with pricing
5
+ *
6
+ * Note: Done at 2024-05-20
7
+ *
8
+ * @see https://platform.openai.com/docs/models/
9
+ * @see https://openai.com/api/pricing/
10
+ */
11
+ export declare const OPENAI_MODELS: Array<AvailableModel & {
12
+ pricing?: {
13
+ prompt: number_usd;
14
+ output: number_usd;
15
+ };
16
+ }>;
17
+ /**
18
+ * TODO: [🧠] Some mechanism to propagate unsureness
19
+ * TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
20
+ * @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
21
+ * @see https://openai.com/api/pricing/
22
+ * @see /other/playground/playground.ts
23
+ * TODO: [🍓] Make better
24
+ * TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
25
+ */
@@ -39,4 +39,5 @@ export type ModelRequirements = {
39
39
  /**
40
40
  * TODO: Maybe figure out better word than "variant"
41
41
  * TODO: Add here more requirement options like max context size, max tokens, etc.
42
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
42
43
  */
@@ -32,7 +32,7 @@ export type Expectations = Partial<Record<Lowercase<ExpectationUnit>, {
32
32
  /**
33
33
  * Units of text measurement
34
34
  */
35
- export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "PARAGRAPHS", "LINES", "PAGES"];
35
+ export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "LINES", "PARAGRAPHS", "PAGES"];
36
36
  /**
37
37
  * Unit of text measurement
38
38
  */
@@ -133,4 +133,5 @@ export {};
133
133
  /**
134
134
  * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
135
135
  * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
136
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
136
137
  */
@@ -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/remote-server",
3
- "version": "0.50.0",
3
+ "version": "0.51.0",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "colors": "1.4.0",
38
38
  "socket.io": "4.7.2",
39
- "spacetrim": "0.11.26"
39
+ "spacetrim": "0.11.25"
40
40
  },
41
41
  "funding": [
42
42
  {
@@ -49,7 +49,7 @@
49
49
  }
50
50
  ],
51
51
  "peerDependencies": {
52
- "@promptbook/core": "0.50.0"
52
+ "@promptbook/core": "0.51.0"
53
53
  },
54
54
  "main": "./umd/index.umd.js",
55
55
  "module": "./esm/index.es.js",
package/umd/index.umd.js CHANGED
@@ -95,7 +95,7 @@
95
95
  /**
96
96
  * The version of the Promptbook library
97
97
  */
98
- var PROMPTBOOK_VERSION = '0.50.0-10';
98
+ var PROMPTBOOK_VERSION = '0.50.0-19';
99
99
 
100
100
  /**
101
101
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
@@ -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,3 +1,4 @@
1
+ import { OPENAI_MODELS } from '../execution/plugins/llm-execution-tools/openai/models';
1
2
  import { OpenAiExecutionTools } from '../execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools';
2
3
  import { OpenAiExecutionToolsOptions } from '../execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions';
3
- export { OpenAiExecutionTools, OpenAiExecutionToolsOptions };
4
+ export { OPENAI_MODELS, OpenAiExecutionTools, OpenAiExecutionToolsOptions };
@@ -10,7 +10,8 @@ import type { ExecutionType } from '../types/ExecutionTypes';
10
10
  import type { ModelRequirements, ModelVariant } from '../types/ModelRequirements';
11
11
  import type { Parameters } from '../types/Parameters';
12
12
  import type { Prompt } from '../types/Prompt';
13
- import type { EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, LlmTemplateJson, PromptDialogJson, PromptTemplateJson, ScriptJson, SimpleTemplateJson } from '../types/PromptbookJson/PromptTemplateJson';
13
+ import type { ExpectationAmount, Expectations, ExpectationUnit, LlmTemplateJson, PromptDialogJson, PromptTemplateJson, ScriptJson, SimpleTemplateJson } from '../types/PromptbookJson/PromptTemplateJson';
14
+ import { EXPECTATION_UNITS } from '../types/PromptbookJson/PromptTemplateJson';
14
15
  import type { PromptTemplateParameterJson } from '../types/PromptbookJson/PromptTemplateParameterJson';
15
16
  import type { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
16
17
  import type { PromptbookString } from '../types/PromptbookString';
@@ -20,7 +21,7 @@ import type { ExecutionReportJson } from '../types/execution-report/ExecutionRep
20
21
  import type { string_char_emoji } from '../types/typeAliasEmoji';
21
22
  import type { client_id, string_char, string_chat_prompt, string_completion_prompt, 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_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version } from '../types/typeAliases';
22
23
  import { FromtoItems } from '../utils/FromtoItems';
23
- export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, 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_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
24
+ export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, 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_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
24
25
  /**
25
26
  * TODO: [🧠][🆔] Is this the best package to export custom errors from?
26
27
  * TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
@@ -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
+ */
@@ -6,6 +6,3 @@ import type { PromptResult } from '../../../PromptResult';
6
6
  * @throws {PromptbookExecutionError} If the usage is not defined in the response from OpenAI
7
7
  */
8
8
  export declare function computeOpenaiUsage(rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResult['usage'];
9
- /**
10
- * TODO: [🍓] Make better
11
- */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * String value found on openai page
3
+ *
4
+ * @private within the library, used only as internal helper for `OPENAI_MODELS` and `computeUsage`
5
+ */
6
+ type string_openai_price = `$${number}.${number} / ${number}M tokens`;
7
+ /**
8
+ * Function computeUsage will create price per one token based on the string value found on openai page
9
+ *
10
+ * @private within the library, used only as internal helper for `OPENAI_MODELS`
11
+ */
12
+ export declare function computeUsage(value: string_openai_price): number;
13
+ export {};
@@ -0,0 +1,25 @@
1
+ import { number_usd } from '../../../../types/typeAliases';
2
+ import type { AvailableModel } from '../../../LlmExecutionTools';
3
+ /**
4
+ * List of available OpenAI models with pricing
5
+ *
6
+ * Note: Done at 2024-05-20
7
+ *
8
+ * @see https://platform.openai.com/docs/models/
9
+ * @see https://openai.com/api/pricing/
10
+ */
11
+ export declare const OPENAI_MODELS: Array<AvailableModel & {
12
+ pricing?: {
13
+ prompt: number_usd;
14
+ output: number_usd;
15
+ };
16
+ }>;
17
+ /**
18
+ * TODO: [🧠] Some mechanism to propagate unsureness
19
+ * TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
20
+ * @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
21
+ * @see https://openai.com/api/pricing/
22
+ * @see /other/playground/playground.ts
23
+ * TODO: [🍓] Make better
24
+ * TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
25
+ */
@@ -39,4 +39,5 @@ export type ModelRequirements = {
39
39
  /**
40
40
  * TODO: Maybe figure out better word than "variant"
41
41
  * TODO: Add here more requirement options like max context size, max tokens, etc.
42
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
42
43
  */
@@ -32,7 +32,7 @@ export type Expectations = Partial<Record<Lowercase<ExpectationUnit>, {
32
32
  /**
33
33
  * Units of text measurement
34
34
  */
35
- export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "PARAGRAPHS", "LINES", "PAGES"];
35
+ export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "LINES", "PARAGRAPHS", "PAGES"];
36
36
  /**
37
37
  * Unit of text measurement
38
38
  */
@@ -133,4 +133,5 @@ export {};
133
133
  /**
134
134
  * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
135
135
  * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
136
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
136
137
  */
@@ -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 {};