@promptbook/cli 0.61.0-10 → 0.61.0-12
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 +760 -475
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +83 -2
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/_packages/utils.index.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -0
- package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +4 -1
- package/esm/typings/src/config.d.ts +4 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +6 -0
- package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/{umd/typings/src/errors/VersionMismatch.d.ts → esm/typings/src/errors/VersionMismatchError.d.ts} +1 -1
- package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +4 -3
- package/esm/typings/src/execution/PromptResult.d.ts +12 -0
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -0
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -0
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +1 -0
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +22 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
- 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/multiple/MultipleLlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/personas/preparePersona.d.ts +4 -2
- package/esm/typings/src/prepare/preparePipeline.d.ts +3 -1
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
- package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
- package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +21 -1
- package/esm/typings/src/types/Parameters.d.ts +0 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -2
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/esm/typings/src/types/PipelineString.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +5 -2
- package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +35 -1
- package/esm/typings/src/utils/emojis.d.ts +2 -2
- package/esm/typings/src/utils/formatNumber.d.ts +1 -1
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +3 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/organization/TODO.d.ts +2 -0
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -0
- package/esm/typings/src/utils/organization/___.d.ts +2 -0
- package/esm/typings/src/utils/organization/just.d.ts +1 -0
- package/esm/typings/src/utils/organization/keepImported.d.ts +12 -0
- package/esm/typings/src/utils/organization/notUsing.d.ts +12 -0
- package/esm/typings/src/utils/organization/really_any.d.ts +2 -0
- package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/esm/typings/src/version.d.ts +3 -0
- package/package.json +2 -3
- package/umd/index.umd.js +763 -477
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +83 -2
- package/umd/typings/src/_packages/core.index.d.ts +2 -2
- package/umd/typings/src/_packages/types.index.d.ts +2 -2
- package/umd/typings/src/_packages/utils.index.d.ts +3 -1
- package/umd/typings/src/cli/cli-commands/hello.d.ts +3 -0
- package/umd/typings/src/cli/cli-commands/make.d.ts +3 -0
- package/umd/typings/src/cli/cli-commands/prettify.d.ts +3 -0
- package/umd/typings/src/cli/promptbookCli.d.ts +1 -0
- package/umd/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/umd/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +4 -1
- package/umd/typings/src/config.d.ts +4 -0
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +6 -0
- package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/{esm/typings/src/errors/VersionMismatch.d.ts → umd/typings/src/errors/VersionMismatchError.d.ts} +1 -1
- package/umd/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
- package/umd/typings/src/execution/LlmExecutionTools.d.ts +3 -1
- package/umd/typings/src/execution/PipelineExecutor.d.ts +4 -3
- package/umd/typings/src/execution/PromptResult.d.ts +12 -0
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -0
- package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -0
- package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +1 -0
- package/umd/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
- package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -0
- package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +22 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/personas/preparePersona.d.ts +4 -2
- package/umd/typings/src/prepare/preparePipeline.d.ts +3 -1
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
- package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
- package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
- package/umd/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
- package/umd/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
- package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
- package/umd/typings/src/types/ModelRequirements.d.ts +21 -1
- package/umd/typings/src/types/Parameters.d.ts +0 -1
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -2
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/umd/typings/src/types/PipelineString.d.ts +1 -1
- package/umd/typings/src/types/Prompt.d.ts +5 -2
- package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/umd/typings/src/types/typeAliases.d.ts +35 -1
- package/umd/typings/src/utils/emojis.d.ts +2 -2
- package/umd/typings/src/utils/formatNumber.d.ts +1 -1
- package/umd/typings/src/utils/isRunningInWhatever.d.ts +3 -0
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
- package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/umd/typings/src/utils/organization/TODO.d.ts +2 -0
- package/umd/typings/src/utils/organization/TODO_USE.d.ts +1 -0
- package/umd/typings/src/utils/organization/___.d.ts +2 -0
- package/umd/typings/src/utils/organization/just.d.ts +1 -0
- package/umd/typings/src/utils/organization/keepImported.d.ts +12 -0
- package/umd/typings/src/utils/organization/notUsing.d.ts +12 -0
- package/umd/typings/src/utils/organization/really_any.d.ts +2 -0
- package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/umd/typings/src/version.d.ts +3 -0
- package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
- package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
package/esm/index.es.js
CHANGED
|
@@ -2,12 +2,13 @@ import commander from 'commander';
|
|
|
2
2
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
3
3
|
import colors from 'colors';
|
|
4
4
|
import { forTime } from 'waitasecond';
|
|
5
|
-
import { access, constants, readFile, readdir, writeFile, mkdir } from 'fs/promises';
|
|
5
|
+
import { access, constants, readFile, readdir, stat, writeFile, mkdir, unlink } from 'fs/promises';
|
|
6
6
|
import { join, dirname } from 'path';
|
|
7
7
|
import { format } from 'prettier';
|
|
8
8
|
import parserHtml from 'prettier/parser-html';
|
|
9
|
+
import hexEncoder from 'crypto-js/enc-hex';
|
|
10
|
+
import sha256 from 'crypto-js/sha256';
|
|
9
11
|
import Anthropic from '@anthropic-ai/sdk';
|
|
10
|
-
import { LoremIpsum } from 'lorem-ipsum';
|
|
11
12
|
import OpenAI from 'openai';
|
|
12
13
|
import glob from 'glob-promise';
|
|
13
14
|
|
|
@@ -142,12 +143,18 @@ var isRunningInNode = new Function("\n try {\n return this === global;
|
|
|
142
143
|
* Detects if the code is running in a web worker
|
|
143
144
|
*/
|
|
144
145
|
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
146
|
+
/**
|
|
147
|
+
* TODO: [🔼] !!! Export via `@promptbook/utils`
|
|
148
|
+
*/
|
|
145
149
|
|
|
146
150
|
/**
|
|
147
151
|
* The version of the Promptbook library
|
|
148
152
|
*/
|
|
149
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
153
|
+
var PROMPTBOOK_VERSION = '0.61.0-11';
|
|
150
154
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
155
|
+
/**
|
|
156
|
+
* TODO: [🔼] !!! Export via `@promptbook/code`
|
|
157
|
+
*/
|
|
151
158
|
|
|
152
159
|
/**
|
|
153
160
|
* Initializes testing `hello` command for Promptbook CLI utilities
|
|
@@ -178,6 +185,9 @@ function initializeHelloCommand(program) {
|
|
|
178
185
|
});
|
|
179
186
|
});
|
|
180
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
190
|
+
*/
|
|
181
191
|
|
|
182
192
|
/**
|
|
183
193
|
* Converts PipelineCollection to serialized JSON
|
|
@@ -208,14 +218,14 @@ function collectionToJson(collection) {
|
|
|
208
218
|
* The maximum number of iterations for a loops
|
|
209
219
|
*/
|
|
210
220
|
var LOOP_LIMIT = 1000;
|
|
211
|
-
/**
|
|
212
|
-
* The maximum number of iterations for a loops which adds characters one by one
|
|
213
|
-
*/
|
|
214
|
-
var CHARACTER_LOOP_LIMIT = 100000;
|
|
215
221
|
/**
|
|
216
222
|
* The maximum number of (LLM) tasks running in parallel
|
|
217
223
|
*/
|
|
218
224
|
var MAX_PARALLEL_COUNT = 5;
|
|
225
|
+
/**
|
|
226
|
+
* The maximum length of the (generated) filename
|
|
227
|
+
*/
|
|
228
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
219
229
|
/**
|
|
220
230
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
221
231
|
*/
|
|
@@ -228,6 +238,10 @@ var RESERVED_PARAMETER_NAMES = [
|
|
|
228
238
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
229
239
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
230
240
|
];
|
|
241
|
+
/*
|
|
242
|
+
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
243
|
+
*/
|
|
244
|
+
// [🟡][🟢][🔵][⚪]
|
|
231
245
|
|
|
232
246
|
/**
|
|
233
247
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -394,7 +408,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
394
408
|
});
|
|
395
409
|
}
|
|
396
410
|
|
|
397
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
411
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {content}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{name:"make-model-requirements",title:"Make modelRequirements",dependentParameterNames:["availableModelNames","personaDescription"],blockType:"PROMPT_TEMPLATE",expectFormat:"JSON",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
398
412
|
|
|
399
413
|
/**
|
|
400
414
|
* Prettify the html code
|
|
@@ -634,7 +648,7 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
634
648
|
return parameterString;
|
|
635
649
|
}
|
|
636
650
|
/**
|
|
637
|
-
* TODO:
|
|
651
|
+
* TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
|
|
638
652
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
639
653
|
* TODO: Escape all
|
|
640
654
|
*/
|
|
@@ -1011,6 +1025,12 @@ function validatePipeline(pipeline) {
|
|
|
1011
1025
|
* > * - ...
|
|
1012
1026
|
* > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
|
|
1013
1027
|
*/
|
|
1028
|
+
/**
|
|
1029
|
+
* TODO: [🧠][🐣] !!!! Validate that all samples match expectations
|
|
1030
|
+
* TODO: [🧠][🐣] !!!! Validate that knowledge is valid (non-void)
|
|
1031
|
+
* TODO: [🧠] !!! Validationg not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1032
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1033
|
+
*/
|
|
1014
1034
|
|
|
1015
1035
|
/**
|
|
1016
1036
|
* This error indicates that promptbook not found in the collection
|
|
@@ -1051,7 +1071,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1051
1071
|
/**
|
|
1052
1072
|
* Constructs a pipeline collection from promptbooks
|
|
1053
1073
|
*
|
|
1054
|
-
* @param promptbooks
|
|
1074
|
+
* @param promptbooks @@@
|
|
1055
1075
|
*
|
|
1056
1076
|
* @private Use instead `createCollectionFromJson`
|
|
1057
1077
|
* Note: During the construction logic of all promptbooks are validated
|
|
@@ -1692,7 +1712,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1692
1712
|
};
|
|
1693
1713
|
/**
|
|
1694
1714
|
* List all available models that can be used
|
|
1695
|
-
* This
|
|
1715
|
+
* This lists is a combination of all available models from all execution tools
|
|
1696
1716
|
*/
|
|
1697
1717
|
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
1698
1718
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1738,6 +1758,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1738
1758
|
}());
|
|
1739
1759
|
/**
|
|
1740
1760
|
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
1761
|
+
* TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
|
|
1762
|
+
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
1741
1763
|
*/
|
|
1742
1764
|
|
|
1743
1765
|
/**
|
|
@@ -1911,27 +1933,6 @@ function checkExpectations(expectations, value) {
|
|
|
1911
1933
|
finally { if (e_1) throw e_1.error; }
|
|
1912
1934
|
}
|
|
1913
1935
|
}
|
|
1914
|
-
/**
|
|
1915
|
-
* Function checkExpectations will check if the expectations on given value are met
|
|
1916
|
-
*
|
|
1917
|
-
* Note: There are two simmilar functions:
|
|
1918
|
-
* - `checkExpectations` which throws an error if the expectations are not met
|
|
1919
|
-
* - `isPassingExpectations` which returns a boolean
|
|
1920
|
-
*
|
|
1921
|
-
* @returns {boolean} True if the expectations are met
|
|
1922
|
-
*/
|
|
1923
|
-
function isPassingExpectations(expectations, value) {
|
|
1924
|
-
try {
|
|
1925
|
-
checkExpectations(expectations, value);
|
|
1926
|
-
return true;
|
|
1927
|
-
}
|
|
1928
|
-
catch (error) {
|
|
1929
|
-
if (!(error instanceof ExpectError)) {
|
|
1930
|
-
throw error;
|
|
1931
|
-
}
|
|
1932
|
-
return false;
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
1936
|
/**
|
|
1936
1937
|
* TODO: [💝] Unite object for expecting amount and format
|
|
1937
1938
|
*/
|
|
@@ -2006,7 +2007,6 @@ function createPipelineExecutor(options) {
|
|
|
2006
2007
|
var _this = this;
|
|
2007
2008
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2008
2009
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
2009
|
-
// TODO: !!!!! Implement new commands
|
|
2010
2010
|
validatePipeline(pipeline);
|
|
2011
2011
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2012
2012
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -2082,7 +2082,10 @@ function createPipelineExecutor(options) {
|
|
|
2082
2082
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
2083
2083
|
parameters: parametersToPass,
|
|
2084
2084
|
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
2085
|
+
// <- TODO: !!!!! Apply {context} and knowledges
|
|
2086
|
+
// <- TODO: !!!!! Apply samples
|
|
2085
2087
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2088
|
+
// <- TODO: !!!!! Apply persona
|
|
2086
2089
|
expectations: currentTemplate.expectations,
|
|
2087
2090
|
expectFormat: currentTemplate.expectFormat,
|
|
2088
2091
|
postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -2529,10 +2532,12 @@ function createPipelineExecutor(options) {
|
|
|
2529
2532
|
}
|
|
2530
2533
|
/**
|
|
2531
2534
|
* TODO: [🪂] Pass maxParallelCount here
|
|
2535
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2532
2536
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2533
2537
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2534
2538
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2535
2539
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2540
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2536
2541
|
*/
|
|
2537
2542
|
|
|
2538
2543
|
/**
|
|
@@ -2543,6 +2548,7 @@ function createPipelineExecutor(options) {
|
|
|
2543
2548
|
*
|
|
2544
2549
|
* @param value any values
|
|
2545
2550
|
* @returns void
|
|
2551
|
+
* @private within the repository
|
|
2546
2552
|
*/
|
|
2547
2553
|
function TODO_USE() {
|
|
2548
2554
|
var value = [];
|
|
@@ -2550,7 +2556,6 @@ function TODO_USE() {
|
|
|
2550
2556
|
value[_i] = arguments[_i];
|
|
2551
2557
|
}
|
|
2552
2558
|
}
|
|
2553
|
-
// TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
|
|
2554
2559
|
|
|
2555
2560
|
/**
|
|
2556
2561
|
* @@@
|
|
@@ -2679,6 +2684,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
2679
2684
|
});
|
|
2680
2685
|
}
|
|
2681
2686
|
/**
|
|
2687
|
+
* TODO: [🔼] !!! Export via `@promptbook/markdown`
|
|
2682
2688
|
* TODO: [🪂] Do it in parallel 11:11
|
|
2683
2689
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2684
2690
|
*/
|
|
@@ -2687,7 +2693,6 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
2687
2693
|
* Prepares the knowle
|
|
2688
2694
|
*
|
|
2689
2695
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2690
|
-
* @private within the package
|
|
2691
2696
|
*/
|
|
2692
2697
|
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2693
2698
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -2702,7 +2707,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
2702
2707
|
var partialPieces, pieces;
|
|
2703
2708
|
return __generator(this, function (_a) {
|
|
2704
2709
|
switch (_a.label) {
|
|
2705
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2710
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!!!! Unhardcode markdown, detect which type it is
|
|
2706
2711
|
options)];
|
|
2707
2712
|
case 1:
|
|
2708
2713
|
partialPieces = _a.sent();
|
|
@@ -2740,6 +2745,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
2740
2745
|
> ):
|
|
2741
2746
|
*/
|
|
2742
2747
|
/**
|
|
2748
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2743
2749
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2744
2750
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2745
2751
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -2752,36 +2758,65 @@ TODO: [🧊] This is how it can look in future
|
|
|
2752
2758
|
* Prepares the persona for the pipeline
|
|
2753
2759
|
*
|
|
2754
2760
|
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2755
|
-
* @private within the package
|
|
2756
2761
|
*/
|
|
2757
2762
|
function preparePersona(personaDescription, options) {
|
|
2758
2763
|
return __awaiter(this, void 0, void 0, function () {
|
|
2759
|
-
var llmTools, _a,
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2764
|
+
var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
2765
|
+
var _c;
|
|
2766
|
+
return __generator(this, function (_d) {
|
|
2767
|
+
switch (_d.label) {
|
|
2768
|
+
case 0:
|
|
2769
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
2770
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2771
|
+
_b = createPipelineExecutor;
|
|
2772
|
+
_c = {};
|
|
2773
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
2774
|
+
case 1:
|
|
2775
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
2776
|
+
_c.tools = {
|
|
2777
|
+
llm: llmTools,
|
|
2778
|
+
},
|
|
2779
|
+
_c)]);
|
|
2780
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
2781
|
+
case 2:
|
|
2782
|
+
availableModels = _d.sent();
|
|
2783
|
+
availableModelNames = availableModels
|
|
2784
|
+
.filter(function (_a) {
|
|
2785
|
+
var modelVariant = _a.modelVariant;
|
|
2786
|
+
return modelVariant === 'CHAT';
|
|
2787
|
+
})
|
|
2788
|
+
.map(function (_a) {
|
|
2789
|
+
var modelName = _a.modelName;
|
|
2790
|
+
return modelName;
|
|
2791
|
+
})
|
|
2792
|
+
.join(',');
|
|
2793
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
2794
|
+
case 3:
|
|
2795
|
+
result = _d.sent();
|
|
2796
|
+
assertsExecutionSuccessful(result);
|
|
2797
|
+
outputParameters = result.outputParameters;
|
|
2798
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
2799
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
2800
|
+
if (isVerbose) {
|
|
2801
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
2802
|
+
}
|
|
2803
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
2804
|
+
return [2 /*return*/, {
|
|
2805
|
+
modelVariant: 'CHAT',
|
|
2806
|
+
modelName: modelName,
|
|
2807
|
+
systemMessage: systemMessage,
|
|
2808
|
+
temperature: temperature,
|
|
2809
|
+
}];
|
|
2810
|
+
}
|
|
2770
2811
|
});
|
|
2771
2812
|
});
|
|
2772
2813
|
}
|
|
2773
2814
|
/**
|
|
2774
|
-
* TODO: [
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
* Simple wrapper `new Date().toISOString()`
|
|
2779
|
-
*
|
|
2780
|
-
* @returns string_date branded type
|
|
2815
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2816
|
+
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
2817
|
+
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
2818
|
+
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
2781
2819
|
*/
|
|
2782
|
-
function $currentDate() {
|
|
2783
|
-
return new Date().toISOString();
|
|
2784
|
-
}
|
|
2785
2820
|
|
|
2786
2821
|
/**
|
|
2787
2822
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
@@ -2805,7 +2840,7 @@ function preparePipeline(pipeline, options) {
|
|
|
2805
2840
|
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
2806
2841
|
currentPreparation = {
|
|
2807
2842
|
id: 1,
|
|
2808
|
-
date: $currentDate(),
|
|
2843
|
+
// TODO: [🍥]> date: $currentDate(),
|
|
2809
2844
|
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2810
2845
|
modelUsage: addUsage(),
|
|
2811
2846
|
};
|
|
@@ -2814,8 +2849,8 @@ function preparePipeline(pipeline, options) {
|
|
|
2814
2849
|
// <- TODO: [🧊]
|
|
2815
2850
|
currentPreparation,
|
|
2816
2851
|
];
|
|
2817
|
-
preparedPersonas =
|
|
2818
|
-
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona) { return __awaiter(_this, void 0, void 0, function () {
|
|
2852
|
+
preparedPersonas = new Array(personas.length);
|
|
2853
|
+
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2819
2854
|
var modelRequirements, preparedPersona;
|
|
2820
2855
|
return __generator(this, function (_a) {
|
|
2821
2856
|
switch (_a.label) {
|
|
@@ -2823,7 +2858,7 @@ function preparePipeline(pipeline, options) {
|
|
|
2823
2858
|
case 1:
|
|
2824
2859
|
modelRequirements = _a.sent();
|
|
2825
2860
|
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
2826
|
-
preparedPersonas
|
|
2861
|
+
preparedPersonas[index] = preparedPersona;
|
|
2827
2862
|
return [2 /*return*/];
|
|
2828
2863
|
}
|
|
2829
2864
|
});
|
|
@@ -2842,11 +2877,186 @@ function preparePipeline(pipeline, options) {
|
|
|
2842
2877
|
});
|
|
2843
2878
|
}
|
|
2844
2879
|
/**
|
|
2880
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2845
2881
|
* TODO: Write tests for `preparePipeline`
|
|
2846
2882
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
2847
2883
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2848
|
-
* TODO: [
|
|
2884
|
+
* TODO: [🎐] !!!! Use here countTotalUsage
|
|
2885
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2886
|
+
*/
|
|
2887
|
+
|
|
2888
|
+
/**
|
|
2889
|
+
* Tests if given string is valid URL.
|
|
2890
|
+
*
|
|
2891
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
2892
|
+
*/
|
|
2893
|
+
function isValidFilePath(filePath) {
|
|
2894
|
+
if (typeof filePath !== 'string') {
|
|
2895
|
+
return false;
|
|
2896
|
+
}
|
|
2897
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
2898
|
+
// Absolute Unix path: /hello.txt
|
|
2899
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
2900
|
+
return true;
|
|
2901
|
+
}
|
|
2902
|
+
// Absolute Windows path: /hello.txt
|
|
2903
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
2904
|
+
return true;
|
|
2905
|
+
}
|
|
2906
|
+
// Relative path: ./hello.txt
|
|
2907
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
2908
|
+
return true;
|
|
2909
|
+
}
|
|
2910
|
+
return false;
|
|
2911
|
+
}
|
|
2912
|
+
|
|
2913
|
+
/**
|
|
2914
|
+
* Parses the knowledge command
|
|
2915
|
+
*
|
|
2916
|
+
* @see ./KNOWLEDGE-README.md for more details
|
|
2917
|
+
* @private within the commands folder
|
|
2918
|
+
*/
|
|
2919
|
+
var knowledgeCommandParser = {
|
|
2920
|
+
/**
|
|
2921
|
+
* Name of the command
|
|
2922
|
+
*/
|
|
2923
|
+
name: 'KNOWLEDGE',
|
|
2924
|
+
/**
|
|
2925
|
+
* BOILERPLATE command can be used in:
|
|
2926
|
+
*/
|
|
2927
|
+
usagePlaces: ['PIPELINE_HEAD'],
|
|
2928
|
+
/**
|
|
2929
|
+
* Description of the KNOWLEDGE command
|
|
2930
|
+
*/
|
|
2931
|
+
description: "Tells promptbook which external knowledge to use",
|
|
2932
|
+
/**
|
|
2933
|
+
* Link to discussion
|
|
2934
|
+
*/
|
|
2935
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
2936
|
+
/**
|
|
2937
|
+
* Example usages of the KNOWLEDGE command
|
|
2938
|
+
*/
|
|
2939
|
+
examples: [
|
|
2940
|
+
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
2941
|
+
'KNOWLEDGE ./hejny-cv.txt',
|
|
2942
|
+
'KNOWLEDGE ./hejny-cv.md',
|
|
2943
|
+
'KNOWLEDGE ./hejny-cv.pdf',
|
|
2944
|
+
'KNOWLEDGE ./hejny-cv.docx',
|
|
2945
|
+
],
|
|
2946
|
+
/**
|
|
2947
|
+
* Parses the KNOWLEDGE command
|
|
2948
|
+
*/
|
|
2949
|
+
parse: function (input) {
|
|
2950
|
+
var args = input.args;
|
|
2951
|
+
var source = args[0];
|
|
2952
|
+
if (source === undefined) {
|
|
2953
|
+
throw new ParsingError("Source is not defined");
|
|
2954
|
+
}
|
|
2955
|
+
if (source.startsWith('http://')) {
|
|
2956
|
+
throw new ParsingError("Source is not secure");
|
|
2957
|
+
}
|
|
2958
|
+
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
2959
|
+
throw new ParsingError("Source not valid");
|
|
2960
|
+
}
|
|
2961
|
+
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
2962
|
+
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
2963
|
+
}
|
|
2964
|
+
return {
|
|
2965
|
+
type: 'KNOWLEDGE',
|
|
2966
|
+
source: source,
|
|
2967
|
+
};
|
|
2968
|
+
},
|
|
2969
|
+
/**
|
|
2970
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
2971
|
+
*/
|
|
2972
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
2973
|
+
var source = personaCommand.source;
|
|
2974
|
+
var name = titleToName(source);
|
|
2975
|
+
pipelineJson.knowledgeSources.push({
|
|
2976
|
+
name: name,
|
|
2977
|
+
source: source,
|
|
2978
|
+
});
|
|
2979
|
+
},
|
|
2980
|
+
};
|
|
2981
|
+
|
|
2982
|
+
/**
|
|
2983
|
+
* Parses the persona command
|
|
2984
|
+
*
|
|
2985
|
+
* @see ./PERSONA-README.md for more details
|
|
2986
|
+
* @private within the commands folder
|
|
2849
2987
|
*/
|
|
2988
|
+
var personaCommandParser = {
|
|
2989
|
+
/**
|
|
2990
|
+
* Name of the command
|
|
2991
|
+
*/
|
|
2992
|
+
name: 'PERSONA',
|
|
2993
|
+
/**
|
|
2994
|
+
* Aliases for the PERSONA command
|
|
2995
|
+
*/
|
|
2996
|
+
aliasNames: ['PERSON'],
|
|
2997
|
+
/**
|
|
2998
|
+
* PERSONA command can be used in:
|
|
2999
|
+
*/
|
|
3000
|
+
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3001
|
+
/**
|
|
3002
|
+
* Description of the PERSONA command
|
|
3003
|
+
*/
|
|
3004
|
+
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3005
|
+
/**
|
|
3006
|
+
* Link to discussion
|
|
3007
|
+
*/
|
|
3008
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3009
|
+
/**
|
|
3010
|
+
* Example usages of the PERSONA command
|
|
3011
|
+
*/
|
|
3012
|
+
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3013
|
+
/**
|
|
3014
|
+
* Parses the PERSONA command
|
|
3015
|
+
*/
|
|
3016
|
+
parse: function (input) {
|
|
3017
|
+
var rawArgs = input.rawArgs;
|
|
3018
|
+
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3019
|
+
var personaName = (personaNameRaw || '').trim();
|
|
3020
|
+
if (personaName === '') {
|
|
3021
|
+
throw new ParsingError("You must set name for the persona");
|
|
3022
|
+
}
|
|
3023
|
+
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3024
|
+
if (personaDescription === '') {
|
|
3025
|
+
personaDescription = null;
|
|
3026
|
+
}
|
|
3027
|
+
return {
|
|
3028
|
+
type: 'PERSONA',
|
|
3029
|
+
personaName: personaName,
|
|
3030
|
+
personaDescription: personaDescription,
|
|
3031
|
+
};
|
|
3032
|
+
},
|
|
3033
|
+
/**
|
|
3034
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3035
|
+
*/
|
|
3036
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
3037
|
+
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
3038
|
+
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
3039
|
+
if (persona === undefined) {
|
|
3040
|
+
pipelineJson.personas.push({
|
|
3041
|
+
name: personaName,
|
|
3042
|
+
description: personaDescription || '',
|
|
3043
|
+
});
|
|
3044
|
+
return;
|
|
3045
|
+
}
|
|
3046
|
+
if (persona.description === personaDescription) {
|
|
3047
|
+
return;
|
|
3048
|
+
}
|
|
3049
|
+
if (personaDescription === null) {
|
|
3050
|
+
return;
|
|
3051
|
+
}
|
|
3052
|
+
if (persona.description === '') {
|
|
3053
|
+
persona.description = personaDescription;
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3056
|
+
console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
3057
|
+
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
3058
|
+
},
|
|
3059
|
+
};
|
|
2850
3060
|
|
|
2851
3061
|
/**
|
|
2852
3062
|
* Removes Markdown formatting tags from a string.
|
|
@@ -3003,7 +3213,7 @@ var blockCommandParser = {
|
|
|
3003
3213
|
'Knowledge BLOCK',
|
|
3004
3214
|
// 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
|
|
3005
3215
|
//---
|
|
3006
|
-
/*
|
|
3216
|
+
/* Note: Not implemented block types will be in examples in future -> */
|
|
3007
3217
|
'Instrument BLOCK',
|
|
3008
3218
|
// 'Instrument', // <- Note: [⛱]
|
|
3009
3219
|
'Action BLOCK',
|
|
@@ -3019,13 +3229,12 @@ var blockCommandParser = {
|
|
|
3019
3229
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
3020
3230
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
3021
3231
|
if (blockTypes.length !== 1) {
|
|
3022
|
-
// console.log('!!!', { blockType });
|
|
3023
3232
|
throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
3024
3233
|
}
|
|
3025
|
-
|
|
3234
|
+
var blockType = blockTypes[0];
|
|
3026
3235
|
return {
|
|
3027
3236
|
type: 'BLOCK',
|
|
3028
|
-
blockType:
|
|
3237
|
+
blockType: blockType,
|
|
3029
3238
|
};
|
|
3030
3239
|
},
|
|
3031
3240
|
};
|
|
@@ -3268,116 +3477,36 @@ var jokerCommandParser = {
|
|
|
3268
3477
|
},
|
|
3269
3478
|
};
|
|
3270
3479
|
|
|
3480
|
+
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3271
3481
|
/**
|
|
3272
|
-
*
|
|
3273
|
-
*
|
|
3274
|
-
*
|
|
3482
|
+
* TODO: [🧠][🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (simmilar that `user` identification is not here)
|
|
3483
|
+
* TODO: [🧠][💱] Add more model options: `stop_token`, `logit_bias`, `logprobs` (`top_logprobs`), `top_k`, `top_p`, `presence_penalty`, `frequency_penalty`, `bestOf`, `logitBias`, `logitBiasType`,...
|
|
3484
|
+
* [💱] Probbably keep using just `temperature` in Promptbook (not `top_k` and `top_p`)
|
|
3485
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3486
|
+
* TODO: Maybe figure out better word than "variant"
|
|
3487
|
+
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3488
|
+
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
3275
3489
|
*/
|
|
3276
|
-
function isValidFilePath(filePath) {
|
|
3277
|
-
if (typeof filePath !== 'string') {
|
|
3278
|
-
return false;
|
|
3279
|
-
}
|
|
3280
|
-
var filePathSlashes = filePath.split('\\').join('/');
|
|
3281
|
-
// Absolute Unix path: /hello.txt
|
|
3282
|
-
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3283
|
-
return true;
|
|
3284
|
-
}
|
|
3285
|
-
// Absolute Windows path: /hello.txt
|
|
3286
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3287
|
-
return true;
|
|
3288
|
-
}
|
|
3289
|
-
// Relative path: ./hello.txt
|
|
3290
|
-
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3291
|
-
return true;
|
|
3292
|
-
}
|
|
3293
|
-
return false;
|
|
3294
|
-
}
|
|
3295
3490
|
|
|
3296
3491
|
/**
|
|
3297
|
-
* Parses the
|
|
3492
|
+
* Parses the model command
|
|
3298
3493
|
*
|
|
3299
|
-
* @see ./
|
|
3494
|
+
* @see ./MODEL-README.md for more details
|
|
3300
3495
|
* @private within the commands folder
|
|
3301
3496
|
*/
|
|
3302
|
-
var
|
|
3497
|
+
var modelCommandParser = {
|
|
3303
3498
|
/**
|
|
3304
3499
|
* Name of the command
|
|
3305
3500
|
*/
|
|
3306
|
-
name: '
|
|
3501
|
+
name: 'MODEL',
|
|
3307
3502
|
/**
|
|
3308
3503
|
* BOILERPLATE command can be used in:
|
|
3309
3504
|
*/
|
|
3310
|
-
usagePlaces: ['PIPELINE_HEAD'],
|
|
3505
|
+
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3311
3506
|
/**
|
|
3312
|
-
* Description of the
|
|
3507
|
+
* Description of the MODEL command
|
|
3313
3508
|
*/
|
|
3314
|
-
description: "Tells
|
|
3315
|
-
/**
|
|
3316
|
-
* Link to discussion
|
|
3317
|
-
*/
|
|
3318
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3319
|
-
/**
|
|
3320
|
-
* Example usages of the KNOWLEDGE command
|
|
3321
|
-
*/
|
|
3322
|
-
examples: [
|
|
3323
|
-
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3324
|
-
'KNOWLEDGE ./hejny-cv.txt',
|
|
3325
|
-
'KNOWLEDGE ./hejny-cv.md',
|
|
3326
|
-
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3327
|
-
'KNOWLEDGE ./hejny-cv.docx',
|
|
3328
|
-
],
|
|
3329
|
-
/**
|
|
3330
|
-
* Parses the KNOWLEDGE command
|
|
3331
|
-
*/
|
|
3332
|
-
parse: function (input) {
|
|
3333
|
-
var args = input.args;
|
|
3334
|
-
var source = args[0];
|
|
3335
|
-
if (source === undefined) {
|
|
3336
|
-
throw new ParsingError("Source is not defined");
|
|
3337
|
-
}
|
|
3338
|
-
if (source.startsWith('http://')) {
|
|
3339
|
-
throw new ParsingError("Source is not secure");
|
|
3340
|
-
}
|
|
3341
|
-
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3342
|
-
throw new ParsingError("Source not valid");
|
|
3343
|
-
}
|
|
3344
|
-
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3345
|
-
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3346
|
-
}
|
|
3347
|
-
return {
|
|
3348
|
-
type: 'KNOWLEDGE',
|
|
3349
|
-
source: source,
|
|
3350
|
-
};
|
|
3351
|
-
},
|
|
3352
|
-
};
|
|
3353
|
-
|
|
3354
|
-
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3355
|
-
/**
|
|
3356
|
-
* TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
|
|
3357
|
-
* TODO: Maybe figure out better word than "variant"
|
|
3358
|
-
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3359
|
-
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
3360
|
-
*/
|
|
3361
|
-
|
|
3362
|
-
/**
|
|
3363
|
-
* Parses the model command
|
|
3364
|
-
*
|
|
3365
|
-
* @see ./MODEL-README.md for more details
|
|
3366
|
-
* @private within the commands folder
|
|
3367
|
-
*/
|
|
3368
|
-
var modelCommandParser = {
|
|
3369
|
-
/**
|
|
3370
|
-
* Name of the command
|
|
3371
|
-
*/
|
|
3372
|
-
name: 'MODEL',
|
|
3373
|
-
/**
|
|
3374
|
-
* BOILERPLATE command can be used in:
|
|
3375
|
-
*/
|
|
3376
|
-
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3377
|
-
/**
|
|
3378
|
-
* Description of the MODEL command
|
|
3379
|
-
*/
|
|
3380
|
-
description: "Tells which model and modelRequirements to use for the prompt template execution",
|
|
3509
|
+
description: "Tells which model and modelRequirements to use for the prompt template execution",
|
|
3381
3510
|
/**
|
|
3382
3511
|
* Link to discussion
|
|
3383
3512
|
*/
|
|
@@ -3495,59 +3624,6 @@ var parameterCommandParser = {
|
|
|
3495
3624
|
},
|
|
3496
3625
|
};
|
|
3497
3626
|
|
|
3498
|
-
/**
|
|
3499
|
-
* Parses the persona command
|
|
3500
|
-
*
|
|
3501
|
-
* @see ./PERSONA-README.md for more details
|
|
3502
|
-
* @private within the commands folder
|
|
3503
|
-
*/
|
|
3504
|
-
var personaCommandParser = {
|
|
3505
|
-
/**
|
|
3506
|
-
* Name of the command
|
|
3507
|
-
*/
|
|
3508
|
-
name: 'PERSONA',
|
|
3509
|
-
/**
|
|
3510
|
-
* Aliases for the PERSONA command
|
|
3511
|
-
*/
|
|
3512
|
-
aliasNames: ['PERSON'],
|
|
3513
|
-
/**
|
|
3514
|
-
* PERSONA command can be used in:
|
|
3515
|
-
*/
|
|
3516
|
-
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3517
|
-
/**
|
|
3518
|
-
* Description of the PERSONA command
|
|
3519
|
-
*/
|
|
3520
|
-
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3521
|
-
/**
|
|
3522
|
-
* Link to discussion
|
|
3523
|
-
*/
|
|
3524
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3525
|
-
/**
|
|
3526
|
-
* Example usages of the PERSONA command
|
|
3527
|
-
*/
|
|
3528
|
-
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3529
|
-
/**
|
|
3530
|
-
* Parses the PERSONA command
|
|
3531
|
-
*/
|
|
3532
|
-
parse: function (input) {
|
|
3533
|
-
var rawArgs = input.rawArgs;
|
|
3534
|
-
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3535
|
-
var personaName = (personaNameRaw || '').trim();
|
|
3536
|
-
if (personaName === '') {
|
|
3537
|
-
throw new ParsingError("You must set name for the persona");
|
|
3538
|
-
}
|
|
3539
|
-
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3540
|
-
if (personaDescription === '') {
|
|
3541
|
-
personaDescription = null;
|
|
3542
|
-
}
|
|
3543
|
-
return {
|
|
3544
|
-
type: 'PERSONA',
|
|
3545
|
-
personaName: personaName,
|
|
3546
|
-
personaDescription: personaDescription,
|
|
3547
|
-
};
|
|
3548
|
-
},
|
|
3549
|
-
};
|
|
3550
|
-
|
|
3551
3627
|
function isValidJavascriptName(javascriptName) {
|
|
3552
3628
|
if (typeof javascriptName !== 'string') {
|
|
3553
3629
|
return false;
|
|
@@ -3765,7 +3841,8 @@ var actionCommandParser = {
|
|
|
3765
3841
|
* Parses the ACTION command
|
|
3766
3842
|
*/
|
|
3767
3843
|
parse: function (input) {
|
|
3768
|
-
input.args;
|
|
3844
|
+
var args = input.args;
|
|
3845
|
+
TODO_USE(args);
|
|
3769
3846
|
return {
|
|
3770
3847
|
type: 'ACTION',
|
|
3771
3848
|
};
|
|
@@ -3803,7 +3880,8 @@ var instrumentCommandParser = {
|
|
|
3803
3880
|
* Parses the INSTRUMENT command
|
|
3804
3881
|
*/
|
|
3805
3882
|
parse: function (input) {
|
|
3806
|
-
input.args;
|
|
3883
|
+
var args = input.args;
|
|
3884
|
+
TODO_USE(args);
|
|
3807
3885
|
return {
|
|
3808
3886
|
type: 'INSTRUMENT',
|
|
3809
3887
|
};
|
|
@@ -3861,6 +3939,7 @@ var boilerplateCommandParser = {
|
|
|
3861
3939
|
};
|
|
3862
3940
|
/**
|
|
3863
3941
|
* TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
|
|
3942
|
+
* Note: [⚪] This should never be in any released package
|
|
3864
3943
|
*/
|
|
3865
3944
|
|
|
3866
3945
|
/**
|
|
@@ -3879,7 +3958,7 @@ var COMMANDS = [
|
|
|
3879
3958
|
actionCommandParser,
|
|
3880
3959
|
instrumentCommandParser,
|
|
3881
3960
|
personaCommandParser,
|
|
3882
|
-
boilerplateCommandParser, // <- TODO:
|
|
3961
|
+
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
3883
3962
|
];
|
|
3884
3963
|
|
|
3885
3964
|
/**
|
|
@@ -3965,7 +4044,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
3965
4044
|
}));
|
|
3966
4045
|
}
|
|
3967
4046
|
/**
|
|
3968
|
-
*
|
|
4047
|
+
* @@@
|
|
3969
4048
|
*/
|
|
3970
4049
|
function getSupportedCommandsMessage() {
|
|
3971
4050
|
return COMMANDS.flatMap(function (_a) {
|
|
@@ -3976,7 +4055,7 @@ function getSupportedCommandsMessage() {
|
|
|
3976
4055
|
}).join('\n');
|
|
3977
4056
|
}
|
|
3978
4057
|
/**
|
|
3979
|
-
*
|
|
4058
|
+
* @@@
|
|
3980
4059
|
*/
|
|
3981
4060
|
function parseCommandVariant(input) {
|
|
3982
4061
|
var e_1, _a;
|
|
@@ -3985,7 +4064,6 @@ function parseCommandVariant(input) {
|
|
|
3985
4064
|
var _loop_1 = function (commandParser) {
|
|
3986
4065
|
var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
3987
4066
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
3988
|
-
// console.log('!!!', { commandName, names });
|
|
3989
4067
|
if (names.includes(commandName)) {
|
|
3990
4068
|
try {
|
|
3991
4069
|
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
@@ -4095,25 +4173,42 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4095
4173
|
var e_1, _a;
|
|
4096
4174
|
var codeBlocks = [];
|
|
4097
4175
|
var lines = markdown.split('\n');
|
|
4176
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
4177
|
+
lines.push('');
|
|
4098
4178
|
var currentCodeBlock = null;
|
|
4099
4179
|
try {
|
|
4100
4180
|
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
4101
4181
|
var line = lines_1_1.value;
|
|
4182
|
+
if (line.startsWith('> ') || line === '>') {
|
|
4183
|
+
if (currentCodeBlock === null) {
|
|
4184
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
4185
|
+
} /* not else */
|
|
4186
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
4187
|
+
if (currentCodeBlock.content !== '') {
|
|
4188
|
+
currentCodeBlock.content += '\n';
|
|
4189
|
+
}
|
|
4190
|
+
currentCodeBlock.content += line.slice(2);
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
4194
|
+
codeBlocks.push(currentCodeBlock);
|
|
4195
|
+
currentCodeBlock = null;
|
|
4196
|
+
}
|
|
4197
|
+
/* not else */
|
|
4102
4198
|
if (line.startsWith('```')) {
|
|
4103
4199
|
var language = line.slice(3).trim() || null;
|
|
4104
4200
|
if (currentCodeBlock === null) {
|
|
4105
|
-
currentCodeBlock = { language: language, content: '' };
|
|
4201
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
4106
4202
|
}
|
|
4107
4203
|
else {
|
|
4108
4204
|
if (language !== null) {
|
|
4109
|
-
|
|
4110
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4205
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4111
4206
|
}
|
|
4112
4207
|
codeBlocks.push(currentCodeBlock);
|
|
4113
4208
|
currentCodeBlock = null;
|
|
4114
4209
|
}
|
|
4115
4210
|
}
|
|
4116
|
-
else if (currentCodeBlock !== null) {
|
|
4211
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
4117
4212
|
if (currentCodeBlock.content !== '') {
|
|
4118
4213
|
currentCodeBlock.content += '\n';
|
|
4119
4214
|
}
|
|
@@ -4129,11 +4224,13 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4129
4224
|
finally { if (e_1) throw e_1.error; }
|
|
4130
4225
|
}
|
|
4131
4226
|
if (currentCodeBlock !== null) {
|
|
4132
|
-
|
|
4133
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4227
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4134
4228
|
}
|
|
4135
4229
|
return codeBlocks;
|
|
4136
4230
|
}
|
|
4231
|
+
/**
|
|
4232
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
4233
|
+
*/
|
|
4137
4234
|
|
|
4138
4235
|
/**
|
|
4139
4236
|
* Extracts exactly ONE code block from markdown.
|
|
@@ -4151,13 +4248,12 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4151
4248
|
function extractOneBlockFromMarkdown(markdown) {
|
|
4152
4249
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
4153
4250
|
if (codeBlocks.length !== 1) {
|
|
4154
|
-
|
|
4155
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
4251
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
4156
4252
|
}
|
|
4157
4253
|
return codeBlocks[0];
|
|
4158
4254
|
}
|
|
4159
4255
|
/***
|
|
4160
|
-
* TODO: [🍓][🌻]
|
|
4256
|
+
* TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
|
|
4161
4257
|
*/
|
|
4162
4258
|
|
|
4163
4259
|
/**
|
|
@@ -4167,13 +4263,13 @@ function parseMarkdownSection(value) {
|
|
|
4167
4263
|
var _a, _b;
|
|
4168
4264
|
var lines = value.split('\n');
|
|
4169
4265
|
if (!lines[0].startsWith('#')) {
|
|
4170
|
-
throw new
|
|
4266
|
+
throw new ParsingError('Markdown section must start with heading');
|
|
4171
4267
|
}
|
|
4172
4268
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
4173
4269
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
4174
4270
|
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
4175
4271
|
if (level < 1 || level > 6) {
|
|
4176
|
-
throw new
|
|
4272
|
+
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
4177
4273
|
}
|
|
4178
4274
|
return { title: title, level: level, content: content };
|
|
4179
4275
|
}
|
|
@@ -4555,7 +4651,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4555
4651
|
existingParameter.description &&
|
|
4556
4652
|
existingParameter.description !== parameterDescription &&
|
|
4557
4653
|
parameterDescription) {
|
|
4558
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description
|
|
4654
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
4559
4655
|
}
|
|
4560
4656
|
if (existingParameter) {
|
|
4561
4657
|
if (parameterDescription) {
|
|
@@ -4574,11 +4670,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4574
4670
|
// =============================================================
|
|
4575
4671
|
// Note: 3️⃣ Process pipeline head
|
|
4576
4672
|
pipelineJson.title = pipelineHead.title;
|
|
4577
|
-
// TODO: [1] DRY description
|
|
4673
|
+
// TODO: [🎾][1] DRY description
|
|
4578
4674
|
var description = pipelineHead.content;
|
|
4579
|
-
// Note: Remove codeblocks - TODO:
|
|
4675
|
+
// Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
|
|
4580
4676
|
description = description.split(/^```.*^```/gms).join('');
|
|
4581
|
-
|
|
4677
|
+
description = description.split(/^>.*$/gm).join('');
|
|
4678
|
+
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
4582
4679
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4583
4680
|
description = spaceTrim$1(description);
|
|
4584
4681
|
if (description === '') {
|
|
@@ -4606,7 +4703,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4606
4703
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4607
4704
|
break;
|
|
4608
4705
|
case 'KNOWLEDGE':
|
|
4609
|
-
|
|
4706
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4610
4707
|
break;
|
|
4611
4708
|
case 'ACTION':
|
|
4612
4709
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4615,7 +4712,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4615
4712
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4616
4713
|
break;
|
|
4617
4714
|
case 'PERSONA':
|
|
4618
|
-
|
|
4715
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4716
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4619
4717
|
break;
|
|
4620
4718
|
case 'BOILERPLATE':
|
|
4621
4719
|
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
@@ -4644,7 +4742,27 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4644
4742
|
var postprocessing = [];
|
|
4645
4743
|
var expectAmount = {};
|
|
4646
4744
|
var expectFormat = undefined;
|
|
4647
|
-
var
|
|
4745
|
+
var isBlockTypeSet = false;
|
|
4746
|
+
var lastLine = section.content.split('\n').pop();
|
|
4747
|
+
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4748
|
+
var resultingParameterName = null;
|
|
4749
|
+
if (resultingParameterNameMatch &&
|
|
4750
|
+
resultingParameterNameMatch.groups !== undefined &&
|
|
4751
|
+
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
4752
|
+
resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
4753
|
+
}
|
|
4754
|
+
var expectResultingParameterName = function () {
|
|
4755
|
+
if (resultingParameterName !== null) {
|
|
4756
|
+
return resultingParameterName;
|
|
4757
|
+
}
|
|
4758
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4759
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
4760
|
+
section.content
|
|
4761
|
+
.split('\n')
|
|
4762
|
+
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4763
|
+
.join('\n')), "\n "); }));
|
|
4764
|
+
};
|
|
4765
|
+
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4648
4766
|
try {
|
|
4649
4767
|
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
4650
4768
|
var listItem = listItems_2_1.value;
|
|
@@ -4652,15 +4770,24 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4652
4770
|
switch (command.type) {
|
|
4653
4771
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4654
4772
|
case 'BLOCK':
|
|
4655
|
-
if (
|
|
4773
|
+
if (isBlockTypeSet) {
|
|
4656
4774
|
throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
|
|
4657
4775
|
}
|
|
4658
4776
|
if (command.blockType === 'SAMPLE') {
|
|
4659
|
-
|
|
4777
|
+
expectResultingParameterName();
|
|
4778
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
4779
|
+
if (parameter === undefined) {
|
|
4780
|
+
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
4781
|
+
}
|
|
4782
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
4783
|
+
parameter.sampleValues.push(content);
|
|
4660
4784
|
return "continue-templates";
|
|
4661
4785
|
}
|
|
4662
4786
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4663
|
-
|
|
4787
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, {
|
|
4788
|
+
type: 'KNOWLEDGE',
|
|
4789
|
+
source: content, // <- TODO: [🐝] !!!! Work with KNOWLEDGE which not referring to the source file/wweb, but its content itself
|
|
4790
|
+
});
|
|
4664
4791
|
return "continue-templates";
|
|
4665
4792
|
}
|
|
4666
4793
|
if (command.blockType === 'ACTION') {
|
|
@@ -4671,8 +4798,9 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4671
4798
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4672
4799
|
return "continue-templates";
|
|
4673
4800
|
}
|
|
4801
|
+
expectResultingParameterName();
|
|
4674
4802
|
blockType = command.blockType;
|
|
4675
|
-
|
|
4803
|
+
isBlockTypeSet = true;
|
|
4676
4804
|
break;
|
|
4677
4805
|
case 'EXPECT_AMOUNT':
|
|
4678
4806
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -4712,16 +4840,20 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4712
4840
|
postprocessing.push(command.functionName);
|
|
4713
4841
|
break;
|
|
4714
4842
|
case 'KNOWLEDGE':
|
|
4715
|
-
|
|
4843
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
4844
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4716
4845
|
break;
|
|
4717
4846
|
case 'ACTION':
|
|
4847
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
4718
4848
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4719
4849
|
break;
|
|
4720
4850
|
case 'INSTRUMENT':
|
|
4851
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
4721
4852
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4722
4853
|
break;
|
|
4723
4854
|
case 'PERSONA':
|
|
4724
|
-
|
|
4855
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4856
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4725
4857
|
break;
|
|
4726
4858
|
case 'BOILERPLATE':
|
|
4727
4859
|
console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
|
|
@@ -4739,7 +4871,6 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4739
4871
|
}
|
|
4740
4872
|
finally { if (e_3) throw e_3.error; }
|
|
4741
4873
|
}
|
|
4742
|
-
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4743
4874
|
if (blockType === 'SCRIPT') {
|
|
4744
4875
|
if (!language) {
|
|
4745
4876
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
@@ -4748,22 +4879,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4748
4879
|
throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
4749
4880
|
}
|
|
4750
4881
|
}
|
|
4751
|
-
|
|
4752
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4753
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
4754
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4755
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
4756
|
-
section.content
|
|
4757
|
-
.split('\n')
|
|
4758
|
-
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4759
|
-
.join('\n')), "\n "); }));
|
|
4760
|
-
}
|
|
4761
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
4762
|
-
// TODO: [1] DRY description
|
|
4882
|
+
// TODO: [🎾][1] DRY description
|
|
4763
4883
|
var description_1 = section.content;
|
|
4764
|
-
// Note: Remove codeblocks
|
|
4884
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
4765
4885
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
4766
|
-
|
|
4886
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
4887
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
4767
4888
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4768
4889
|
description_1 = spaceTrim$1(description_1);
|
|
4769
4890
|
if (description_1 === '') {
|
|
@@ -4797,13 +4918,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4797
4918
|
modelRequirements: templateModelRequirements,
|
|
4798
4919
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4799
4920
|
content: content,
|
|
4800
|
-
resultingParameterName:
|
|
4921
|
+
resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
|
|
4801
4922
|
};
|
|
4802
4923
|
if (blockType !== 'PROMPT_TEMPLATE') {
|
|
4803
4924
|
delete template.modelRequirements;
|
|
4804
4925
|
}
|
|
4805
4926
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
4806
|
-
pipelineJson.promptTemplates.push(template
|
|
4927
|
+
pipelineJson.promptTemplates.push(template);
|
|
4807
4928
|
};
|
|
4808
4929
|
try {
|
|
4809
4930
|
// =============================================================
|
|
@@ -4870,6 +4991,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4870
4991
|
* TODO: Use spaceTrim more effectively
|
|
4871
4992
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
4872
4993
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
4994
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
4995
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4873
4996
|
*/
|
|
4874
4997
|
|
|
4875
4998
|
/**
|
|
@@ -4909,6 +5032,7 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
4909
5032
|
}
|
|
4910
5033
|
/**
|
|
4911
5034
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
5035
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4912
5036
|
*/
|
|
4913
5037
|
|
|
4914
5038
|
/**
|
|
@@ -5042,6 +5166,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
5042
5166
|
else {
|
|
5043
5167
|
colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
|
|
5044
5168
|
// TODO: !! Implement;
|
|
5169
|
+
// TODO: [🌗]
|
|
5045
5170
|
}
|
|
5046
5171
|
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
|
|
5047
5172
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -5086,6 +5211,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
5086
5211
|
case 5:
|
|
5087
5212
|
// TODO: Handle non-valid JSON files
|
|
5088
5213
|
promptbook = _d.apply(_c, [_e.sent()]);
|
|
5214
|
+
// TODO: [🌗]
|
|
5089
5215
|
promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
|
|
5090
5216
|
return [3 /*break*/, 7];
|
|
5091
5217
|
case 6:
|
|
@@ -5232,6 +5358,126 @@ function listAllFiles(path, isRecursive) {
|
|
|
5232
5358
|
}
|
|
5233
5359
|
/**
|
|
5234
5360
|
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
5361
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
5362
|
+
*/
|
|
5363
|
+
|
|
5364
|
+
/**
|
|
5365
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
5366
|
+
*/
|
|
5367
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
5368
|
+
__extends(EnvironmentMismatchError, _super);
|
|
5369
|
+
function EnvironmentMismatchError(message) {
|
|
5370
|
+
var _this = _super.call(this, message) || this;
|
|
5371
|
+
_this.name = 'EnvironmentMismatchError';
|
|
5372
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
5373
|
+
return _this;
|
|
5374
|
+
}
|
|
5375
|
+
return EnvironmentMismatchError;
|
|
5376
|
+
}(Error));
|
|
5377
|
+
|
|
5378
|
+
/**
|
|
5379
|
+
* @@@
|
|
5380
|
+
*
|
|
5381
|
+
* @private for `FilesStorage`
|
|
5382
|
+
*/
|
|
5383
|
+
function nameToSubfolderPath(name) {
|
|
5384
|
+
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
5385
|
+
}
|
|
5386
|
+
|
|
5387
|
+
/**
|
|
5388
|
+
* @@@
|
|
5389
|
+
*/
|
|
5390
|
+
var FilesStorage = /** @class */ (function () {
|
|
5391
|
+
function FilesStorage(options) {
|
|
5392
|
+
this.options = options;
|
|
5393
|
+
if (!isRunningInNode()) {
|
|
5394
|
+
throw new EnvironmentMismatchError("FilesStorage works only in Node.js environment");
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
/**
|
|
5398
|
+
* @@@
|
|
5399
|
+
*/
|
|
5400
|
+
FilesStorage.prototype.getFilenameForKey = function (key) {
|
|
5401
|
+
var name = titleToName(key);
|
|
5402
|
+
var hash = sha256(hexEncoder.parse(name)).toString( /* hex */);
|
|
5403
|
+
return join.apply(void 0, __spreadArray(__spreadArray([this.options.cacheFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
|
|
5404
|
+
};
|
|
5405
|
+
/**
|
|
5406
|
+
* @@@ Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
5407
|
+
*/
|
|
5408
|
+
FilesStorage.prototype.getItem = function (key) {
|
|
5409
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5410
|
+
var filename, isFileExisting, fileContent, value;
|
|
5411
|
+
return __generator(this, function (_a) {
|
|
5412
|
+
switch (_a.label) {
|
|
5413
|
+
case 0:
|
|
5414
|
+
filename = this.getFilenameForKey(key);
|
|
5415
|
+
return [4 /*yield*/, stat(filename)
|
|
5416
|
+
.then(function (fileStat) { return fileStat.isFile(); })
|
|
5417
|
+
.catch(function () { return false; })];
|
|
5418
|
+
case 1:
|
|
5419
|
+
isFileExisting = _a.sent();
|
|
5420
|
+
if (!isFileExisting) {
|
|
5421
|
+
return [2 /*return*/, null];
|
|
5422
|
+
}
|
|
5423
|
+
return [4 /*yield*/, readFile(filename, 'utf-8')];
|
|
5424
|
+
case 2:
|
|
5425
|
+
fileContent = _a.sent();
|
|
5426
|
+
value = JSON.parse(fileContent);
|
|
5427
|
+
// TODO: [🌗]
|
|
5428
|
+
return [2 /*return*/, value];
|
|
5429
|
+
}
|
|
5430
|
+
});
|
|
5431
|
+
});
|
|
5432
|
+
};
|
|
5433
|
+
/**
|
|
5434
|
+
* @@@ Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
5435
|
+
*/
|
|
5436
|
+
FilesStorage.prototype.setItem = function (key, value) {
|
|
5437
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5438
|
+
var filename, fileContent;
|
|
5439
|
+
return __generator(this, function (_a) {
|
|
5440
|
+
switch (_a.label) {
|
|
5441
|
+
case 0:
|
|
5442
|
+
filename = this.getFilenameForKey(key);
|
|
5443
|
+
fileContent = JSON.stringify(value, null, 4);
|
|
5444
|
+
return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
|
|
5445
|
+
case 1:
|
|
5446
|
+
_a.sent(); // <- [0]
|
|
5447
|
+
return [4 /*yield*/, writeFile(filename, fileContent, 'utf-8')];
|
|
5448
|
+
case 2:
|
|
5449
|
+
_a.sent();
|
|
5450
|
+
return [2 /*return*/];
|
|
5451
|
+
}
|
|
5452
|
+
});
|
|
5453
|
+
});
|
|
5454
|
+
};
|
|
5455
|
+
/**
|
|
5456
|
+
* @@@ Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
5457
|
+
*/
|
|
5458
|
+
FilesStorage.prototype.removeItem = function (key) {
|
|
5459
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5460
|
+
var filename;
|
|
5461
|
+
return __generator(this, function (_a) {
|
|
5462
|
+
switch (_a.label) {
|
|
5463
|
+
case 0:
|
|
5464
|
+
filename = this.getFilenameForKey(key);
|
|
5465
|
+
// TODO: [🧠] What to use `unlink` or `rm`
|
|
5466
|
+
return [4 /*yield*/, unlink(filename)];
|
|
5467
|
+
case 1:
|
|
5468
|
+
// TODO: [🧠] What to use `unlink` or `rm`
|
|
5469
|
+
_a.sent();
|
|
5470
|
+
return [2 /*return*/];
|
|
5471
|
+
}
|
|
5472
|
+
});
|
|
5473
|
+
});
|
|
5474
|
+
};
|
|
5475
|
+
return FilesStorage;
|
|
5476
|
+
}());
|
|
5477
|
+
/**
|
|
5478
|
+
* TODO: [🔼] !!! Export via `@promptbook/node`
|
|
5479
|
+
* TODO: [🌗] Maybe some checkers, not all valid JSONs are desired and valid values
|
|
5480
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
5235
5481
|
*/
|
|
5236
5482
|
|
|
5237
5483
|
/**
|
|
@@ -5279,7 +5525,7 @@ function getCurrentIsoDate() {
|
|
|
5279
5525
|
/**
|
|
5280
5526
|
* Function computeUsage will create price per one token based on the string value found on openai page
|
|
5281
5527
|
*
|
|
5282
|
-
* @private within the
|
|
5528
|
+
* @private within the repository, used only as internal helper for `OPENAI_MODELS`
|
|
5283
5529
|
*/
|
|
5284
5530
|
function computeUsage(value) {
|
|
5285
5531
|
var _a = __read(value.split(' / '), 2), price = _a[0], tokens = _a[1];
|
|
@@ -5352,7 +5598,7 @@ var ANTHROPIC_CLAUDE_MODELS = [
|
|
|
5352
5598
|
];
|
|
5353
5599
|
/**
|
|
5354
5600
|
* Note: [🤖] Add models of new variant
|
|
5355
|
-
* TODO:
|
|
5601
|
+
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
5356
5602
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
5357
5603
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
5358
5604
|
* TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
|
|
@@ -5410,6 +5656,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5410
5656
|
model: modelRequirements.modelName || this.getDefaultChatModel().modelName,
|
|
5411
5657
|
max_tokens: modelRequirements.maxTokens || 4096,
|
|
5412
5658
|
// <- TODO: Make some global max cap for maxTokens
|
|
5659
|
+
// <- TODO: !!!!! Use here `systemMessage`, `temperature` and `seed`
|
|
5413
5660
|
messages: [
|
|
5414
5661
|
{
|
|
5415
5662
|
role: 'user',
|
|
@@ -5479,6 +5726,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5479
5726
|
model: rawResponse.model || model,
|
|
5480
5727
|
max_tokens: modelRequirements.maxTokens || 2000, // <- Note: 2000 is for lagacy reasons
|
|
5481
5728
|
// <- TODO: Make some global max cap for maxTokens
|
|
5729
|
+
// <- TODO: Use here `systemMessage`, `temperature` and `seed`
|
|
5482
5730
|
};
|
|
5483
5731
|
|
|
5484
5732
|
const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
|
|
@@ -5565,201 +5813,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
5565
5813
|
* TODO: [🧠] Maybe handle errors via transformAnthropicError (like transformAzureError)
|
|
5566
5814
|
* TODO: Maybe Create some common util for callChatModel and callCompletionModel
|
|
5567
5815
|
* TODO: Maybe make custom OpenaiError
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
/**
|
|
5571
|
-
* Gets the expectations and creates a fake text that meets the expectations
|
|
5572
|
-
*
|
|
5573
|
-
* Note: You can provide postprocessing functions to modify the text before checking the expectations
|
|
5574
|
-
* The result will be the text BEFORE the postprocessing
|
|
5575
|
-
*
|
|
5576
|
-
* @private internal util for MockedFackedLlmExecutionTools
|
|
5577
|
-
*/
|
|
5578
|
-
function $fakeTextToExpectations(expectations, postprocessing) {
|
|
5579
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
5580
|
-
var lorem, loremText, text, loopLimit, textToCheck, _a, _b, func, e_1_1;
|
|
5581
|
-
var e_1, _c;
|
|
5582
|
-
return __generator(this, function (_d) {
|
|
5583
|
-
switch (_d.label) {
|
|
5584
|
-
case 0:
|
|
5585
|
-
lorem = new LoremIpsum({
|
|
5586
|
-
wordsPerSentence: { min: 5, max: 15 },
|
|
5587
|
-
sentencesPerParagraph: { min: 5, max: 15 },
|
|
5588
|
-
});
|
|
5589
|
-
loremText = '';
|
|
5590
|
-
text = '';
|
|
5591
|
-
loopLimit = CHARACTER_LOOP_LIMIT;
|
|
5592
|
-
_d.label = 1;
|
|
5593
|
-
case 1:
|
|
5594
|
-
if (!(loopLimit-- > 0)) return [3 /*break*/, 11];
|
|
5595
|
-
textToCheck = text;
|
|
5596
|
-
_d.label = 2;
|
|
5597
|
-
case 2:
|
|
5598
|
-
_d.trys.push([2, 7, 8, 9]);
|
|
5599
|
-
_a = (e_1 = void 0, __values(postprocessing || [])), _b = _a.next();
|
|
5600
|
-
_d.label = 3;
|
|
5601
|
-
case 3:
|
|
5602
|
-
if (!!_b.done) return [3 /*break*/, 6];
|
|
5603
|
-
func = _b.value;
|
|
5604
|
-
return [4 /*yield*/, func(textToCheck)];
|
|
5605
|
-
case 4:
|
|
5606
|
-
textToCheck = _d.sent();
|
|
5607
|
-
_d.label = 5;
|
|
5608
|
-
case 5:
|
|
5609
|
-
_b = _a.next();
|
|
5610
|
-
return [3 /*break*/, 3];
|
|
5611
|
-
case 6: return [3 /*break*/, 9];
|
|
5612
|
-
case 7:
|
|
5613
|
-
e_1_1 = _d.sent();
|
|
5614
|
-
e_1 = { error: e_1_1 };
|
|
5615
|
-
return [3 /*break*/, 9];
|
|
5616
|
-
case 8:
|
|
5617
|
-
try {
|
|
5618
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
5619
|
-
}
|
|
5620
|
-
finally { if (e_1) throw e_1.error; }
|
|
5621
|
-
return [7 /*endfinally*/];
|
|
5622
|
-
case 9:
|
|
5623
|
-
if (isPassingExpectations(expectations, textToCheck)) {
|
|
5624
|
-
return [2 /*return*/, text]; // <- Note: Returning the text because the postprocessing
|
|
5625
|
-
}
|
|
5626
|
-
if (loremText === '') {
|
|
5627
|
-
loremText = lorem.generateParagraphs(1) + '\n\n';
|
|
5628
|
-
}
|
|
5629
|
-
text += loremText.substring(0, 1);
|
|
5630
|
-
loremText = loremText.substring(1);
|
|
5631
|
-
_d.label = 10;
|
|
5632
|
-
case 10: return [3 /*break*/, 1];
|
|
5633
|
-
case 11: throw new Error(spaceTrim$1(function (block) { return "\n Can not generate fake text to met the expectations\n\n Loop limit reached\n The expectations:\n ".concat(block(JSON.stringify(expectations, null, 4)), "\n\n The draft text:\n ").concat(block(text), "\n\n "); }));
|
|
5634
|
-
}
|
|
5635
|
-
});
|
|
5636
|
-
});
|
|
5637
|
-
}
|
|
5638
|
-
/**
|
|
5639
|
-
* TODO: [💝] Unite object for expecting amount and format - use here also a format
|
|
5640
|
-
*/
|
|
5641
|
-
|
|
5642
|
-
/**
|
|
5643
|
-
* Mocked execution Tools for just faking expected responses for testing purposes
|
|
5644
|
-
*/
|
|
5645
|
-
var MockedFackedLlmExecutionTools = /** @class */ (function () {
|
|
5646
|
-
function MockedFackedLlmExecutionTools(options) {
|
|
5647
|
-
if (options === void 0) { options = {}; }
|
|
5648
|
-
this.options = options;
|
|
5649
|
-
}
|
|
5650
|
-
Object.defineProperty(MockedFackedLlmExecutionTools.prototype, "title", {
|
|
5651
|
-
get: function () {
|
|
5652
|
-
return 'Mocked facked';
|
|
5653
|
-
},
|
|
5654
|
-
enumerable: false,
|
|
5655
|
-
configurable: true
|
|
5656
|
-
});
|
|
5657
|
-
Object.defineProperty(MockedFackedLlmExecutionTools.prototype, "description", {
|
|
5658
|
-
get: function () {
|
|
5659
|
-
return 'Use faked lorem ipsum data - just for testing';
|
|
5660
|
-
},
|
|
5661
|
-
enumerable: false,
|
|
5662
|
-
configurable: true
|
|
5663
|
-
});
|
|
5664
|
-
/**
|
|
5665
|
-
* Fakes chat model
|
|
5666
|
-
*/
|
|
5667
|
-
MockedFackedLlmExecutionTools.prototype.callChatModel = function (prompt) {
|
|
5668
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
5669
|
-
var content, result;
|
|
5670
|
-
return __generator(this, function (_a) {
|
|
5671
|
-
switch (_a.label) {
|
|
5672
|
-
case 0:
|
|
5673
|
-
if (this.options.isVerbose) {
|
|
5674
|
-
console.info('💬 Mocked faked prompt', prompt);
|
|
5675
|
-
}
|
|
5676
|
-
return [4 /*yield*/, $fakeTextToExpectations(prompt.expectations || {
|
|
5677
|
-
sentences: { min: 1, max: 1 },
|
|
5678
|
-
}, prompt.postprocessing)];
|
|
5679
|
-
case 1:
|
|
5680
|
-
content = _a.sent();
|
|
5681
|
-
result = {
|
|
5682
|
-
content: content,
|
|
5683
|
-
modelName: 'mocked-facked',
|
|
5684
|
-
timing: {
|
|
5685
|
-
start: getCurrentIsoDate(),
|
|
5686
|
-
complete: getCurrentIsoDate(),
|
|
5687
|
-
},
|
|
5688
|
-
usage: addUsage( /* <- TODO: [🧠] Compute here at least words, characters,... etc */),
|
|
5689
|
-
rawResponse: {
|
|
5690
|
-
note: 'This is mocked echo',
|
|
5691
|
-
},
|
|
5692
|
-
// <- [🤹♂️]
|
|
5693
|
-
};
|
|
5694
|
-
if (this.options.isVerbose) {
|
|
5695
|
-
console.info('💬 Mocked faked result', result);
|
|
5696
|
-
}
|
|
5697
|
-
return [2 /*return*/, result];
|
|
5698
|
-
}
|
|
5699
|
-
});
|
|
5700
|
-
});
|
|
5701
|
-
};
|
|
5702
|
-
/**
|
|
5703
|
-
* Fakes completion model
|
|
5704
|
-
*/
|
|
5705
|
-
MockedFackedLlmExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
5706
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
5707
|
-
return __generator(this, function (_a) {
|
|
5708
|
-
return [2 /*return*/, this.callChatModel(prompt)];
|
|
5709
|
-
});
|
|
5710
|
-
});
|
|
5711
|
-
};
|
|
5712
|
-
/**
|
|
5713
|
-
* Fakes embedding model
|
|
5714
|
-
*/
|
|
5715
|
-
MockedFackedLlmExecutionTools.prototype.callEmbeddingModel = function (prompt) {
|
|
5716
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
5717
|
-
var content, result;
|
|
5718
|
-
return __generator(this, function (_a) {
|
|
5719
|
-
content = new Array(25).fill(0).map(function () { return Math.random() * 2 - 1; });
|
|
5720
|
-
result = {
|
|
5721
|
-
content: content,
|
|
5722
|
-
modelName: 'mocked-facked',
|
|
5723
|
-
timing: {
|
|
5724
|
-
start: getCurrentIsoDate(),
|
|
5725
|
-
complete: getCurrentIsoDate(),
|
|
5726
|
-
},
|
|
5727
|
-
usage: addUsage( /* <- TODO: [🧠] Compute here at least words, characters,... etc */),
|
|
5728
|
-
rawResponse: {
|
|
5729
|
-
note: 'This is mocked embedding',
|
|
5730
|
-
},
|
|
5731
|
-
// <- [🤹♂️]
|
|
5732
|
-
};
|
|
5733
|
-
if (this.options.isVerbose) {
|
|
5734
|
-
console.info('💬 Mocked faked result', result);
|
|
5735
|
-
}
|
|
5736
|
-
return [2 /*return*/, result];
|
|
5737
|
-
});
|
|
5738
|
-
});
|
|
5739
|
-
};
|
|
5740
|
-
// <- Note: [🤖] callXxxModel
|
|
5741
|
-
/**
|
|
5742
|
-
* List all available fake-models that can be used
|
|
5743
|
-
*/
|
|
5744
|
-
MockedFackedLlmExecutionTools.prototype.listModels = function () {
|
|
5745
|
-
return [
|
|
5746
|
-
{
|
|
5747
|
-
modelTitle: 'Fake chat',
|
|
5748
|
-
modelName: 'mocked-echo',
|
|
5749
|
-
modelVariant: 'CHAT',
|
|
5750
|
-
},
|
|
5751
|
-
{
|
|
5752
|
-
modelTitle: 'Fake completion',
|
|
5753
|
-
modelName: 'mocked-echo',
|
|
5754
|
-
modelVariant: 'COMPLETION',
|
|
5755
|
-
},
|
|
5756
|
-
// <- Note: [🤖]
|
|
5757
|
-
];
|
|
5758
|
-
};
|
|
5759
|
-
return MockedFackedLlmExecutionTools;
|
|
5760
|
-
}());
|
|
5761
|
-
/**
|
|
5762
|
-
* TODO: [🕵️♀️] Maybe just remove
|
|
5816
|
+
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
5763
5817
|
*/
|
|
5764
5818
|
|
|
5765
5819
|
/**
|
|
@@ -6109,6 +6163,7 @@ var OPENAI_MODELS = [
|
|
|
6109
6163
|
* @see /other/playground/playground.ts
|
|
6110
6164
|
* TODO: [🍓] Make better
|
|
6111
6165
|
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
6166
|
+
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
6112
6167
|
*/
|
|
6113
6168
|
|
|
6114
6169
|
/**
|
|
@@ -6200,6 +6255,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6200
6255
|
model: model,
|
|
6201
6256
|
max_tokens: modelRequirements.maxTokens,
|
|
6202
6257
|
// <- TODO: Make some global max cap for maxTokens
|
|
6258
|
+
// <- TODO: !!!!! Use here `systemMessage`, `temperature` and `seed`
|
|
6203
6259
|
};
|
|
6204
6260
|
if (expectFormat === 'JSON') {
|
|
6205
6261
|
modelSettings.response_format = {
|
|
@@ -6273,6 +6329,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6273
6329
|
model: model,
|
|
6274
6330
|
max_tokens: modelRequirements.maxTokens || 2000, // <- Note: 2000 is for lagacy reasons
|
|
6275
6331
|
// <- TODO: Make some global max cap for maxTokens
|
|
6332
|
+
// <- TODO: !!!!! Use here `systemMessage`, `temperature` and `seed`
|
|
6276
6333
|
};
|
|
6277
6334
|
rawRequest = __assign(__assign({}, modelSettings), { prompt: content, user: this.options.user });
|
|
6278
6335
|
start = getCurrentIsoDate();
|
|
@@ -6423,6 +6480,236 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
6423
6480
|
* TODO: [🧠][🧙♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
|
|
6424
6481
|
* TODO: Maybe Create some common util for callChatModel and callCompletionModel
|
|
6425
6482
|
* TODO: Maybe make custom OpenaiError
|
|
6483
|
+
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
6484
|
+
*/
|
|
6485
|
+
|
|
6486
|
+
/**
|
|
6487
|
+
* @@@
|
|
6488
|
+
*
|
|
6489
|
+
* Note: This function is not cached, every call creates new instance of LlmExecutionTools
|
|
6490
|
+
*
|
|
6491
|
+
* It looks for environment variables:
|
|
6492
|
+
* - `process.env.OPENAI_API_KEY`
|
|
6493
|
+
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
6494
|
+
*
|
|
6495
|
+
* @returns @@@
|
|
6496
|
+
*/
|
|
6497
|
+
function createLlmToolsFromEnv() {
|
|
6498
|
+
if (!isRunningInNode()) {
|
|
6499
|
+
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
6500
|
+
}
|
|
6501
|
+
var llmTools = [];
|
|
6502
|
+
if (typeof process.env.OPENAI_API_KEY === 'string') {
|
|
6503
|
+
llmTools.push(new OpenAiExecutionTools({
|
|
6504
|
+
isVerbose: true,
|
|
6505
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
6506
|
+
}));
|
|
6507
|
+
}
|
|
6508
|
+
if (typeof process.env.ANTHROPIC_CLAUDE_API_KEY === 'string') {
|
|
6509
|
+
llmTools.push(new AnthropicClaudeExecutionTools({
|
|
6510
|
+
isVerbose: true,
|
|
6511
|
+
apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
|
|
6512
|
+
}));
|
|
6513
|
+
}
|
|
6514
|
+
if (llmTools.length === 0) {
|
|
6515
|
+
throw new Error(spaceTrim("\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n "));
|
|
6516
|
+
}
|
|
6517
|
+
else if (llmTools.length === 1) {
|
|
6518
|
+
return llmTools[0];
|
|
6519
|
+
}
|
|
6520
|
+
else {
|
|
6521
|
+
return joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(llmTools), false));
|
|
6522
|
+
}
|
|
6523
|
+
}
|
|
6524
|
+
/**
|
|
6525
|
+
* TODO: [🔼] !!! Export via `@promptbook/node`
|
|
6526
|
+
* TODO: @@@ write discussion about this - wizzard
|
|
6527
|
+
* TODO: Add Azure
|
|
6528
|
+
* TODO: [🧠] Which name is better `createLlmToolsFromEnv` or `createLlmToolsFromEnvironment`?
|
|
6529
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
6530
|
+
* TODO: [🧠] Maybe pass env as argument
|
|
6531
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
6532
|
+
*/
|
|
6533
|
+
|
|
6534
|
+
/**
|
|
6535
|
+
* Stores
|
|
6536
|
+
*/
|
|
6537
|
+
var MemoryStorage = /** @class */ (function () {
|
|
6538
|
+
function MemoryStorage() {
|
|
6539
|
+
this.storage = {};
|
|
6540
|
+
}
|
|
6541
|
+
Object.defineProperty(MemoryStorage.prototype, "length", {
|
|
6542
|
+
/**
|
|
6543
|
+
* Returns the number of key/value pairs currently present in the list associated with the object.
|
|
6544
|
+
*/
|
|
6545
|
+
get: function () {
|
|
6546
|
+
return Object.keys(this.storage).length;
|
|
6547
|
+
},
|
|
6548
|
+
enumerable: false,
|
|
6549
|
+
configurable: true
|
|
6550
|
+
});
|
|
6551
|
+
/**
|
|
6552
|
+
* Empties the list associated with the object of all key/value pairs, if there are any.
|
|
6553
|
+
*/
|
|
6554
|
+
MemoryStorage.prototype.clear = function () {
|
|
6555
|
+
this.storage = {};
|
|
6556
|
+
};
|
|
6557
|
+
/**
|
|
6558
|
+
* Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
6559
|
+
*/
|
|
6560
|
+
MemoryStorage.prototype.getItem = function (key) {
|
|
6561
|
+
return this.storage[key] || null;
|
|
6562
|
+
};
|
|
6563
|
+
/**
|
|
6564
|
+
* Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
|
|
6565
|
+
*/
|
|
6566
|
+
MemoryStorage.prototype.key = function (index) {
|
|
6567
|
+
return Object.keys(this.storage)[index] || null;
|
|
6568
|
+
};
|
|
6569
|
+
/**
|
|
6570
|
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
6571
|
+
*/
|
|
6572
|
+
MemoryStorage.prototype.setItem = function (key, value) {
|
|
6573
|
+
this.storage[key] = value;
|
|
6574
|
+
};
|
|
6575
|
+
/**
|
|
6576
|
+
* Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
6577
|
+
*/
|
|
6578
|
+
MemoryStorage.prototype.removeItem = function (key) {
|
|
6579
|
+
delete this.storage[key];
|
|
6580
|
+
};
|
|
6581
|
+
return MemoryStorage;
|
|
6582
|
+
}());
|
|
6583
|
+
/**
|
|
6584
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
6585
|
+
*/
|
|
6586
|
+
|
|
6587
|
+
/**
|
|
6588
|
+
* Simple wrapper `new Date().toISOString()`
|
|
6589
|
+
*
|
|
6590
|
+
* @returns string_date branded type
|
|
6591
|
+
*/
|
|
6592
|
+
function $currentDate() {
|
|
6593
|
+
return new Date().toISOString();
|
|
6594
|
+
}
|
|
6595
|
+
|
|
6596
|
+
/**
|
|
6597
|
+
* Intercepts LLM tools and counts total usage of the tools
|
|
6598
|
+
*
|
|
6599
|
+
* @param llmTools LLM tools to be intercepted with usage counting
|
|
6600
|
+
* @returns LLM tools with same functionality with added total cost counting
|
|
6601
|
+
*/
|
|
6602
|
+
function cacheLlmTools(llmTools, options) {
|
|
6603
|
+
var _this = this;
|
|
6604
|
+
if (options === void 0) { options = {}; }
|
|
6605
|
+
var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a;
|
|
6606
|
+
var proxyTools = {
|
|
6607
|
+
get title() {
|
|
6608
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
6609
|
+
return llmTools.title;
|
|
6610
|
+
},
|
|
6611
|
+
get description() {
|
|
6612
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
6613
|
+
return llmTools.description;
|
|
6614
|
+
},
|
|
6615
|
+
listModels: function () {
|
|
6616
|
+
// TODO: [🧠] Should be model listing also cached?
|
|
6617
|
+
return /* not await */ llmTools.listModels();
|
|
6618
|
+
},
|
|
6619
|
+
};
|
|
6620
|
+
var callCommonModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6621
|
+
var key, cacheItem, promptResult, _a;
|
|
6622
|
+
return __generator(this, function (_b) {
|
|
6623
|
+
switch (_b.label) {
|
|
6624
|
+
case 0:
|
|
6625
|
+
key = titleToName(prompt.title.substring(0, MAX_FILENAME_LENGTH - 10) +
|
|
6626
|
+
'-' +
|
|
6627
|
+
sha256(hexEncoder.parse(JSON.stringify(prompt.parameters))).toString( /* hex */));
|
|
6628
|
+
return [4 /*yield*/, storage.getItem(key)];
|
|
6629
|
+
case 1:
|
|
6630
|
+
cacheItem = _b.sent();
|
|
6631
|
+
if (cacheItem) {
|
|
6632
|
+
return [2 /*return*/, cacheItem.promptResult];
|
|
6633
|
+
}
|
|
6634
|
+
_a = prompt.modelRequirements.modelVariant;
|
|
6635
|
+
switch (_a) {
|
|
6636
|
+
case 'CHAT': return [3 /*break*/, 2];
|
|
6637
|
+
case 'COMPLETION': return [3 /*break*/, 4];
|
|
6638
|
+
case 'EMBEDDING': return [3 /*break*/, 6];
|
|
6639
|
+
}
|
|
6640
|
+
return [3 /*break*/, 8];
|
|
6641
|
+
case 2: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
6642
|
+
case 3:
|
|
6643
|
+
promptResult = _b.sent();
|
|
6644
|
+
return [3 /*break*/, 9];
|
|
6645
|
+
case 4: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
6646
|
+
case 5:
|
|
6647
|
+
promptResult = _b.sent();
|
|
6648
|
+
return [3 /*break*/, 9];
|
|
6649
|
+
case 6: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
6650
|
+
case 7:
|
|
6651
|
+
promptResult = _b.sent();
|
|
6652
|
+
return [3 /*break*/, 9];
|
|
6653
|
+
case 8: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
|
|
6654
|
+
case 9: return [4 /*yield*/, storage.setItem(key, {
|
|
6655
|
+
date: $currentDate(),
|
|
6656
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
6657
|
+
prompt: prompt,
|
|
6658
|
+
promptResult: promptResult,
|
|
6659
|
+
})];
|
|
6660
|
+
case 10:
|
|
6661
|
+
_b.sent();
|
|
6662
|
+
return [2 /*return*/, promptResult];
|
|
6663
|
+
}
|
|
6664
|
+
});
|
|
6665
|
+
}); };
|
|
6666
|
+
if (llmTools.callChatModel !== undefined) {
|
|
6667
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6668
|
+
return __generator(this, function (_a) {
|
|
6669
|
+
return [2 /*return*/, /* not await */ callCommonModel(prompt)];
|
|
6670
|
+
});
|
|
6671
|
+
}); };
|
|
6672
|
+
}
|
|
6673
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
6674
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6675
|
+
return __generator(this, function (_a) {
|
|
6676
|
+
return [2 /*return*/, /* not await */ callCommonModel(prompt)];
|
|
6677
|
+
});
|
|
6678
|
+
}); };
|
|
6679
|
+
}
|
|
6680
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
6681
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6682
|
+
return __generator(this, function (_a) {
|
|
6683
|
+
return [2 /*return*/, /* not await */ callCommonModel(prompt)];
|
|
6684
|
+
});
|
|
6685
|
+
}); };
|
|
6686
|
+
}
|
|
6687
|
+
// <- Note: [🤖]
|
|
6688
|
+
return proxyTools;
|
|
6689
|
+
}
|
|
6690
|
+
/**
|
|
6691
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
6692
|
+
* TODO: @@@ write discussion about this and storages
|
|
6693
|
+
* write how to combine multiple interceptors
|
|
6694
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
6695
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
6696
|
+
*/
|
|
6697
|
+
|
|
6698
|
+
/**
|
|
6699
|
+
* Returns LLM tools for CLI
|
|
6700
|
+
*
|
|
6701
|
+
* @private within the repository - for CLI utils
|
|
6702
|
+
*/
|
|
6703
|
+
function getLlmToolsForCli() {
|
|
6704
|
+
if (!isRunningInNode()) {
|
|
6705
|
+
throw new EnvironmentMismatchError('Function `getLlmToolsForTestingAndScriptsAndPlayground` works only in Node.js environment');
|
|
6706
|
+
}
|
|
6707
|
+
return cacheLlmTools(createLlmToolsFromEnv(), {
|
|
6708
|
+
storage: new FilesStorage({ cacheFolderPath: join(process.cwd(), '/.promptbook/executions-cache') }),
|
|
6709
|
+
});
|
|
6710
|
+
}
|
|
6711
|
+
/**
|
|
6712
|
+
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
6426
6713
|
*/
|
|
6427
6714
|
|
|
6428
6715
|
/**
|
|
@@ -6441,7 +6728,6 @@ function initializeMakeCommand(program) {
|
|
|
6441
6728
|
helloCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
|
|
6442
6729
|
helloCommand.option('--verbose', "Is verbose", false);
|
|
6443
6730
|
helloCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), PIPELINE_COLLECTION_BASE_FILENAME);
|
|
6444
|
-
// TODO: !!! Auto-detect AI api keys + explicit api keys as argv
|
|
6445
6731
|
helloCommand.action(function (path, _a) {
|
|
6446
6732
|
var projectName = _a.projectName, format = _a.format, validation = _a.validation, verbose = _a.verbose, outFile = _a.outFile;
|
|
6447
6733
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -6451,7 +6737,6 @@ function initializeMakeCommand(program) {
|
|
|
6451
6737
|
return __generator(this, function (_f) {
|
|
6452
6738
|
switch (_f.label) {
|
|
6453
6739
|
case 0:
|
|
6454
|
-
console.info('!!!', { projectName: projectName, path: path, format: format, validation: validation, verbose: verbose, outFile: outFile });
|
|
6455
6740
|
isVerbose = verbose;
|
|
6456
6741
|
formats = (format || '')
|
|
6457
6742
|
.split(',')
|
|
@@ -6465,17 +6750,7 @@ function initializeMakeCommand(program) {
|
|
|
6465
6750
|
console.error(colors.red("You can use only one format when saving to a file"));
|
|
6466
6751
|
process.exit(1);
|
|
6467
6752
|
}
|
|
6468
|
-
llmTools =
|
|
6469
|
-
// TODO: !!!! Remove mocked
|
|
6470
|
-
new MockedFackedLlmExecutionTools({
|
|
6471
|
-
isVerbose: isVerbose,
|
|
6472
|
-
}), new AnthropicClaudeExecutionTools({
|
|
6473
|
-
isVerbose: isVerbose,
|
|
6474
|
-
apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
|
|
6475
|
-
}), new OpenAiExecutionTools({
|
|
6476
|
-
isVerbose: isVerbose,
|
|
6477
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
6478
|
-
}));
|
|
6753
|
+
llmTools = getLlmToolsForCli();
|
|
6479
6754
|
return [4 /*yield*/, createCollectionFromDirectory(path, {
|
|
6480
6755
|
llmTools: llmTools,
|
|
6481
6756
|
isVerbose: isVerbose,
|
|
@@ -6592,11 +6867,14 @@ function initializeMakeCommand(program) {
|
|
|
6592
6867
|
});
|
|
6593
6868
|
});
|
|
6594
6869
|
}
|
|
6870
|
+
/**
|
|
6871
|
+
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
6872
|
+
*/
|
|
6595
6873
|
|
|
6596
6874
|
/**
|
|
6597
6875
|
* Add or modify an auto-generated section in a markdown file
|
|
6598
6876
|
*
|
|
6599
|
-
* @private within the
|
|
6877
|
+
* @private within the repository
|
|
6600
6878
|
*/
|
|
6601
6879
|
function addAutoGeneratedSection(content, options) {
|
|
6602
6880
|
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
@@ -6608,7 +6886,10 @@ function addAutoGeneratedSection(content, options) {
|
|
|
6608
6886
|
}
|
|
6609
6887
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
6610
6888
|
if (!placeForSection) {
|
|
6611
|
-
throw new
|
|
6889
|
+
throw new ParsingError(
|
|
6890
|
+
// <- [🧠] Maybe something better than `ParsingError`
|
|
6891
|
+
"No place where to put the section <!--".concat(sectionName, "-->"));
|
|
6892
|
+
// <- [🚞]
|
|
6612
6893
|
}
|
|
6613
6894
|
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
6614
6895
|
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
@@ -6848,6 +7129,9 @@ function initializePrettifyCommand(program) {
|
|
|
6848
7129
|
});
|
|
6849
7130
|
});
|
|
6850
7131
|
}
|
|
7132
|
+
/**
|
|
7133
|
+
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
7134
|
+
*/
|
|
6851
7135
|
|
|
6852
7136
|
/**
|
|
6853
7137
|
* Runs CLI utilities of Promptbook package
|
|
@@ -6857,7 +7141,7 @@ function promptbookCli() {
|
|
|
6857
7141
|
var program;
|
|
6858
7142
|
return __generator(this, function (_a) {
|
|
6859
7143
|
if (!isRunningInNode()) {
|
|
6860
|
-
throw new
|
|
7144
|
+
throw new EnvironmentMismatchError(spaceTrim$1("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
|
|
6861
7145
|
}
|
|
6862
7146
|
program = new commander.Command();
|
|
6863
7147
|
program.name('promptbook');
|
|
@@ -6875,6 +7159,7 @@ function promptbookCli() {
|
|
|
6875
7159
|
* TODO: [🥠] Do not export to utils directly, its just for CLI script
|
|
6876
7160
|
* TODO: [🕌] When more functionalities, rename
|
|
6877
7161
|
* Note: 11:11
|
|
7162
|
+
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
6878
7163
|
*/
|
|
6879
7164
|
|
|
6880
7165
|
// @promptbook/cli
|