@promptbook/utils 0.71.0-0 → 0.72.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/esm/index.es.js +114 -153
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +5 -11
- package/esm/typings/src/_packages/openai.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -12
- package/esm/typings/src/_packages/utils.index.d.ts +4 -4
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +2 -3
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -16
- package/esm/typings/src/config.d.ts +1 -14
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +0 -3
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +1 -2
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +0 -5
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +8 -9
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +72 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
- package/esm/typings/src/execution/utils/addUsage.d.ts +0 -56
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +0 -2
- package/esm/typings/src/execution/utils/usage-constants.d.ts +127 -0
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +4 -3
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +15 -14
- package/esm/typings/src/formats/csv/{CsvFormatDefinition.d.ts → ListFormatDefinition.d.ts} +3 -6
- package/esm/typings/src/formats/index.d.ts +1 -1
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +3 -4
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +16 -0
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +3 -4
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceTools.d.ts +1 -1
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -2
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +3 -2
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +37 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +14 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -2
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +2 -9
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +0 -1
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +0 -5
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +0 -3
- package/esm/typings/src/utils/expectation-counters/index.d.ts +0 -3
- package/esm/typings/src/utils/{parameters/extractParameterNames.d.ts → extractParameterNames.d.ts} +2 -2
- package/esm/typings/src/utils/organization/{empty_object.d.ts → f.d.ts} +1 -5
- package/esm/typings/src/utils/{parameters/replaceParameters.d.ts → replaceParameters.d.ts} +2 -2
- package/package.json +12 -16
- package/umd/index.umd.js +114 -153
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +0 -23
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTemplateResult.d.ts +0 -45
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +0 -20
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +0 -40
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +0 -10
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +0 -55
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +0 -62
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCells.d.ts +0 -19
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +0 -74
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +0 -34
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTemplate.d.ts +0 -10
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTemplate.d.ts +0 -27
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTemplate.d.ts +0 -30
- package/esm/typings/src/execution/createPipelineExecutor/getSamplesForTemplate.d.ts +0 -10
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -30
- package/esm/typings/src/formats/csv/CsvSettings.d.ts +0 -13
- package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +0 -19
- package/esm/typings/src/utils/organization/just_empty_object.d.ts +0 -12
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +0 -27
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +0 -10
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.test.d.ts +0 -1
- /package/esm/typings/src/{utils/parameters/extractParameterNames.test.d.ts → execution/utils/usageToHuman.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{parameters/mapAvailableToExpectedParameters.test.d.ts → extractParameterNames.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{parameters/replaceParameters.test.d.ts → replaceParameters.test.d.ts} +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
2
|
+
import type { ChatPromptResult } from '../../execution/PromptResult';
|
|
3
|
+
import type { Prompt } from '../../types/Prompt';
|
|
4
|
+
import type { string_markdown } from '../../types/typeAliases';
|
|
5
|
+
import type { string_markdown_text } from '../../types/typeAliases';
|
|
6
|
+
import type { string_title } from '../../types/typeAliases';
|
|
7
|
+
import type { OpenAiAssistantExecutionToolsOptions } from './OpenAiAssistantExecutionToolsOptions';
|
|
8
|
+
import { OpenAiExecutionTools } from './OpenAiExecutionTools';
|
|
9
|
+
/**
|
|
10
|
+
* Execution Tools for calling OpenAI API Assistants
|
|
11
|
+
*
|
|
12
|
+
* This is usefull for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
|
|
13
|
+
*
|
|
14
|
+
* @public exported from `@promptbook/openai`
|
|
15
|
+
*/
|
|
16
|
+
export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
|
|
17
|
+
private readonly assistantId?;
|
|
18
|
+
/**
|
|
19
|
+
* Creates OpenAI Execution Tools.
|
|
20
|
+
*
|
|
21
|
+
* @param options which are relevant are directly passed to the OpenAI client
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: OpenAiAssistantExecutionToolsOptions);
|
|
24
|
+
get title(): string_title & string_markdown_text;
|
|
25
|
+
get description(): string_markdown;
|
|
26
|
+
/**
|
|
27
|
+
* Calls OpenAI API to use a chat model.
|
|
28
|
+
*/
|
|
29
|
+
callChatModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements' | 'format'>): Promise<ChatPromptResult>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* TODO: !!!!!! DO not use colors - can be used in browser
|
|
33
|
+
* TODO: [🧠][🧙♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
|
|
34
|
+
* TODO: Maybe make custom OpenAiError
|
|
35
|
+
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
36
|
+
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
37
|
+
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ClientOptions } from 'openai';
|
|
2
|
+
import type { string_token } from '../../types/typeAliases';
|
|
3
|
+
import type { OpenAiExecutionToolsOptions } from './OpenAiExecutionToolsOptions';
|
|
4
|
+
/**
|
|
5
|
+
* Options for `OpenAiAssistantExecutionTools`
|
|
6
|
+
*
|
|
7
|
+
* @public exported from `@promptbook/openai`
|
|
8
|
+
*/
|
|
9
|
+
export type OpenAiAssistantExecutionToolsOptions = OpenAiExecutionToolsOptions & ClientOptions & {
|
|
10
|
+
/**
|
|
11
|
+
* Which assistant to use
|
|
12
|
+
*/
|
|
13
|
+
assistantId?: string_token;
|
|
14
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
1
2
|
import type { AvailableModel } from '../../execution/AvailableModel';
|
|
2
3
|
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
3
4
|
import type { ChatPromptResult } from '../../execution/PromptResult';
|
|
@@ -14,7 +15,7 @@ import type { OpenAiExecutionToolsOptions } from './OpenAiExecutionToolsOptions'
|
|
|
14
15
|
* @public exported from `@promptbook/openai`
|
|
15
16
|
*/
|
|
16
17
|
export declare class OpenAiExecutionTools implements LlmExecutionTools {
|
|
17
|
-
|
|
18
|
+
protected readonly options: OpenAiExecutionToolsOptions;
|
|
18
19
|
/**
|
|
19
20
|
* OpenAI API client.
|
|
20
21
|
*/
|
|
@@ -27,7 +28,7 @@ export declare class OpenAiExecutionTools implements LlmExecutionTools {
|
|
|
27
28
|
constructor(options?: OpenAiExecutionToolsOptions);
|
|
28
29
|
get title(): string_title & string_markdown_text;
|
|
29
30
|
get description(): string_markdown;
|
|
30
|
-
|
|
31
|
+
getClient(): Promise<OpenAI>;
|
|
31
32
|
/**
|
|
32
33
|
* Check the `options` passed to `constructor`
|
|
33
34
|
*/
|
|
@@ -20,7 +20,7 @@ import type { RemoteLlmExecutionToolsOptions } from './interfaces/RemoteLlmExecu
|
|
|
20
20
|
* @public exported from `@promptbook/remote-client`
|
|
21
21
|
*/
|
|
22
22
|
export declare class RemoteLlmExecutionTools implements LlmExecutionTools {
|
|
23
|
-
|
|
23
|
+
protected readonly options: RemoteLlmExecutionToolsOptions;
|
|
24
24
|
constructor(options: RemoteLlmExecutionToolsOptions);
|
|
25
25
|
get title(): string_title & string_markdown_text;
|
|
26
26
|
get description(): string_markdown;
|
|
@@ -9,7 +9,7 @@ import type { JavascriptExecutionToolsOptions } from './JavascriptExecutionTools
|
|
|
9
9
|
* @public exported from `@promptbook/execute-javascript`
|
|
10
10
|
*/
|
|
11
11
|
export declare class JavascriptEvalExecutionTools implements ScriptExecutionTools {
|
|
12
|
-
|
|
12
|
+
protected readonly options: JavascriptExecutionToolsOptions;
|
|
13
13
|
constructor(options?: JavascriptExecutionToolsOptions);
|
|
14
14
|
/**
|
|
15
15
|
* Executes a JavaScript
|
|
@@ -9,7 +9,7 @@ import type { ScriptExecutionToolsExecuteOptions } from '../../execution/ScriptE
|
|
|
9
9
|
* @private still in development
|
|
10
10
|
*/
|
|
11
11
|
export declare class PythonExecutionTools implements ScriptExecutionTools {
|
|
12
|
-
|
|
12
|
+
protected readonly options: CommonExecutionToolsOptions;
|
|
13
13
|
constructor(options?: CommonExecutionToolsOptions);
|
|
14
14
|
/**
|
|
15
15
|
* Executes a Python
|
|
@@ -9,7 +9,7 @@ import type { ScriptExecutionToolsExecuteOptions } from '../../execution/ScriptE
|
|
|
9
9
|
* @private still in development
|
|
10
10
|
*/
|
|
11
11
|
export declare class TypescriptExecutionTools implements ScriptExecutionTools {
|
|
12
|
-
|
|
12
|
+
protected readonly options: CommonExecutionToolsOptions;
|
|
13
13
|
constructor(options?: CommonExecutionToolsOptions);
|
|
14
14
|
/**
|
|
15
15
|
* Executes a TypeScript
|
|
@@ -6,7 +6,7 @@ import type { FilesStorageOptions } from './FilesStorageOptions';
|
|
|
6
6
|
* @public exported from `@promptbook/node`
|
|
7
7
|
*/
|
|
8
8
|
export declare class FilesStorage<TItem> implements PromptbookStorage<TItem> {
|
|
9
|
-
|
|
9
|
+
protected readonly options: FilesStorageOptions;
|
|
10
10
|
constructor(options: FilesStorageOptions);
|
|
11
11
|
/**
|
|
12
12
|
* @@@
|
|
@@ -11,18 +11,11 @@ import type { string_name } from '../typeAliases';
|
|
|
11
11
|
*/
|
|
12
12
|
export type KnowledgeSourceJson = {
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* @@@
|
|
15
15
|
*/
|
|
16
16
|
readonly name: string_name;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* It can be a link, a relative path to file or direct text or combination of those
|
|
21
|
-
*
|
|
22
|
-
* For example `"https://pavolhejny.com/"`
|
|
23
|
-
* For example `"./pavol-hejny-cv.pdf"`
|
|
24
|
-
* For example `"Pavol Hejný has web https://pavolhejny.com/"`
|
|
25
|
-
* For example `"Pavol Hejný is web developer and creator of Promptbook and Collboard"`
|
|
18
|
+
* @@@
|
|
26
19
|
*/
|
|
27
20
|
readonly sourceContent: string_knowledge_source_content;
|
|
28
21
|
};
|
|
@@ -33,7 +33,6 @@ export type ParameterJson = {
|
|
|
33
33
|
readonly sampleValues?: Array<string_parameter_value>;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
|
-
* TODO: [🧠] !!!!!! Should be here registered subparameter from foreach or not?
|
|
37
36
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
38
37
|
* TODO: [🍙] Make some standard order of json properties
|
|
39
38
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ForeachJson } from '../../commands/FOREACH/ForeachJson';
|
|
2
1
|
import type { FormatCommand } from '../../commands/FORMAT/FormatCommand';
|
|
3
2
|
import type { TemplateType } from '../../commands/TEMPLATE/TemplateTypes';
|
|
4
3
|
import type { string_javascript } from '../typeAliases';
|
|
@@ -43,10 +42,6 @@ export interface TemplateJsonCommon {
|
|
|
43
42
|
* @see https://github.com/webgptorg/promptbook/discussions/66
|
|
44
43
|
*/
|
|
45
44
|
readonly jokerParameterNames?: Array<string_parameter_name>;
|
|
46
|
-
/**
|
|
47
|
-
* @@@
|
|
48
|
-
*/
|
|
49
|
-
readonly foreach?: ForeachJson;
|
|
50
45
|
/**
|
|
51
46
|
* Type of the execution
|
|
52
47
|
* This determines if the template is send to LLM, user or some scripting evaluation
|
|
@@ -6,6 +6,3 @@ import type { ExpectationUnit } from '../../types/PipelineJson/Expectations';
|
|
|
6
6
|
* @public exported from `@promptbook/utils`
|
|
7
7
|
*/
|
|
8
8
|
export declare const CountUtils: Record<ExpectationUnit, (text: string) => ExpectationAmount>;
|
|
9
|
-
/**
|
|
10
|
-
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
11
|
-
*/
|
package/esm/typings/src/utils/{parameters/extractParameterNames.d.ts → extractParameterNames.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { string_parameter_name } from '
|
|
2
|
-
import type { string_template } from '
|
|
1
|
+
import type { string_parameter_name } from '../types/typeAliases';
|
|
2
|
+
import type { string_template } from '../types/typeAliases';
|
|
3
3
|
/**
|
|
4
4
|
* Parses the template and returns the list of all parameter names
|
|
5
5
|
*
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Organizational helper to better mark the place where to really use empty object `{}`
|
|
3
3
|
*
|
|
4
|
-
* Note: There are 2 similar types>
|
|
5
|
-
* - `empty_object` @@@
|
|
6
|
-
* - `just_empty_object` @@@
|
|
7
|
-
*
|
|
8
4
|
* @private within the repository
|
|
9
5
|
*/
|
|
10
|
-
export type
|
|
6
|
+
export type really_empty_object = Record<string, never>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Parameters } from '
|
|
2
|
-
import type { string_template } from '
|
|
1
|
+
import type { Parameters } from '../types/typeAliases';
|
|
2
|
+
import type { string_template } from '../types/typeAliases';
|
|
3
3
|
/**
|
|
4
4
|
* Replaces parameters in template with values from parameters object
|
|
5
5
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.0-0",
|
|
4
4
|
"description": "Supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -12,25 +12,21 @@
|
|
|
12
12
|
"Pavol Hejný <me@pavolhejny.com> (https://www.pavolhejny.com/)"
|
|
13
13
|
],
|
|
14
14
|
"keywords": [
|
|
15
|
-
"ai",
|
|
16
|
-
"llm",
|
|
17
|
-
"prompt",
|
|
18
|
-
"template",
|
|
19
|
-
"language-model",
|
|
20
|
-
"chatgpt",
|
|
21
15
|
"autogpt",
|
|
22
|
-
"machine-learning",
|
|
23
|
-
"natural-language-processing",
|
|
24
|
-
"nlp",
|
|
25
16
|
"openai",
|
|
26
17
|
"gpt-3",
|
|
27
18
|
"gpt-4",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
19
|
+
"chatgpt",
|
|
20
|
+
"ai",
|
|
21
|
+
"machine-learning",
|
|
22
|
+
"natural-language-processing",
|
|
23
|
+
"nlp",
|
|
24
|
+
"prompt",
|
|
25
|
+
"template",
|
|
26
|
+
"pipeline",
|
|
27
|
+
"automation",
|
|
28
|
+
"text-generation",
|
|
29
|
+
"language-model"
|
|
34
30
|
],
|
|
35
31
|
"license": "CC-BY-4.0",
|
|
36
32
|
"bugs": {
|
package/umd/index.umd.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/**
|
|
13
13
|
* The version of the Promptbook library
|
|
14
14
|
*/
|
|
15
|
-
var PROMPTBOOK_VERSION = '0.
|
|
15
|
+
var PROMPTBOOK_VERSION = '0.68.5';
|
|
16
16
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
17
17
|
|
|
18
18
|
/*! *****************************************************************************
|
|
@@ -633,9 +633,6 @@
|
|
|
633
633
|
return promptbookMermaid;
|
|
634
634
|
}
|
|
635
635
|
/**
|
|
636
|
-
* TODO: !!!!! FOREACH in mermaid graph
|
|
637
|
-
* TODO: !!!!! Knowledge in mermaid graph
|
|
638
|
-
* TODO: !!!!! Personas in mermaid graph
|
|
639
636
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
640
637
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
641
638
|
*/
|
|
@@ -745,72 +742,52 @@
|
|
|
745
742
|
* @public exported from `@promptbook/utils`
|
|
746
743
|
*/
|
|
747
744
|
function extractParameterNamesFromTemplate(template) {
|
|
748
|
-
var e_1, _a, e_2, _b, e_3, _c
|
|
749
|
-
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames
|
|
745
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
746
|
+
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
|
|
750
747
|
var parameterNames = new Set();
|
|
751
748
|
try {
|
|
752
|
-
for (var
|
|
753
|
-
var parameterName =
|
|
749
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
750
|
+
var parameterName = _e.value;
|
|
754
751
|
parameterNames.add(parameterName);
|
|
755
752
|
}
|
|
756
753
|
}
|
|
757
754
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
758
755
|
finally {
|
|
759
756
|
try {
|
|
760
|
-
if (
|
|
757
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
761
758
|
}
|
|
762
759
|
finally { if (e_1) throw e_1.error; }
|
|
763
760
|
}
|
|
764
761
|
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
765
762
|
try {
|
|
766
|
-
for (var
|
|
767
|
-
var parameterName =
|
|
763
|
+
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
764
|
+
var parameterName = _g.value;
|
|
768
765
|
parameterNames.add(parameterName);
|
|
769
766
|
}
|
|
770
767
|
}
|
|
771
768
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
772
769
|
finally {
|
|
773
770
|
try {
|
|
774
|
-
if (
|
|
771
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
775
772
|
}
|
|
776
773
|
finally { if (e_2) throw e_2.error; }
|
|
777
774
|
}
|
|
778
775
|
}
|
|
779
776
|
try {
|
|
780
|
-
for (var
|
|
781
|
-
var jokerName =
|
|
777
|
+
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
778
|
+
var jokerName = _j.value;
|
|
782
779
|
parameterNames.add(jokerName);
|
|
783
780
|
}
|
|
784
781
|
}
|
|
785
782
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
786
783
|
finally {
|
|
787
784
|
try {
|
|
788
|
-
if (
|
|
785
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
789
786
|
}
|
|
790
787
|
finally { if (e_3) throw e_3.error; }
|
|
791
788
|
}
|
|
792
789
|
parameterNames.delete('content');
|
|
793
790
|
// <- Note {websiteContent} is used in `preparedContent`
|
|
794
|
-
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
795
|
-
if (foreach !== undefined) {
|
|
796
|
-
try {
|
|
797
|
-
for (var _l = __values(foreach.subparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
798
|
-
var subparameterName = _m.value;
|
|
799
|
-
if (parameterNames.has(subparameterName)) {
|
|
800
|
-
parameterNames.delete(subparameterName);
|
|
801
|
-
parameterNames.add(foreach.parameterName);
|
|
802
|
-
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
807
|
-
finally {
|
|
808
|
-
try {
|
|
809
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
810
|
-
}
|
|
811
|
-
finally { if (e_4) throw e_4.error; }
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
791
|
return parameterNames;
|
|
815
792
|
}
|
|
816
793
|
/**
|
|
@@ -1295,9 +1272,6 @@
|
|
|
1295
1272
|
LINES: countLines,
|
|
1296
1273
|
PAGES: countPages,
|
|
1297
1274
|
};
|
|
1298
|
-
/**
|
|
1299
|
-
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
1300
|
-
*/
|
|
1301
1275
|
|
|
1302
1276
|
/**
|
|
1303
1277
|
* Makes first letter of a string uppercase
|
|
@@ -1552,6 +1526,108 @@
|
|
|
1552
1526
|
return true;
|
|
1553
1527
|
}
|
|
1554
1528
|
|
|
1529
|
+
/**
|
|
1530
|
+
* Function parseNumber will parse number from string
|
|
1531
|
+
*
|
|
1532
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1533
|
+
* Note: it also works only with decimal numbers
|
|
1534
|
+
*
|
|
1535
|
+
* @returns parsed number
|
|
1536
|
+
* @throws {ParseError} if the value is not a number
|
|
1537
|
+
*
|
|
1538
|
+
* @public exported from `@promptbook/utils`
|
|
1539
|
+
*/
|
|
1540
|
+
function parseNumber(value) {
|
|
1541
|
+
var originalValue = value;
|
|
1542
|
+
if (typeof value === 'number') {
|
|
1543
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1544
|
+
}
|
|
1545
|
+
if (typeof value !== 'string') {
|
|
1546
|
+
return 0;
|
|
1547
|
+
}
|
|
1548
|
+
value = value.trim();
|
|
1549
|
+
if (value.startsWith('+')) {
|
|
1550
|
+
return parseNumber(value.substring(1));
|
|
1551
|
+
}
|
|
1552
|
+
if (value.startsWith('-')) {
|
|
1553
|
+
var number = parseNumber(value.substring(1));
|
|
1554
|
+
if (number === 0) {
|
|
1555
|
+
return 0; // <- Note: To prevent -0
|
|
1556
|
+
}
|
|
1557
|
+
return -number;
|
|
1558
|
+
}
|
|
1559
|
+
value = value.replace(/,/g, '.');
|
|
1560
|
+
value = value.toUpperCase();
|
|
1561
|
+
if (value === '') {
|
|
1562
|
+
return 0;
|
|
1563
|
+
}
|
|
1564
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
1565
|
+
return Infinity;
|
|
1566
|
+
}
|
|
1567
|
+
if (value.includes('/')) {
|
|
1568
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1569
|
+
var numerator = parseNumber(numerator_);
|
|
1570
|
+
var denominator = parseNumber(denominator_);
|
|
1571
|
+
if (denominator === 0) {
|
|
1572
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1573
|
+
}
|
|
1574
|
+
return numerator / denominator;
|
|
1575
|
+
}
|
|
1576
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1577
|
+
return 0;
|
|
1578
|
+
}
|
|
1579
|
+
if (value.includes('E')) {
|
|
1580
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1581
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1582
|
+
}
|
|
1583
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1584
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1585
|
+
}
|
|
1586
|
+
var num = parseFloat(value);
|
|
1587
|
+
if (isNaN(num)) {
|
|
1588
|
+
throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1589
|
+
}
|
|
1590
|
+
return num;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1594
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
1595
|
+
*/
|
|
1596
|
+
|
|
1597
|
+
/**
|
|
1598
|
+
* Generates random seed
|
|
1599
|
+
*
|
|
1600
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
1601
|
+
* Warning: This function is not cryptographically secure (it uses Math.random internally)
|
|
1602
|
+
* @public exported from `@promptbook/utils`
|
|
1603
|
+
*/
|
|
1604
|
+
function $randomSeed() {
|
|
1605
|
+
return Math.random();
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
/**
|
|
1609
|
+
* Removes quotes from a string
|
|
1610
|
+
*
|
|
1611
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1612
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
1613
|
+
* Note: There are two simmilar functions:
|
|
1614
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
1615
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
1616
|
+
*
|
|
1617
|
+
* @param text optionally quoted text
|
|
1618
|
+
* @returns text without quotes
|
|
1619
|
+
* @public exported from `@promptbook/utils`
|
|
1620
|
+
*/
|
|
1621
|
+
function removeQuotes(text) {
|
|
1622
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
1623
|
+
return text.slice(1, -1);
|
|
1624
|
+
}
|
|
1625
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
1626
|
+
return text.slice(1, -1);
|
|
1627
|
+
}
|
|
1628
|
+
return text;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1555
1631
|
/**
|
|
1556
1632
|
* @@@
|
|
1557
1633
|
*
|
|
@@ -1754,7 +1830,6 @@
|
|
|
1754
1830
|
'samples',
|
|
1755
1831
|
'modelName',
|
|
1756
1832
|
'currentDate',
|
|
1757
|
-
// <- TODO: !!!!! list here all command names
|
|
1758
1833
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
1759
1834
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
1760
1835
|
]);
|
|
@@ -1770,18 +1845,6 @@
|
|
|
1770
1845
|
* @private within the repository
|
|
1771
1846
|
*/
|
|
1772
1847
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
1773
|
-
// <- TODO: [🧜♂️]
|
|
1774
|
-
/**
|
|
1775
|
-
* @@@
|
|
1776
|
-
*
|
|
1777
|
-
* @public exported from `@promptbook/core`
|
|
1778
|
-
*/
|
|
1779
|
-
Object.freeze({
|
|
1780
|
-
delimiter: ',',
|
|
1781
|
-
quoteChar: '"',
|
|
1782
|
-
newline: '\n',
|
|
1783
|
-
skipEmptyLines: true,
|
|
1784
|
-
});
|
|
1785
1848
|
/**
|
|
1786
1849
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
1787
1850
|
*/
|
|
@@ -1865,108 +1928,6 @@
|
|
|
1865
1928
|
return replacedTemplate;
|
|
1866
1929
|
}
|
|
1867
1930
|
|
|
1868
|
-
/**
|
|
1869
|
-
* Function parseNumber will parse number from string
|
|
1870
|
-
*
|
|
1871
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1872
|
-
* Note: it also works only with decimal numbers
|
|
1873
|
-
*
|
|
1874
|
-
* @returns parsed number
|
|
1875
|
-
* @throws {ParseError} if the value is not a number
|
|
1876
|
-
*
|
|
1877
|
-
* @public exported from `@promptbook/utils`
|
|
1878
|
-
*/
|
|
1879
|
-
function parseNumber(value) {
|
|
1880
|
-
var originalValue = value;
|
|
1881
|
-
if (typeof value === 'number') {
|
|
1882
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1883
|
-
}
|
|
1884
|
-
if (typeof value !== 'string') {
|
|
1885
|
-
return 0;
|
|
1886
|
-
}
|
|
1887
|
-
value = value.trim();
|
|
1888
|
-
if (value.startsWith('+')) {
|
|
1889
|
-
return parseNumber(value.substring(1));
|
|
1890
|
-
}
|
|
1891
|
-
if (value.startsWith('-')) {
|
|
1892
|
-
var number = parseNumber(value.substring(1));
|
|
1893
|
-
if (number === 0) {
|
|
1894
|
-
return 0; // <- Note: To prevent -0
|
|
1895
|
-
}
|
|
1896
|
-
return -number;
|
|
1897
|
-
}
|
|
1898
|
-
value = value.replace(/,/g, '.');
|
|
1899
|
-
value = value.toUpperCase();
|
|
1900
|
-
if (value === '') {
|
|
1901
|
-
return 0;
|
|
1902
|
-
}
|
|
1903
|
-
if (value === '♾' || value.startsWith('INF')) {
|
|
1904
|
-
return Infinity;
|
|
1905
|
-
}
|
|
1906
|
-
if (value.includes('/')) {
|
|
1907
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1908
|
-
var numerator = parseNumber(numerator_);
|
|
1909
|
-
var denominator = parseNumber(denominator_);
|
|
1910
|
-
if (denominator === 0) {
|
|
1911
|
-
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1912
|
-
}
|
|
1913
|
-
return numerator / denominator;
|
|
1914
|
-
}
|
|
1915
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1916
|
-
return 0;
|
|
1917
|
-
}
|
|
1918
|
-
if (value.includes('E')) {
|
|
1919
|
-
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1920
|
-
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1921
|
-
}
|
|
1922
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1923
|
-
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1924
|
-
}
|
|
1925
|
-
var num = parseFloat(value);
|
|
1926
|
-
if (isNaN(num)) {
|
|
1927
|
-
throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1928
|
-
}
|
|
1929
|
-
return num;
|
|
1930
|
-
}
|
|
1931
|
-
/**
|
|
1932
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1933
|
-
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
1934
|
-
*/
|
|
1935
|
-
|
|
1936
|
-
/**
|
|
1937
|
-
* Generates random seed
|
|
1938
|
-
*
|
|
1939
|
-
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
1940
|
-
* Warning: This function is not cryptographically secure (it uses Math.random internally)
|
|
1941
|
-
* @public exported from `@promptbook/utils`
|
|
1942
|
-
*/
|
|
1943
|
-
function $randomSeed() {
|
|
1944
|
-
return Math.random();
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
/**
|
|
1948
|
-
* Removes quotes from a string
|
|
1949
|
-
*
|
|
1950
|
-
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1951
|
-
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
1952
|
-
* Note: There are two simmilar functions:
|
|
1953
|
-
* - `removeQuotes` which removes only bounding quotes
|
|
1954
|
-
* - `unwrapResult` which removes whole introduce sentence
|
|
1955
|
-
*
|
|
1956
|
-
* @param text optionally quoted text
|
|
1957
|
-
* @returns text without quotes
|
|
1958
|
-
* @public exported from `@promptbook/utils`
|
|
1959
|
-
*/
|
|
1960
|
-
function removeQuotes(text) {
|
|
1961
|
-
if (text.startsWith('"') && text.endsWith('"')) {
|
|
1962
|
-
return text.slice(1, -1);
|
|
1963
|
-
}
|
|
1964
|
-
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
1965
|
-
return text.slice(1, -1);
|
|
1966
|
-
}
|
|
1967
|
-
return text;
|
|
1968
|
-
}
|
|
1969
|
-
|
|
1970
1931
|
/**
|
|
1971
1932
|
* @@@
|
|
1972
1933
|
*
|