@promptbook/cli 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.
- package/esm/index.es.js +123 -71
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/execute-javascript.index.d.ts +44 -1
- package/esm/typings/_packages/openai.index.d.ts +2 -1
- package/esm/typings/_packages/types.index.d.ts +3 -2
- package/esm/typings/_packages/utils.index.d.ts +9 -2
- package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
- package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
- package/esm/typings/conversion/utils/extractVariables.d.ts +4 -3
- package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +0 -3
- package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +13 -0
- package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
- package/esm/typings/execution/plugins/llm-execution-tools/openai/models.d.ts +25 -0
- package/esm/typings/types/ModelRequirements.d.ts +1 -0
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -1
- package/esm/typings/utils/extractParameters.d.ts +1 -3
- package/esm/typings/utils/sets/difference.d.ts +4 -0
- package/esm/typings/utils/sets/difference.test.d.ts +1 -0
- package/esm/typings/utils/sets/intersection.d.ts +4 -0
- package/esm/typings/utils/sets/intersection.test.d.ts +1 -0
- package/esm/typings/utils/sets/union.d.ts +4 -0
- package/esm/typings/utils/sets/union.test.d.ts +1 -0
- package/package.json +4 -4
- package/umd/index.umd.js +123 -71
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/execute-javascript.index.d.ts +44 -1
- package/umd/typings/_packages/openai.index.d.ts +2 -1
- package/umd/typings/_packages/types.index.d.ts +3 -2
- package/umd/typings/_packages/utils.index.d.ts +9 -2
- package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
- package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
- package/umd/typings/conversion/utils/extractVariables.d.ts +4 -3
- package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +0 -3
- package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +13 -0
- package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
- package/umd/typings/execution/plugins/llm-execution-tools/openai/models.d.ts +25 -0
- package/umd/typings/types/ModelRequirements.d.ts +1 -0
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -1
- package/umd/typings/utils/extractParameters.d.ts +1 -3
- package/umd/typings/utils/sets/difference.d.ts +4 -0
- package/umd/typings/utils/sets/difference.test.d.ts +1 -0
- package/umd/typings/utils/sets/intersection.d.ts +4 -0
- package/umd/typings/utils/sets/intersection.test.d.ts +1 -0
- package/umd/typings/utils/sets/union.d.ts +4 -0
- package/umd/typings/utils/sets/union.test.d.ts +1 -0
|
@@ -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 {
|
|
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
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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):
|
|
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 @@
|
|
|
1
|
+
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
|
+
*/
|
|
@@ -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", "
|
|
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):
|
|
8
|
+
export declare function extractParameters(template: string_template): Set<string_name>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/cli",
|
|
3
|
-
"version": "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,
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"commander": "12.0.0",
|
|
39
39
|
"glob-promise": "6.0.5",
|
|
40
40
|
"prettier": "2.8.1",
|
|
41
|
-
"spacetrim": "0.11.
|
|
42
|
-
"waitasecond": "1.11.
|
|
41
|
+
"spacetrim": "0.11.25",
|
|
42
|
+
"waitasecond": "1.11.69"
|
|
43
43
|
},
|
|
44
44
|
"funding": [
|
|
45
45
|
{
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@promptbook/core": "0.
|
|
55
|
+
"@promptbook/core": "0.51.0"
|
|
56
56
|
},
|
|
57
57
|
"main": "./umd/index.umd.js",
|
|
58
58
|
"module": "./esm/index.es.js",
|
package/umd/index.umd.js
CHANGED
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
/**
|
|
147
147
|
* The version of the Promptbook library
|
|
148
148
|
*/
|
|
149
|
-
var PROMPTBOOK_VERSION = '0.50.0-
|
|
149
|
+
var PROMPTBOOK_VERSION = '0.50.0-19';
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -167,37 +167,6 @@
|
|
|
167
167
|
*/
|
|
168
168
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
169
169
|
|
|
170
|
-
/**
|
|
171
|
-
* Parses the template and returns the list of all parameter names
|
|
172
|
-
*
|
|
173
|
-
* @param template the template with parameters in {curly} braces
|
|
174
|
-
* @returns the list of parameter names
|
|
175
|
-
*
|
|
176
|
-
* @private within the library
|
|
177
|
-
*/
|
|
178
|
-
function extractParameters(template) {
|
|
179
|
-
var e_1, _a;
|
|
180
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
181
|
-
var parameterNames = [];
|
|
182
|
-
try {
|
|
183
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
184
|
-
var match = matches_1_1.value;
|
|
185
|
-
var parameterName = match[0].slice(1, -1);
|
|
186
|
-
if (!parameterNames.includes(parameterName)) {
|
|
187
|
-
parameterNames.push(parameterName);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
192
|
-
finally {
|
|
193
|
-
try {
|
|
194
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
195
|
-
}
|
|
196
|
-
finally { if (e_1) throw e_1.error; }
|
|
197
|
-
}
|
|
198
|
-
return parameterNames;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
170
|
/**
|
|
202
171
|
* Computes the deepness of the markdown structure.
|
|
203
172
|
*
|
|
@@ -463,17 +432,80 @@
|
|
|
463
432
|
return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
464
433
|
}
|
|
465
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Creates a new set with all elements that are present in either set
|
|
437
|
+
*/
|
|
438
|
+
function union() {
|
|
439
|
+
var e_1, _a, e_2, _b;
|
|
440
|
+
var sets = [];
|
|
441
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
442
|
+
sets[_i] = arguments[_i];
|
|
443
|
+
}
|
|
444
|
+
var union = new Set();
|
|
445
|
+
try {
|
|
446
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
447
|
+
var set = sets_1_1.value;
|
|
448
|
+
try {
|
|
449
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
450
|
+
var item = _d.value;
|
|
451
|
+
union.add(item);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
455
|
+
finally {
|
|
456
|
+
try {
|
|
457
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
458
|
+
}
|
|
459
|
+
finally { if (e_2) throw e_2.error; }
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
464
|
+
finally {
|
|
465
|
+
try {
|
|
466
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
467
|
+
}
|
|
468
|
+
finally { if (e_1) throw e_1.error; }
|
|
469
|
+
}
|
|
470
|
+
return union;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Parses the template and returns the list of all parameter names
|
|
475
|
+
*
|
|
476
|
+
* @param template the template with parameters in {curly} braces
|
|
477
|
+
* @returns the list of parameter names
|
|
478
|
+
*/
|
|
479
|
+
function extractParameters(template) {
|
|
480
|
+
var e_1, _a;
|
|
481
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
482
|
+
var parameterNames = new Set();
|
|
483
|
+
try {
|
|
484
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
485
|
+
var match = matches_1_1.value;
|
|
486
|
+
var parameterName = match[0].slice(1, -1);
|
|
487
|
+
parameterNames.add(parameterName);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
491
|
+
finally {
|
|
492
|
+
try {
|
|
493
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
494
|
+
}
|
|
495
|
+
finally { if (e_1) throw e_1.error; }
|
|
496
|
+
}
|
|
497
|
+
return parameterNames;
|
|
498
|
+
}
|
|
499
|
+
|
|
466
500
|
/**
|
|
467
501
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
468
502
|
*
|
|
469
503
|
* @param script from which to extract the variables
|
|
470
504
|
* @returns the list of variable names
|
|
471
505
|
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
472
|
-
*
|
|
473
|
-
* @private within the promptbookStringToJson
|
|
474
506
|
*/
|
|
475
507
|
function extractVariables(script) {
|
|
476
|
-
var variables =
|
|
508
|
+
var variables = new Set();
|
|
477
509
|
script = "(()=>{".concat(script, "})()");
|
|
478
510
|
try {
|
|
479
511
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -497,7 +529,7 @@
|
|
|
497
529
|
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
498
530
|
}
|
|
499
531
|
else {
|
|
500
|
-
variables.
|
|
532
|
+
variables.add(undefinedName);
|
|
501
533
|
script = "const ".concat(undefinedName, " = '';") + script;
|
|
502
534
|
}
|
|
503
535
|
}
|
|
@@ -510,6 +542,53 @@
|
|
|
510
542
|
}
|
|
511
543
|
return variables;
|
|
512
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
551
|
+
*
|
|
552
|
+
* @param promptTemplate the template with used parameters
|
|
553
|
+
* @returns the set of parameter names
|
|
554
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
555
|
+
*/
|
|
556
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
557
|
+
var e_1, _a, e_2, _b;
|
|
558
|
+
var parameterNames = new Set();
|
|
559
|
+
try {
|
|
560
|
+
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
561
|
+
var parameterName = _d.value;
|
|
562
|
+
parameterNames.add(parameterName);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
566
|
+
finally {
|
|
567
|
+
try {
|
|
568
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
569
|
+
}
|
|
570
|
+
finally { if (e_1) throw e_1.error; }
|
|
571
|
+
}
|
|
572
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
573
|
+
try {
|
|
574
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
575
|
+
var parameterName = _f.value;
|
|
576
|
+
parameterNames.add(parameterName);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
580
|
+
finally {
|
|
581
|
+
try {
|
|
582
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
583
|
+
}
|
|
584
|
+
finally { if (e_2) throw e_2.error; }
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return parameterNames;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* TODO: [🔣] If script require contentLanguage
|
|
591
|
+
*/
|
|
513
592
|
|
|
514
593
|
/**
|
|
515
594
|
* Removes emojis from a string and fix whitespaces
|
|
@@ -1212,10 +1291,11 @@
|
|
|
1212
1291
|
/**
|
|
1213
1292
|
* Units of text measurement
|
|
1214
1293
|
*/
|
|
1215
|
-
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', '
|
|
1294
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
1216
1295
|
/**
|
|
1217
1296
|
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
1218
1297
|
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
1298
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
1219
1299
|
*/
|
|
1220
1300
|
|
|
1221
1301
|
/**
|
|
@@ -1563,11 +1643,11 @@
|
|
|
1563
1643
|
finally { if (e_1) throw e_1.error; }
|
|
1564
1644
|
}
|
|
1565
1645
|
var _loop_1 = function (section) {
|
|
1566
|
-
var e_3, _e
|
|
1646
|
+
var e_3, _e;
|
|
1567
1647
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1568
1648
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1569
1649
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1570
|
-
var dependentParameterNames =
|
|
1650
|
+
var dependentParameterNames = new Set();
|
|
1571
1651
|
var executionType = 'PROMPT_TEMPLATE';
|
|
1572
1652
|
var jokers = [];
|
|
1573
1653
|
var postprocessing = [];
|
|
@@ -1581,7 +1661,7 @@
|
|
|
1581
1661
|
switch (command.type) {
|
|
1582
1662
|
case 'JOKER':
|
|
1583
1663
|
jokers.push(command.parameterName);
|
|
1584
|
-
dependentParameterNames.
|
|
1664
|
+
dependentParameterNames.add(command.parameterName);
|
|
1585
1665
|
break;
|
|
1586
1666
|
case 'EXECUTE':
|
|
1587
1667
|
if (isExecutionTypeChanged) {
|
|
@@ -1635,7 +1715,7 @@
|
|
|
1635
1715
|
}
|
|
1636
1716
|
finally { if (e_3) throw e_3.error; }
|
|
1637
1717
|
}
|
|
1638
|
-
var
|
|
1718
|
+
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
1639
1719
|
if (executionType === 'SCRIPT') {
|
|
1640
1720
|
if (!language) {
|
|
1641
1721
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
@@ -1674,40 +1754,12 @@
|
|
|
1674
1754
|
if (Object.keys(postprocessing).length === 0) {
|
|
1675
1755
|
postprocessing = undefined;
|
|
1676
1756
|
}
|
|
1677
|
-
|
|
1678
|
-
for (var _j = (e_4 = void 0, __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(section.title)), false), __read(extractParameters(description_1 || '')), false), __read(extractParameters(content)), false))), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1679
|
-
var parameterName = _k.value;
|
|
1680
|
-
dependentParameterNames.push(parameterName);
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1684
|
-
finally {
|
|
1685
|
-
try {
|
|
1686
|
-
if (_k && !_k.done && (_f = _j.return)) _f.call(_j);
|
|
1687
|
-
}
|
|
1688
|
-
finally { if (e_4) throw e_4.error; }
|
|
1689
|
-
}
|
|
1690
|
-
if (executionType === 'SCRIPT') {
|
|
1691
|
-
try {
|
|
1692
|
-
for (var _l = (e_5 = void 0, __values(extractVariables(content))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1693
|
-
var parameterName = _m.value;
|
|
1694
|
-
dependentParameterNames.push(parameterName);
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1698
|
-
finally {
|
|
1699
|
-
try {
|
|
1700
|
-
if (_m && !_m.done && (_g = _l.return)) _g.call(_l);
|
|
1701
|
-
}
|
|
1702
|
-
finally { if (e_5) throw e_5.error; }
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
|
|
1757
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1706
1758
|
promptbookJson.promptTemplates.push({
|
|
1707
1759
|
name: titleToName(section.title),
|
|
1708
1760
|
title: section.title,
|
|
1709
1761
|
description: description_1,
|
|
1710
|
-
dependentParameterNames: dependentParameterNames,
|
|
1762
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1711
1763
|
executionType: executionType,
|
|
1712
1764
|
jokers: jokers,
|
|
1713
1765
|
postprocessing: postprocessing,
|