@promptbook/core 0.75.3 → 0.75.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +193 -121
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -2
- package/esm/typings/src/config.d.ts +9 -1
- package/esm/typings/src/errors/0-BoilerplateError.d.ts +12 -0
- package/esm/typings/src/errors/{index.d.ts → 0-index.d.ts} +10 -2
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$registeredScrapersMessage.d.ts +2 -1
- package/package.json +1 -1
- package/umd/index.umd.js +202 -129
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -22,7 +22,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
22
22
|
*
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.75.
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.75.4';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -835,6 +835,16 @@ var DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
|
835
835
|
* @public exported from `@promptbook/core`
|
|
836
836
|
*/
|
|
837
837
|
var DEFAULT_IS_VERBOSE = false;
|
|
838
|
+
/**
|
|
839
|
+
* @@@
|
|
840
|
+
*
|
|
841
|
+
* Note: This is experimental feature
|
|
842
|
+
*
|
|
843
|
+
* @public exported from `@promptbook/core`
|
|
844
|
+
*/
|
|
845
|
+
function SET_IS_VERBOSE(isVerbose) {
|
|
846
|
+
DEFAULT_IS_VERBOSE = isVerbose;
|
|
847
|
+
}
|
|
838
848
|
/**
|
|
839
849
|
* @@@
|
|
840
850
|
*
|
|
@@ -2343,6 +2353,42 @@ function joinLlmExecutionTools() {
|
|
|
2343
2353
|
|
|
2344
2354
|
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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-persona.book.md"}];
|
|
2345
2355
|
|
|
2356
|
+
/**
|
|
2357
|
+
* This error indicates problems parsing the format value
|
|
2358
|
+
*
|
|
2359
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
2360
|
+
* This is not thrown directly but in extended classes
|
|
2361
|
+
*
|
|
2362
|
+
* @public exported from `@promptbook/core`
|
|
2363
|
+
*/
|
|
2364
|
+
var AbstractFormatError = /** @class */ (function (_super) {
|
|
2365
|
+
__extends(AbstractFormatError, _super);
|
|
2366
|
+
// Note: To allow instanceof do not put here error `name`
|
|
2367
|
+
// public readonly name = 'AbstractFormatError';
|
|
2368
|
+
function AbstractFormatError(message) {
|
|
2369
|
+
var _this = _super.call(this, message) || this;
|
|
2370
|
+
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
2371
|
+
return _this;
|
|
2372
|
+
}
|
|
2373
|
+
return AbstractFormatError;
|
|
2374
|
+
}(Error));
|
|
2375
|
+
|
|
2376
|
+
/**
|
|
2377
|
+
* This error indicates problem with parsing of CSV
|
|
2378
|
+
*
|
|
2379
|
+
* @public exported from `@promptbook/core`
|
|
2380
|
+
*/
|
|
2381
|
+
var CsvFormatError = /** @class */ (function (_super) {
|
|
2382
|
+
__extends(CsvFormatError, _super);
|
|
2383
|
+
function CsvFormatError(message) {
|
|
2384
|
+
var _this = _super.call(this, message) || this;
|
|
2385
|
+
_this.name = 'CsvFormatError';
|
|
2386
|
+
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
2387
|
+
return _this;
|
|
2388
|
+
}
|
|
2389
|
+
return CsvFormatError;
|
|
2390
|
+
}(AbstractFormatError));
|
|
2391
|
+
|
|
2346
2392
|
/**
|
|
2347
2393
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2348
2394
|
*
|
|
@@ -2394,6 +2440,22 @@ var ExpectError = /** @class */ (function (_super) {
|
|
|
2394
2440
|
return ExpectError;
|
|
2395
2441
|
}(Error));
|
|
2396
2442
|
|
|
2443
|
+
/**
|
|
2444
|
+
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
2445
|
+
*
|
|
2446
|
+
* @public exported from `@promptbook/core`
|
|
2447
|
+
*/
|
|
2448
|
+
var KnowledgeScrapeError = /** @class */ (function (_super) {
|
|
2449
|
+
__extends(KnowledgeScrapeError, _super);
|
|
2450
|
+
function KnowledgeScrapeError(message) {
|
|
2451
|
+
var _this = _super.call(this, message) || this;
|
|
2452
|
+
_this.name = 'KnowledgeScrapeError';
|
|
2453
|
+
Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
|
|
2454
|
+
return _this;
|
|
2455
|
+
}
|
|
2456
|
+
return KnowledgeScrapeError;
|
|
2457
|
+
}(Error));
|
|
2458
|
+
|
|
2397
2459
|
/**
|
|
2398
2460
|
* This error type indicates that some limit was reached
|
|
2399
2461
|
*
|
|
@@ -2432,10 +2494,14 @@ var NotYetImplementedError = /** @class */ (function (_super) {
|
|
|
2432
2494
|
* @public exported from `@promptbook/core`
|
|
2433
2495
|
*/
|
|
2434
2496
|
var ERRORS = {
|
|
2435
|
-
|
|
2497
|
+
AbstractFormatError: AbstractFormatError,
|
|
2498
|
+
CsvFormatError: CsvFormatError,
|
|
2436
2499
|
CollectionError: CollectionError,
|
|
2437
2500
|
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2501
|
+
ExpectError: ExpectError,
|
|
2502
|
+
KnowledgeScrapeError: KnowledgeScrapeError,
|
|
2438
2503
|
LimitReachedError: LimitReachedError,
|
|
2504
|
+
MissingToolsError: MissingToolsError,
|
|
2439
2505
|
NotFoundError: NotFoundError,
|
|
2440
2506
|
NotYetImplementedError: NotYetImplementedError,
|
|
2441
2507
|
ParseError: ParseError,
|
|
@@ -2748,42 +2814,6 @@ function union() {
|
|
|
2748
2814
|
return union;
|
|
2749
2815
|
}
|
|
2750
2816
|
|
|
2751
|
-
/**
|
|
2752
|
-
* This error indicates problems parsing the format value
|
|
2753
|
-
*
|
|
2754
|
-
* For example, when the format value is not a valid JSON or CSV
|
|
2755
|
-
* This is not thrown directly but in extended classes
|
|
2756
|
-
*
|
|
2757
|
-
* @public exported from `@promptbook/core`
|
|
2758
|
-
*/
|
|
2759
|
-
var AbstractFormatError = /** @class */ (function (_super) {
|
|
2760
|
-
__extends(AbstractFormatError, _super);
|
|
2761
|
-
// Note: To allow instanceof do not put here error `name`
|
|
2762
|
-
// public readonly name = 'AbstractFormatError';
|
|
2763
|
-
function AbstractFormatError(message) {
|
|
2764
|
-
var _this = _super.call(this, message) || this;
|
|
2765
|
-
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
2766
|
-
return _this;
|
|
2767
|
-
}
|
|
2768
|
-
return AbstractFormatError;
|
|
2769
|
-
}(Error));
|
|
2770
|
-
|
|
2771
|
-
/**
|
|
2772
|
-
* This error indicates problem with parsing of CSV
|
|
2773
|
-
*
|
|
2774
|
-
* @public exported from `@promptbook/core`
|
|
2775
|
-
*/
|
|
2776
|
-
var CsvFormatError = /** @class */ (function (_super) {
|
|
2777
|
-
__extends(CsvFormatError, _super);
|
|
2778
|
-
function CsvFormatError(message) {
|
|
2779
|
-
var _this = _super.call(this, message) || this;
|
|
2780
|
-
_this.name = 'CsvFormatError';
|
|
2781
|
-
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
2782
|
-
return _this;
|
|
2783
|
-
}
|
|
2784
|
-
return CsvFormatError;
|
|
2785
|
-
}(AbstractFormatError));
|
|
2786
|
-
|
|
2787
2817
|
/**
|
|
2788
2818
|
* @@@
|
|
2789
2819
|
*
|
|
@@ -2824,7 +2854,7 @@ var CsvFormatDefinition = {
|
|
|
2824
2854
|
case 0:
|
|
2825
2855
|
csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
2826
2856
|
if (csv.errors.length !== 0) {
|
|
2827
|
-
throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2857
|
+
throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
|
|
2828
2858
|
}
|
|
2829
2859
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2830
2860
|
var _a, _b;
|
|
@@ -2862,7 +2892,7 @@ var CsvFormatDefinition = {
|
|
|
2862
2892
|
case 0:
|
|
2863
2893
|
csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
2864
2894
|
if (csv.errors.length !== 0) {
|
|
2865
|
-
throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2895
|
+
throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
|
|
2866
2896
|
}
|
|
2867
2897
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, rowIndex) { return __awaiter(_this, void 0, void 0, function () {
|
|
2868
2898
|
var _this = this;
|
|
@@ -4922,22 +4952,6 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
4922
4952
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
4923
4953
|
*/
|
|
4924
4954
|
|
|
4925
|
-
/**
|
|
4926
|
-
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
4927
|
-
*
|
|
4928
|
-
* @public exported from `@promptbook/core`
|
|
4929
|
-
*/
|
|
4930
|
-
var KnowledgeScrapeError = /** @class */ (function (_super) {
|
|
4931
|
-
__extends(KnowledgeScrapeError, _super);
|
|
4932
|
-
function KnowledgeScrapeError(message) {
|
|
4933
|
-
var _this = _super.call(this, message) || this;
|
|
4934
|
-
_this.name = 'KnowledgeScrapeError';
|
|
4935
|
-
Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
|
|
4936
|
-
return _this;
|
|
4937
|
-
}
|
|
4938
|
-
return KnowledgeScrapeError;
|
|
4939
|
-
}(Error));
|
|
4940
|
-
|
|
4941
4955
|
/**
|
|
4942
4956
|
* @@@
|
|
4943
4957
|
*
|
|
@@ -5057,9 +5071,15 @@ var $Register = /** @class */ (function () {
|
|
|
5057
5071
|
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
5058
5072
|
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
5059
5073
|
if (!existingRegistration) {
|
|
5074
|
+
if (DEFAULT_IS_VERBOSE) {
|
|
5075
|
+
console.warn("[\uD83D\uDCE6] Registering `".concat(packageName, ".").concat(className, "` to `").concat(this.registerName, "`"));
|
|
5076
|
+
}
|
|
5060
5077
|
this.storage.push(registered);
|
|
5061
5078
|
}
|
|
5062
5079
|
else {
|
|
5080
|
+
if (DEFAULT_IS_VERBOSE) {
|
|
5081
|
+
console.warn("[\uD83D\uDCE6] Re-registering `".concat(packageName, ".").concat(className, "` to `").concat(this.registerName, "`"));
|
|
5082
|
+
}
|
|
5063
5083
|
this.storage[existingRegistrationIndex] = registered;
|
|
5064
5084
|
}
|
|
5065
5085
|
return {
|
|
@@ -5108,8 +5128,8 @@ var $scrapersRegister = new $Register('scraper_constructors');
|
|
|
5108
5128
|
*
|
|
5109
5129
|
* @private internal function of `createScrapersFromConfiguration` and `createScrapersFromEnv`
|
|
5110
5130
|
*/
|
|
5111
|
-
function $registeredScrapersMessage() {
|
|
5112
|
-
var e_1, _a, e_2, _b;
|
|
5131
|
+
function $registeredScrapersMessage(availableScrapers) {
|
|
5132
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
5113
5133
|
/**
|
|
5114
5134
|
* Mixes registered scrapers from $scrapersMetadataRegister and $scrapersRegister
|
|
5115
5135
|
*/
|
|
@@ -5121,15 +5141,15 @@ function $registeredScrapersMessage() {
|
|
|
5121
5141
|
all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
|
|
5122
5142
|
};
|
|
5123
5143
|
try {
|
|
5124
|
-
for (var
|
|
5125
|
-
var
|
|
5144
|
+
for (var _d = __values($scrapersMetadataRegister.list()), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
5145
|
+
var _f = _e.value, packageName = _f.packageName, className = _f.className, mimeTypes = _f.mimeTypes, documentationUrl = _f.documentationUrl, isAvilableInBrowser = _f.isAvilableInBrowser;
|
|
5126
5146
|
_loop_1(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
|
|
5127
5147
|
}
|
|
5128
5148
|
}
|
|
5129
5149
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5130
5150
|
finally {
|
|
5131
5151
|
try {
|
|
5132
|
-
if (
|
|
5152
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
5133
5153
|
}
|
|
5134
5154
|
finally { if (e_1) throw e_1.error; }
|
|
5135
5155
|
}
|
|
@@ -5140,18 +5160,31 @@ function $registeredScrapersMessage() {
|
|
|
5140
5160
|
all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
|
|
5141
5161
|
};
|
|
5142
5162
|
try {
|
|
5143
|
-
for (var
|
|
5144
|
-
var
|
|
5163
|
+
for (var _g = __values($scrapersRegister.list()), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
5164
|
+
var _j = _h.value, packageName = _j.packageName, className = _j.className, mimeTypes = _j.mimeTypes, documentationUrl = _j.documentationUrl, isAvilableInBrowser = _j.isAvilableInBrowser;
|
|
5145
5165
|
_loop_2(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
|
|
5146
5166
|
}
|
|
5147
5167
|
}
|
|
5148
5168
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5149
5169
|
finally {
|
|
5150
5170
|
try {
|
|
5151
|
-
if (
|
|
5171
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
5152
5172
|
}
|
|
5153
5173
|
finally { if (e_2) throw e_2.error; }
|
|
5154
5174
|
}
|
|
5175
|
+
try {
|
|
5176
|
+
for (var availableScrapers_1 = __values(availableScrapers), availableScrapers_1_1 = availableScrapers_1.next(); !availableScrapers_1_1.done; availableScrapers_1_1 = availableScrapers_1.next()) {
|
|
5177
|
+
var metadata_1 = availableScrapers_1_1.value.metadata;
|
|
5178
|
+
all.push(metadata_1);
|
|
5179
|
+
}
|
|
5180
|
+
}
|
|
5181
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
5182
|
+
finally {
|
|
5183
|
+
try {
|
|
5184
|
+
if (availableScrapers_1_1 && !availableScrapers_1_1.done && (_c = availableScrapers_1.return)) _c.call(availableScrapers_1);
|
|
5185
|
+
}
|
|
5186
|
+
finally { if (e_3) throw e_3.error; }
|
|
5187
|
+
}
|
|
5155
5188
|
var metadata = all.map(function (metadata) {
|
|
5156
5189
|
var isMetadataAviailable = $scrapersMetadataRegister
|
|
5157
5190
|
.list()
|
|
@@ -5165,42 +5198,44 @@ function $registeredScrapersMessage() {
|
|
|
5165
5198
|
var packageName = _a.packageName, className = _a.className;
|
|
5166
5199
|
return metadata.packageName === packageName && metadata.className === className;
|
|
5167
5200
|
});
|
|
5168
|
-
|
|
5201
|
+
var isAvilableInTools = availableScrapers.some(function (_a) {
|
|
5202
|
+
var _b = _a.metadata, packageName = _b.packageName, className = _b.className;
|
|
5203
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
5204
|
+
});
|
|
5205
|
+
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
|
|
5169
5206
|
});
|
|
5170
5207
|
if (metadata.length === 0) {
|
|
5171
|
-
return "No scrapers are available";
|
|
5208
|
+
return spaceTrim("\n **No scrapers are available**\n\n This is a unexpected behavior, you are probably using some broken version of Promptbook\n At least there should be available the metadata of the scrapers\n ");
|
|
5172
5209
|
}
|
|
5173
5210
|
return spaceTrim(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
|
|
5174
5211
|
.map(function (_a, i) {
|
|
5175
|
-
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser;
|
|
5176
|
-
var more;
|
|
5177
|
-
// TODO:
|
|
5178
|
-
if (
|
|
5179
|
-
more
|
|
5180
|
-
}
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
more = "(installed)";
|
|
5194
|
-
}
|
|
5195
|
-
else {
|
|
5196
|
-
more = "*(unknown state, looks like a unexpected behavior)*";
|
|
5197
|
-
}
|
|
5212
|
+
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
|
|
5213
|
+
var more = [];
|
|
5214
|
+
// TODO: [🧠] Maybe use `documentationUrl`
|
|
5215
|
+
if (isMetadataAviailable) {
|
|
5216
|
+
more.push("\u2B1C Metadata registered");
|
|
5217
|
+
} // not else
|
|
5218
|
+
if (isInstalled) {
|
|
5219
|
+
more.push("\uD83D\uDFE9 Installed");
|
|
5220
|
+
} // not else
|
|
5221
|
+
if (isAvilableInTools) {
|
|
5222
|
+
more.push("\uD83D\uDFE6 Available in tools");
|
|
5223
|
+
} // not else
|
|
5224
|
+
if (!isMetadataAviailable && isInstalled) {
|
|
5225
|
+
more.push("When no metadata registered but scraper is installed, it is an unexpected behavior");
|
|
5226
|
+
} // not else
|
|
5227
|
+
if (!isInstalled && isAvilableInTools) {
|
|
5228
|
+
more.push("When the scraper is not installed but available in tools, it is an unexpected compatibility behavior");
|
|
5229
|
+
} // not else
|
|
5198
5230
|
if (!isAvilableInBrowser) {
|
|
5199
|
-
more
|
|
5231
|
+
more.push("Not usable in browser");
|
|
5200
5232
|
}
|
|
5201
|
-
|
|
5233
|
+
var moreText = more.length === 0 ? '' : " *(".concat(more.join('; '), ")*");
|
|
5234
|
+
return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` compatible to scrape ").concat(mimeTypes
|
|
5235
|
+
.map(function (mimeType) { return "\"".concat(mimeType, "\""); })
|
|
5236
|
+
.join(', ')).concat(moreText);
|
|
5202
5237
|
})
|
|
5203
|
-
.join('\n')), "\n "); });
|
|
5238
|
+
.join('\n')), "\n\n Legend:\n - \u2B1C **Metadata registered** means that Promptbook knows about the scraper, it is similar to registration in some registry\n - \uD83D\uDFE9 **Installed** means that you have imported package with particular scraper\n - \uD83D\uDFE6 **Available in tools** means that you have passed scraper as dependency into prepare or execution process\n\n "); });
|
|
5204
5239
|
}
|
|
5205
5240
|
/**
|
|
5206
5241
|
* TODO: [®] DRY Register logic
|
|
@@ -5536,57 +5571,75 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5536
5571
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, rootDirname = options.rootDirname, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
5537
5572
|
knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
5538
5573
|
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
5539
|
-
var partialPieces, sourceHandler,
|
|
5540
|
-
var e_1,
|
|
5541
|
-
return __generator(this, function (
|
|
5542
|
-
switch (
|
|
5574
|
+
var partialPieces, sourceHandler, scrapers, _loop_1, scrapers_1, scrapers_1_1, scraper, state_1, e_1_1, pieces;
|
|
5575
|
+
var e_1, _a;
|
|
5576
|
+
return __generator(this, function (_b) {
|
|
5577
|
+
switch (_b.label) {
|
|
5543
5578
|
case 0:
|
|
5544
5579
|
partialPieces = null;
|
|
5545
5580
|
return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname: rootDirname, isVerbose: isVerbose })];
|
|
5546
5581
|
case 1:
|
|
5547
|
-
sourceHandler =
|
|
5548
|
-
|
|
5582
|
+
sourceHandler = _b.sent();
|
|
5583
|
+
scrapers = arrayableToArray(tools.scrapers);
|
|
5584
|
+
_loop_1 = function (scraper) {
|
|
5585
|
+
var partialPiecesUnchecked;
|
|
5586
|
+
return __generator(this, function (_c) {
|
|
5587
|
+
switch (_c.label) {
|
|
5588
|
+
case 0:
|
|
5589
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
5590
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
5591
|
+
) {
|
|
5592
|
+
return [2 /*return*/, "continue"];
|
|
5593
|
+
}
|
|
5594
|
+
return [4 /*yield*/, scraper.scrape(sourceHandler)];
|
|
5595
|
+
case 1:
|
|
5596
|
+
partialPiecesUnchecked = _c.sent();
|
|
5597
|
+
if (partialPiecesUnchecked !== null) {
|
|
5598
|
+
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
5599
|
+
return [2 /*return*/, "break"];
|
|
5600
|
+
}
|
|
5601
|
+
console.warn(spaceTrim(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
|
|
5602
|
+
.split('\n')
|
|
5603
|
+
.map(function (line) { return "> ".concat(line); })
|
|
5604
|
+
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
5605
|
+
return [2 /*return*/];
|
|
5606
|
+
}
|
|
5607
|
+
});
|
|
5608
|
+
};
|
|
5609
|
+
_b.label = 2;
|
|
5549
5610
|
case 2:
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5611
|
+
_b.trys.push([2, 7, 8, 9]);
|
|
5612
|
+
scrapers_1 = __values(scrapers), scrapers_1_1 = scrapers_1.next();
|
|
5613
|
+
_b.label = 3;
|
|
5553
5614
|
case 3:
|
|
5554
|
-
if (!!
|
|
5555
|
-
scraper =
|
|
5556
|
-
|
|
5557
|
-
// <- TODO: [🦔] Implement mime-type wildcards
|
|
5558
|
-
) {
|
|
5559
|
-
return [3 /*break*/, 5];
|
|
5560
|
-
}
|
|
5561
|
-
return [4 /*yield*/, scraper.scrape(sourceHandler)];
|
|
5615
|
+
if (!!scrapers_1_1.done) return [3 /*break*/, 6];
|
|
5616
|
+
scraper = scrapers_1_1.value;
|
|
5617
|
+
return [5 /*yield**/, _loop_1(scraper)];
|
|
5562
5618
|
case 4:
|
|
5563
|
-
|
|
5564
|
-
if (
|
|
5565
|
-
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
5566
|
-
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
5619
|
+
state_1 = _b.sent();
|
|
5620
|
+
if (state_1 === "break")
|
|
5567
5621
|
return [3 /*break*/, 6];
|
|
5568
|
-
|
|
5569
|
-
_d.label = 5;
|
|
5622
|
+
_b.label = 5;
|
|
5570
5623
|
case 5:
|
|
5571
|
-
|
|
5624
|
+
scrapers_1_1 = scrapers_1.next();
|
|
5572
5625
|
return [3 /*break*/, 3];
|
|
5573
5626
|
case 6: return [3 /*break*/, 9];
|
|
5574
5627
|
case 7:
|
|
5575
|
-
e_1_1 =
|
|
5628
|
+
e_1_1 = _b.sent();
|
|
5576
5629
|
e_1 = { error: e_1_1 };
|
|
5577
5630
|
return [3 /*break*/, 9];
|
|
5578
5631
|
case 8:
|
|
5579
5632
|
try {
|
|
5580
|
-
if (
|
|
5633
|
+
if (scrapers_1_1 && !scrapers_1_1.done && (_a = scrapers_1.return)) _a.call(scrapers_1);
|
|
5581
5634
|
}
|
|
5582
5635
|
finally { if (e_1) throw e_1.error; }
|
|
5583
5636
|
return [7 /*endfinally*/];
|
|
5584
5637
|
case 9:
|
|
5585
5638
|
if (partialPieces === null) {
|
|
5586
|
-
throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge
|
|
5639
|
+
throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
|
|
5587
5640
|
.split('\n')
|
|
5588
5641
|
.map(function (line) { return "> ".concat(line); })
|
|
5589
|
-
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage()), "\n\n\n "); }));
|
|
5642
|
+
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
5590
5643
|
}
|
|
5591
5644
|
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
5592
5645
|
{
|
|
@@ -9082,6 +9135,25 @@ var CallbackInterfaceTools = /** @class */ (function () {
|
|
|
9082
9135
|
return CallbackInterfaceTools;
|
|
9083
9136
|
}());
|
|
9084
9137
|
|
|
9138
|
+
/**
|
|
9139
|
+
* This error indicates @@@
|
|
9140
|
+
*
|
|
9141
|
+
* @public exported from `@promptbook/core`
|
|
9142
|
+
*/
|
|
9143
|
+
var BoilerplateError = /** @class */ (function (_super) {
|
|
9144
|
+
__extends(BoilerplateError, _super);
|
|
9145
|
+
function BoilerplateError(message) {
|
|
9146
|
+
var _this = _super.call(this, message) || this;
|
|
9147
|
+
_this.name = 'BoilerplateError';
|
|
9148
|
+
Object.setPrototypeOf(_this, BoilerplateError.prototype);
|
|
9149
|
+
return _this;
|
|
9150
|
+
}
|
|
9151
|
+
return BoilerplateError;
|
|
9152
|
+
}(Error));
|
|
9153
|
+
/**
|
|
9154
|
+
* TODO: @@@ Do not forget to add the error into `0-index.ts` ERRORS
|
|
9155
|
+
*/
|
|
9156
|
+
|
|
9085
9157
|
/**
|
|
9086
9158
|
* Pretty print an embedding vector for logging
|
|
9087
9159
|
*
|
|
@@ -10405,5 +10477,5 @@ var PrefixStorage = /** @class */ (function () {
|
|
|
10405
10477
|
return PrefixStorage;
|
|
10406
10478
|
}());
|
|
10407
10479
|
|
|
10408
|
-
export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, ERRORS, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
10480
|
+
export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, ERRORS, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
10409
10481
|
//# sourceMappingURL=index.es.js.map
|