@promptbook/cli 0.81.0-8 → 0.82.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -4
- package/esm/index.es.js +1193 -796
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +38 -0
- package/esm/typings/src/_packages/core.index.d.ts +12 -4
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/node.index.d.ts +0 -2
- package/esm/typings/src/_packages/remote-client.index.d.ts +7 -3
- package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
- package/esm/typings/src/_packages/templates.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +34 -30
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +2 -2
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -0
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/commands/index.d.ts +1 -1
- package/esm/typings/src/config.d.ts +3 -3
- package/esm/typings/src/conversion/compilePipeline.d.ts +1 -4
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +18 -0
- package/esm/typings/src/conversion/{precompilePipeline.d.ts → parsePipeline.d.ts} +3 -3
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +7 -7
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +1 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -2
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +9 -4
- package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
- package/esm/typings/src/formfactors/index.d.ts +31 -9
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
- package/esm/typings/src/high-level-abstractions/index.d.ts +3 -3
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +3 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +1 -1
- package/esm/typings/src/other/templates/getBookTemplates.d.ts +22 -0
- package/esm/typings/src/personas/preparePersona.d.ts +4 -4
- package/esm/typings/src/pipeline/PipelineString.d.ts +0 -3
- package/esm/typings/src/pipeline/book-notation.d.ts +14 -0
- package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
- package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -1
- package/esm/typings/src/prepare/preparePipeline.d.ts +4 -2
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +14 -0
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Error.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Request.d.ts +4 -4
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Response.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Progress.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Request.d.ts +5 -5
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Response.d.ts +1 -1
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteLlmExecutionToolsOptions.d.ts +7 -7
- package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteServerOptions.d.ts +10 -10
- package/esm/typings/src/scrapers/_common/Converter.d.ts +1 -0
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +3 -0
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -0
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +3 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +2 -1
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -1
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
- package/esm/typings/src/types/typeAliases.d.ts +16 -2
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/{removeContentComments.d.ts → removeMarkdownComments.d.ts} +2 -2
- package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -2
- package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
- package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
- package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +52 -8
- package/package.json +1 -1
- package/umd/index.umd.js +1193 -796
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/other/templates/getBookTemplate.d.ts +0 -21
- package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
- /package/esm/typings/src/conversion/{precompilePipeline.test.d.ts → parsePipeline.test.d.ts} +0 -0
- /package/esm/typings/src/{llm-providers/remote → remote-server}/startRemoteServer.d.ts +0 -0
- /package/esm/typings/src/utils/markdown/{removeContentComments.test.d.ts → removeMarkdownComments.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* @generated
|
|
52
52
|
* @see https://github.com/webgptorg/promptbook
|
|
53
53
|
*/
|
|
54
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-
|
|
54
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
|
|
55
55
|
/**
|
|
56
56
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
57
57
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
*
|
|
236
236
|
* @public exported from `@promptbook/core`
|
|
237
237
|
*/
|
|
238
|
-
var
|
|
238
|
+
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
239
239
|
/**
|
|
240
240
|
* Warning message for the generated sections and files files
|
|
241
241
|
*
|
|
@@ -320,6 +320,7 @@
|
|
|
320
320
|
* @public exported from `@promptbook/core`
|
|
321
321
|
*/
|
|
322
322
|
var DEFAULT_BOOKS_DIRNAME = './books';
|
|
323
|
+
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
323
324
|
/**
|
|
324
325
|
* Where to store the cache of executions for promptbook CLI
|
|
325
326
|
*
|
|
@@ -531,7 +532,7 @@
|
|
|
531
532
|
/**
|
|
532
533
|
* Make error report URL for the given error
|
|
533
534
|
*
|
|
534
|
-
* @private
|
|
535
|
+
* @private private within the repository
|
|
535
536
|
*/
|
|
536
537
|
function getErrorReportUrl(error) {
|
|
537
538
|
var report = {
|
|
@@ -702,7 +703,7 @@
|
|
|
702
703
|
if (!(error instanceof Error)) {
|
|
703
704
|
throw error;
|
|
704
705
|
}
|
|
705
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.
|
|
706
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
706
707
|
}
|
|
707
708
|
/*
|
|
708
709
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -732,7 +733,7 @@
|
|
|
732
733
|
}
|
|
733
734
|
/**
|
|
734
735
|
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
735
|
-
* TODO: [🧠][main]
|
|
736
|
+
* TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
736
737
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
737
738
|
*/
|
|
738
739
|
|
|
@@ -744,7 +745,6 @@
|
|
|
744
745
|
function deepClone(objectValue) {
|
|
745
746
|
return JSON.parse(JSON.stringify(objectValue));
|
|
746
747
|
/*
|
|
747
|
-
!!!!!!!!
|
|
748
748
|
TODO: [🧠] Is there a better implementation?
|
|
749
749
|
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
750
750
|
> for (const propertyName of propertyNames) {
|
|
@@ -856,7 +856,7 @@
|
|
|
856
856
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
857
857
|
*/
|
|
858
858
|
|
|
859
|
-
// <- TODO:
|
|
859
|
+
// <- TODO: Auto convert to type `import { ... } from 'type-fest';`
|
|
860
860
|
/**
|
|
861
861
|
* Tests if the value is [🚉] serializable as JSON
|
|
862
862
|
*
|
|
@@ -886,7 +886,7 @@
|
|
|
886
886
|
}
|
|
887
887
|
}
|
|
888
888
|
/**
|
|
889
|
-
* TODO: [🧠][main]
|
|
889
|
+
* TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
890
890
|
* TODO: [🧠][💺] Can be done this on type-level?
|
|
891
891
|
*/
|
|
892
892
|
|
|
@@ -979,21 +979,44 @@
|
|
|
979
979
|
if (typeof filename !== 'string') {
|
|
980
980
|
return false;
|
|
981
981
|
}
|
|
982
|
+
if (filename.split('\n').length > 1) {
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
if (filename.split(' ').length >
|
|
986
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
982
989
|
var filenameSlashes = filename.split('\\').join('/');
|
|
983
990
|
// Absolute Unix path: /hello.txt
|
|
984
991
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
992
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
985
993
|
return true;
|
|
986
994
|
}
|
|
987
995
|
// Absolute Windows path: /hello.txt
|
|
988
996
|
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
997
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
989
998
|
return true;
|
|
990
999
|
}
|
|
991
1000
|
// Relative path: ./hello.txt
|
|
992
1001
|
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
1002
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
// Allow paths like foo/hello
|
|
1006
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
1007
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
1008
|
+
return true;
|
|
1009
|
+
}
|
|
1010
|
+
// Allow paths like hello.book
|
|
1011
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
1012
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
993
1013
|
return true;
|
|
994
1014
|
}
|
|
995
1015
|
return false;
|
|
996
1016
|
}
|
|
1017
|
+
/**
|
|
1018
|
+
* TODO: [🍏] Implement for MacOs
|
|
1019
|
+
*/
|
|
997
1020
|
|
|
998
1021
|
/**
|
|
999
1022
|
* Tests if given string is valid URL.
|
|
@@ -1628,7 +1651,7 @@
|
|
|
1628
1651
|
return [3 /*break*/, 11];
|
|
1629
1652
|
case 10: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
|
|
1630
1653
|
case 11:
|
|
1631
|
-
// TODO: [🧠]
|
|
1654
|
+
// TODO: [🧠] !!5 How to do timing in mixed cache / non-cache situation
|
|
1632
1655
|
// promptResult.timing: FromtoItems
|
|
1633
1656
|
return [4 /*yield*/, storage.setItem(key, {
|
|
1634
1657
|
date: $getCurrentDate(),
|
|
@@ -1637,7 +1660,7 @@
|
|
|
1637
1660
|
promptResult: promptResult,
|
|
1638
1661
|
})];
|
|
1639
1662
|
case 12:
|
|
1640
|
-
// TODO: [🧠]
|
|
1663
|
+
// TODO: [🧠] !!5 How to do timing in mixed cache / non-cache situation
|
|
1641
1664
|
// promptResult.timing: FromtoItems
|
|
1642
1665
|
_c.sent();
|
|
1643
1666
|
return [2 /*return*/, promptResult];
|
|
@@ -2058,6 +2081,25 @@
|
|
|
2058
2081
|
* TODO: [®] DRY Register logic
|
|
2059
2082
|
*/
|
|
2060
2083
|
|
|
2084
|
+
/**
|
|
2085
|
+
* Determines if the given path is a root path.
|
|
2086
|
+
*
|
|
2087
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
2088
|
+
* @public exported from `@promptbook/utils`
|
|
2089
|
+
*/
|
|
2090
|
+
function isRootPath(value) {
|
|
2091
|
+
if (value === '/') {
|
|
2092
|
+
return true;
|
|
2093
|
+
}
|
|
2094
|
+
if (/^[A-Z]:\\$/i.test(value)) {
|
|
2095
|
+
return true;
|
|
2096
|
+
}
|
|
2097
|
+
return false;
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* TODO: [🍏] Make for MacOS paths
|
|
2101
|
+
*/
|
|
2102
|
+
|
|
2061
2103
|
/**
|
|
2062
2104
|
* @@@
|
|
2063
2105
|
*
|
|
@@ -2072,17 +2114,45 @@
|
|
|
2072
2114
|
* @public exported from `@promptbook/node`
|
|
2073
2115
|
*/
|
|
2074
2116
|
function $provideLlmToolsConfigurationFromEnv() {
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2118
|
+
var rootDirname, i, envFilename, llmToolsConfiguration;
|
|
2119
|
+
return __generator(this, function (_a) {
|
|
2120
|
+
switch (_a.label) {
|
|
2121
|
+
case 0:
|
|
2122
|
+
if (!$isRunningInNode()) {
|
|
2123
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
2124
|
+
}
|
|
2125
|
+
rootDirname = process.cwd();
|
|
2126
|
+
i = 0;
|
|
2127
|
+
_a.label = 1;
|
|
2128
|
+
case 1:
|
|
2129
|
+
if (!(i < LOOP_LIMIT)) return [3 /*break*/, 4];
|
|
2130
|
+
envFilename = path.join(rootDirname, '.env' /* <- TODO: [🕝] Make here more candidates */);
|
|
2131
|
+
return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
|
|
2132
|
+
case 2:
|
|
2133
|
+
// console.log({ rootDirname, envFilename });
|
|
2134
|
+
if (_a.sent()) {
|
|
2135
|
+
dotenv__namespace.config({ path: envFilename });
|
|
2136
|
+
return [3 /*break*/, 4];
|
|
2137
|
+
}
|
|
2138
|
+
if (isRootPath(rootDirname)) {
|
|
2139
|
+
return [3 /*break*/, 4];
|
|
2140
|
+
}
|
|
2141
|
+
// Note: If the directory does not exist, try the parent directory
|
|
2142
|
+
rootDirname = path.join(rootDirname, '..');
|
|
2143
|
+
_a.label = 3;
|
|
2144
|
+
case 3:
|
|
2145
|
+
i++;
|
|
2146
|
+
return [3 /*break*/, 1];
|
|
2147
|
+
case 4:
|
|
2148
|
+
llmToolsConfiguration = $llmToolsMetadataRegister
|
|
2149
|
+
.list()
|
|
2150
|
+
.map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
|
|
2151
|
+
.filter(function (configuration) { return configuration !== null; });
|
|
2152
|
+
return [2 /*return*/, llmToolsConfiguration];
|
|
2153
|
+
}
|
|
2154
|
+
});
|
|
2155
|
+
});
|
|
2086
2156
|
}
|
|
2087
2157
|
/**
|
|
2088
2158
|
* TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
|
|
@@ -2597,15 +2667,28 @@
|
|
|
2597
2667
|
*/
|
|
2598
2668
|
function $provideLlmToolsFromEnv(options) {
|
|
2599
2669
|
if (options === void 0) { options = {}; }
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2670
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2671
|
+
var configuration;
|
|
2672
|
+
return __generator(this, function (_a) {
|
|
2673
|
+
switch (_a.label) {
|
|
2674
|
+
case 0:
|
|
2675
|
+
if (!$isRunningInNode()) {
|
|
2676
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
2677
|
+
}
|
|
2678
|
+
return [4 /*yield*/, $provideLlmToolsConfigurationFromEnv()];
|
|
2679
|
+
case 1:
|
|
2680
|
+
configuration = _a.sent();
|
|
2681
|
+
if (configuration.length === 0) {
|
|
2682
|
+
if ($llmToolsMetadataRegister.list().length === 0) {
|
|
2683
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n No LLM tools registered, this is probably a bug in the Promptbook library\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
|
|
2684
|
+
}
|
|
2685
|
+
// TODO: [🥃]
|
|
2686
|
+
throw new Error(spaceTrim__default["default"](function (block) { return "\n No LLM tools found in the environment\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
|
|
2687
|
+
}
|
|
2688
|
+
return [2 /*return*/, createLlmToolsFromConfiguration(configuration, options)];
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
});
|
|
2609
2692
|
}
|
|
2610
2693
|
/**
|
|
2611
2694
|
* TODO: @@@ write `$provideLlmToolsFromEnv` vs `$provideLlmToolsConfigurationFromEnv` vs `createLlmToolsFromConfiguration`
|
|
@@ -2622,22 +2705,35 @@
|
|
|
2622
2705
|
*
|
|
2623
2706
|
* @private within the repository - for CLI utils
|
|
2624
2707
|
*/
|
|
2625
|
-
function $
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2708
|
+
function $provideLlmToolsForWizzardOrCli(options) {
|
|
2709
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2710
|
+
var isCacheReloaded, _a, _b;
|
|
2711
|
+
return __generator(this, function (_c) {
|
|
2712
|
+
switch (_c.label) {
|
|
2713
|
+
case 0:
|
|
2714
|
+
if (!$isRunningInNode()) {
|
|
2715
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsForWizzardOrCli` works only in Node.js environment');
|
|
2716
|
+
}
|
|
2717
|
+
isCacheReloaded = (options !== null && options !== void 0 ? options : {}).isCacheReloaded;
|
|
2718
|
+
_a = cacheLlmTools;
|
|
2719
|
+
_b = countTotalUsage;
|
|
2720
|
+
// <- Note: for example here we don`t want the [🌯]
|
|
2721
|
+
return [4 /*yield*/, $provideLlmToolsFromEnv()];
|
|
2722
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply(void 0, [
|
|
2723
|
+
// <- Note: for example here we don`t want the [🌯]
|
|
2724
|
+
_c.sent()]),
|
|
2725
|
+
{
|
|
2726
|
+
storage: new FileCacheStorage({ fs: $provideFilesystemForNode() }, {
|
|
2727
|
+
rootFolderPath: path.join(process.cwd(), DEFAULT_EXECUTIONS_CACHE_DIRNAME),
|
|
2728
|
+
}),
|
|
2729
|
+
isCacheReloaded: isCacheReloaded,
|
|
2730
|
+
}])];
|
|
2731
|
+
}
|
|
2732
|
+
});
|
|
2637
2733
|
});
|
|
2638
2734
|
}
|
|
2639
2735
|
/**
|
|
2640
|
-
* Note: [
|
|
2736
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
2641
2737
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2642
2738
|
* TODO: [🥃] Allow `ptbk make` without llm tools
|
|
2643
2739
|
* TODO: This should be maybe not under `_common` but under `utils-internal` / `utils/internal`
|
|
@@ -2655,10 +2751,14 @@
|
|
|
2655
2751
|
listModelsCommand.description(spaceTrim__default["default"]("\n List all available and configured LLM models\n "));
|
|
2656
2752
|
listModelsCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2657
2753
|
return __generator(this, function (_a) {
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2754
|
+
switch (_a.label) {
|
|
2755
|
+
case 0: return [4 /*yield*/, $provideLlmToolsForWizzardOrCli({})];
|
|
2756
|
+
case 1:
|
|
2757
|
+
_a.sent();
|
|
2758
|
+
// <- Note: Providing LLM tools will make a side effect of registering all available LLM tools to show the message
|
|
2759
|
+
console.info($registeredLlmToolsMessage());
|
|
2760
|
+
return [2 /*return*/, process.exit(0)];
|
|
2761
|
+
}
|
|
2662
2762
|
});
|
|
2663
2763
|
}); });
|
|
2664
2764
|
}
|
|
@@ -2694,99 +2794,67 @@
|
|
|
2694
2794
|
* TODO: [🧠] Maybe clear `sourceFile` or clear when exposing through API or remote server
|
|
2695
2795
|
*/
|
|
2696
2796
|
|
|
2797
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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 - Write maximum ideally 2 words, maximum 5 words\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou 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 - Write maximum ideally 2 words, maximum 5 words\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",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}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
|
|
2798
|
+
|
|
2697
2799
|
/**
|
|
2698
|
-
*
|
|
2800
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2801
|
+
*
|
|
2802
|
+
* @public exported from `@promptbook/utils`
|
|
2803
|
+
*/
|
|
2804
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
2805
|
+
try {
|
|
2806
|
+
JSON.parse(value);
|
|
2807
|
+
return true;
|
|
2808
|
+
}
|
|
2809
|
+
catch (error) {
|
|
2810
|
+
if (!(error instanceof Error)) {
|
|
2811
|
+
throw error;
|
|
2812
|
+
}
|
|
2813
|
+
if (error.message.includes('Unexpected token')) {
|
|
2814
|
+
return false;
|
|
2815
|
+
}
|
|
2816
|
+
return false;
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
/**
|
|
2821
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
2699
2822
|
*
|
|
2700
2823
|
* @public exported from `@promptbook/core`
|
|
2701
2824
|
*/
|
|
2702
|
-
var
|
|
2703
|
-
__extends(
|
|
2704
|
-
function
|
|
2705
|
-
var _this = _super.call(this,
|
|
2706
|
-
_this.name = '
|
|
2707
|
-
Object.setPrototypeOf(_this,
|
|
2825
|
+
var ParseError = /** @class */ (function (_super) {
|
|
2826
|
+
__extends(ParseError, _super);
|
|
2827
|
+
function ParseError(message) {
|
|
2828
|
+
var _this = _super.call(this, message) || this;
|
|
2829
|
+
_this.name = 'ParseError';
|
|
2830
|
+
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
2708
2831
|
return _this;
|
|
2709
2832
|
}
|
|
2710
|
-
return
|
|
2833
|
+
return ParseError;
|
|
2711
2834
|
}(Error));
|
|
2835
|
+
/**
|
|
2836
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
2837
|
+
*/
|
|
2712
2838
|
|
|
2713
2839
|
/**
|
|
2714
|
-
*
|
|
2840
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
2841
|
+
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
2715
2842
|
*
|
|
2716
|
-
* @param
|
|
2717
|
-
* @
|
|
2718
|
-
* @
|
|
2719
|
-
* @public exported from `@promptbook/
|
|
2720
|
-
* @deprecated [🪂] Use queues instead
|
|
2843
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
2844
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
2845
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
2846
|
+
* @public exported from `@promptbook/core`
|
|
2721
2847
|
*/
|
|
2722
|
-
function
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
case 0:
|
|
2729
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
2730
|
-
index = 0;
|
|
2731
|
-
runningTasks = [];
|
|
2732
|
-
tasks = [];
|
|
2733
|
-
_loop_1 = function (item) {
|
|
2734
|
-
var currentIndex, task;
|
|
2735
|
-
return __generator(this, function (_f) {
|
|
2736
|
-
switch (_f.label) {
|
|
2737
|
-
case 0:
|
|
2738
|
-
currentIndex = index++;
|
|
2739
|
-
task = callbackfunction(item, currentIndex, array);
|
|
2740
|
-
tasks.push(task);
|
|
2741
|
-
runningTasks.push(task);
|
|
2742
|
-
/* not await */ Promise.resolve(task).then(function () {
|
|
2743
|
-
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
2744
|
-
});
|
|
2745
|
-
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
2746
|
-
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
2747
|
-
case 1:
|
|
2748
|
-
_f.sent();
|
|
2749
|
-
_f.label = 2;
|
|
2750
|
-
case 2: return [2 /*return*/];
|
|
2751
|
-
}
|
|
2752
|
-
});
|
|
2753
|
-
};
|
|
2754
|
-
_e.label = 1;
|
|
2755
|
-
case 1:
|
|
2756
|
-
_e.trys.push([1, 6, 7, 8]);
|
|
2757
|
-
_b = __values(array), _c = _b.next();
|
|
2758
|
-
_e.label = 2;
|
|
2759
|
-
case 2:
|
|
2760
|
-
if (!!_c.done) return [3 /*break*/, 5];
|
|
2761
|
-
item = _c.value;
|
|
2762
|
-
return [5 /*yield**/, _loop_1(item)];
|
|
2763
|
-
case 3:
|
|
2764
|
-
_e.sent();
|
|
2765
|
-
_e.label = 4;
|
|
2766
|
-
case 4:
|
|
2767
|
-
_c = _b.next();
|
|
2768
|
-
return [3 /*break*/, 2];
|
|
2769
|
-
case 5: return [3 /*break*/, 8];
|
|
2770
|
-
case 6:
|
|
2771
|
-
e_1_1 = _e.sent();
|
|
2772
|
-
e_1 = { error: e_1_1 };
|
|
2773
|
-
return [3 /*break*/, 8];
|
|
2774
|
-
case 7:
|
|
2775
|
-
try {
|
|
2776
|
-
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
2777
|
-
}
|
|
2778
|
-
finally { if (e_1) throw e_1.error; }
|
|
2779
|
-
return [7 /*endfinally*/];
|
|
2780
|
-
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
2781
|
-
case 9:
|
|
2782
|
-
_e.sent();
|
|
2783
|
-
return [2 /*return*/];
|
|
2784
|
-
}
|
|
2785
|
-
});
|
|
2786
|
-
});
|
|
2848
|
+
function validatePipelineString(pipelineString) {
|
|
2849
|
+
if (isValidJsonString(pipelineString)) {
|
|
2850
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
2851
|
+
}
|
|
2852
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
2853
|
+
return pipelineString;
|
|
2787
2854
|
}
|
|
2788
|
-
|
|
2789
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou 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> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",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}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"}];
|
|
2855
|
+
/**
|
|
2856
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
2857
|
+
*/
|
|
2790
2858
|
|
|
2791
2859
|
/**
|
|
2792
2860
|
* Prettify the html code
|
|
@@ -2854,7 +2922,7 @@
|
|
|
2854
2922
|
if (bookVersion !== "undefined") {
|
|
2855
2923
|
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
2856
2924
|
}
|
|
2857
|
-
// TODO: [main]
|
|
2925
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
2858
2926
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
2859
2927
|
try {
|
|
2860
2928
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -3002,12 +3070,12 @@
|
|
|
3002
3070
|
pipelineString += '```' + contentLanguage;
|
|
3003
3071
|
pipelineString += '\n';
|
|
3004
3072
|
pipelineString += spaceTrim__default["default"](content);
|
|
3005
|
-
// <- TODO: [main]
|
|
3073
|
+
// <- TODO: [main] !!3 Escape
|
|
3006
3074
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
3007
3075
|
pipelineString += '\n';
|
|
3008
3076
|
pipelineString += '```';
|
|
3009
3077
|
pipelineString += '\n\n';
|
|
3010
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main]
|
|
3078
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
3011
3079
|
}
|
|
3012
3080
|
}
|
|
3013
3081
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -3017,7 +3085,7 @@
|
|
|
3017
3085
|
}
|
|
3018
3086
|
finally { if (e_3) throw e_3.error; }
|
|
3019
3087
|
}
|
|
3020
|
-
return pipelineString;
|
|
3088
|
+
return validatePipelineString(pipelineString);
|
|
3021
3089
|
}
|
|
3022
3090
|
/**
|
|
3023
3091
|
* @private internal utility of `pipelineJsonToString`
|
|
@@ -3038,25 +3106,6 @@
|
|
|
3038
3106
|
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
3039
3107
|
*/
|
|
3040
3108
|
|
|
3041
|
-
/**
|
|
3042
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
3043
|
-
*
|
|
3044
|
-
* @public exported from `@promptbook/core`
|
|
3045
|
-
*/
|
|
3046
|
-
var ParseError = /** @class */ (function (_super) {
|
|
3047
|
-
__extends(ParseError, _super);
|
|
3048
|
-
function ParseError(message) {
|
|
3049
|
-
var _this = _super.call(this, message) || this;
|
|
3050
|
-
_this.name = 'ParseError';
|
|
3051
|
-
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
3052
|
-
return _this;
|
|
3053
|
-
}
|
|
3054
|
-
return ParseError;
|
|
3055
|
-
}(Error));
|
|
3056
|
-
/**
|
|
3057
|
-
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
3058
|
-
*/
|
|
3059
|
-
|
|
3060
3109
|
/**
|
|
3061
3110
|
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
3062
3111
|
*
|
|
@@ -3111,7 +3160,7 @@
|
|
|
3111
3160
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
3112
3161
|
return false;
|
|
3113
3162
|
}
|
|
3114
|
-
// <- TODO: [main]
|
|
3163
|
+
// <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
|
|
3115
3164
|
return true;
|
|
3116
3165
|
}
|
|
3117
3166
|
|
|
@@ -3182,9 +3231,6 @@
|
|
|
3182
3231
|
if (!url.startsWith('https://')) {
|
|
3183
3232
|
return false;
|
|
3184
3233
|
}
|
|
3185
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
3186
|
-
return false;
|
|
3187
|
-
}
|
|
3188
3234
|
if (url.includes('#')) {
|
|
3189
3235
|
// TODO: [🐠]
|
|
3190
3236
|
return false;
|
|
@@ -3215,11 +3261,11 @@
|
|
|
3215
3261
|
*/
|
|
3216
3262
|
function validatePipeline(pipeline) {
|
|
3217
3263
|
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
3218
|
-
|
|
3264
|
+
validatePipeline_InnerFunction(pipeline);
|
|
3219
3265
|
}
|
|
3220
3266
|
else {
|
|
3221
3267
|
try {
|
|
3222
|
-
|
|
3268
|
+
validatePipeline_InnerFunction(pipeline);
|
|
3223
3269
|
}
|
|
3224
3270
|
catch (error) {
|
|
3225
3271
|
if (!(error instanceof PipelineLogicError)) {
|
|
@@ -3233,7 +3279,7 @@
|
|
|
3233
3279
|
/**
|
|
3234
3280
|
* @private internal function for `validatePipeline`
|
|
3235
3281
|
*/
|
|
3236
|
-
function
|
|
3282
|
+
function validatePipeline_InnerFunction(pipeline) {
|
|
3237
3283
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
3238
3284
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
3239
3285
|
var pipelineIdentification = (function () {
|
|
@@ -3457,11 +3503,11 @@
|
|
|
3457
3503
|
_loop_3();
|
|
3458
3504
|
}
|
|
3459
3505
|
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
3460
|
-
// TODO:
|
|
3506
|
+
// TODO: !!6 Implement this
|
|
3461
3507
|
// pipeline.formfactorName
|
|
3462
3508
|
}
|
|
3463
3509
|
/**
|
|
3464
|
-
* TODO:
|
|
3510
|
+
* TODO: [🧞♀️] Do not allow joker + foreach
|
|
3465
3511
|
* TODO: [🧠] Work with promptbookVersion
|
|
3466
3512
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
3467
3513
|
* > /**
|
|
@@ -3473,11 +3519,11 @@
|
|
|
3473
3519
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
3474
3520
|
*/
|
|
3475
3521
|
/**
|
|
3476
|
-
* TODO: [🧳][main]
|
|
3477
|
-
* TODO: [🧳][🐝][main]
|
|
3478
|
-
* TODO: [🧳][main]
|
|
3479
|
-
* TODO: [🧳][main]
|
|
3480
|
-
* TODO: [🧳][main]
|
|
3522
|
+
* TODO: [🧳][main] !!4 Validate that all examples match expectations
|
|
3523
|
+
* TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
|
|
3524
|
+
* TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
|
|
3525
|
+
* TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
3526
|
+
* TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
|
|
3481
3527
|
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
3482
3528
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3483
3529
|
*/
|
|
@@ -3613,7 +3659,7 @@
|
|
|
3613
3659
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
3614
3660
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
3615
3661
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
3616
|
-
throw new PipelineUrlError(spaceTrim.spaceTrim("\n Pipeline with URL
|
|
3662
|
+
throw new PipelineUrlError(spaceTrim.spaceTrim("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
3617
3663
|
}
|
|
3618
3664
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
3619
3665
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -3678,6 +3724,22 @@
|
|
|
3678
3724
|
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
3679
3725
|
}
|
|
3680
3726
|
|
|
3727
|
+
/**
|
|
3728
|
+
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
3729
|
+
*
|
|
3730
|
+
* @public exported from `@promptbook/core`
|
|
3731
|
+
*/
|
|
3732
|
+
var MissingToolsError = /** @class */ (function (_super) {
|
|
3733
|
+
__extends(MissingToolsError, _super);
|
|
3734
|
+
function MissingToolsError(message) {
|
|
3735
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
|
|
3736
|
+
_this.name = 'MissingToolsError';
|
|
3737
|
+
Object.setPrototypeOf(_this, MissingToolsError.prototype);
|
|
3738
|
+
return _this;
|
|
3739
|
+
}
|
|
3740
|
+
return MissingToolsError;
|
|
3741
|
+
}(Error));
|
|
3742
|
+
|
|
3681
3743
|
/**
|
|
3682
3744
|
* This error indicates problems parsing the format value
|
|
3683
3745
|
*
|
|
@@ -3885,11 +3947,16 @@
|
|
|
3885
3947
|
/**
|
|
3886
3948
|
* Determine if the pipeline is fully prepared
|
|
3887
3949
|
*
|
|
3950
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
3951
|
+
*
|
|
3888
3952
|
* @public exported from `@promptbook/core`
|
|
3889
3953
|
*/
|
|
3890
3954
|
function isPipelinePrepared(pipeline) {
|
|
3891
3955
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
3892
3956
|
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
3957
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
3958
|
+
return false;
|
|
3959
|
+
}
|
|
3893
3960
|
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
3894
3961
|
return false;
|
|
3895
3962
|
}
|
|
@@ -3905,7 +3972,7 @@
|
|
|
3905
3972
|
return true;
|
|
3906
3973
|
}
|
|
3907
3974
|
/**
|
|
3908
|
-
* TODO: [🔃][main]
|
|
3975
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
3909
3976
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
3910
3977
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
3911
3978
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -3915,25 +3982,100 @@
|
|
|
3915
3982
|
*/
|
|
3916
3983
|
|
|
3917
3984
|
/**
|
|
3918
|
-
*
|
|
3985
|
+
* Format either small or big number
|
|
3919
3986
|
*
|
|
3920
3987
|
* @public exported from `@promptbook/utils`
|
|
3921
3988
|
*/
|
|
3922
|
-
function
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
console.error(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
3989
|
+
function numberToString(value) {
|
|
3990
|
+
if (value === 0) {
|
|
3991
|
+
return '0';
|
|
3926
3992
|
}
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3993
|
+
else if (Number.isNaN(value)) {
|
|
3994
|
+
return VALUE_STRINGS.nan;
|
|
3995
|
+
}
|
|
3996
|
+
else if (value === Infinity) {
|
|
3997
|
+
return VALUE_STRINGS.infinity;
|
|
3998
|
+
}
|
|
3999
|
+
else if (value === -Infinity) {
|
|
4000
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4001
|
+
}
|
|
4002
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4003
|
+
var factor = Math.pow(10, exponent);
|
|
4004
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4005
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4006
|
+
return valueRounded.toFixed(exponent);
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
return value.toString();
|
|
4010
|
+
}
|
|
4011
|
+
|
|
4012
|
+
/**
|
|
4013
|
+
* Function `valueToString` will convert the given value to string
|
|
4014
|
+
* This is useful and used in the `templateParameters` function
|
|
4015
|
+
*
|
|
4016
|
+
* Note: This function is not just calling `toString` method
|
|
4017
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4018
|
+
* See `VALUE_STRINGS`
|
|
4019
|
+
*
|
|
4020
|
+
* Note: There are 2 similar functions
|
|
4021
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4022
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4023
|
+
*
|
|
4024
|
+
* @public exported from `@promptbook/utils`
|
|
4025
|
+
*/
|
|
4026
|
+
function valueToString(value) {
|
|
4027
|
+
try {
|
|
4028
|
+
if (value === '') {
|
|
4029
|
+
return VALUE_STRINGS.empty;
|
|
4030
|
+
}
|
|
4031
|
+
else if (value === null) {
|
|
4032
|
+
return VALUE_STRINGS.null;
|
|
4033
|
+
}
|
|
4034
|
+
else if (value === undefined) {
|
|
4035
|
+
return VALUE_STRINGS.undefined;
|
|
4036
|
+
}
|
|
4037
|
+
else if (typeof value === 'string') {
|
|
4038
|
+
return value;
|
|
4039
|
+
}
|
|
4040
|
+
else if (typeof value === 'number') {
|
|
4041
|
+
return numberToString(value);
|
|
4042
|
+
}
|
|
4043
|
+
else if (value instanceof Date) {
|
|
4044
|
+
return value.toISOString();
|
|
4045
|
+
}
|
|
4046
|
+
else {
|
|
4047
|
+
return JSON.stringify(value);
|
|
4048
|
+
}
|
|
4049
|
+
}
|
|
4050
|
+
catch (error) {
|
|
4051
|
+
if (!(error instanceof Error)) {
|
|
4052
|
+
throw error;
|
|
4053
|
+
}
|
|
4054
|
+
console.error(error);
|
|
4055
|
+
return VALUE_STRINGS.unserializable;
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
|
|
4059
|
+
/**
|
|
4060
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
4061
|
+
*
|
|
4062
|
+
* @public exported from `@promptbook/utils`
|
|
4063
|
+
*/
|
|
4064
|
+
function serializeError(error) {
|
|
4065
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
4066
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
4067
|
+
console.error(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
4068
|
+
}
|
|
4069
|
+
return {
|
|
4070
|
+
name: name,
|
|
4071
|
+
message: message,
|
|
4072
|
+
stack: stack,
|
|
4073
|
+
};
|
|
4074
|
+
}
|
|
4075
|
+
|
|
4076
|
+
/**
|
|
4077
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4078
|
+
*
|
|
3937
4079
|
* @param script from which to extract the variables
|
|
3938
4080
|
* @returns the list of variable names
|
|
3939
4081
|
* @throws {ParseError} if the script is invalid
|
|
@@ -3985,7 +4127,7 @@
|
|
|
3985
4127
|
if (!(error instanceof Error)) {
|
|
3986
4128
|
throw error;
|
|
3987
4129
|
}
|
|
3988
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n
|
|
4130
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
|
|
3989
4131
|
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3990
4132
|
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3991
4133
|
}
|
|
@@ -4265,27 +4407,6 @@
|
|
|
4265
4407
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
4266
4408
|
*/
|
|
4267
4409
|
|
|
4268
|
-
/**
|
|
4269
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
4270
|
-
*
|
|
4271
|
-
* @public exported from `@promptbook/utils`
|
|
4272
|
-
*/
|
|
4273
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
4274
|
-
try {
|
|
4275
|
-
JSON.parse(value);
|
|
4276
|
-
return true;
|
|
4277
|
-
}
|
|
4278
|
-
catch (error) {
|
|
4279
|
-
if (!(error instanceof Error)) {
|
|
4280
|
-
throw error;
|
|
4281
|
-
}
|
|
4282
|
-
if (error.message.includes('Unexpected token')) {
|
|
4283
|
-
return false;
|
|
4284
|
-
}
|
|
4285
|
-
return false;
|
|
4286
|
-
}
|
|
4287
|
-
}
|
|
4288
|
-
|
|
4289
4410
|
/**
|
|
4290
4411
|
* Definition for JSON format
|
|
4291
4412
|
*
|
|
@@ -4623,81 +4744,6 @@
|
|
|
4623
4744
|
return [input];
|
|
4624
4745
|
}
|
|
4625
4746
|
|
|
4626
|
-
/**
|
|
4627
|
-
* Format either small or big number
|
|
4628
|
-
*
|
|
4629
|
-
* @public exported from `@promptbook/utils`
|
|
4630
|
-
*/
|
|
4631
|
-
function numberToString(value) {
|
|
4632
|
-
if (value === 0) {
|
|
4633
|
-
return '0';
|
|
4634
|
-
}
|
|
4635
|
-
else if (Number.isNaN(value)) {
|
|
4636
|
-
return VALUE_STRINGS.nan;
|
|
4637
|
-
}
|
|
4638
|
-
else if (value === Infinity) {
|
|
4639
|
-
return VALUE_STRINGS.infinity;
|
|
4640
|
-
}
|
|
4641
|
-
else if (value === -Infinity) {
|
|
4642
|
-
return VALUE_STRINGS.negativeInfinity;
|
|
4643
|
-
}
|
|
4644
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4645
|
-
var factor = Math.pow(10, exponent);
|
|
4646
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
4647
|
-
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4648
|
-
return valueRounded.toFixed(exponent);
|
|
4649
|
-
}
|
|
4650
|
-
}
|
|
4651
|
-
return value.toString();
|
|
4652
|
-
}
|
|
4653
|
-
|
|
4654
|
-
/**
|
|
4655
|
-
* Function `valueToString` will convert the given value to string
|
|
4656
|
-
* This is useful and used in the `templateParameters` function
|
|
4657
|
-
*
|
|
4658
|
-
* Note: This function is not just calling `toString` method
|
|
4659
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
4660
|
-
* See `VALUE_STRINGS`
|
|
4661
|
-
*
|
|
4662
|
-
* Note: There are 2 similar functions
|
|
4663
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4664
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4665
|
-
*
|
|
4666
|
-
* @public exported from `@promptbook/utils`
|
|
4667
|
-
*/
|
|
4668
|
-
function valueToString(value) {
|
|
4669
|
-
try {
|
|
4670
|
-
if (value === '') {
|
|
4671
|
-
return VALUE_STRINGS.empty;
|
|
4672
|
-
}
|
|
4673
|
-
else if (value === null) {
|
|
4674
|
-
return VALUE_STRINGS.null;
|
|
4675
|
-
}
|
|
4676
|
-
else if (value === undefined) {
|
|
4677
|
-
return VALUE_STRINGS.undefined;
|
|
4678
|
-
}
|
|
4679
|
-
else if (typeof value === 'string') {
|
|
4680
|
-
return value;
|
|
4681
|
-
}
|
|
4682
|
-
else if (typeof value === 'number') {
|
|
4683
|
-
return numberToString(value);
|
|
4684
|
-
}
|
|
4685
|
-
else if (value instanceof Date) {
|
|
4686
|
-
return value.toISOString();
|
|
4687
|
-
}
|
|
4688
|
-
else {
|
|
4689
|
-
return JSON.stringify(value);
|
|
4690
|
-
}
|
|
4691
|
-
}
|
|
4692
|
-
catch (error) {
|
|
4693
|
-
if (!(error instanceof Error)) {
|
|
4694
|
-
throw error;
|
|
4695
|
-
}
|
|
4696
|
-
console.error(error);
|
|
4697
|
-
return VALUE_STRINGS.unserializable;
|
|
4698
|
-
}
|
|
4699
|
-
}
|
|
4700
|
-
|
|
4701
4747
|
/**
|
|
4702
4748
|
* Replaces parameters in template with values from parameters object
|
|
4703
4749
|
*
|
|
@@ -4754,6 +4800,8 @@
|
|
|
4754
4800
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
4755
4801
|
}
|
|
4756
4802
|
parameterValue = valueToString(parameterValue);
|
|
4803
|
+
// Escape curly braces in parameter values to prevent prompt-injection
|
|
4804
|
+
parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
|
|
4757
4805
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
4758
4806
|
parameterValue = parameterValue
|
|
4759
4807
|
.split('\n')
|
|
@@ -5113,7 +5161,7 @@
|
|
|
5113
5161
|
promptTitle: task.title,
|
|
5114
5162
|
promptMessage: templateParameters(task.description || '', parameters),
|
|
5115
5163
|
defaultValue: templateParameters(preparedContent, parameters),
|
|
5116
|
-
// TODO: [🧠]
|
|
5164
|
+
// TODO: [🧠] Figure out how to define placeholder in .book.md file
|
|
5117
5165
|
placeholder: undefined,
|
|
5118
5166
|
priority: priority,
|
|
5119
5167
|
}))];
|
|
@@ -5813,7 +5861,10 @@
|
|
|
5813
5861
|
finally { if (e_2) throw e_2.error; }
|
|
5814
5862
|
return [7 /*endfinally*/];
|
|
5815
5863
|
case 19:
|
|
5816
|
-
parametersToPass = inputParameters
|
|
5864
|
+
parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
|
|
5865
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
5866
|
+
return [key, valueToString(value)];
|
|
5867
|
+
}));
|
|
5817
5868
|
_g.label = 20;
|
|
5818
5869
|
case 20:
|
|
5819
5870
|
_g.trys.push([20, 25, , 28]);
|
|
@@ -6049,46 +6100,122 @@
|
|
|
6049
6100
|
*/
|
|
6050
6101
|
|
|
6051
6102
|
/**
|
|
6052
|
-
*
|
|
6103
|
+
* Async version of Array.forEach
|
|
6053
6104
|
*
|
|
6054
|
-
* @
|
|
6055
|
-
* @
|
|
6105
|
+
* @param array - Array to iterate over
|
|
6106
|
+
* @param options - Options for the function
|
|
6107
|
+
* @param callbackfunction - Function to call for each item
|
|
6108
|
+
* @public exported from `@promptbook/utils`
|
|
6109
|
+
* @deprecated [🪂] Use queues instead
|
|
6056
6110
|
*/
|
|
6057
|
-
function
|
|
6111
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
6058
6112
|
return __awaiter(this, void 0, void 0, function () {
|
|
6059
|
-
var _a,
|
|
6060
|
-
var
|
|
6061
|
-
return __generator(this, function (
|
|
6062
|
-
switch (
|
|
6113
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
6114
|
+
var e_1, _d;
|
|
6115
|
+
return __generator(this, function (_e) {
|
|
6116
|
+
switch (_e.label) {
|
|
6063
6117
|
case 0:
|
|
6064
|
-
_a = options.
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6118
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
6119
|
+
index = 0;
|
|
6120
|
+
runningTasks = [];
|
|
6121
|
+
tasks = [];
|
|
6122
|
+
_loop_1 = function (item) {
|
|
6123
|
+
var currentIndex, task;
|
|
6124
|
+
return __generator(this, function (_f) {
|
|
6125
|
+
switch (_f.label) {
|
|
6126
|
+
case 0:
|
|
6127
|
+
currentIndex = index++;
|
|
6128
|
+
task = callbackfunction(item, currentIndex, array);
|
|
6129
|
+
tasks.push(task);
|
|
6130
|
+
runningTasks.push(task);
|
|
6131
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
6132
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
6133
|
+
});
|
|
6134
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
6135
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
6136
|
+
case 1:
|
|
6137
|
+
_f.sent();
|
|
6138
|
+
_f.label = 2;
|
|
6139
|
+
case 2: return [2 /*return*/];
|
|
6140
|
+
}
|
|
6141
|
+
});
|
|
6142
|
+
};
|
|
6143
|
+
_e.label = 1;
|
|
6072
6144
|
case 1:
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
_llms = arrayableToArray(tools.llm);
|
|
6077
|
-
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
6078
|
-
return [4 /*yield*/, llmTools.listModels()];
|
|
6145
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
6146
|
+
_b = __values(array), _c = _b.next();
|
|
6147
|
+
_e.label = 2;
|
|
6079
6148
|
case 2:
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6149
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
6150
|
+
item = _c.value;
|
|
6151
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
6152
|
+
case 3:
|
|
6153
|
+
_e.sent();
|
|
6154
|
+
_e.label = 4;
|
|
6155
|
+
case 4:
|
|
6156
|
+
_c = _b.next();
|
|
6157
|
+
return [3 /*break*/, 2];
|
|
6158
|
+
case 5: return [3 /*break*/, 8];
|
|
6159
|
+
case 6:
|
|
6160
|
+
e_1_1 = _e.sent();
|
|
6161
|
+
e_1 = { error: e_1_1 };
|
|
6162
|
+
return [3 /*break*/, 8];
|
|
6163
|
+
case 7:
|
|
6164
|
+
try {
|
|
6165
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
6166
|
+
}
|
|
6167
|
+
finally { if (e_1) throw e_1.error; }
|
|
6168
|
+
return [7 /*endfinally*/];
|
|
6169
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
6170
|
+
case 9:
|
|
6171
|
+
_e.sent();
|
|
6172
|
+
return [2 /*return*/];
|
|
6173
|
+
}
|
|
6174
|
+
});
|
|
6175
|
+
});
|
|
6176
|
+
}
|
|
6177
|
+
|
|
6178
|
+
/**
|
|
6179
|
+
* Prepares the persona for the pipeline
|
|
6180
|
+
*
|
|
6181
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
6182
|
+
* @public exported from `@promptbook/core`
|
|
6183
|
+
*/
|
|
6184
|
+
function preparePersona(personaDescription, tools, options) {
|
|
6185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6186
|
+
var _a, isVerbose, collection, preparePersonaExecutor, _b, _llms, llmTools, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
6187
|
+
var _c;
|
|
6188
|
+
return __generator(this, function (_d) {
|
|
6189
|
+
switch (_d.label) {
|
|
6190
|
+
case 0:
|
|
6191
|
+
_a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
|
|
6192
|
+
if (tools === undefined || tools.llm === undefined) {
|
|
6193
|
+
throw new MissingToolsError('LLM tools are required for preparing persona');
|
|
6194
|
+
}
|
|
6195
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
6196
|
+
_b = createPipelineExecutor;
|
|
6197
|
+
_c = {};
|
|
6198
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book.md')];
|
|
6199
|
+
case 1:
|
|
6200
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
6201
|
+
_c.tools = tools,
|
|
6202
|
+
_c)]);
|
|
6203
|
+
_llms = arrayableToArray(tools.llm);
|
|
6204
|
+
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
6205
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
6206
|
+
case 2:
|
|
6207
|
+
availableModels = _d.sent();
|
|
6208
|
+
availableModelNames = availableModels
|
|
6209
|
+
.filter(function (_a) {
|
|
6210
|
+
var modelVariant = _a.modelVariant;
|
|
6211
|
+
return modelVariant === 'CHAT';
|
|
6212
|
+
})
|
|
6213
|
+
.map(function (_a) {
|
|
6214
|
+
var modelName = _a.modelName;
|
|
6215
|
+
return modelName;
|
|
6216
|
+
})
|
|
6217
|
+
.join(',');
|
|
6218
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
6092
6219
|
case 3:
|
|
6093
6220
|
result = _d.sent();
|
|
6094
6221
|
assertsExecutionSuccessful(result);
|
|
@@ -6110,10 +6237,10 @@
|
|
|
6110
6237
|
});
|
|
6111
6238
|
}
|
|
6112
6239
|
/**
|
|
6113
|
-
* TODO: [🔃][main]
|
|
6114
|
-
* TODO: [🏢]
|
|
6115
|
-
* TODO: [🏢]
|
|
6116
|
-
* TODO: [🏢]
|
|
6240
|
+
* TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
|
|
6241
|
+
* TODO: [🏢] Check validity of `modelName` in pipeline
|
|
6242
|
+
* TODO: [🏢] Check validity of `systemMessage` in pipeline
|
|
6243
|
+
* TODO: [🏢] Check validity of `temperature` in pipeline
|
|
6117
6244
|
*/
|
|
6118
6245
|
|
|
6119
6246
|
/**
|
|
@@ -6323,6 +6450,9 @@
|
|
|
6323
6450
|
}
|
|
6324
6451
|
});
|
|
6325
6452
|
}); };
|
|
6453
|
+
/**
|
|
6454
|
+
* TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
|
|
6455
|
+
*/
|
|
6326
6456
|
|
|
6327
6457
|
/**
|
|
6328
6458
|
* @@@
|
|
@@ -6390,7 +6520,7 @@
|
|
|
6390
6520
|
},
|
|
6391
6521
|
}];
|
|
6392
6522
|
case 2:
|
|
6393
|
-
if (!
|
|
6523
|
+
if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
|
|
6394
6524
|
if (tools.fs === undefined) {
|
|
6395
6525
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
6396
6526
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -6405,7 +6535,7 @@
|
|
|
6405
6535
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
6406
6536
|
case 3:
|
|
6407
6537
|
if (!(_f.sent())) {
|
|
6408
|
-
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
6538
|
+
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(sourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
6409
6539
|
}
|
|
6410
6540
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
6411
6541
|
return [2 /*return*/, {
|
|
@@ -6518,7 +6648,7 @@
|
|
|
6518
6648
|
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
6519
6649
|
return [2 /*return*/, "break"];
|
|
6520
6650
|
}
|
|
6521
|
-
console.warn(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n
|
|
6651
|
+
console.warn(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.sourceContent
|
|
6522
6652
|
.split('\n')
|
|
6523
6653
|
.map(function (line) { return "> ".concat(line); })
|
|
6524
6654
|
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -6556,7 +6686,7 @@
|
|
|
6556
6686
|
return [7 /*endfinally*/];
|
|
6557
6687
|
case 9:
|
|
6558
6688
|
if (partialPieces === null) {
|
|
6559
|
-
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n
|
|
6689
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
|
|
6560
6690
|
.split('\n')
|
|
6561
6691
|
.map(function (line) { return "> ".concat(line); })
|
|
6562
6692
|
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -6647,7 +6777,7 @@
|
|
|
6647
6777
|
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
6648
6778
|
* TODO: [🧠] Add context to each task (if missing)
|
|
6649
6779
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
6650
|
-
* TODO: [♨][main]
|
|
6780
|
+
* TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
|
|
6651
6781
|
* TODO: Write tests for `preparePipeline`
|
|
6652
6782
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
6653
6783
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -6655,7 +6785,9 @@
|
|
|
6655
6785
|
*/
|
|
6656
6786
|
|
|
6657
6787
|
/**
|
|
6658
|
-
* Prepare pipeline
|
|
6788
|
+
* Prepare pipeline locally
|
|
6789
|
+
*
|
|
6790
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
6659
6791
|
*
|
|
6660
6792
|
* Note: This function does not validate logic of the pipeline
|
|
6661
6793
|
* Note: This function acts as part of compilation process
|
|
@@ -6669,16 +6801,17 @@
|
|
|
6669
6801
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
6670
6802
|
knowledgeSources /*
|
|
6671
6803
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
6672
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
6804
|
+
<- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
6805
|
+
var _d;
|
|
6673
6806
|
var _this = this;
|
|
6674
|
-
return __generator(this, function (
|
|
6675
|
-
switch (
|
|
6807
|
+
return __generator(this, function (_e) {
|
|
6808
|
+
switch (_e.label) {
|
|
6676
6809
|
case 0:
|
|
6677
6810
|
if (isPipelinePrepared(pipeline)) {
|
|
6678
6811
|
return [2 /*return*/, pipeline];
|
|
6679
6812
|
}
|
|
6680
6813
|
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
6681
|
-
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
6814
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
|
|
6682
6815
|
if (tools === undefined || tools.llm === undefined) {
|
|
6683
6816
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
6684
6817
|
}
|
|
@@ -6696,6 +6829,33 @@
|
|
|
6696
6829
|
// <- TODO: [🧊]
|
|
6697
6830
|
currentPreparation,
|
|
6698
6831
|
];
|
|
6832
|
+
title = pipeline.title;
|
|
6833
|
+
if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
|
|
6834
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
6835
|
+
_c = createPipelineExecutor;
|
|
6836
|
+
_d = {};
|
|
6837
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
|
|
6838
|
+
case 1:
|
|
6839
|
+
prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
|
|
6840
|
+
_d.tools = tools,
|
|
6841
|
+
_d)]);
|
|
6842
|
+
return [4 /*yield*/, prepareTitleExecutor({
|
|
6843
|
+
book: sources.map(function (_a) {
|
|
6844
|
+
var content = _a.content;
|
|
6845
|
+
return content;
|
|
6846
|
+
}).join('\n\n'),
|
|
6847
|
+
})];
|
|
6848
|
+
case 2:
|
|
6849
|
+
result = _e.sent();
|
|
6850
|
+
assertsExecutionSuccessful(result);
|
|
6851
|
+
outputParameters = result.outputParameters;
|
|
6852
|
+
titleRaw = outputParameters.title;
|
|
6853
|
+
if (isVerbose) {
|
|
6854
|
+
console.info("The title is \"".concat(titleRaw, "\""));
|
|
6855
|
+
}
|
|
6856
|
+
title = titleRaw || DEFAULT_BOOK_TITLE;
|
|
6857
|
+
_e.label = 3;
|
|
6858
|
+
case 3:
|
|
6699
6859
|
preparedPersonas = new Array(personas.length);
|
|
6700
6860
|
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 () {
|
|
6701
6861
|
var modelRequirements, preparedPersona;
|
|
@@ -6714,12 +6874,12 @@
|
|
|
6714
6874
|
}
|
|
6715
6875
|
});
|
|
6716
6876
|
}); })];
|
|
6717
|
-
case
|
|
6718
|
-
|
|
6877
|
+
case 4:
|
|
6878
|
+
_e.sent();
|
|
6719
6879
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
6720
6880
|
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
6721
|
-
case
|
|
6722
|
-
partialknowledgePiecesPrepared =
|
|
6881
|
+
case 5:
|
|
6882
|
+
partialknowledgePiecesPrepared = _e.sent();
|
|
6723
6883
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
6724
6884
|
return [4 /*yield*/, prepareTasks({
|
|
6725
6885
|
parameters: parameters,
|
|
@@ -6730,8 +6890,8 @@
|
|
|
6730
6890
|
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
6731
6891
|
isVerbose: isVerbose,
|
|
6732
6892
|
})];
|
|
6733
|
-
case
|
|
6734
|
-
tasksPrepared = (
|
|
6893
|
+
case 6:
|
|
6894
|
+
tasksPrepared = (_e.sent()).tasksPrepared;
|
|
6735
6895
|
// ----- /Tasks preparation -----
|
|
6736
6896
|
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
6737
6897
|
// Note: Count total usage
|
|
@@ -6742,7 +6902,7 @@
|
|
|
6742
6902
|
order: ORDER_OF_PIPELINE_JSON,
|
|
6743
6903
|
value: __assign(__assign({}, pipeline), {
|
|
6744
6904
|
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
6745
|
-
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
6905
|
+
title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
6746
6906
|
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
6747
6907
|
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
6748
6908
|
})];
|
|
@@ -6751,7 +6911,7 @@
|
|
|
6751
6911
|
});
|
|
6752
6912
|
}
|
|
6753
6913
|
/**
|
|
6754
|
-
* TODO: Write tests for `preparePipeline`
|
|
6914
|
+
* TODO: Write tests for `preparePipeline` and `preparePipelineOnRemoteServer`
|
|
6755
6915
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
6756
6916
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
6757
6917
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
@@ -6837,7 +6997,7 @@
|
|
|
6837
6997
|
if (sourceContent === '') {
|
|
6838
6998
|
throw new ParseError("Source is not defined");
|
|
6839
6999
|
}
|
|
6840
|
-
// TODO: [main]
|
|
7000
|
+
// TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
|
|
6841
7001
|
if (sourceContent.startsWith('http://')) {
|
|
6842
7002
|
throw new ParseError("Source is not secure");
|
|
6843
7003
|
}
|
|
@@ -7009,7 +7169,7 @@
|
|
|
7009
7169
|
expectResultingParameterName();
|
|
7010
7170
|
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
|
|
7011
7171
|
if (parameter === undefined) {
|
|
7012
|
-
// TODO:
|
|
7172
|
+
// TODO: !!6 Change to logic error for higher level abstraction of chatbot to work
|
|
7013
7173
|
throw new ParseError("Parameter `{".concat($taskJson.resultingParameterName, "}` is not defined so can not define example value of it"));
|
|
7014
7174
|
}
|
|
7015
7175
|
parameter.exampleValues = parameter.exampleValues || [];
|
|
@@ -7020,7 +7180,7 @@
|
|
|
7020
7180
|
if (command.taskType === 'KNOWLEDGE') {
|
|
7021
7181
|
knowledgeCommandParser.$applyToPipelineJson({
|
|
7022
7182
|
type: 'KNOWLEDGE',
|
|
7023
|
-
sourceContent: $taskJson.content, // <- TODO: [🐝][main]
|
|
7183
|
+
sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
7024
7184
|
}, $pipelineJson);
|
|
7025
7185
|
$taskJson.isTask = false;
|
|
7026
7186
|
return;
|
|
@@ -7899,20 +8059,24 @@
|
|
|
7899
8059
|
*/
|
|
7900
8060
|
var GeneratorFormfactorDefinition = {
|
|
7901
8061
|
name: 'GENERATOR',
|
|
7902
|
-
description: "
|
|
8062
|
+
description: "Generates any kind (in HTML with possible scripts and css format) of content from input message",
|
|
7903
8063
|
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
|
|
7904
8064
|
pipelineInterface: {
|
|
7905
8065
|
inputParameters: [
|
|
7906
|
-
/* @@@ */
|
|
7907
8066
|
{
|
|
7908
|
-
name: '
|
|
7909
|
-
description:
|
|
8067
|
+
name: 'inputMessage',
|
|
8068
|
+
description: "Input message to be image made from",
|
|
7910
8069
|
isInput: true,
|
|
7911
8070
|
isOutput: false,
|
|
7912
8071
|
},
|
|
7913
8072
|
],
|
|
7914
8073
|
outputParameters: [
|
|
7915
|
-
|
|
8074
|
+
{
|
|
8075
|
+
name: 'result',
|
|
8076
|
+
description: "Result in HTML to be shown to user",
|
|
8077
|
+
isInput: false,
|
|
8078
|
+
isOutput: true,
|
|
8079
|
+
},
|
|
7916
8080
|
],
|
|
7917
8081
|
},
|
|
7918
8082
|
};
|
|
@@ -7944,6 +8108,35 @@
|
|
|
7944
8108
|
pipelineInterface: GENERIC_PIPELINE_INTERFACE,
|
|
7945
8109
|
};
|
|
7946
8110
|
|
|
8111
|
+
/**
|
|
8112
|
+
* Image generator is form of app that generates image from input message
|
|
8113
|
+
*
|
|
8114
|
+
* @public exported from `@promptbook/core`
|
|
8115
|
+
*/
|
|
8116
|
+
var ImageGeneratorFormfactorDefinition = {
|
|
8117
|
+
name: 'IMAGE_GENERATOR',
|
|
8118
|
+
description: "Generates prompt for image generation from input message",
|
|
8119
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
|
|
8120
|
+
pipelineInterface: {
|
|
8121
|
+
inputParameters: [
|
|
8122
|
+
{
|
|
8123
|
+
name: 'inputMessage',
|
|
8124
|
+
description: "Input message to be image made from",
|
|
8125
|
+
isInput: true,
|
|
8126
|
+
isOutput: false,
|
|
8127
|
+
},
|
|
8128
|
+
],
|
|
8129
|
+
outputParameters: [
|
|
8130
|
+
{
|
|
8131
|
+
name: 'prompt',
|
|
8132
|
+
description: "Prompt to be used for image generation",
|
|
8133
|
+
isInput: false,
|
|
8134
|
+
isOutput: true,
|
|
8135
|
+
},
|
|
8136
|
+
],
|
|
8137
|
+
},
|
|
8138
|
+
};
|
|
8139
|
+
|
|
7947
8140
|
/**
|
|
7948
8141
|
* Matcher is form of app that @@@
|
|
7949
8142
|
*
|
|
@@ -8042,6 +8235,7 @@
|
|
|
8042
8235
|
SheetsFormfactorDefinition,
|
|
8043
8236
|
MatcherFormfactorDefinition,
|
|
8044
8237
|
GeneratorFormfactorDefinition,
|
|
8238
|
+
ImageGeneratorFormfactorDefinition,
|
|
8045
8239
|
];
|
|
8046
8240
|
/**
|
|
8047
8241
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8428,7 +8622,7 @@
|
|
|
8428
8622
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
8429
8623
|
*/
|
|
8430
8624
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
8431
|
-
// Note: [🍣] Do nothing, its application is implemented separately in `
|
|
8625
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
|
|
8432
8626
|
},
|
|
8433
8627
|
/**
|
|
8434
8628
|
* Apply the PARAMETER command to the `pipelineJson`
|
|
@@ -8436,7 +8630,7 @@
|
|
|
8436
8630
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
8437
8631
|
*/
|
|
8438
8632
|
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
8439
|
-
// Note: [🍣] Do nothing, its application is implemented separately in `
|
|
8633
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
|
|
8440
8634
|
},
|
|
8441
8635
|
/**
|
|
8442
8636
|
* Converts the PARAMETER command back to string
|
|
@@ -8931,7 +9125,7 @@
|
|
|
8931
9125
|
instrumentCommandParser,
|
|
8932
9126
|
personaCommandParser,
|
|
8933
9127
|
foreachCommandParser,
|
|
8934
|
-
boilerplateCommandParser, // <- TODO:
|
|
9128
|
+
boilerplateCommandParser, // <- TODO: Only in development, remove in production
|
|
8935
9129
|
// <- Note: [♓️][💩] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
|
|
8936
9130
|
];
|
|
8937
9131
|
/**
|
|
@@ -9355,7 +9549,7 @@
|
|
|
9355
9549
|
isOutput: true,
|
|
9356
9550
|
exampleValues: ['Hello, I am a Pavol`s virtual avatar. How can I help you?'],
|
|
9357
9551
|
});
|
|
9358
|
-
// TODO:
|
|
9552
|
+
// TODO: Use spaceTrim in multiline strings
|
|
9359
9553
|
$pipelineJson.tasks.push({
|
|
9360
9554
|
taskType: 'PROMPT_TASK',
|
|
9361
9555
|
name: 'create-an-answer',
|
|
@@ -9363,8 +9557,11 @@
|
|
|
9363
9557
|
content: 'Write a response to the user message:\n\n**Question from user**\n\n> {userMessage}\n\n**Previous conversation**\n\n> {previousConversationSummary}',
|
|
9364
9558
|
resultingParameterName: 'chatbotResponse',
|
|
9365
9559
|
personaName: personaName,
|
|
9366
|
-
dependentParameterNames: [
|
|
9367
|
-
|
|
9560
|
+
dependentParameterNames: [
|
|
9561
|
+
'userMessage',
|
|
9562
|
+
'previousConversationSummary' /* TODO: [🧠][📛], 'knowledge'*/,
|
|
9563
|
+
],
|
|
9564
|
+
// TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
9368
9565
|
}, {
|
|
9369
9566
|
taskType: 'PROMPT_TASK',
|
|
9370
9567
|
name: 'summarize-the-conversation',
|
|
@@ -9378,24 +9575,27 @@
|
|
|
9378
9575
|
max: 10,
|
|
9379
9576
|
},
|
|
9380
9577
|
},
|
|
9381
|
-
dependentParameterNames: ['userMessage', 'chatbotResponse' /*
|
|
9382
|
-
//
|
|
9578
|
+
dependentParameterNames: ['userMessage', 'chatbotResponse' /* TODO: [🧠][📛], 'knowledge'*/],
|
|
9579
|
+
// TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
9383
9580
|
}, {
|
|
9384
9581
|
taskType: 'SIMPLE_TASK',
|
|
9385
9582
|
name: 'title',
|
|
9386
9583
|
title: 'Title',
|
|
9387
9584
|
content: '{conversationSummary}',
|
|
9388
9585
|
resultingParameterName: 'title',
|
|
9389
|
-
dependentParameterNames: ['conversationSummary' /*
|
|
9390
|
-
//
|
|
9586
|
+
dependentParameterNames: ['conversationSummary' /* TODO: [🧠][📛], 'knowledge'*/],
|
|
9587
|
+
// TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
9391
9588
|
});
|
|
9392
9589
|
},
|
|
9393
9590
|
};
|
|
9591
|
+
/**
|
|
9592
|
+
* TODO: [🧠][📛] Should this be here?
|
|
9593
|
+
*/
|
|
9394
9594
|
|
|
9395
9595
|
/**
|
|
9396
9596
|
* All high-level abstractions
|
|
9397
9597
|
*
|
|
9398
|
-
* @private internal index of `
|
|
9598
|
+
* @private internal index of `parsePipeline` (= used for sync) and `preparePipeline` (= used for async)
|
|
9399
9599
|
*/
|
|
9400
9600
|
var HIGH_LEVEL_ABSTRACTIONS = [
|
|
9401
9601
|
ImplicitFormfactorHla,
|
|
@@ -9529,7 +9729,7 @@
|
|
|
9529
9729
|
return;
|
|
9530
9730
|
}
|
|
9531
9731
|
if (!section.startsWith('#')) {
|
|
9532
|
-
section = "# ".concat(
|
|
9732
|
+
section = "# ".concat(DEFAULT_BOOK_TITLE, "\n\n").concat(section);
|
|
9533
9733
|
}
|
|
9534
9734
|
sections.push(section);
|
|
9535
9735
|
buffer = [];
|
|
@@ -9584,7 +9784,7 @@
|
|
|
9584
9784
|
/**
|
|
9585
9785
|
* Normalizes the markdown by flattening the structure
|
|
9586
9786
|
*
|
|
9587
|
-
* - It always have h1 - if there is no h1 in the markdown, it will be added
|
|
9787
|
+
* - It always have h1 - if there is no h1 in the markdown, it will be added `DEFAULT_BOOK_TITLE`
|
|
9588
9788
|
* - All other headings are normalized to h2
|
|
9589
9789
|
*
|
|
9590
9790
|
* @public exported from `@promptbook/markdown-utils`
|
|
@@ -9593,7 +9793,7 @@
|
|
|
9593
9793
|
var e_1, _a;
|
|
9594
9794
|
var sections = splitMarkdownIntoSections(markdown);
|
|
9595
9795
|
if (sections.length === 0) {
|
|
9596
|
-
return "# ".concat(
|
|
9796
|
+
return "# ".concat(DEFAULT_BOOK_TITLE);
|
|
9597
9797
|
}
|
|
9598
9798
|
var flattenedMarkdown = '';
|
|
9599
9799
|
var parsedSections = sections.map(parseMarkdownSection);
|
|
@@ -9604,7 +9804,7 @@
|
|
|
9604
9804
|
}
|
|
9605
9805
|
else {
|
|
9606
9806
|
parsedSections.unshift(firstSection);
|
|
9607
|
-
flattenedMarkdown += "# ".concat(
|
|
9807
|
+
flattenedMarkdown += "# ".concat(DEFAULT_BOOK_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
|
|
9608
9808
|
}
|
|
9609
9809
|
try {
|
|
9610
9810
|
for (var parsedSections_1 = __values(parsedSections), parsedSections_1_1 = parsedSections_1.next(); !parsedSections_1_1.done; parsedSections_1_1 = parsedSections_1.next()) {
|
|
@@ -9631,13 +9831,13 @@
|
|
|
9631
9831
|
*/
|
|
9632
9832
|
|
|
9633
9833
|
/**
|
|
9634
|
-
* Removes
|
|
9834
|
+
* Removes Markdown (or HTML) comments
|
|
9635
9835
|
*
|
|
9636
9836
|
* @param {string} content - The string to remove comments from.
|
|
9637
9837
|
* @returns {string} The input string with all comments removed.
|
|
9638
9838
|
* @public exported from `@promptbook/markdown-utils`
|
|
9639
9839
|
*/
|
|
9640
|
-
function
|
|
9840
|
+
function removeMarkdownComments(content) {
|
|
9641
9841
|
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
9642
9842
|
}
|
|
9643
9843
|
|
|
@@ -9646,7 +9846,7 @@
|
|
|
9646
9846
|
*
|
|
9647
9847
|
* Note: There are 3 similar functions:
|
|
9648
9848
|
* - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
9649
|
-
* - `
|
|
9849
|
+
* - `parsePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
9650
9850
|
* - `preparePipeline` - just one step in the compilation process
|
|
9651
9851
|
*
|
|
9652
9852
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
@@ -9657,10 +9857,10 @@
|
|
|
9657
9857
|
* @throws {ParseError} if the promptbook string is not valid
|
|
9658
9858
|
* @public exported from `@promptbook/core`
|
|
9659
9859
|
*/
|
|
9660
|
-
function
|
|
9860
|
+
function parsePipeline(pipelineString) {
|
|
9661
9861
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
9662
9862
|
var $pipelineJson = {
|
|
9663
|
-
title:
|
|
9863
|
+
title: DEFAULT_BOOK_TITLE,
|
|
9664
9864
|
parameters: [],
|
|
9665
9865
|
tasks: [],
|
|
9666
9866
|
knowledgeSources: [],
|
|
@@ -9671,7 +9871,7 @@
|
|
|
9671
9871
|
{
|
|
9672
9872
|
type: 'BOOK',
|
|
9673
9873
|
path: null,
|
|
9674
|
-
// <- TODO:
|
|
9874
|
+
// <- TODO: !!6 Pass here path of the file
|
|
9675
9875
|
content: pipelineString,
|
|
9676
9876
|
},
|
|
9677
9877
|
],
|
|
@@ -9689,18 +9889,44 @@
|
|
|
9689
9889
|
}
|
|
9690
9890
|
// =============================================================
|
|
9691
9891
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
9892
|
+
// ==============
|
|
9893
|
+
// Note: 1️⃣◽1️⃣ Remove #!shebang and comments
|
|
9692
9894
|
if (pipelineString.startsWith('#!')) {
|
|
9693
9895
|
var _g = __read(pipelineString.split('\n')), shebangLine_1 = _g[0], restLines = _g.slice(1);
|
|
9694
9896
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
9695
9897
|
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
9696
9898
|
}
|
|
9697
|
-
pipelineString = restLines.join('\n');
|
|
9698
|
-
}
|
|
9699
|
-
pipelineString =
|
|
9899
|
+
pipelineString = validatePipelineString(restLines.join('\n'));
|
|
9900
|
+
}
|
|
9901
|
+
pipelineString = removeMarkdownComments(pipelineString);
|
|
9902
|
+
pipelineString = spaceTrim.spaceTrim(pipelineString);
|
|
9903
|
+
// <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
|
|
9904
|
+
// ==============
|
|
9905
|
+
// Note: 1️⃣◽2️⃣ Process flat pipeline
|
|
9906
|
+
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
9907
|
+
var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
|
|
9908
|
+
// TODO: Also (double)check
|
|
9909
|
+
// > const usedCommands
|
|
9910
|
+
// > const isBlocksUsed
|
|
9911
|
+
// > const returnStatementCount
|
|
9912
|
+
var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
|
|
9913
|
+
// console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
|
|
9914
|
+
if (isFlatPipeline) {
|
|
9915
|
+
var pipelineStringLines = pipelineString.split('\n');
|
|
9916
|
+
var returnStatement_1 = pipelineStringLines.pop();
|
|
9917
|
+
var prompt_1 = spaceTrim.spaceTrim(pipelineStringLines.join('\n'));
|
|
9918
|
+
pipelineString = validatePipelineString(spaceTrim.spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt_1), "\n ```\n\n ").concat(returnStatement_1, "\n "); }));
|
|
9919
|
+
// <- TODO: Maybe use book` notation
|
|
9920
|
+
// console.log(pipelineString);
|
|
9921
|
+
}
|
|
9922
|
+
// ==============
|
|
9923
|
+
// Note: 1️⃣◽3️⃣ Parse the markdown
|
|
9700
9924
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
9701
9925
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
9702
9926
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
9703
9927
|
var _h = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _h[0], pipelineSections = _h.slice(1); /* <- Note: [🥞] */
|
|
9928
|
+
// ==============
|
|
9929
|
+
// Note: 1️⃣◽4️⃣ Check markdown structure
|
|
9704
9930
|
if (pipelineHead === undefined) {
|
|
9705
9931
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
9706
9932
|
}
|
|
@@ -10084,14 +10310,14 @@
|
|
|
10084
10310
|
// =============================================================
|
|
10085
10311
|
return exportJson({
|
|
10086
10312
|
name: 'pipelineJson',
|
|
10087
|
-
message: "Result of `
|
|
10313
|
+
message: "Result of `parsePipeline`",
|
|
10088
10314
|
order: ORDER_OF_PIPELINE_JSON,
|
|
10089
10315
|
value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
|
|
10090
10316
|
});
|
|
10091
10317
|
}
|
|
10092
10318
|
/**
|
|
10093
10319
|
* TODO: [🧠] Maybe more things here can be refactored as high-level abstractions
|
|
10094
|
-
* TODO: [main]
|
|
10320
|
+
* TODO: [main] !!4 Warn if used only sync version
|
|
10095
10321
|
* TODO: [🚞] Report here line/column of error
|
|
10096
10322
|
* TODO: Use spaceTrim more effectively
|
|
10097
10323
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
@@ -10104,10 +10330,7 @@
|
|
|
10104
10330
|
/**
|
|
10105
10331
|
* Compile pipeline from string (markdown) format to JSON format
|
|
10106
10332
|
*
|
|
10107
|
-
*
|
|
10108
|
-
* - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
10109
|
-
* - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
10110
|
-
* - `preparePipeline` - just one step in the compilation process
|
|
10333
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
10111
10334
|
*
|
|
10112
10335
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
10113
10336
|
* Note: This function acts as compilation process
|
|
@@ -10125,7 +10348,7 @@
|
|
|
10125
10348
|
return __generator(this, function (_a) {
|
|
10126
10349
|
switch (_a.label) {
|
|
10127
10350
|
case 0:
|
|
10128
|
-
pipelineJson =
|
|
10351
|
+
pipelineJson = parsePipeline(pipelineString);
|
|
10129
10352
|
if (!(tools !== undefined && tools.llm !== undefined)) return [3 /*break*/, 2];
|
|
10130
10353
|
return [4 /*yield*/, preparePipeline(pipelineJson, tools, options || {
|
|
10131
10354
|
rootDirname: null,
|
|
@@ -10134,7 +10357,7 @@
|
|
|
10134
10357
|
pipelineJson = _a.sent();
|
|
10135
10358
|
_a.label = 2;
|
|
10136
10359
|
case 2:
|
|
10137
|
-
// Note: No need to use `$exportJson` because `
|
|
10360
|
+
// Note: No need to use `$exportJson` because `parsePipeline` and `preparePipeline` already do that
|
|
10138
10361
|
return [2 /*return*/, pipelineJson];
|
|
10139
10362
|
}
|
|
10140
10363
|
});
|
|
@@ -10498,23 +10721,95 @@
|
|
|
10498
10721
|
*/
|
|
10499
10722
|
|
|
10500
10723
|
/**
|
|
10501
|
-
*
|
|
10502
|
-
*
|
|
10503
|
-
* - When there are multiple or no code blocks the function throws a `ParseError`
|
|
10724
|
+
* Creates a Mermaid graph based on the promptbook
|
|
10504
10725
|
*
|
|
10505
|
-
* Note:
|
|
10506
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
10507
|
-
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
10508
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
10509
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
10726
|
+
* Note: The result is not wrapped in a Markdown code block
|
|
10510
10727
|
*
|
|
10511
|
-
* @public exported from `@promptbook/
|
|
10512
|
-
* @throws {ParseError} if there is not exactly one code block in the markdown
|
|
10728
|
+
* @public exported from `@promptbook/utils`
|
|
10513
10729
|
*/
|
|
10514
|
-
function
|
|
10515
|
-
var
|
|
10516
|
-
|
|
10730
|
+
function renderPromptbookMermaid(pipelineJson, options) {
|
|
10731
|
+
var _a = (options || {}).linkTask, linkTask = _a === void 0 ? function () { return null; } : _a;
|
|
10732
|
+
var parameterNameToTaskName = function (parameterName) {
|
|
10733
|
+
var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
10734
|
+
if (!parameter) {
|
|
10735
|
+
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
10736
|
+
// <- TODO: !!6 This causes problems when {knowledge} and other reserved parameters are used
|
|
10737
|
+
}
|
|
10738
|
+
if (parameter.isInput) {
|
|
10739
|
+
return 'input';
|
|
10740
|
+
}
|
|
10741
|
+
var task = pipelineJson.tasks.find(function (task) { return task.resultingParameterName === parameterName; });
|
|
10742
|
+
if (!task) {
|
|
10743
|
+
throw new Error("Could not find task for {".concat(parameterName, "}"));
|
|
10744
|
+
}
|
|
10745
|
+
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
10746
|
+
};
|
|
10747
|
+
var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
10748
|
+
.flatMap(function (_a) {
|
|
10749
|
+
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
10750
|
+
return __spreadArray([
|
|
10751
|
+
"".concat(parameterNameToTaskName(resultingParameterName), "(\"").concat(title, "\")")
|
|
10752
|
+
], __read(dependentParameterNames.map(function (dependentParameterName) {
|
|
10753
|
+
return "".concat(parameterNameToTaskName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTaskName(resultingParameterName));
|
|
10754
|
+
})), false);
|
|
10755
|
+
})
|
|
10756
|
+
.join('\n')), "\n\n ").concat(block(pipelineJson.parameters
|
|
10757
|
+
.filter(function (_a) {
|
|
10758
|
+
var isOutput = _a.isOutput;
|
|
10759
|
+
return isOutput;
|
|
10760
|
+
})
|
|
10761
|
+
.map(function (_a) {
|
|
10762
|
+
var name = _a.name;
|
|
10763
|
+
return "".concat(parameterNameToTaskName(name), "--\"{").concat(name, "}\"-->output");
|
|
10764
|
+
})
|
|
10765
|
+
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.tasks
|
|
10766
|
+
.map(function (task) {
|
|
10767
|
+
var link = linkTask(task);
|
|
10768
|
+
if (link === null) {
|
|
10769
|
+
return '';
|
|
10770
|
+
}
|
|
10771
|
+
var href = link.href, title = link.title;
|
|
10772
|
+
var taskName = parameterNameToTaskName(task.resultingParameterName);
|
|
10773
|
+
return "click ".concat(taskName, " href \"").concat(href, "\" \"").concat(title, "\";");
|
|
10774
|
+
})
|
|
10775
|
+
.filter(function (line) { return line !== ''; })
|
|
10776
|
+
.join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
|
|
10777
|
+
return promptbookMermaid;
|
|
10517
10778
|
}
|
|
10779
|
+
/**
|
|
10780
|
+
* TODO: [🧠] FOREACH in mermaid graph
|
|
10781
|
+
* TODO: [🧠] Knowledge in mermaid graph
|
|
10782
|
+
* TODO: [🧠] Personas in mermaid graph
|
|
10783
|
+
* TODO: Maybe use some Mermaid package instead of string templating
|
|
10784
|
+
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
10785
|
+
*/
|
|
10786
|
+
|
|
10787
|
+
/**
|
|
10788
|
+
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
10789
|
+
*
|
|
10790
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
10791
|
+
*
|
|
10792
|
+
* @public exported from `@promptbook/utils`
|
|
10793
|
+
*/
|
|
10794
|
+
var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
10795
|
+
|
|
10796
|
+
/**
|
|
10797
|
+
* Detects if the code is running in jest environment
|
|
10798
|
+
*
|
|
10799
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
10800
|
+
*
|
|
10801
|
+
* @public exported from `@promptbook/utils`
|
|
10802
|
+
*/
|
|
10803
|
+
var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
|
|
10804
|
+
|
|
10805
|
+
/**
|
|
10806
|
+
* Detects if the code is running in a web worker
|
|
10807
|
+
*
|
|
10808
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
10809
|
+
*
|
|
10810
|
+
* @public exported from `@promptbook/utils`
|
|
10811
|
+
*/
|
|
10812
|
+
var $isRunningInWebWorker = 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");
|
|
10518
10813
|
|
|
10519
10814
|
/**
|
|
10520
10815
|
* Makes first letter of a string uppercase
|
|
@@ -10525,6 +10820,21 @@
|
|
|
10525
10820
|
return word.substring(0, 1).toLowerCase() + word.substring(1);
|
|
10526
10821
|
}
|
|
10527
10822
|
|
|
10823
|
+
/**
|
|
10824
|
+
* Parses keywords from a string
|
|
10825
|
+
*
|
|
10826
|
+
* @param {string} input
|
|
10827
|
+
* @returns {Set} of keywords without diacritics in lowercase
|
|
10828
|
+
* @public exported from `@promptbook/utils`
|
|
10829
|
+
*/
|
|
10830
|
+
function parseKeywordsFromString(input) {
|
|
10831
|
+
var keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
|
|
10832
|
+
.toLowerCase()
|
|
10833
|
+
.split(/[^a-z0-9]+/gs)
|
|
10834
|
+
.filter(function (value) { return value; });
|
|
10835
|
+
return new Set(keywords);
|
|
10836
|
+
}
|
|
10837
|
+
|
|
10528
10838
|
/**
|
|
10529
10839
|
* @@@
|
|
10530
10840
|
*
|
|
@@ -10578,21 +10888,6 @@
|
|
|
10578
10888
|
return sentence.replace(/\s+/gs, ' ').trim();
|
|
10579
10889
|
}
|
|
10580
10890
|
|
|
10581
|
-
/**
|
|
10582
|
-
* Parses keywords from a string
|
|
10583
|
-
*
|
|
10584
|
-
* @param {string} input
|
|
10585
|
-
* @returns {Set} of keywords without diacritics in lowercase
|
|
10586
|
-
* @public exported from `@promptbook/utils`
|
|
10587
|
-
*/
|
|
10588
|
-
function parseKeywordsFromString(input) {
|
|
10589
|
-
var keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
|
|
10590
|
-
.toLowerCase()
|
|
10591
|
-
.split(/[^a-z0-9]+/gs)
|
|
10592
|
-
.filter(function (value) { return value; });
|
|
10593
|
-
return new Set(keywords);
|
|
10594
|
-
}
|
|
10595
|
-
|
|
10596
10891
|
/**
|
|
10597
10892
|
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
|
10598
10893
|
*
|
|
@@ -10699,6 +10994,25 @@
|
|
|
10699
10994
|
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
10700
10995
|
*/
|
|
10701
10996
|
|
|
10997
|
+
/**
|
|
10998
|
+
* Extracts code block from markdown.
|
|
10999
|
+
*
|
|
11000
|
+
* - When there are multiple or no code blocks the function throws a `ParseError`
|
|
11001
|
+
*
|
|
11002
|
+
* Note: There are multiple simmilar function:
|
|
11003
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
11004
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
11005
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
11006
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
11007
|
+
*
|
|
11008
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
11009
|
+
* @throws {ParseError} if there is not exactly one code block in the markdown
|
|
11010
|
+
*/
|
|
11011
|
+
function extractBlock(markdown) {
|
|
11012
|
+
var content = extractOneBlockFromMarkdown(markdown).content;
|
|
11013
|
+
return content;
|
|
11014
|
+
}
|
|
11015
|
+
|
|
10702
11016
|
/**
|
|
10703
11017
|
* Does nothing, but preserves the function in the bundle
|
|
10704
11018
|
* Compiler is tricked into thinking the function is used
|
|
@@ -10733,37 +11047,10 @@
|
|
|
10733
11047
|
}); })();
|
|
10734
11048
|
}
|
|
10735
11049
|
/**
|
|
10736
|
-
* TODO:
|
|
11050
|
+
* TODO: Probbably remove in favour of `keepImported`
|
|
11051
|
+
* TODO: [1] This maybe does memory leak
|
|
10737
11052
|
*/
|
|
10738
11053
|
|
|
10739
|
-
/**
|
|
10740
|
-
* Converts anything to string that can be used for debugging and logging
|
|
10741
|
-
*
|
|
10742
|
-
* @param value String value for logging
|
|
10743
|
-
* @private internal util
|
|
10744
|
-
*/
|
|
10745
|
-
function unknownToString(value) {
|
|
10746
|
-
if (value === undefined) {
|
|
10747
|
-
return 'undefined';
|
|
10748
|
-
}
|
|
10749
|
-
else if (value === null) {
|
|
10750
|
-
return 'null';
|
|
10751
|
-
}
|
|
10752
|
-
else if (['number', 'string', 'boolean'].includes(typeof value)) {
|
|
10753
|
-
return typeof value + ' ' + value.toString();
|
|
10754
|
-
}
|
|
10755
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
10756
|
-
return 'array containing [' + value.map(function (item) { return unknownToString(item); }).join(', ') + ']';
|
|
10757
|
-
}
|
|
10758
|
-
else if (typeof value === 'object') {
|
|
10759
|
-
// TODO: Maybe serialize the object
|
|
10760
|
-
return 'object';
|
|
10761
|
-
}
|
|
10762
|
-
else {
|
|
10763
|
-
return 'unknown (Search in promptbook code for [🔹])';
|
|
10764
|
-
}
|
|
10765
|
-
}
|
|
10766
|
-
|
|
10767
11054
|
/**
|
|
10768
11055
|
* ScriptExecutionTools for JavaScript implemented via eval
|
|
10769
11056
|
*
|
|
@@ -10893,7 +11180,7 @@
|
|
|
10893
11180
|
case 2:
|
|
10894
11181
|
result = _a.sent();
|
|
10895
11182
|
if (typeof result !== 'string') {
|
|
10896
|
-
throw new PipelineExecutionError("Script must return a string, but returned ".concat(
|
|
11183
|
+
throw new PipelineExecutionError("Script must return a string, but returned ".concat(valueToString(result)));
|
|
10897
11184
|
}
|
|
10898
11185
|
return [3 /*break*/, 4];
|
|
10899
11186
|
case 3:
|
|
@@ -10920,7 +11207,7 @@
|
|
|
10920
11207
|
throw error_1;
|
|
10921
11208
|
case 4:
|
|
10922
11209
|
if (typeof result !== 'string') {
|
|
10923
|
-
throw new PipelineExecutionError("Script must return a string, but ".concat(
|
|
11210
|
+
throw new PipelineExecutionError("Script must return a string, but ".concat(valueToString(result)));
|
|
10924
11211
|
}
|
|
10925
11212
|
return [2 /*return*/, result];
|
|
10926
11213
|
}
|
|
@@ -10960,9 +11247,11 @@
|
|
|
10960
11247
|
throw new EnvironmentMismatchError('Function `$getExecutionToolsForNode` works only in Node.js environment');
|
|
10961
11248
|
}
|
|
10962
11249
|
fs = $provideFilesystemForNode();
|
|
10963
|
-
|
|
10964
|
-
return [4 /*yield*/, $provideExecutablesForNode(options)];
|
|
11250
|
+
return [4 /*yield*/, $provideLlmToolsFromEnv(options)];
|
|
10965
11251
|
case 1:
|
|
11252
|
+
llm = _b.sent();
|
|
11253
|
+
return [4 /*yield*/, $provideExecutablesForNode(options)];
|
|
11254
|
+
case 2:
|
|
10966
11255
|
executables = _b.sent();
|
|
10967
11256
|
_a = {
|
|
10968
11257
|
llm: llm,
|
|
@@ -10970,7 +11259,7 @@
|
|
|
10970
11259
|
executables: executables
|
|
10971
11260
|
};
|
|
10972
11261
|
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, options)];
|
|
10973
|
-
case
|
|
11262
|
+
case 3:
|
|
10974
11263
|
tools = (_a.scrapers = _b.sent(),
|
|
10975
11264
|
_a.script = [new JavascriptExecutionTools(options)],
|
|
10976
11265
|
_a);
|
|
@@ -11193,7 +11482,7 @@
|
|
|
11193
11482
|
*/
|
|
11194
11483
|
function createCollectionFromDirectory(path$1, tools, options) {
|
|
11195
11484
|
return __awaiter(this, void 0, void 0, function () {
|
|
11196
|
-
var
|
|
11485
|
+
var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
|
|
11197
11486
|
var _this = this;
|
|
11198
11487
|
return __generator(this, function (_f) {
|
|
11199
11488
|
switch (_f.label) {
|
|
@@ -11208,18 +11497,18 @@
|
|
|
11208
11497
|
throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
|
|
11209
11498
|
// <- TODO: [🧠] What is the best error type here`
|
|
11210
11499
|
}
|
|
11211
|
-
|
|
11500
|
+
madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
|
|
11212
11501
|
// <- TODO: [🦒] Allow to override (pass different value into the function)
|
|
11213
11502
|
, ".json"));
|
|
11214
|
-
return [4 /*yield*/, isFileExisting(
|
|
11503
|
+
return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
|
|
11215
11504
|
case 3:
|
|
11216
11505
|
if (!(_f.sent())) ;
|
|
11217
11506
|
else {
|
|
11218
|
-
colors__default["default"].green("(In future, not implemented yet) Using your compiled pipeline collection ".concat(
|
|
11219
|
-
// TODO:
|
|
11507
|
+
colors__default["default"].green("(In future, not implemented yet) Using your compiled pipeline collection ".concat(madeLibraryFilePath));
|
|
11508
|
+
// TODO: Implement;
|
|
11220
11509
|
// TODO: [🌗]
|
|
11221
11510
|
}
|
|
11222
|
-
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
|
|
11511
|
+
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e, rootUrl = _a.rootUrl;
|
|
11223
11512
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
11224
11513
|
var fileNames, collection, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
11225
11514
|
var e_1, _a;
|
|
@@ -11245,34 +11534,35 @@
|
|
|
11245
11534
|
});
|
|
11246
11535
|
collection = new Map();
|
|
11247
11536
|
_loop_1 = function (fileName) {
|
|
11248
|
-
var sourceFile, rootDirname, pipeline, pipelineString, _c, _d, existing, error_1, wrappedErrorMessage;
|
|
11249
|
-
return __generator(this, function (
|
|
11250
|
-
switch (
|
|
11537
|
+
var sourceFile, rootDirname, pipeline, pipelineString, _c, _d, _e, pipelineUrl, existing, error_1, wrappedErrorMessage;
|
|
11538
|
+
return __generator(this, function (_f) {
|
|
11539
|
+
switch (_f.label) {
|
|
11251
11540
|
case 0:
|
|
11252
11541
|
sourceFile = './' + fileName.split('\\').join('/');
|
|
11253
11542
|
rootDirname = path.dirname(sourceFile).split('\\').join('/');
|
|
11254
|
-
|
|
11543
|
+
_f.label = 1;
|
|
11255
11544
|
case 1:
|
|
11256
|
-
|
|
11545
|
+
_f.trys.push([1, 8, , 9]);
|
|
11257
11546
|
pipeline = null;
|
|
11258
11547
|
if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
|
|
11548
|
+
_c = validatePipelineString;
|
|
11259
11549
|
return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
|
|
11260
11550
|
case 2:
|
|
11261
|
-
pipelineString = (
|
|
11551
|
+
pipelineString = _c.apply(void 0, [_f.sent()]);
|
|
11262
11552
|
return [4 /*yield*/, compilePipeline(pipelineString, tools, {
|
|
11263
11553
|
rootDirname: rootDirname,
|
|
11264
11554
|
})];
|
|
11265
11555
|
case 3:
|
|
11266
|
-
pipeline =
|
|
11556
|
+
pipeline = _f.sent();
|
|
11267
11557
|
pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
|
|
11268
11558
|
return [3 /*break*/, 7];
|
|
11269
11559
|
case 4:
|
|
11270
11560
|
if (!fileName.endsWith('.book.json')) return [3 /*break*/, 6];
|
|
11271
|
-
|
|
11561
|
+
_e = (_d = JSON).parse;
|
|
11272
11562
|
return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
|
|
11273
11563
|
case 5:
|
|
11274
11564
|
// TODO: Handle non-valid JSON files
|
|
11275
|
-
pipeline =
|
|
11565
|
+
pipeline = _e.apply(_d, [_f.sent()]);
|
|
11276
11566
|
// TODO: [🌗]
|
|
11277
11567
|
pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
|
|
11278
11568
|
return [3 /*break*/, 7];
|
|
@@ -11280,10 +11570,24 @@
|
|
|
11280
11570
|
if (isVerbose) {
|
|
11281
11571
|
console.info(colors__default["default"].gray("Skipped file ".concat(fileName.split('\\').join('/'), " \u2013\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060 Not a book")));
|
|
11282
11572
|
}
|
|
11283
|
-
|
|
11573
|
+
_f.label = 7;
|
|
11284
11574
|
case 7:
|
|
11285
11575
|
// ---
|
|
11286
11576
|
if (pipeline !== null) {
|
|
11577
|
+
if (rootUrl !== undefined) {
|
|
11578
|
+
if (pipeline.pipelineUrl === undefined) {
|
|
11579
|
+
pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
|
|
11580
|
+
if (isVerbose) {
|
|
11581
|
+
console.info(colors__default["default"].yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
|
|
11582
|
+
.split('\\')
|
|
11583
|
+
.join('/'))));
|
|
11584
|
+
}
|
|
11585
|
+
pipeline = __assign(__assign({}, pipeline), { pipelineUrl: pipelineUrl });
|
|
11586
|
+
}
|
|
11587
|
+
else if (!pipeline.pipelineUrl.startsWith(rootUrl)) {
|
|
11588
|
+
throw new PipelineUrlError(spaceTrim__default["default"]("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is not a child of the root URL ").concat(rootUrl, " \uD83C\uDF4F\n\n File:\n ").concat(sourceFile || 'Unknown', "\n\n ")));
|
|
11589
|
+
}
|
|
11590
|
+
}
|
|
11287
11591
|
// TODO: [👠] DRY
|
|
11288
11592
|
if (pipeline.pipelineUrl === undefined) {
|
|
11289
11593
|
if (isVerbose) {
|
|
@@ -11315,17 +11619,17 @@
|
|
|
11315
11619
|
}
|
|
11316
11620
|
else {
|
|
11317
11621
|
existing = collection.get(pipeline.pipelineUrl);
|
|
11318
|
-
throw new PipelineUrlError(spaceTrim__default["default"]("\n Pipeline with URL
|
|
11622
|
+
throw new PipelineUrlError(spaceTrim__default["default"]("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is already in the collection \uD83C\uDF4F\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
11319
11623
|
}
|
|
11320
11624
|
}
|
|
11321
11625
|
}
|
|
11322
11626
|
return [3 /*break*/, 9];
|
|
11323
11627
|
case 8:
|
|
11324
|
-
error_1 =
|
|
11628
|
+
error_1 = _f.sent();
|
|
11325
11629
|
if (!(error_1 instanceof Error)) {
|
|
11326
11630
|
throw error_1;
|
|
11327
11631
|
}
|
|
11328
|
-
wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n
|
|
11632
|
+
wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n Original error message:\n ").concat(block(error_1.message), "\n\n Original stack trace:\n ").concat(block(error_1.stack || ''), "\n\n ---\n\n "); }) + '\n';
|
|
11329
11633
|
if (isCrashedOnError) {
|
|
11330
11634
|
throw new CollectionError(wrappedErrorMessage);
|
|
11331
11635
|
}
|
|
@@ -11460,6 +11764,7 @@
|
|
|
11460
11764
|
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
11461
11765
|
'Path to promptbook collection directory', DEFAULT_BOOKS_DIRNAME);
|
|
11462
11766
|
makeCommand.option('--project-name', "Name of the project for whom collection is", 'Untitled Promptbook project');
|
|
11767
|
+
makeCommand.option('--root-url <url>', "Root URL of all pipelines to make", undefined);
|
|
11463
11768
|
makeCommand.option('-f, --format <format>', spaceTrim__default["default"]("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳🌈] */);
|
|
11464
11769
|
makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
|
|
11465
11770
|
makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
|
|
@@ -11468,7 +11773,7 @@
|
|
|
11468
11773
|
makeCommand.option('-o, --output <path>', spaceTrim__default["default"]("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_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 ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
|
|
11469
11774
|
makeCommand.option('-fn, --function-name <functionName>', spaceTrim__default["default"]("\n Name of the function to get pipeline collection\n\n Note: This can be used only with \"javascript\" or \"typescript\" format\n\n "), DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME);
|
|
11470
11775
|
makeCommand.action(function (path$1, _a) {
|
|
11471
|
-
var projectName = _a.projectName, format = _a.format, functionName = _a.functionName, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, output = _a.output;
|
|
11776
|
+
var projectName = _a.projectName, rootUrl = _a.rootUrl, format = _a.format, functionName = _a.functionName, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, output = _a.output;
|
|
11472
11777
|
return __awaiter(_this, void 0, void 0, function () {
|
|
11473
11778
|
var formats, validations, prepareAndScrapeOptions, fs, llm, executables, tools, collection, pipelinesUrls, validations_1, validations_1_1, validation_1, pipelinesUrls_1, pipelinesUrls_1_1, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
|
|
11474
11779
|
var _b, e_2, _c, e_1, _d;
|
|
@@ -11480,6 +11785,10 @@
|
|
|
11480
11785
|
console.error(colors__default["default"].red("Function name \"".concat(functionName, "\" is not valid javascript name")));
|
|
11481
11786
|
return [2 /*return*/, process.exit(1)];
|
|
11482
11787
|
}
|
|
11788
|
+
if (!isValidUrl(rootUrl) /* <- Note: Not using `isValidPipelineUrl` because this is root url not book url */) {
|
|
11789
|
+
console.error(colors__default["default"].red("Root URL ".concat(rootUrl, " is not valid URL")));
|
|
11790
|
+
return [2 /*return*/, process.exit(1)];
|
|
11791
|
+
}
|
|
11483
11792
|
formats = (format || '')
|
|
11484
11793
|
.split(',')
|
|
11485
11794
|
.map(function (_) { return _.trim(); })
|
|
@@ -11497,16 +11806,18 @@
|
|
|
11497
11806
|
isCacheReloaded: isCacheReloaded,
|
|
11498
11807
|
};
|
|
11499
11808
|
fs = $provideFilesystemForNode(prepareAndScrapeOptions);
|
|
11500
|
-
|
|
11501
|
-
return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
|
|
11809
|
+
return [4 /*yield*/, $provideLlmToolsForWizzardOrCli(prepareAndScrapeOptions)];
|
|
11502
11810
|
case 1:
|
|
11811
|
+
llm = _e.sent();
|
|
11812
|
+
return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
|
|
11813
|
+
case 2:
|
|
11503
11814
|
executables = _e.sent();
|
|
11504
11815
|
_b = {
|
|
11505
11816
|
llm: llm,
|
|
11506
11817
|
fs: fs
|
|
11507
11818
|
};
|
|
11508
11819
|
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, prepareAndScrapeOptions)];
|
|
11509
|
-
case
|
|
11820
|
+
case 3:
|
|
11510
11821
|
tools = (_b.scrapers = _e.sent(),
|
|
11511
11822
|
_b.script = [
|
|
11512
11823
|
/*new JavascriptExecutionTools(options)*/
|
|
@@ -11514,36 +11825,39 @@
|
|
|
11514
11825
|
_b);
|
|
11515
11826
|
return [4 /*yield*/, createCollectionFromDirectory(path$1, tools, {
|
|
11516
11827
|
isVerbose: isVerbose,
|
|
11828
|
+
rootUrl: rootUrl,
|
|
11517
11829
|
isRecursive: true,
|
|
11830
|
+
isLazyLoaded: false,
|
|
11831
|
+
isCrashedOnError: true,
|
|
11518
11832
|
// <- TODO: [🍖] Add `intermediateFilesStrategy`
|
|
11519
11833
|
})];
|
|
11520
|
-
case
|
|
11834
|
+
case 4:
|
|
11521
11835
|
collection = _e.sent();
|
|
11522
11836
|
return [4 /*yield*/, collection.listPipelines()];
|
|
11523
|
-
case
|
|
11837
|
+
case 5:
|
|
11524
11838
|
pipelinesUrls = _e.sent();
|
|
11525
11839
|
if (pipelinesUrls.length === 0) {
|
|
11526
11840
|
console.error(colors__default["default"].red("No books found in \"".concat(path$1, "\"")));
|
|
11527
11841
|
return [2 /*return*/, process.exit(1)];
|
|
11528
11842
|
}
|
|
11529
|
-
_e.label = 5;
|
|
11530
|
-
case 5:
|
|
11531
|
-
_e.trys.push([5, 16, 17, 18]);
|
|
11532
|
-
validations_1 = __values(validations), validations_1_1 = validations_1.next();
|
|
11533
11843
|
_e.label = 6;
|
|
11534
11844
|
case 6:
|
|
11535
|
-
|
|
11536
|
-
|
|
11845
|
+
_e.trys.push([6, 17, 18, 19]);
|
|
11846
|
+
validations_1 = __values(validations), validations_1_1 = validations_1.next();
|
|
11537
11847
|
_e.label = 7;
|
|
11538
11848
|
case 7:
|
|
11539
|
-
|
|
11540
|
-
|
|
11849
|
+
if (!!validations_1_1.done) return [3 /*break*/, 16];
|
|
11850
|
+
validation_1 = validations_1_1.value;
|
|
11541
11851
|
_e.label = 8;
|
|
11542
11852
|
case 8:
|
|
11543
|
-
|
|
11853
|
+
_e.trys.push([8, 13, 14, 15]);
|
|
11854
|
+
pipelinesUrls_1 = (e_1 = void 0, __values(pipelinesUrls)), pipelinesUrls_1_1 = pipelinesUrls_1.next();
|
|
11855
|
+
_e.label = 9;
|
|
11856
|
+
case 9:
|
|
11857
|
+
if (!!pipelinesUrls_1_1.done) return [3 /*break*/, 12];
|
|
11544
11858
|
pipelineUrl = pipelinesUrls_1_1.value;
|
|
11545
11859
|
return [4 /*yield*/, collection.getPipelineByUrl(pipelineUrl)];
|
|
11546
|
-
case
|
|
11860
|
+
case 10:
|
|
11547
11861
|
pipeline = _e.sent();
|
|
11548
11862
|
if (validation_1 === 'logic') {
|
|
11549
11863
|
validatePipeline(pipeline);
|
|
@@ -11551,37 +11865,37 @@
|
|
|
11551
11865
|
console.info(colors__default["default"].cyan("Validated logic of ".concat(pipeline.pipelineUrl)));
|
|
11552
11866
|
}
|
|
11553
11867
|
}
|
|
11554
|
-
_e.label =
|
|
11555
|
-
case
|
|
11868
|
+
_e.label = 11;
|
|
11869
|
+
case 11:
|
|
11556
11870
|
pipelinesUrls_1_1 = pipelinesUrls_1.next();
|
|
11557
|
-
return [3 /*break*/,
|
|
11558
|
-
case
|
|
11559
|
-
case
|
|
11871
|
+
return [3 /*break*/, 9];
|
|
11872
|
+
case 12: return [3 /*break*/, 15];
|
|
11873
|
+
case 13:
|
|
11560
11874
|
e_1_1 = _e.sent();
|
|
11561
11875
|
e_1 = { error: e_1_1 };
|
|
11562
|
-
return [3 /*break*/,
|
|
11563
|
-
case
|
|
11876
|
+
return [3 /*break*/, 15];
|
|
11877
|
+
case 14:
|
|
11564
11878
|
try {
|
|
11565
11879
|
if (pipelinesUrls_1_1 && !pipelinesUrls_1_1.done && (_d = pipelinesUrls_1.return)) _d.call(pipelinesUrls_1);
|
|
11566
11880
|
}
|
|
11567
11881
|
finally { if (e_1) throw e_1.error; }
|
|
11568
11882
|
return [7 /*endfinally*/];
|
|
11569
|
-
case
|
|
11883
|
+
case 15:
|
|
11570
11884
|
validations_1_1 = validations_1.next();
|
|
11571
|
-
return [3 /*break*/,
|
|
11572
|
-
case
|
|
11573
|
-
case
|
|
11885
|
+
return [3 /*break*/, 7];
|
|
11886
|
+
case 16: return [3 /*break*/, 19];
|
|
11887
|
+
case 17:
|
|
11574
11888
|
e_2_1 = _e.sent();
|
|
11575
11889
|
e_2 = { error: e_2_1 };
|
|
11576
|
-
return [3 /*break*/,
|
|
11577
|
-
case
|
|
11890
|
+
return [3 /*break*/, 19];
|
|
11891
|
+
case 18:
|
|
11578
11892
|
try {
|
|
11579
11893
|
if (validations_1_1 && !validations_1_1.done && (_c = validations_1.return)) _c.call(validations_1);
|
|
11580
11894
|
}
|
|
11581
11895
|
finally { if (e_2) throw e_2.error; }
|
|
11582
11896
|
return [7 /*endfinally*/];
|
|
11583
|
-
case
|
|
11584
|
-
case
|
|
11897
|
+
case 19: return [4 /*yield*/, collectionToJson(collection)];
|
|
11898
|
+
case 20:
|
|
11585
11899
|
collectionJson = _e.sent();
|
|
11586
11900
|
collectionJsonString = stringifyPipelineJson(collectionJson).trim();
|
|
11587
11901
|
collectionJsonItems = (function () {
|
|
@@ -11613,32 +11927,32 @@
|
|
|
11613
11927
|
case 2:
|
|
11614
11928
|
_a.sent();
|
|
11615
11929
|
// Note: Log despite of verbose mode
|
|
11616
|
-
console.info(colors__default["default"].green("
|
|
11930
|
+
console.info(colors__default["default"].green("Made ".concat(filename.split('\\').join('/'))));
|
|
11617
11931
|
return [2 /*return*/];
|
|
11618
11932
|
}
|
|
11619
11933
|
});
|
|
11620
11934
|
}); };
|
|
11621
|
-
if (!formats.includes('json')) return [3 /*break*/,
|
|
11935
|
+
if (!formats.includes('json')) return [3 /*break*/, 22];
|
|
11622
11936
|
formats = formats.filter(function (format) { return format !== 'json'; });
|
|
11623
11937
|
return [4 /*yield*/, saveFile('json', collectionJsonString)];
|
|
11624
|
-
case 20:
|
|
11625
|
-
_e.sent();
|
|
11626
|
-
_e.label = 21;
|
|
11627
11938
|
case 21:
|
|
11628
|
-
|
|
11939
|
+
_e.sent();
|
|
11940
|
+
_e.label = 22;
|
|
11941
|
+
case 22:
|
|
11942
|
+
if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 24];
|
|
11629
11943
|
formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
|
|
11630
11944
|
return [4 /*yield*/, saveFile('js', spaceTrim__default["default"](function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @private internal cache for `").concat(functionName, "`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
|
|
11631
|
-
case 22:
|
|
11632
|
-
(_e.sent()) + '\n';
|
|
11633
|
-
_e.label = 23;
|
|
11634
11945
|
case 23:
|
|
11635
|
-
|
|
11636
|
-
|
|
11637
|
-
return [4 /*yield*/, saveFile('ts', spaceTrim__default["default"](function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `").concat(functionName, "`\n * @generated\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(): PipelineCollection{\n if(pipelineCollection===null){\n\n // TODO: !!!!!! Use book string literal notation\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pipelineCollection = (createCollectionFromJson as (..._: any) => PipelineCollection)(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
|
|
11946
|
+
(_e.sent()) + '\n';
|
|
11947
|
+
_e.label = 24;
|
|
11638
11948
|
case 24:
|
|
11639
|
-
|
|
11640
|
-
|
|
11949
|
+
if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 26];
|
|
11950
|
+
formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
|
|
11951
|
+
return [4 /*yield*/, saveFile('ts', spaceTrim__default["default"](function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `").concat(functionName, "`\n * @generated\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(): PipelineCollection{\n if(pipelineCollection===null){\n\n // TODO: !!6 Use book string literal notation\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pipelineCollection = (createCollectionFromJson as (..._: any) => PipelineCollection)(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
|
|
11641
11952
|
case 25:
|
|
11953
|
+
_e.sent();
|
|
11954
|
+
_e.label = 26;
|
|
11955
|
+
case 26:
|
|
11642
11956
|
if (formats.length > 0) {
|
|
11643
11957
|
console.warn(colors__default["default"].yellow("Format ".concat(formats.join(' and '), " is not supported")));
|
|
11644
11958
|
}
|
|
@@ -11653,7 +11967,7 @@
|
|
|
11653
11967
|
});
|
|
11654
11968
|
}
|
|
11655
11969
|
/**
|
|
11656
|
-
* TODO: [🥃][main]
|
|
11970
|
+
* TODO: [🥃][main] !!3 Allow `ptbk make` without configuring any llm tools
|
|
11657
11971
|
* TODO: [0] DRY Javascript and typescript - Maybe make ONLY typescript and for javascript just remove types
|
|
11658
11972
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11659
11973
|
* Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
|
|
@@ -11671,85 +11985,21 @@
|
|
|
11671
11985
|
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
11672
11986
|
var sectionMatch = content.match(sectionRegex);
|
|
11673
11987
|
var contentToInsert = spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
|
|
11674
|
-
if (sectionMatch) {
|
|
11675
|
-
return content.replace(sectionRegex, contentToInsert);
|
|
11676
|
-
}
|
|
11677
|
-
// Note: Following is the case when the section is not found in the file so we add it there
|
|
11678
|
-
var placeForSection =
|
|
11679
|
-
if (placeForSection !== null) {
|
|
11680
|
-
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
11681
|
-
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
11682
|
-
}
|
|
11683
|
-
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
11684
|
-
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
11685
|
-
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
|
|
11686
|
-
}
|
|
11687
|
-
/**
|
|
11688
|
-
* TODO: [🏛] This can be part of markdown builder
|
|
11689
|
-
*/
|
|
11690
|
-
|
|
11691
|
-
/**
|
|
11692
|
-
* Creates a Mermaid graph based on the promptbook
|
|
11693
|
-
*
|
|
11694
|
-
* Note: The result is not wrapped in a Markdown code block
|
|
11695
|
-
*
|
|
11696
|
-
* @public exported from `@promptbook/utils`
|
|
11697
|
-
*/
|
|
11698
|
-
function renderPromptbookMermaid(pipelineJson, options) {
|
|
11699
|
-
var _a = (options || {}).linkTask, linkTask = _a === void 0 ? function () { return null; } : _a;
|
|
11700
|
-
var parameterNameToTaskName = function (parameterName) {
|
|
11701
|
-
var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
11702
|
-
if (!parameter) {
|
|
11703
|
-
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
11704
|
-
// <- TODO: !!!!!! This causes problems when {knowledge} and other reserved parameters are used
|
|
11705
|
-
}
|
|
11706
|
-
if (parameter.isInput) {
|
|
11707
|
-
return 'input';
|
|
11708
|
-
}
|
|
11709
|
-
var task = pipelineJson.tasks.find(function (task) { return task.resultingParameterName === parameterName; });
|
|
11710
|
-
if (!task) {
|
|
11711
|
-
throw new Error("Could not find task for {".concat(parameterName, "}"));
|
|
11712
|
-
}
|
|
11713
|
-
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
11714
|
-
};
|
|
11715
|
-
var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
11716
|
-
.flatMap(function (_a) {
|
|
11717
|
-
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
11718
|
-
return __spreadArray([
|
|
11719
|
-
"".concat(parameterNameToTaskName(resultingParameterName), "(\"").concat(title, "\")")
|
|
11720
|
-
], __read(dependentParameterNames.map(function (dependentParameterName) {
|
|
11721
|
-
return "".concat(parameterNameToTaskName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTaskName(resultingParameterName));
|
|
11722
|
-
})), false);
|
|
11723
|
-
})
|
|
11724
|
-
.join('\n')), "\n\n ").concat(block(pipelineJson.parameters
|
|
11725
|
-
.filter(function (_a) {
|
|
11726
|
-
var isOutput = _a.isOutput;
|
|
11727
|
-
return isOutput;
|
|
11728
|
-
})
|
|
11729
|
-
.map(function (_a) {
|
|
11730
|
-
var name = _a.name;
|
|
11731
|
-
return "".concat(parameterNameToTaskName(name), "--\"{").concat(name, "}\"-->output");
|
|
11732
|
-
})
|
|
11733
|
-
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.tasks
|
|
11734
|
-
.map(function (task) {
|
|
11735
|
-
var link = linkTask(task);
|
|
11736
|
-
if (link === null) {
|
|
11737
|
-
return '';
|
|
11738
|
-
}
|
|
11739
|
-
var href = link.href, title = link.title;
|
|
11740
|
-
var taskName = parameterNameToTaskName(task.resultingParameterName);
|
|
11741
|
-
return "click ".concat(taskName, " href \"").concat(href, "\" \"").concat(title, "\";");
|
|
11742
|
-
})
|
|
11743
|
-
.filter(function (line) { return line !== ''; })
|
|
11744
|
-
.join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
|
|
11745
|
-
return promptbookMermaid;
|
|
11988
|
+
if (sectionMatch) {
|
|
11989
|
+
return content.replace(sectionRegex, contentToInsert);
|
|
11990
|
+
}
|
|
11991
|
+
// Note: Following is the case when the section is not found in the file so we add it there
|
|
11992
|
+
var placeForSection = removeMarkdownComments(content).match(/^##.*$/im);
|
|
11993
|
+
if (placeForSection !== null) {
|
|
11994
|
+
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
11995
|
+
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
11996
|
+
}
|
|
11997
|
+
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
11998
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
11999
|
+
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
|
|
11746
12000
|
}
|
|
11747
12001
|
/**
|
|
11748
|
-
* TODO: [
|
|
11749
|
-
* TODO: [🧠] !! Knowledge in mermaid graph
|
|
11750
|
-
* TODO: [🧠] !! Personas in mermaid graph
|
|
11751
|
-
* TODO: Maybe use some Mermaid package instead of string templating
|
|
11752
|
-
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
12002
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
11753
12003
|
*/
|
|
11754
12004
|
|
|
11755
12005
|
/**
|
|
@@ -11782,6 +12032,7 @@
|
|
|
11782
12032
|
case 2:
|
|
11783
12033
|
if (isPrettifyed) {
|
|
11784
12034
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
12035
|
+
// <- TODO: [😧] `prettifyMarkdown` should preserve discriminated type *(or at lease `PipelineString`)*
|
|
11785
12036
|
}
|
|
11786
12037
|
return [2 /*return*/, pipelineString];
|
|
11787
12038
|
}
|
|
@@ -11810,18 +12061,18 @@
|
|
|
11810
12061
|
prettifyCommand.action(function (filesGlob, _a) {
|
|
11811
12062
|
var ignore = _a.ignore, isVerbose = _a.verbose;
|
|
11812
12063
|
return __awaiter(_this, void 0, void 0, function () {
|
|
11813
|
-
var filenames, filenames_1, filenames_1_1, filename, pipelineMarkdown, error_1, e_1_1;
|
|
11814
|
-
var e_1,
|
|
11815
|
-
return __generator(this, function (
|
|
11816
|
-
switch (
|
|
12064
|
+
var filenames, filenames_1, filenames_1_1, filename, pipelineMarkdown, _b, error_1, e_1_1;
|
|
12065
|
+
var e_1, _c;
|
|
12066
|
+
return __generator(this, function (_d) {
|
|
12067
|
+
switch (_d.label) {
|
|
11817
12068
|
case 0: return [4 /*yield*/, glob__default["default"](filesGlob, { ignore: ignore })];
|
|
11818
12069
|
case 1:
|
|
11819
|
-
filenames =
|
|
11820
|
-
|
|
12070
|
+
filenames = _d.sent();
|
|
12071
|
+
_d.label = 2;
|
|
11821
12072
|
case 2:
|
|
11822
|
-
|
|
12073
|
+
_d.trys.push([2, 11, 12, 13]);
|
|
11823
12074
|
filenames_1 = __values(filenames), filenames_1_1 = filenames_1.next();
|
|
11824
|
-
|
|
12075
|
+
_d.label = 3;
|
|
11825
12076
|
case 3:
|
|
11826
12077
|
if (!!filenames_1_1.done) return [3 /*break*/, 10];
|
|
11827
12078
|
filename = filenames_1_1.value;
|
|
@@ -11829,28 +12080,29 @@
|
|
|
11829
12080
|
console.info(colors__default["default"].gray("Skipping ".concat(filename)));
|
|
11830
12081
|
return [3 /*break*/, 9];
|
|
11831
12082
|
}
|
|
12083
|
+
_b = validatePipelineString;
|
|
11832
12084
|
return [4 /*yield*/, promises.readFile(filename, 'utf-8')];
|
|
11833
12085
|
case 4:
|
|
11834
|
-
pipelineMarkdown = (
|
|
11835
|
-
|
|
12086
|
+
pipelineMarkdown = _b.apply(void 0, [_d.sent()]);
|
|
12087
|
+
_d.label = 5;
|
|
11836
12088
|
case 5:
|
|
11837
|
-
|
|
12089
|
+
_d.trys.push([5, 8, , 9]);
|
|
11838
12090
|
return [4 /*yield*/, prettifyPipelineString(pipelineMarkdown, {
|
|
11839
12091
|
isGraphAdded: true,
|
|
11840
12092
|
isPrettifyed: true,
|
|
11841
12093
|
// <- [🕌]
|
|
11842
12094
|
})];
|
|
11843
12095
|
case 6:
|
|
11844
|
-
pipelineMarkdown =
|
|
12096
|
+
pipelineMarkdown = _d.sent();
|
|
11845
12097
|
return [4 /*yield*/, promises.writeFile(filename, pipelineMarkdown)];
|
|
11846
12098
|
case 7:
|
|
11847
|
-
|
|
12099
|
+
_d.sent();
|
|
11848
12100
|
if (isVerbose) {
|
|
11849
12101
|
console.info(colors__default["default"].green("Prettify ".concat(filename)));
|
|
11850
12102
|
}
|
|
11851
12103
|
return [3 /*break*/, 9];
|
|
11852
12104
|
case 8:
|
|
11853
|
-
error_1 =
|
|
12105
|
+
error_1 = _d.sent();
|
|
11854
12106
|
if (!(error_1 instanceof Error)) {
|
|
11855
12107
|
throw error_1;
|
|
11856
12108
|
}
|
|
@@ -11863,12 +12115,12 @@
|
|
|
11863
12115
|
return [3 /*break*/, 3];
|
|
11864
12116
|
case 10: return [3 /*break*/, 13];
|
|
11865
12117
|
case 11:
|
|
11866
|
-
e_1_1 =
|
|
12118
|
+
e_1_1 = _d.sent();
|
|
11867
12119
|
e_1 = { error: e_1_1 };
|
|
11868
12120
|
return [3 /*break*/, 13];
|
|
11869
12121
|
case 12:
|
|
11870
12122
|
try {
|
|
11871
|
-
if (filenames_1_1 && !filenames_1_1.done && (
|
|
12123
|
+
if (filenames_1_1 && !filenames_1_1.done && (_c = filenames_1.return)) _c.call(filenames_1);
|
|
11872
12124
|
}
|
|
11873
12125
|
finally { if (e_1) throw e_1.error; }
|
|
11874
12126
|
return [7 /*endfinally*/];
|
|
@@ -12194,6 +12446,187 @@
|
|
|
12194
12446
|
* TODO: [🧠] Should be in generated file GENERATOR_WARNING
|
|
12195
12447
|
*/
|
|
12196
12448
|
|
|
12449
|
+
/**
|
|
12450
|
+
* Function `isValidPipelineString` will validate the if the string is a valid pipeline string
|
|
12451
|
+
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
12452
|
+
*
|
|
12453
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
12454
|
+
* @returns {boolean} if the string is a valid pipeline string
|
|
12455
|
+
* @public exported from `@promptbook/core`
|
|
12456
|
+
*/
|
|
12457
|
+
function isValidPipelineString(pipelineString) {
|
|
12458
|
+
try {
|
|
12459
|
+
validatePipelineString(pipelineString);
|
|
12460
|
+
return true;
|
|
12461
|
+
}
|
|
12462
|
+
catch (error) {
|
|
12463
|
+
if (!(error instanceof Error)) {
|
|
12464
|
+
throw error;
|
|
12465
|
+
}
|
|
12466
|
+
return false;
|
|
12467
|
+
}
|
|
12468
|
+
}
|
|
12469
|
+
/**
|
|
12470
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
12471
|
+
*/
|
|
12472
|
+
|
|
12473
|
+
/**
|
|
12474
|
+
* @see ./wizzard.ts `getPipeline` method
|
|
12475
|
+
*
|
|
12476
|
+
* @private usable through `ptbk run` and `@prompbook/wizzard`
|
|
12477
|
+
*/
|
|
12478
|
+
function $getCompiledBook(tools, pipelineSource, options) {
|
|
12479
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
12480
|
+
var fs, fetch, filePathRaw, filePath, filePathCandidates, filePathCandidates_1, filePathCandidates_1_1, filePathCandidate, pipelineString, _a, pipelineJson, e_1_1, rootDirname, _loop_1, i, state_1, response_1, pipelineString, pipelineJson, pipelineJson;
|
|
12481
|
+
var e_1, _b;
|
|
12482
|
+
var _this = this;
|
|
12483
|
+
return __generator(this, function (_c) {
|
|
12484
|
+
switch (_c.label) {
|
|
12485
|
+
case 0:
|
|
12486
|
+
fs = tools.fs, fetch = tools.fetch;
|
|
12487
|
+
if (!isValidFilePath(pipelineSource)) return [3 /*break*/, 10];
|
|
12488
|
+
filePathRaw = pipelineSource;
|
|
12489
|
+
filePath = null;
|
|
12490
|
+
filePathCandidates = [filePathRaw, "".concat(filePathRaw, ".md"), "".concat(filePathRaw, ".book.md"), "".concat(filePathRaw, ".book.md")];
|
|
12491
|
+
filePathCandidates = __spreadArray(__spreadArray([], __read(filePathCandidates), false), __read(filePathCandidates.map(function (path) { return path.split('\\').join('/'); })), false);
|
|
12492
|
+
_c.label = 1;
|
|
12493
|
+
case 1:
|
|
12494
|
+
_c.trys.push([1, 8, 9, 10]);
|
|
12495
|
+
filePathCandidates_1 = __values(filePathCandidates), filePathCandidates_1_1 = filePathCandidates_1.next();
|
|
12496
|
+
_c.label = 2;
|
|
12497
|
+
case 2:
|
|
12498
|
+
if (!!filePathCandidates_1_1.done) return [3 /*break*/, 7];
|
|
12499
|
+
filePathCandidate = filePathCandidates_1_1.value;
|
|
12500
|
+
return [4 /*yield*/, isFileExisting(filePathCandidate, fs)
|
|
12501
|
+
// <- TODO: Also test that among the candidates the file is book not just any file
|
|
12502
|
+
];
|
|
12503
|
+
case 3:
|
|
12504
|
+
if (!_c.sent()) return [3 /*break*/, 6];
|
|
12505
|
+
filePath = filePathCandidate;
|
|
12506
|
+
_a = validatePipelineString;
|
|
12507
|
+
return [4 /*yield*/, fs.readFile(filePath, 'utf-8')];
|
|
12508
|
+
case 4:
|
|
12509
|
+
pipelineString = _a.apply(void 0, [_c.sent()]);
|
|
12510
|
+
return [4 /*yield*/, compilePipeline(pipelineString, tools, __assign({ rootDirname: process.cwd() }, options))];
|
|
12511
|
+
case 5:
|
|
12512
|
+
pipelineJson = _c.sent();
|
|
12513
|
+
return [2 /*return*/, pipelineJson];
|
|
12514
|
+
case 6:
|
|
12515
|
+
filePathCandidates_1_1 = filePathCandidates_1.next();
|
|
12516
|
+
return [3 /*break*/, 2];
|
|
12517
|
+
case 7: return [3 /*break*/, 10];
|
|
12518
|
+
case 8:
|
|
12519
|
+
e_1_1 = _c.sent();
|
|
12520
|
+
e_1 = { error: e_1_1 };
|
|
12521
|
+
return [3 /*break*/, 10];
|
|
12522
|
+
case 9:
|
|
12523
|
+
try {
|
|
12524
|
+
if (filePathCandidates_1_1 && !filePathCandidates_1_1.done && (_b = filePathCandidates_1.return)) _b.call(filePathCandidates_1);
|
|
12525
|
+
}
|
|
12526
|
+
finally { if (e_1) throw e_1.error; }
|
|
12527
|
+
return [7 /*endfinally*/];
|
|
12528
|
+
case 10:
|
|
12529
|
+
if (!isValidPipelineUrl(pipelineSource)) return [3 /*break*/, 14];
|
|
12530
|
+
rootDirname = process.cwd();
|
|
12531
|
+
_loop_1 = function (i) {
|
|
12532
|
+
var booksDirname, collection_1, pipeline;
|
|
12533
|
+
return __generator(this, function (_d) {
|
|
12534
|
+
switch (_d.label) {
|
|
12535
|
+
case 0:
|
|
12536
|
+
booksDirname = path.join(rootDirname, DEFAULT_BOOKS_DIRNAME /* <- TODO: [🕝] Make here more candidates */);
|
|
12537
|
+
return [4 /*yield*/, isDirectoryExisting(booksDirname, fs)];
|
|
12538
|
+
case 1:
|
|
12539
|
+
if (!_d.sent()) return [3 /*break*/, 4];
|
|
12540
|
+
return [4 /*yield*/, createCollectionFromDirectory(booksDirname, tools, __assign({ isRecursive: true, rootDirname: booksDirname }, options))];
|
|
12541
|
+
case 2:
|
|
12542
|
+
collection_1 = _d.sent();
|
|
12543
|
+
return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
12544
|
+
var error_1;
|
|
12545
|
+
return __generator(this, function (_a) {
|
|
12546
|
+
switch (_a.label) {
|
|
12547
|
+
case 0:
|
|
12548
|
+
_a.trys.push([0, 2, , 3]);
|
|
12549
|
+
return [4 /*yield*/, collection_1.getPipelineByUrl(pipelineSource)];
|
|
12550
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
12551
|
+
case 2:
|
|
12552
|
+
error_1 = _a.sent();
|
|
12553
|
+
if (!(error_1 instanceof NotFoundError)) {
|
|
12554
|
+
throw error_1;
|
|
12555
|
+
}
|
|
12556
|
+
// Note: If the pipeline was not found in the collection, try next strategy
|
|
12557
|
+
return [2 /*return*/, null];
|
|
12558
|
+
case 3: return [2 /*return*/];
|
|
12559
|
+
}
|
|
12560
|
+
});
|
|
12561
|
+
}); })()];
|
|
12562
|
+
case 3:
|
|
12563
|
+
pipeline = _d.sent();
|
|
12564
|
+
// console.log({ pipeline });
|
|
12565
|
+
if (pipeline !== null) {
|
|
12566
|
+
return [2 /*return*/, { value: pipeline }];
|
|
12567
|
+
}
|
|
12568
|
+
_d.label = 4;
|
|
12569
|
+
case 4:
|
|
12570
|
+
if (isRootPath(rootDirname)) {
|
|
12571
|
+
return [2 /*return*/, "break-up_to_root"];
|
|
12572
|
+
}
|
|
12573
|
+
// Note: If the directory does not exist, try the parent directory
|
|
12574
|
+
rootDirname = path.join(rootDirname, '..');
|
|
12575
|
+
return [2 /*return*/];
|
|
12576
|
+
}
|
|
12577
|
+
});
|
|
12578
|
+
};
|
|
12579
|
+
i = 0;
|
|
12580
|
+
_c.label = 11;
|
|
12581
|
+
case 11:
|
|
12582
|
+
if (!(i < LOOP_LIMIT)) return [3 /*break*/, 14];
|
|
12583
|
+
return [5 /*yield**/, _loop_1(i)];
|
|
12584
|
+
case 12:
|
|
12585
|
+
state_1 = _c.sent();
|
|
12586
|
+
if (typeof state_1 === "object")
|
|
12587
|
+
return [2 /*return*/, state_1.value];
|
|
12588
|
+
switch (state_1) {
|
|
12589
|
+
case "break-up_to_root": return [3 /*break*/, 14];
|
|
12590
|
+
}
|
|
12591
|
+
_c.label = 13;
|
|
12592
|
+
case 13:
|
|
12593
|
+
i++;
|
|
12594
|
+
return [3 /*break*/, 11];
|
|
12595
|
+
case 14:
|
|
12596
|
+
if (!isValidPipelineUrl(pipelineSource)) return [3 /*break*/, 18];
|
|
12597
|
+
return [4 /*yield*/, fetch(pipelineSource)];
|
|
12598
|
+
case 15:
|
|
12599
|
+
response_1 = _c.sent();
|
|
12600
|
+
if (response_1.status >= 300) {
|
|
12601
|
+
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Book not found on URL:\n ".concat(block(pipelineSource), "\n\n Request failed with status ").concat(block(response_1.status.toString()), " ").concat(block(response_1.statusText), "\n "); }));
|
|
12602
|
+
}
|
|
12603
|
+
return [4 /*yield*/, response_1.text()];
|
|
12604
|
+
case 16:
|
|
12605
|
+
pipelineString = _c.sent();
|
|
12606
|
+
// console.log({ pipelineString });
|
|
12607
|
+
if (!isValidPipelineString(pipelineString)) {
|
|
12608
|
+
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Book not found on URL:\n ".concat(block(pipelineSource), "\n\n Requested URL does not seem to contain a valid book\n "); }));
|
|
12609
|
+
}
|
|
12610
|
+
return [4 /*yield*/, compilePipeline(pipelineString, tools, __assign({ rootDirname: null }, options))];
|
|
12611
|
+
case 17:
|
|
12612
|
+
pipelineJson = _c.sent();
|
|
12613
|
+
return [2 /*return*/, pipelineJson];
|
|
12614
|
+
case 18:
|
|
12615
|
+
if (!isValidPipelineString(pipelineSource)) return [3 /*break*/, 20];
|
|
12616
|
+
return [4 /*yield*/, compilePipeline(pipelineSource, tools, __assign({ rootDirname: null }, options))];
|
|
12617
|
+
case 19:
|
|
12618
|
+
pipelineJson = _c.sent();
|
|
12619
|
+
return [2 /*return*/, pipelineJson];
|
|
12620
|
+
case 20: /* not else */ throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Book not found:\n ".concat(block(pipelineSource), "\n\n Pipelines can be loaded from:\n 1) As a file ./books/write-cv.book.md\n 2) As a URL https://promptbook.studio/hejny/write-cv.book.md found in ./books folder recursively\n 2) As a URL https://promptbook.studio/hejny/write-cv.book.md fetched from the internet\n 3) As a string\n\n\n "); }));
|
|
12621
|
+
}
|
|
12622
|
+
});
|
|
12623
|
+
});
|
|
12624
|
+
}
|
|
12625
|
+
/**
|
|
12626
|
+
* TODO: Write unit test
|
|
12627
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
12628
|
+
*/
|
|
12629
|
+
|
|
12197
12630
|
/**
|
|
12198
12631
|
* Run the interactive chatbot in CLI
|
|
12199
12632
|
*
|
|
@@ -12320,20 +12753,20 @@
|
|
|
12320
12753
|
var runCommand = program.command('run', { isDefault: true });
|
|
12321
12754
|
runCommand.description(spaceTrim__default["default"]("\n Runs a pipeline\n "));
|
|
12322
12755
|
// TODO: [🧅] DRY command arguments
|
|
12323
|
-
runCommand.argument('<
|
|
12756
|
+
runCommand.argument('<pipelineSource>',
|
|
12324
12757
|
// <- Note: [🧟♂️] This is NOT promptbook collection directory BUT direct path to .book.md file
|
|
12325
|
-
'Path to book file');
|
|
12758
|
+
'Path to book file OR URL to book file');
|
|
12326
12759
|
runCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
|
|
12327
12760
|
runCommand.option('-v, --verbose', "Is output verbose", false);
|
|
12328
12761
|
runCommand.option('--no-interactive', "Input is not interactive, if true you need to pass all the input parameters through --json");
|
|
12329
12762
|
runCommand.option('--no-formfactor', "When set, behavior of the interactive mode is not changed by the formfactor of the pipeline");
|
|
12330
12763
|
runCommand.option('-j, --json <json>', "Pass all or some input parameters as JSON record, if used the output is also returned as JSON");
|
|
12331
12764
|
runCommand.option('-s, --save-report <path>', "Save report to file");
|
|
12332
|
-
runCommand.action(function (
|
|
12333
|
-
var isCacheReloaded, isInteractive, isFormfactorUsed, json, isVerbose, saveReport, inputParameters, prepareAndScrapeOptions, fs,
|
|
12334
|
-
var
|
|
12335
|
-
return __generator(this, function (
|
|
12336
|
-
switch (
|
|
12765
|
+
runCommand.action(function (pipelineSource, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
12766
|
+
var isCacheReloaded, isInteractive, isFormfactorUsed, json, isVerbose, saveReport, inputParameters, prepareAndScrapeOptions, fs, llm, error_1, executables, tools, pipeline, error_2, pipelineExecutor, questions, response, result, isSuccessful, errors, warnings, outputParameters, executionReport, executionReportString, _a, _b, error, _c, _d, warning, _e, _f, key, value, separator;
|
|
12767
|
+
var _g, e_1, _h, e_2, _j, e_3, _k;
|
|
12768
|
+
return __generator(this, function (_l) {
|
|
12769
|
+
switch (_l.label) {
|
|
12337
12770
|
case 0:
|
|
12338
12771
|
isCacheReloaded = options.reload, isInteractive = options.interactive, isFormfactorUsed = options.formfactor, json = options.json, isVerbose = options.verbose, saveReport = options.saveReport;
|
|
12339
12772
|
if (saveReport && !saveReport.endsWith('.json') && !saveReport.endsWith('.md')) {
|
|
@@ -12353,104 +12786,65 @@
|
|
|
12353
12786
|
console.info(colors__default["default"].gray('--- Preparing tools ---'));
|
|
12354
12787
|
}
|
|
12355
12788
|
fs = $provideFilesystemForNode(prepareAndScrapeOptions);
|
|
12356
|
-
|
|
12357
|
-
filePathCandidates = [filePathRaw, "".concat(filePathRaw, ".md"), "".concat(filePathRaw, ".book.md"), "".concat(filePathRaw, ".book.md")];
|
|
12358
|
-
filePathCandidates = __spreadArray(__spreadArray([], __read(filePathCandidates), false), __read(filePathCandidates.map(function (path) { return path.split('\\').join('/'); })), false);
|
|
12359
|
-
_m.label = 1;
|
|
12789
|
+
_l.label = 1;
|
|
12360
12790
|
case 1:
|
|
12361
|
-
|
|
12362
|
-
|
|
12363
|
-
_m.label = 2;
|
|
12791
|
+
_l.trys.push([1, 3, , 4]);
|
|
12792
|
+
return [4 /*yield*/, $provideLlmToolsForWizzardOrCli(prepareAndScrapeOptions)];
|
|
12364
12793
|
case 2:
|
|
12365
|
-
|
|
12366
|
-
|
|
12367
|
-
return [4 /*yield*/, isFileExisting(filePathCandidate, fs)
|
|
12368
|
-
// <- TODO: Also test that among the candidates the file is book not just any file
|
|
12369
|
-
];
|
|
12794
|
+
llm = _l.sent();
|
|
12795
|
+
return [3 /*break*/, 4];
|
|
12370
12796
|
case 3:
|
|
12371
|
-
|
|
12372
|
-
|
|
12373
|
-
|
|
12374
|
-
filePath = filePathCandidate;
|
|
12375
|
-
return [3 /*break*/, 5];
|
|
12376
|
-
}
|
|
12377
|
-
_m.label = 4;
|
|
12378
|
-
case 4:
|
|
12379
|
-
filePathCandidates_1_1 = filePathCandidates_1.next();
|
|
12380
|
-
return [3 /*break*/, 2];
|
|
12381
|
-
case 5: return [3 /*break*/, 8];
|
|
12382
|
-
case 6:
|
|
12383
|
-
e_1_1 = _m.sent();
|
|
12384
|
-
e_1 = { error: e_1_1 };
|
|
12385
|
-
return [3 /*break*/, 8];
|
|
12386
|
-
case 7:
|
|
12387
|
-
try {
|
|
12388
|
-
if (filePathCandidates_1_1 && !filePathCandidates_1_1.done && (_g = filePathCandidates_1.return)) _g.call(filePathCandidates_1);
|
|
12389
|
-
}
|
|
12390
|
-
finally { if (e_1) throw e_1.error; }
|
|
12391
|
-
return [7 /*endfinally*/];
|
|
12392
|
-
case 8:
|
|
12393
|
-
if (filePath === null) {
|
|
12394
|
-
console.error(colors__default["default"].red("File \"".concat(filePathRaw, "\" does not exist")));
|
|
12395
|
-
return [2 /*return*/, process.exit(1)];
|
|
12396
|
-
}
|
|
12397
|
-
try {
|
|
12398
|
-
llm = $provideLlmToolsForCli(prepareAndScrapeOptions);
|
|
12797
|
+
error_1 = _l.sent();
|
|
12798
|
+
if (!(error_1 instanceof Error)) {
|
|
12799
|
+
throw error_1;
|
|
12399
12800
|
}
|
|
12400
|
-
|
|
12401
|
-
|
|
12402
|
-
throw error;
|
|
12403
|
-
}
|
|
12404
|
-
if (!error.message.includes('No LLM tools')) {
|
|
12405
|
-
throw error;
|
|
12406
|
-
}
|
|
12407
|
-
console.error(colors__default["default"].red(spaceTrim__default["default"](function (block) { return "\n You need to configure LLM tools first\n\n 1) Create .env file at the root of your project\n 2) Configure API keys for LLM tools\n\n For example:\n ".concat(block($llmToolsMetadataRegister
|
|
12408
|
-
.list()
|
|
12409
|
-
.map(function (_a) {
|
|
12410
|
-
var title = _a.title, envVariables = _a.envVariables;
|
|
12411
|
-
return "- ".concat((envVariables || []).join(' + '), " (").concat(title, ")");
|
|
12412
|
-
})
|
|
12413
|
-
.join('\n')), "\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); })));
|
|
12414
|
-
return [2 /*return*/, process.exit(1)];
|
|
12801
|
+
if (!error_1.message.includes('No LLM tools')) {
|
|
12802
|
+
throw error_1;
|
|
12415
12803
|
}
|
|
12416
|
-
return
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12804
|
+
console.error(colors__default["default"].red(spaceTrim__default["default"](function (block) { return "\n You need to configure LLM tools first\n\n 1) Create .env file at the root of your project\n 2) Configure API keys for LLM tools\n\n For example:\n ".concat(block($llmToolsMetadataRegister
|
|
12805
|
+
.list()
|
|
12806
|
+
.map(function (_a) {
|
|
12807
|
+
var title = _a.title, envVariables = _a.envVariables;
|
|
12808
|
+
return "- ".concat((envVariables || []).join(' + '), " (").concat(title, ")");
|
|
12809
|
+
})
|
|
12810
|
+
.join('\n')), "\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); })));
|
|
12811
|
+
return [2 /*return*/, process.exit(1)];
|
|
12812
|
+
case 4: return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
|
|
12813
|
+
case 5:
|
|
12814
|
+
executables = _l.sent();
|
|
12815
|
+
_g = {
|
|
12420
12816
|
llm: llm,
|
|
12421
|
-
fs: fs
|
|
12817
|
+
fs: fs,
|
|
12818
|
+
fetch: scraperFetch
|
|
12422
12819
|
};
|
|
12423
12820
|
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, prepareAndScrapeOptions)];
|
|
12424
|
-
case
|
|
12425
|
-
tools = (
|
|
12426
|
-
|
|
12821
|
+
case 6:
|
|
12822
|
+
tools = (_g.scrapers = _l.sent(),
|
|
12823
|
+
_g.script = [
|
|
12427
12824
|
/*new JavascriptExecutionTools(options)*/
|
|
12428
12825
|
],
|
|
12429
|
-
|
|
12826
|
+
_g);
|
|
12430
12827
|
if (isVerbose) {
|
|
12431
12828
|
console.info(colors__default["default"].gray('--- Reading file ---'));
|
|
12432
12829
|
}
|
|
12433
|
-
return [4 /*yield*/, promises.readFile(filePath, 'utf-8')];
|
|
12434
|
-
case 11:
|
|
12435
|
-
pipelineString = (_m.sent());
|
|
12436
12830
|
if (isVerbose) {
|
|
12437
12831
|
console.info(colors__default["default"].gray('--- Preparing pipeline ---'));
|
|
12438
12832
|
}
|
|
12439
|
-
|
|
12440
|
-
case
|
|
12441
|
-
|
|
12442
|
-
return [4 /*yield*/,
|
|
12443
|
-
case
|
|
12444
|
-
pipeline =
|
|
12445
|
-
return [3 /*break*/,
|
|
12446
|
-
case
|
|
12447
|
-
|
|
12448
|
-
if (!(
|
|
12449
|
-
throw
|
|
12833
|
+
_l.label = 7;
|
|
12834
|
+
case 7:
|
|
12835
|
+
_l.trys.push([7, 9, , 10]);
|
|
12836
|
+
return [4 /*yield*/, $getCompiledBook(tools, pipelineSource, prepareAndScrapeOptions)];
|
|
12837
|
+
case 8:
|
|
12838
|
+
pipeline = _l.sent();
|
|
12839
|
+
return [3 /*break*/, 10];
|
|
12840
|
+
case 9:
|
|
12841
|
+
error_2 = _l.sent();
|
|
12842
|
+
if (!(error_2 instanceof ParseError)) {
|
|
12843
|
+
throw error_2;
|
|
12450
12844
|
}
|
|
12451
|
-
console.error(colors__default["default"].red(spaceTrim__default["default"](function (block) { return "\n ".concat(block(
|
|
12845
|
+
console.error(colors__default["default"].red(spaceTrim__default["default"](function (block) { return "\n ".concat(block(error_2.message), "\n\n in ").concat(pipelineSource, "\n "); })));
|
|
12452
12846
|
return [2 /*return*/, process.exit(1)];
|
|
12453
|
-
case
|
|
12847
|
+
case 10:
|
|
12454
12848
|
if (isVerbose) {
|
|
12455
12849
|
console.info(colors__default["default"].gray('--- Validating pipeline ---'));
|
|
12456
12850
|
}
|
|
@@ -12536,8 +12930,8 @@
|
|
|
12536
12930
|
return [2 /*return*/, process.exit(1)];
|
|
12537
12931
|
}
|
|
12538
12932
|
return [4 /*yield*/, prompts__default["default"](questions)];
|
|
12539
|
-
case
|
|
12540
|
-
response =
|
|
12933
|
+
case 11:
|
|
12934
|
+
response = _l.sent();
|
|
12541
12935
|
// <- TODO: [🧠][🍼] Change behavior according to the formfactor
|
|
12542
12936
|
inputParameters = __assign(__assign({}, inputParameters), response);
|
|
12543
12937
|
// TODO: Maybe do some validation of the response (and --json argument which is passed)
|
|
@@ -12550,26 +12944,26 @@
|
|
|
12550
12944
|
console.info(taskProgress);
|
|
12551
12945
|
}
|
|
12552
12946
|
})];
|
|
12553
|
-
case
|
|
12554
|
-
result =
|
|
12947
|
+
case 12:
|
|
12948
|
+
result = _l.sent();
|
|
12555
12949
|
isSuccessful = result.isSuccessful, errors = result.errors, warnings = result.warnings, outputParameters = result.outputParameters, executionReport = result.executionReport;
|
|
12556
12950
|
if (isVerbose) {
|
|
12557
12951
|
console.info(colors__default["default"].gray('--- Detailed Result ---'));
|
|
12558
12952
|
console.info({ isSuccessful: isSuccessful, errors: errors, warnings: warnings, outputParameters: outputParameters, executionReport: executionReport });
|
|
12559
12953
|
}
|
|
12560
|
-
if (!(saveReport && saveReport.endsWith('.json'))) return [3 /*break*/,
|
|
12954
|
+
if (!(saveReport && saveReport.endsWith('.json'))) return [3 /*break*/, 14];
|
|
12561
12955
|
return [4 /*yield*/, promises.writeFile(saveReport, JSON.stringify(executionReport, null, 4) + '\n', 'utf-8')];
|
|
12562
|
-
case
|
|
12563
|
-
|
|
12564
|
-
return [3 /*break*/,
|
|
12565
|
-
case
|
|
12566
|
-
if (!(saveReport && saveReport.endsWith('.md'))) return [3 /*break*/,
|
|
12956
|
+
case 13:
|
|
12957
|
+
_l.sent();
|
|
12958
|
+
return [3 /*break*/, 16];
|
|
12959
|
+
case 14:
|
|
12960
|
+
if (!(saveReport && saveReport.endsWith('.md'))) return [3 /*break*/, 16];
|
|
12567
12961
|
executionReportString = executionReportJsonToString(executionReport);
|
|
12568
12962
|
return [4 /*yield*/, promises.writeFile(saveReport, executionReportString, 'utf-8')];
|
|
12569
|
-
case
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
case
|
|
12963
|
+
case 15:
|
|
12964
|
+
_l.sent();
|
|
12965
|
+
_l.label = 16;
|
|
12966
|
+
case 16:
|
|
12573
12967
|
if (saveReport && isVerbose) {
|
|
12574
12968
|
console.info(colors__default["default"].green("Report saved to ".concat(saveReport)));
|
|
12575
12969
|
}
|
|
@@ -12587,12 +12981,12 @@
|
|
|
12587
12981
|
console.error(colors__default["default"].red(colors__default["default"].bold(error.name) + ': ' + error.message));
|
|
12588
12982
|
}
|
|
12589
12983
|
}
|
|
12590
|
-
catch (
|
|
12984
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
12591
12985
|
finally {
|
|
12592
12986
|
try {
|
|
12593
|
-
if (_b && !_b.done && (
|
|
12987
|
+
if (_b && !_b.done && (_h = _a.return)) _h.call(_a);
|
|
12594
12988
|
}
|
|
12595
|
-
finally { if (
|
|
12989
|
+
finally { if (e_1) throw e_1.error; }
|
|
12596
12990
|
}
|
|
12597
12991
|
try {
|
|
12598
12992
|
for (_c = __values(warnings || []), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
@@ -12600,12 +12994,12 @@
|
|
|
12600
12994
|
console.error(colors__default["default"].red(colors__default["default"].bold(warning.name) + ': ' + warning.message));
|
|
12601
12995
|
}
|
|
12602
12996
|
}
|
|
12603
|
-
catch (
|
|
12997
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
12604
12998
|
finally {
|
|
12605
12999
|
try {
|
|
12606
|
-
if (_d && !_d.done && (
|
|
13000
|
+
if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
|
|
12607
13001
|
}
|
|
12608
|
-
finally { if (
|
|
13002
|
+
finally { if (e_2) throw e_2.error; }
|
|
12609
13003
|
}
|
|
12610
13004
|
if (json === undefined) {
|
|
12611
13005
|
try {
|
|
@@ -12616,12 +13010,12 @@
|
|
|
12616
13010
|
console.info(colors__default["default"].green(colors__default["default"].bold(key) + separator + value));
|
|
12617
13011
|
}
|
|
12618
13012
|
}
|
|
12619
|
-
catch (
|
|
13013
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
12620
13014
|
finally {
|
|
12621
13015
|
try {
|
|
12622
|
-
if (_f && !_f.done && (
|
|
13016
|
+
if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
|
|
12623
13017
|
}
|
|
12624
|
-
finally { if (
|
|
13018
|
+
finally { if (e_3) throw e_3.error; }
|
|
12625
13019
|
}
|
|
12626
13020
|
}
|
|
12627
13021
|
else {
|
|
@@ -12633,9 +13027,9 @@
|
|
|
12633
13027
|
}); });
|
|
12634
13028
|
}
|
|
12635
13029
|
/**
|
|
12636
|
-
* TODO:
|
|
13030
|
+
* TODO: !!5 Catch and wrap all errors from CLI
|
|
12637
13031
|
* TODO: [🧠] Pass `maxExecutionAttempts`, `csvSettings`
|
|
12638
|
-
* TODO: [🥃][main]
|
|
13032
|
+
* TODO: [🥃][main] !!3 Allow `ptbk run` without configuring any llm tools
|
|
12639
13033
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
12640
13034
|
* Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
|
|
12641
13035
|
* TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
|
|
@@ -12659,75 +13053,78 @@
|
|
|
12659
13053
|
testCommand.action(function (filesGlob, _a) {
|
|
12660
13054
|
var ignore = _a.ignore, isCacheReloaded = _a.reload, isVerbose = _a.verbose;
|
|
12661
13055
|
return __awaiter(_this, void 0, void 0, function () {
|
|
12662
|
-
var prepareAndScrapeOptions, fs, llm, executables, tools, filenames, filenames_1, filenames_1_1, filename, pipeline, pipelineMarkdown, _b, _c, error_1, e_1_1;
|
|
12663
|
-
var
|
|
12664
|
-
return __generator(this, function (
|
|
12665
|
-
switch (
|
|
13056
|
+
var prepareAndScrapeOptions, fs, llm, executables, tools, filenames, filenames_1, filenames_1_1, filename, pipeline, pipelineMarkdown, _b, _c, _d, error_1, e_1_1;
|
|
13057
|
+
var _e, e_1, _f;
|
|
13058
|
+
return __generator(this, function (_g) {
|
|
13059
|
+
switch (_g.label) {
|
|
12666
13060
|
case 0:
|
|
12667
13061
|
prepareAndScrapeOptions = {
|
|
12668
13062
|
isVerbose: isVerbose,
|
|
12669
13063
|
isCacheReloaded: isCacheReloaded,
|
|
12670
13064
|
};
|
|
12671
13065
|
fs = $provideFilesystemForNode(prepareAndScrapeOptions);
|
|
12672
|
-
|
|
12673
|
-
return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
|
|
13066
|
+
return [4 /*yield*/, $provideLlmToolsForWizzardOrCli(prepareAndScrapeOptions)];
|
|
12674
13067
|
case 1:
|
|
12675
|
-
|
|
12676
|
-
|
|
13068
|
+
llm = _g.sent();
|
|
13069
|
+
return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
|
|
13070
|
+
case 2:
|
|
13071
|
+
executables = _g.sent();
|
|
13072
|
+
_e = {
|
|
12677
13073
|
llm: llm,
|
|
12678
13074
|
fs: fs
|
|
12679
13075
|
};
|
|
12680
13076
|
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, prepareAndScrapeOptions)];
|
|
12681
|
-
case
|
|
12682
|
-
tools = (
|
|
12683
|
-
|
|
13077
|
+
case 3:
|
|
13078
|
+
tools = (_e.scrapers = _g.sent(),
|
|
13079
|
+
_e.script = [
|
|
12684
13080
|
/*new JavascriptExecutionTools(options)*/
|
|
12685
13081
|
],
|
|
12686
|
-
|
|
13082
|
+
_e);
|
|
12687
13083
|
return [4 /*yield*/, glob__default["default"](filesGlob, { ignore: ignore })];
|
|
12688
|
-
case 3:
|
|
12689
|
-
filenames = _f.sent();
|
|
12690
|
-
_f.label = 4;
|
|
12691
13084
|
case 4:
|
|
12692
|
-
|
|
12693
|
-
|
|
12694
|
-
_f.label = 5;
|
|
13085
|
+
filenames = _g.sent();
|
|
13086
|
+
_g.label = 5;
|
|
12695
13087
|
case 5:
|
|
12696
|
-
|
|
12697
|
-
|
|
12698
|
-
|
|
13088
|
+
_g.trys.push([5, 17, 18, 19]);
|
|
13089
|
+
filenames_1 = __values(filenames), filenames_1_1 = filenames_1.next();
|
|
13090
|
+
_g.label = 6;
|
|
12699
13091
|
case 6:
|
|
12700
|
-
|
|
13092
|
+
if (!!filenames_1_1.done) return [3 /*break*/, 16];
|
|
13093
|
+
filename = filenames_1_1.value;
|
|
13094
|
+
_g.label = 7;
|
|
13095
|
+
case 7:
|
|
13096
|
+
_g.trys.push([7, 14, , 15]);
|
|
12701
13097
|
pipeline = void 0;
|
|
12702
|
-
if (!filename.endsWith('.book.md')) return [3 /*break*/,
|
|
13098
|
+
if (!filename.endsWith('.book.md')) return [3 /*break*/, 10];
|
|
13099
|
+
_b = validatePipelineString;
|
|
12703
13100
|
return [4 /*yield*/, promises.readFile(filename, 'utf-8')];
|
|
12704
|
-
case 7:
|
|
12705
|
-
pipelineMarkdown = (_f.sent());
|
|
12706
|
-
return [4 /*yield*/, compilePipeline(pipelineMarkdown, tools)];
|
|
12707
13101
|
case 8:
|
|
12708
|
-
|
|
13102
|
+
pipelineMarkdown = _b.apply(void 0, [_g.sent()]);
|
|
13103
|
+
return [4 /*yield*/, compilePipeline(pipelineMarkdown, tools)];
|
|
13104
|
+
case 9:
|
|
13105
|
+
pipeline = _g.sent();
|
|
12709
13106
|
if (isVerbose) {
|
|
12710
13107
|
console.info(colors__default["default"].green("Parsed ".concat(filename)));
|
|
12711
13108
|
}
|
|
12712
|
-
|
|
12713
|
-
case 9:
|
|
12714
|
-
if (!filename.endsWith('.book.json')) return [3 /*break*/, 11];
|
|
12715
|
-
_c = (_b = JSON).parse;
|
|
12716
|
-
return [4 /*yield*/, promises.readFile(filename, 'utf-8')];
|
|
13109
|
+
_g.label = 10;
|
|
12717
13110
|
case 10:
|
|
12718
|
-
|
|
12719
|
-
|
|
13111
|
+
if (!filename.endsWith('.book.json')) return [3 /*break*/, 12];
|
|
13112
|
+
_d = (_c = JSON).parse;
|
|
13113
|
+
return [4 /*yield*/, promises.readFile(filename, 'utf-8')];
|
|
12720
13114
|
case 11:
|
|
13115
|
+
pipeline = _d.apply(_c, [_g.sent()]);
|
|
13116
|
+
return [3 /*break*/, 13];
|
|
13117
|
+
case 12:
|
|
12721
13118
|
if (isVerbose) {
|
|
12722
13119
|
console.info(colors__default["default"].gray("Skipping ".concat(filename)));
|
|
12723
13120
|
}
|
|
12724
|
-
return [3 /*break*/,
|
|
12725
|
-
case
|
|
13121
|
+
return [3 /*break*/, 15];
|
|
13122
|
+
case 13:
|
|
12726
13123
|
validatePipeline(pipeline);
|
|
12727
13124
|
console.info(colors__default["default"].green("Validated ".concat(filename)));
|
|
12728
|
-
return [3 /*break*/,
|
|
12729
|
-
case
|
|
12730
|
-
error_1 =
|
|
13125
|
+
return [3 /*break*/, 15];
|
|
13126
|
+
case 14:
|
|
13127
|
+
error_1 = _g.sent();
|
|
12731
13128
|
if (!(error_1 instanceof Error)) {
|
|
12732
13129
|
throw error_1;
|
|
12733
13130
|
}
|
|
@@ -12735,21 +13132,21 @@
|
|
|
12735
13132
|
console.error(colors__default["default"].bgRed(error_1.name /* <- 11:11 */));
|
|
12736
13133
|
console.error(colors__default["default"].red(error_1.stack || error_1.message));
|
|
12737
13134
|
return [2 /*return*/, process.exit(1)];
|
|
12738
|
-
case
|
|
13135
|
+
case 15:
|
|
12739
13136
|
filenames_1_1 = filenames_1.next();
|
|
12740
|
-
return [3 /*break*/,
|
|
12741
|
-
case
|
|
12742
|
-
case 16:
|
|
12743
|
-
e_1_1 = _f.sent();
|
|
12744
|
-
e_1 = { error: e_1_1 };
|
|
12745
|
-
return [3 /*break*/, 18];
|
|
13137
|
+
return [3 /*break*/, 6];
|
|
13138
|
+
case 16: return [3 /*break*/, 19];
|
|
12746
13139
|
case 17:
|
|
13140
|
+
e_1_1 = _g.sent();
|
|
13141
|
+
e_1 = { error: e_1_1 };
|
|
13142
|
+
return [3 /*break*/, 19];
|
|
13143
|
+
case 18:
|
|
12747
13144
|
try {
|
|
12748
|
-
if (filenames_1_1 && !filenames_1_1.done && (
|
|
13145
|
+
if (filenames_1_1 && !filenames_1_1.done && (_f = filenames_1.return)) _f.call(filenames_1);
|
|
12749
13146
|
}
|
|
12750
13147
|
finally { if (e_1) throw e_1.error; }
|
|
12751
13148
|
return [7 /*endfinally*/];
|
|
12752
|
-
case
|
|
13149
|
+
case 19:
|
|
12753
13150
|
console.info(colors__default["default"].green("All pipelines are valid"));
|
|
12754
13151
|
return [2 /*return*/, process.exit(0)];
|
|
12755
13152
|
}
|
|
@@ -12830,6 +13227,7 @@
|
|
|
12830
13227
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
12831
13228
|
*
|
|
12832
13229
|
* @public exported from `@promptbook/core`
|
|
13230
|
+
* @public exported from `@promptbook/wizzard`
|
|
12833
13231
|
* @public exported from `@promptbook/cli`
|
|
12834
13232
|
*/
|
|
12835
13233
|
var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -13151,12 +13549,12 @@
|
|
|
13151
13549
|
output: computeUsage("$2.40 / 1M tokens"),
|
|
13152
13550
|
},
|
|
13153
13551
|
},
|
|
13154
|
-
// TODO: [main]
|
|
13552
|
+
// TODO: [main] !!3 Claude 1 and 2 has also completion versions - ask Hoagy
|
|
13155
13553
|
],
|
|
13156
13554
|
});
|
|
13157
13555
|
/**
|
|
13158
13556
|
* Note: [🤖] Add models of new variant
|
|
13159
|
-
* TODO: [🧠][main]
|
|
13557
|
+
* TODO: [🧠][main] !!3 Add embedding models OR Anthropic has only chat+completion models?
|
|
13160
13558
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
13161
13559
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
13162
13560
|
* TODO: [🎰] Some mechanism to auto-update available models
|
|
@@ -13531,8 +13929,8 @@
|
|
|
13531
13929
|
className: 'AnthropicClaudeExecutionTools',
|
|
13532
13930
|
});
|
|
13533
13931
|
/**
|
|
13534
|
-
* TODO: [🧠][main]
|
|
13535
|
-
* TODO: [🧠][🧱][main]
|
|
13932
|
+
* TODO: [🧠][main] !!4 Make anonymous this with all LLM providers
|
|
13933
|
+
* TODO: [🧠][🧱][main] !!4 Maybe change all `new AnthropicClaudeExecutionTools` -> `createAnthropicClaudeExecutionTools` in manual
|
|
13536
13934
|
* TODO: [🧠] Maybe auto-detect usage in browser and determine default value of `isProxied`
|
|
13537
13935
|
* TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
|
|
13538
13936
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
@@ -13544,7 +13942,9 @@
|
|
|
13544
13942
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
13545
13943
|
*
|
|
13546
13944
|
* @public exported from `@promptbook/anthropic-claude`
|
|
13945
|
+
* @public exported from `@promptbook/wizzard`
|
|
13547
13946
|
* @public exported from `@promptbook/cli`
|
|
13947
|
+
*
|
|
13548
13948
|
*/
|
|
13549
13949
|
var _AnthropicClaudeRegistration = $llmToolsRegister.register(createAnthropicClaudeExecutionTools);
|
|
13550
13950
|
/**
|
|
@@ -13558,6 +13958,7 @@
|
|
|
13558
13958
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
13559
13959
|
*
|
|
13560
13960
|
* @public exported from `@promptbook/core`
|
|
13961
|
+
* @public exported from `@promptbook/wizzard`
|
|
13561
13962
|
* @public exported from `@promptbook/cli`
|
|
13562
13963
|
*/
|
|
13563
13964
|
var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -13934,7 +14335,7 @@
|
|
|
13934
14335
|
prompt: computeUsage("$5.00 / 1M tokens"),
|
|
13935
14336
|
output: computeUsage("$15.00 / 1M tokens"),
|
|
13936
14337
|
},
|
|
13937
|
-
//TODO: [main]
|
|
14338
|
+
//TODO: [main] !!3 Add gpt-4o-mini-2024-07-18 and all others to be up to date
|
|
13938
14339
|
},
|
|
13939
14340
|
/**/
|
|
13940
14341
|
/**/
|
|
@@ -14084,7 +14485,7 @@
|
|
|
14084
14485
|
AzureOpenAiExecutionTools.prototype.listModels = function () {
|
|
14085
14486
|
return __awaiter(this, void 0, void 0, function () {
|
|
14086
14487
|
return __generator(this, function (_a) {
|
|
14087
|
-
// TODO: [main]
|
|
14488
|
+
// TODO: [main] !!3 Do here some filtering which models are really available as deployment
|
|
14088
14489
|
// @see https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/deployments?api-version=2023-05-01
|
|
14089
14490
|
return [2 /*return*/, OPENAI_MODELS.map(function (_a) {
|
|
14090
14491
|
var modelTitle = _a.modelTitle, modelName = _a.modelName, modelVariant = _a.modelVariant;
|
|
@@ -14365,6 +14766,7 @@
|
|
|
14365
14766
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
14366
14767
|
*
|
|
14367
14768
|
* @public exported from `@promptbook/azure-openai`
|
|
14769
|
+
* @public exported from `@promptbook/wizzard`
|
|
14368
14770
|
* @public exported from `@promptbook/cli`
|
|
14369
14771
|
*/
|
|
14370
14772
|
var _AzureOpenAiRegistration = $llmToolsRegister.register(createAzureOpenAiExecutionTools);
|
|
@@ -14373,21 +14775,13 @@
|
|
|
14373
14775
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
14374
14776
|
*/
|
|
14375
14777
|
|
|
14376
|
-
/**
|
|
14377
|
-
* Detects if the code is running in jest environment
|
|
14378
|
-
*
|
|
14379
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
14380
|
-
*
|
|
14381
|
-
* @public exported from `@promptbook/utils`
|
|
14382
|
-
*/
|
|
14383
|
-
var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
|
|
14384
|
-
|
|
14385
14778
|
/**
|
|
14386
14779
|
* Registration of LLM provider metadata
|
|
14387
14780
|
*
|
|
14388
14781
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
14389
14782
|
*
|
|
14390
14783
|
* @public exported from `@promptbook/core`
|
|
14784
|
+
* @public exported from `@promptbook/wizzard`
|
|
14391
14785
|
* @public exported from `@promptbook/cli`
|
|
14392
14786
|
*/
|
|
14393
14787
|
var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -14646,6 +15040,7 @@
|
|
|
14646
15040
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
14647
15041
|
*
|
|
14648
15042
|
* @public exported from `@promptbook/google`
|
|
15043
|
+
* @public exported from `@promptbook/wizzard`
|
|
14649
15044
|
* @public exported from `@promptbook/cli`
|
|
14650
15045
|
*/
|
|
14651
15046
|
var _GoogleRegistration = $llmToolsRegister.register(createGoogleExecutionTools);
|
|
@@ -14660,6 +15055,7 @@
|
|
|
14660
15055
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
14661
15056
|
*
|
|
14662
15057
|
* @public exported from `@promptbook/core`
|
|
15058
|
+
* @public exported from `@promptbook/wizzard`
|
|
14663
15059
|
* @public exported from `@promptbook/cli`
|
|
14664
15060
|
*/
|
|
14665
15061
|
var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -14698,6 +15094,7 @@
|
|
|
14698
15094
|
* Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
|
|
14699
15095
|
*
|
|
14700
15096
|
* @public exported from `@promptbook/core`
|
|
15097
|
+
* @public exported from `@promptbook/wizzard`
|
|
14701
15098
|
* @public exported from `@promptbook/cli`
|
|
14702
15099
|
*/
|
|
14703
15100
|
var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -14740,24 +15137,6 @@
|
|
|
14740
15137
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
14741
15138
|
*/
|
|
14742
15139
|
|
|
14743
|
-
/**
|
|
14744
|
-
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
14745
|
-
*
|
|
14746
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
14747
|
-
*
|
|
14748
|
-
* @public exported from `@promptbook/utils`
|
|
14749
|
-
*/
|
|
14750
|
-
var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
14751
|
-
|
|
14752
|
-
/**
|
|
14753
|
-
* Detects if the code is running in a web worker
|
|
14754
|
-
*
|
|
14755
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
14756
|
-
*
|
|
14757
|
-
* @public exported from `@promptbook/utils`
|
|
14758
|
-
*/
|
|
14759
|
-
var $isRunningInWebWorker = 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");
|
|
14760
|
-
|
|
14761
15140
|
/**
|
|
14762
15141
|
* Computes the usage of the OpenAI API based on the response from OpenAI
|
|
14763
15142
|
*
|
|
@@ -15260,7 +15639,7 @@
|
|
|
15260
15639
|
assistant_id: this.assistantId,
|
|
15261
15640
|
thread: {
|
|
15262
15641
|
messages: [
|
|
15263
|
-
// TODO: [🗯]
|
|
15642
|
+
// TODO: [🗯] Allow threads to be passed
|
|
15264
15643
|
{ role: 'user', content: rawPromptContent },
|
|
15265
15644
|
],
|
|
15266
15645
|
},
|
|
@@ -15363,7 +15742,7 @@
|
|
|
15363
15742
|
* @public exported from `@promptbook/openai`
|
|
15364
15743
|
*/
|
|
15365
15744
|
var createOpenAiAssistantExecutionTools = Object.assign(function (options) {
|
|
15366
|
-
// TODO: [🧠][main]
|
|
15745
|
+
// TODO: [🧠][main] !!4 If browser, auto add `dangerouslyAllowBrowser`
|
|
15367
15746
|
if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
|
|
15368
15747
|
options = __assign(__assign({}, options), { dangerouslyAllowBrowser: true });
|
|
15369
15748
|
}
|
|
@@ -15383,7 +15762,7 @@
|
|
|
15383
15762
|
* @public exported from `@promptbook/openai`
|
|
15384
15763
|
*/
|
|
15385
15764
|
var createOpenAiExecutionTools = Object.assign(function (options) {
|
|
15386
|
-
// TODO: [🧠][main]
|
|
15765
|
+
// TODO: [🧠][main] !!4 If browser, auto add `dangerouslyAllowBrowser`
|
|
15387
15766
|
if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
|
|
15388
15767
|
options = __assign(__assign({}, options), { dangerouslyAllowBrowser: true });
|
|
15389
15768
|
}
|
|
@@ -15403,6 +15782,7 @@
|
|
|
15403
15782
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
15404
15783
|
*
|
|
15405
15784
|
* @public exported from `@promptbook/openai`
|
|
15785
|
+
* @public exported from `@promptbook/wizzard`
|
|
15406
15786
|
* @public exported from `@promptbook/cli`
|
|
15407
15787
|
*/
|
|
15408
15788
|
var _OpenAiRegistration = $llmToolsRegister.register(createOpenAiExecutionTools);
|
|
@@ -15412,6 +15792,7 @@
|
|
|
15412
15792
|
* Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
|
|
15413
15793
|
*
|
|
15414
15794
|
* @public exported from `@promptbook/openai`
|
|
15795
|
+
* @public exported from `@promptbook/wizzard`
|
|
15415
15796
|
* @public exported from `@promptbook/cli`
|
|
15416
15797
|
*/
|
|
15417
15798
|
var _OpenAiAssistantRegistration = $llmToolsRegister.register(createOpenAiAssistantExecutionTools);
|
|
@@ -15665,6 +16046,7 @@
|
|
|
15665
16046
|
mimeTypes: ['text/markdown', 'text/plain'],
|
|
15666
16047
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
15667
16048
|
isAvilableInBrowser: true,
|
|
16049
|
+
// <- Note: [🌏] This is the only scraper which makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
15668
16050
|
requiredExecutables: [],
|
|
15669
16051
|
}); /* <- Note: [🤛] */
|
|
15670
16052
|
/**
|
|
@@ -15673,6 +16055,7 @@
|
|
|
15673
16055
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
15674
16056
|
*
|
|
15675
16057
|
* @public exported from `@promptbook/core`
|
|
16058
|
+
* @public exported from `@promptbook/wizzard`
|
|
15676
16059
|
* @public exported from `@promptbook/cli`
|
|
15677
16060
|
*/
|
|
15678
16061
|
var _MarkdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
@@ -15758,12 +16141,12 @@
|
|
|
15758
16141
|
outputParameters = result.outputParameters;
|
|
15759
16142
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
15760
16143
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
15761
|
-
// <- TODO: [main]
|
|
16144
|
+
// <- TODO: [main] Smarter split and filter out empty pieces
|
|
15762
16145
|
if (isVerbose) {
|
|
15763
16146
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
15764
16147
|
}
|
|
15765
16148
|
return [4 /*yield*/, Promise.all(
|
|
15766
|
-
// TODO: [🪂]
|
|
16149
|
+
// TODO: [🪂] Do not send all at once but in chunks
|
|
15767
16150
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
15768
16151
|
var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
15769
16152
|
return __generator(this, function (_c) {
|
|
@@ -15862,6 +16245,7 @@
|
|
|
15862
16245
|
mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
15863
16246
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
15864
16247
|
isAvilableInBrowser: false,
|
|
16248
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
15865
16249
|
requiredExecutables: ['Pandoc'],
|
|
15866
16250
|
}); /* <- Note: [🤛] */
|
|
15867
16251
|
/**
|
|
@@ -15870,6 +16254,7 @@
|
|
|
15870
16254
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
15871
16255
|
*
|
|
15872
16256
|
* @public exported from `@promptbook/core`
|
|
16257
|
+
* @public exported from `@promptbook/wizzard`
|
|
15873
16258
|
* @public exported from `@promptbook/cli`
|
|
15874
16259
|
*/
|
|
15875
16260
|
var _DocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(documentScraperMetadata);
|
|
@@ -16025,6 +16410,7 @@
|
|
|
16025
16410
|
mimeTypes: ['application/msword', 'text/rtf'],
|
|
16026
16411
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
16027
16412
|
isAvilableInBrowser: false,
|
|
16413
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
16028
16414
|
requiredExecutables: [
|
|
16029
16415
|
'Pandoc',
|
|
16030
16416
|
'LibreOffice',
|
|
@@ -16037,6 +16423,7 @@
|
|
|
16037
16423
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16038
16424
|
*
|
|
16039
16425
|
* @public exported from `@promptbook/core`
|
|
16426
|
+
* @public exported from `@promptbook/wizzard`
|
|
16040
16427
|
* @public exported from `@promptbook/cli`
|
|
16041
16428
|
*/
|
|
16042
16429
|
var _LegacyDocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
|
|
@@ -16207,6 +16594,7 @@
|
|
|
16207
16594
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16208
16595
|
*
|
|
16209
16596
|
* @public exported from `@promptbook/legacy-documents`
|
|
16597
|
+
* @public exported from `@promptbook/wizzard`
|
|
16210
16598
|
* @public exported from `@promptbook/cli`
|
|
16211
16599
|
*/
|
|
16212
16600
|
var _LegacyDocumentScraperRegistration = $scrapersRegister.register(createLegacyDocumentScraper);
|
|
@@ -16233,6 +16621,7 @@
|
|
|
16233
16621
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16234
16622
|
*
|
|
16235
16623
|
* @public exported from `@promptbook/documents`
|
|
16624
|
+
* @public exported from `@promptbook/wizzard`
|
|
16236
16625
|
* @public exported from `@promptbook/cli`
|
|
16237
16626
|
*/
|
|
16238
16627
|
var _DocumentScraperRegistration = $scrapersRegister.register(createDocumentScraper);
|
|
@@ -16259,6 +16648,7 @@
|
|
|
16259
16648
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16260
16649
|
*
|
|
16261
16650
|
* @public exported from `@promptbook/markdown-utils`
|
|
16651
|
+
* @public exported from `@promptbook/wizzard`
|
|
16262
16652
|
* @public exported from `@promptbook/cli`
|
|
16263
16653
|
*/
|
|
16264
16654
|
var _MarkdownScraperRegistration = $scrapersRegister.register(createMarkdownScraper);
|
|
@@ -16278,7 +16668,8 @@
|
|
|
16278
16668
|
className: 'PdfScraper',
|
|
16279
16669
|
mimeTypes: ['application/pdf'],
|
|
16280
16670
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
16281
|
-
isAvilableInBrowser:
|
|
16671
|
+
isAvilableInBrowser: false,
|
|
16672
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
16282
16673
|
requiredExecutables: [],
|
|
16283
16674
|
}); /* <- Note: [🤛] */
|
|
16284
16675
|
/**
|
|
@@ -16287,6 +16678,7 @@
|
|
|
16287
16678
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16288
16679
|
*
|
|
16289
16680
|
* @public exported from `@promptbook/core`
|
|
16681
|
+
* @public exported from `@promptbook/wizzard`
|
|
16290
16682
|
* @public exported from `@promptbook/cli`
|
|
16291
16683
|
*/
|
|
16292
16684
|
var _PdfScraperMetadataRegistration = $scrapersMetadataRegister.register(pdfScraperMetadata);
|
|
@@ -16351,6 +16743,7 @@
|
|
|
16351
16743
|
* TODO: [👣] Converted pdf documents can act as cached items - there is no need to run conversion each time
|
|
16352
16744
|
* TODO: [🪂] Do it in parallel 11:11
|
|
16353
16745
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
16746
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
16354
16747
|
*/
|
|
16355
16748
|
|
|
16356
16749
|
/**
|
|
@@ -16371,6 +16764,7 @@
|
|
|
16371
16764
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16372
16765
|
*
|
|
16373
16766
|
* @public exported from `@promptbook/pdf`
|
|
16767
|
+
* @public exported from `@promptbook/wizzard`
|
|
16374
16768
|
* @public exported from `@promptbook/cli`
|
|
16375
16769
|
*/
|
|
16376
16770
|
var _PdfScraperRegistration = $scrapersRegister.register(createPdfScraper);
|
|
@@ -16391,6 +16785,7 @@
|
|
|
16391
16785
|
mimeTypes: ['text/html'],
|
|
16392
16786
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
16393
16787
|
isAvilableInBrowser: false,
|
|
16788
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
16394
16789
|
requiredExecutables: [],
|
|
16395
16790
|
}); /* <- Note: [🤛] */
|
|
16396
16791
|
/**
|
|
@@ -16399,6 +16794,7 @@
|
|
|
16399
16794
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16400
16795
|
*
|
|
16401
16796
|
* @public exported from `@promptbook/core`
|
|
16797
|
+
* @public exported from `@promptbook/wizzard`
|
|
16402
16798
|
* @public exported from `@promptbook/cli`
|
|
16403
16799
|
*/
|
|
16404
16800
|
var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
|
|
@@ -16572,6 +16968,7 @@
|
|
|
16572
16968
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16573
16969
|
*
|
|
16574
16970
|
* @public exported from `@promptbook/website-crawler`
|
|
16971
|
+
* @public exported from `@promptbook/wizzard`
|
|
16575
16972
|
* @public exported from `@promptbook/cli`
|
|
16576
16973
|
*/
|
|
16577
16974
|
var _WebsiteScraperRegistration = $scrapersRegister.register(createWebsiteScraper);
|