@promptbook/cli 0.92.0-11 → 0.92.0-12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +128 -106
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -4
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +3 -1
- package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +3 -3
- package/esm/typings/src/formats/_common/{FormatSubvalueDefinition.d.ts → FormatSubvalueParser.d.ts} +1 -1
- package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
- package/esm/typings/src/formats/index.d.ts +2 -2
- package/esm/typings/src/formats/json/{JsonFormatDefinition.d.ts → JsonFormatParser.d.ts} +6 -6
- package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
- package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +1 -1
- package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +10 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +7 -0
- package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +128 -106
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
package/esm/index.es.js
CHANGED
|
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
47
47
|
* @generated
|
|
48
48
|
* @see https://github.com/webgptorg/promptbook
|
|
49
49
|
*/
|
|
50
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
50
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-12';
|
|
51
51
|
/**
|
|
52
52
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
53
53
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -4944,6 +4944,35 @@ function isPipelinePrepared(pipeline) {
|
|
|
4944
4944
|
* - [♨] Are tasks prepared
|
|
4945
4945
|
*/
|
|
4946
4946
|
|
|
4947
|
+
/**
|
|
4948
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
4949
|
+
*
|
|
4950
|
+
* @public exported from `@promptbook/utils`
|
|
4951
|
+
*/
|
|
4952
|
+
function serializeError(error) {
|
|
4953
|
+
const { name, message, stack } = error;
|
|
4954
|
+
const { id } = error;
|
|
4955
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
4956
|
+
console.error(spaceTrim((block) => `
|
|
4957
|
+
|
|
4958
|
+
Cannot serialize error with name "${name}"
|
|
4959
|
+
|
|
4960
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
4961
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
4962
|
+
|
|
4963
|
+
|
|
4964
|
+
${block(stack || message)}
|
|
4965
|
+
|
|
4966
|
+
`));
|
|
4967
|
+
}
|
|
4968
|
+
return {
|
|
4969
|
+
name: name,
|
|
4970
|
+
message,
|
|
4971
|
+
stack,
|
|
4972
|
+
id, // Include id in the serialized object
|
|
4973
|
+
};
|
|
4974
|
+
}
|
|
4975
|
+
|
|
4947
4976
|
/**
|
|
4948
4977
|
* Recursively converts JSON strings to JSON objects
|
|
4949
4978
|
|
|
@@ -5113,35 +5142,6 @@ function createTask(options) {
|
|
|
5113
5142
|
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
5114
5143
|
*/
|
|
5115
5144
|
|
|
5116
|
-
/**
|
|
5117
|
-
* Serializes an error into a [🚉] JSON-serializable object
|
|
5118
|
-
*
|
|
5119
|
-
* @public exported from `@promptbook/utils`
|
|
5120
|
-
*/
|
|
5121
|
-
function serializeError(error) {
|
|
5122
|
-
const { name, message, stack } = error;
|
|
5123
|
-
const { id } = error;
|
|
5124
|
-
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
5125
|
-
console.error(spaceTrim((block) => `
|
|
5126
|
-
|
|
5127
|
-
Cannot serialize error with name "${name}"
|
|
5128
|
-
|
|
5129
|
-
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
5130
|
-
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
${block(stack || message)}
|
|
5134
|
-
|
|
5135
|
-
`));
|
|
5136
|
-
}
|
|
5137
|
-
return {
|
|
5138
|
-
name: name,
|
|
5139
|
-
message,
|
|
5140
|
-
stack,
|
|
5141
|
-
id, // Include id in the serialized object
|
|
5142
|
-
};
|
|
5143
|
-
}
|
|
5144
|
-
|
|
5145
5145
|
/**
|
|
5146
5146
|
* Format either small or big number
|
|
5147
5147
|
*
|
|
@@ -5393,6 +5393,24 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
5393
5393
|
// encoding: 'utf-8',
|
|
5394
5394
|
});
|
|
5395
5395
|
|
|
5396
|
+
/**
|
|
5397
|
+
* Converts a CSV string into an object
|
|
5398
|
+
*
|
|
5399
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
5400
|
+
*
|
|
5401
|
+
* @private - for now until `@promptbook/csv` is released
|
|
5402
|
+
*/
|
|
5403
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
5404
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
5405
|
+
// Note: Autoheal invalid '\n' characters
|
|
5406
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
5407
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
5408
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
5409
|
+
}
|
|
5410
|
+
const csv = parse(value, settings);
|
|
5411
|
+
return csv;
|
|
5412
|
+
}
|
|
5413
|
+
|
|
5396
5414
|
/**
|
|
5397
5415
|
* Function to check if a string is valid CSV
|
|
5398
5416
|
*
|
|
@@ -5415,31 +5433,13 @@ function isValidCsvString(value) {
|
|
|
5415
5433
|
}
|
|
5416
5434
|
}
|
|
5417
5435
|
|
|
5418
|
-
/**
|
|
5419
|
-
* Converts a CSV string into an object
|
|
5420
|
-
*
|
|
5421
|
-
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
5422
|
-
*
|
|
5423
|
-
* @private - for now until `@promptbook/csv` is released
|
|
5424
|
-
*/
|
|
5425
|
-
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
5426
|
-
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
5427
|
-
// Note: Autoheal invalid '\n' characters
|
|
5428
|
-
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
5429
|
-
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
5430
|
-
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
5431
|
-
}
|
|
5432
|
-
const csv = parse(value, settings);
|
|
5433
|
-
return csv;
|
|
5434
|
-
}
|
|
5435
|
-
|
|
5436
5436
|
/**
|
|
5437
5437
|
* Definition for CSV spreadsheet
|
|
5438
5438
|
*
|
|
5439
5439
|
* @public exported from `@promptbook/core`
|
|
5440
5440
|
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
5441
5441
|
*/
|
|
5442
|
-
const
|
|
5442
|
+
const CsvFormatParser = {
|
|
5443
5443
|
formatName: 'CSV',
|
|
5444
5444
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
5445
5445
|
isValid(value, settings, schema) {
|
|
@@ -5451,7 +5451,7 @@ const CsvFormatDefinition = {
|
|
|
5451
5451
|
heal(value, settings, schema) {
|
|
5452
5452
|
throw new Error('Not implemented');
|
|
5453
5453
|
},
|
|
5454
|
-
|
|
5454
|
+
subvalueParsers: [
|
|
5455
5455
|
{
|
|
5456
5456
|
subvalueName: 'ROW',
|
|
5457
5457
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -5512,10 +5512,10 @@ const CsvFormatDefinition = {
|
|
|
5512
5512
|
],
|
|
5513
5513
|
};
|
|
5514
5514
|
/**
|
|
5515
|
-
* TODO: [🍓] In `
|
|
5516
|
-
* TODO: [🍓] In `
|
|
5517
|
-
* TODO: [🍓] In `
|
|
5518
|
-
* TODO: [🍓] In `
|
|
5515
|
+
* TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
|
|
5516
|
+
* TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
|
|
5517
|
+
* TODO: [🍓] In `CsvFormatParser` implement `heal
|
|
5518
|
+
* TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
|
|
5519
5519
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
5520
5520
|
*/
|
|
5521
5521
|
|
|
@@ -5524,7 +5524,7 @@ const CsvFormatDefinition = {
|
|
|
5524
5524
|
*
|
|
5525
5525
|
* @private still in development [🏢]
|
|
5526
5526
|
*/
|
|
5527
|
-
const
|
|
5527
|
+
const JsonFormatParser = {
|
|
5528
5528
|
formatName: 'JSON',
|
|
5529
5529
|
mimeType: 'application/json',
|
|
5530
5530
|
isValid(value, settings, schema) {
|
|
@@ -5536,28 +5536,28 @@ const JsonFormatDefinition = {
|
|
|
5536
5536
|
heal(value, settings, schema) {
|
|
5537
5537
|
throw new Error('Not implemented');
|
|
5538
5538
|
},
|
|
5539
|
-
|
|
5539
|
+
subvalueParsers: [],
|
|
5540
5540
|
};
|
|
5541
5541
|
/**
|
|
5542
5542
|
* TODO: [🧠] Maybe propper instance of object
|
|
5543
5543
|
* TODO: [0] Make string_serialized_json
|
|
5544
5544
|
* TODO: [1] Make type for JSON Settings and Schema
|
|
5545
5545
|
* TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
|
|
5546
|
-
* TODO: [🍓] In `
|
|
5547
|
-
* TODO: [🍓] In `
|
|
5548
|
-
* TODO: [🍓] In `
|
|
5549
|
-
* TODO: [🍓] In `
|
|
5546
|
+
* TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
|
|
5547
|
+
* TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
|
|
5548
|
+
* TODO: [🍓] In `JsonFormatParser` implement `heal
|
|
5549
|
+
* TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
|
|
5550
5550
|
* TODO: [🏢] Allow to expect something inside JSON objects and other formats
|
|
5551
5551
|
*/
|
|
5552
5552
|
|
|
5553
5553
|
/**
|
|
5554
5554
|
* Definition for any text - this will be always valid
|
|
5555
5555
|
*
|
|
5556
|
-
* Note: This is not useful for validation, but for splitting and mapping with `
|
|
5556
|
+
* Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
|
|
5557
5557
|
*
|
|
5558
5558
|
* @public exported from `@promptbook/core`
|
|
5559
5559
|
*/
|
|
5560
|
-
const
|
|
5560
|
+
const TextFormatParser = {
|
|
5561
5561
|
formatName: 'TEXT',
|
|
5562
5562
|
isValid(value) {
|
|
5563
5563
|
return typeof value === 'string';
|
|
@@ -5566,9 +5566,9 @@ const TextFormatDefinition = {
|
|
|
5566
5566
|
return typeof partialValue === 'string';
|
|
5567
5567
|
},
|
|
5568
5568
|
heal() {
|
|
5569
|
-
throw new UnexpectedError('It does not make sense to call `
|
|
5569
|
+
throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
|
|
5570
5570
|
},
|
|
5571
|
-
|
|
5571
|
+
subvalueParsers: [
|
|
5572
5572
|
{
|
|
5573
5573
|
subvalueName: 'LINE',
|
|
5574
5574
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -5588,10 +5588,10 @@ const TextFormatDefinition = {
|
|
|
5588
5588
|
/**
|
|
5589
5589
|
* TODO: [1] Make type for XML Text and Schema
|
|
5590
5590
|
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
5591
|
-
* TODO: [🍓] In `
|
|
5592
|
-
* TODO: [🍓] In `
|
|
5593
|
-
* TODO: [🍓] In `
|
|
5594
|
-
* TODO: [🍓] In `
|
|
5591
|
+
* TODO: [🍓] In `TextFormatParser` implement simple `isValid`
|
|
5592
|
+
* TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
|
|
5593
|
+
* TODO: [🍓] In `TextFormatParser` implement `heal
|
|
5594
|
+
* TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
|
|
5595
5595
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
5596
5596
|
*/
|
|
5597
5597
|
|
|
@@ -5624,7 +5624,7 @@ function isValidXmlString(value) {
|
|
|
5624
5624
|
*
|
|
5625
5625
|
* @private still in development [🏢]
|
|
5626
5626
|
*/
|
|
5627
|
-
const
|
|
5627
|
+
const XmlFormatParser = {
|
|
5628
5628
|
formatName: 'XML',
|
|
5629
5629
|
mimeType: 'application/xml',
|
|
5630
5630
|
isValid(value, settings, schema) {
|
|
@@ -5636,17 +5636,17 @@ const XmlFormatDefinition = {
|
|
|
5636
5636
|
heal(value, settings, schema) {
|
|
5637
5637
|
throw new Error('Not implemented');
|
|
5638
5638
|
},
|
|
5639
|
-
|
|
5639
|
+
subvalueParsers: [],
|
|
5640
5640
|
};
|
|
5641
5641
|
/**
|
|
5642
5642
|
* TODO: [🧠] Maybe propper instance of object
|
|
5643
5643
|
* TODO: [0] Make string_serialized_xml
|
|
5644
5644
|
* TODO: [1] Make type for XML Settings and Schema
|
|
5645
5645
|
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
5646
|
-
* TODO: [🍓] In `
|
|
5647
|
-
* TODO: [🍓] In `
|
|
5648
|
-
* TODO: [🍓] In `
|
|
5649
|
-
* TODO: [🍓] In `
|
|
5646
|
+
* TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
|
|
5647
|
+
* TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
|
|
5648
|
+
* TODO: [🍓] In `XmlFormatParser` implement `heal
|
|
5649
|
+
* TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
|
|
5650
5650
|
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
5651
5651
|
*/
|
|
5652
5652
|
|
|
@@ -5655,12 +5655,7 @@ const XmlFormatDefinition = {
|
|
|
5655
5655
|
*
|
|
5656
5656
|
* @private internal index of `...` <- TODO [🏢]
|
|
5657
5657
|
*/
|
|
5658
|
-
const FORMAT_DEFINITIONS = [
|
|
5659
|
-
JsonFormatDefinition,
|
|
5660
|
-
XmlFormatDefinition,
|
|
5661
|
-
TextFormatDefinition,
|
|
5662
|
-
CsvFormatDefinition,
|
|
5663
|
-
];
|
|
5658
|
+
const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
|
|
5664
5659
|
/**
|
|
5665
5660
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5666
5661
|
*/
|
|
@@ -5830,7 +5825,7 @@ function extractJsonBlock(markdown) {
|
|
|
5830
5825
|
}
|
|
5831
5826
|
/**
|
|
5832
5827
|
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
5833
|
-
* TODO: [🏢] Make this logic part of `
|
|
5828
|
+
* TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
|
|
5834
5829
|
*/
|
|
5835
5830
|
|
|
5836
5831
|
/**
|
|
@@ -6051,7 +6046,7 @@ const CountUtils = {
|
|
|
6051
6046
|
PAGES: countPages,
|
|
6052
6047
|
};
|
|
6053
6048
|
/**
|
|
6054
|
-
* TODO: [🧠][🤠] This should be probbably as part of `
|
|
6049
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatParser`
|
|
6055
6050
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6056
6051
|
*/
|
|
6057
6052
|
|
|
@@ -6079,7 +6074,7 @@ function checkExpectations(expectations, value) {
|
|
|
6079
6074
|
}
|
|
6080
6075
|
/**
|
|
6081
6076
|
* TODO: [💝] Unite object for expecting amount and format
|
|
6082
|
-
* TODO: [🧠][🤠] This should be part of `
|
|
6077
|
+
* TODO: [🧠][🤠] This should be part of `TextFormatParser`
|
|
6083
6078
|
* Note: [💝] and [🤠] are interconnected together
|
|
6084
6079
|
*/
|
|
6085
6080
|
|
|
@@ -6307,7 +6302,7 @@ async function executeAttempts(options) {
|
|
|
6307
6302
|
if (task.format) {
|
|
6308
6303
|
if (task.format === 'JSON') {
|
|
6309
6304
|
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
6310
|
-
// TODO: [🏢] Do more universally via `
|
|
6305
|
+
// TODO: [🏢] Do more universally via `FormatParser`
|
|
6311
6306
|
try {
|
|
6312
6307
|
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
6313
6308
|
}
|
|
@@ -6445,16 +6440,16 @@ async function executeFormatSubvalues(options) {
|
|
|
6445
6440
|
${block(pipelineIdentification)}
|
|
6446
6441
|
`));
|
|
6447
6442
|
}
|
|
6448
|
-
const
|
|
6449
|
-
if (
|
|
6443
|
+
const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
|
|
6444
|
+
if (subvalueParser === undefined) {
|
|
6450
6445
|
throw new UnexpectedError(
|
|
6451
6446
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
6452
6447
|
spaceTrim((block) => `
|
|
6453
6448
|
Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
|
|
6454
6449
|
|
|
6455
6450
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
6456
|
-
${block(formatDefinition.
|
|
6457
|
-
.map((
|
|
6451
|
+
${block(formatDefinition.subvalueParsers
|
|
6452
|
+
.map((subvalueParser) => subvalueParser.subvalueName)
|
|
6458
6453
|
.map((subvalueName) => `- ${subvalueName}`)
|
|
6459
6454
|
.join('\n'))}
|
|
6460
6455
|
|
|
@@ -6468,7 +6463,7 @@ async function executeFormatSubvalues(options) {
|
|
|
6468
6463
|
formatSettings = csvSettings;
|
|
6469
6464
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
6470
6465
|
}
|
|
6471
|
-
const resultString = await
|
|
6466
|
+
const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
|
|
6472
6467
|
let mappedParameters;
|
|
6473
6468
|
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
6474
6469
|
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
@@ -6530,6 +6525,27 @@ async function getExamplesForTask(task) {
|
|
|
6530
6525
|
return RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */;
|
|
6531
6526
|
}
|
|
6532
6527
|
|
|
6528
|
+
/**
|
|
6529
|
+
* Computes the cosine similarity between two embedding vectors
|
|
6530
|
+
*
|
|
6531
|
+
* Note: This is helping function for RAG (retrieval-augmented generation)
|
|
6532
|
+
*
|
|
6533
|
+
* @param embeddingVector1
|
|
6534
|
+
* @param embeddingVector2
|
|
6535
|
+
* @returns Cosine similarity between the two vectors
|
|
6536
|
+
*
|
|
6537
|
+
* @public exported from `@promptbook/core`
|
|
6538
|
+
*/
|
|
6539
|
+
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
6540
|
+
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
6541
|
+
throw new TypeError('Embedding vectors must have the same length');
|
|
6542
|
+
}
|
|
6543
|
+
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
6544
|
+
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
6545
|
+
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
6546
|
+
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
6547
|
+
}
|
|
6548
|
+
|
|
6533
6549
|
/**
|
|
6534
6550
|
* @@@
|
|
6535
6551
|
*
|
|
@@ -6556,7 +6572,7 @@ async function getKnowledgeForTask(options) {
|
|
|
6556
6572
|
},
|
|
6557
6573
|
content: task.content,
|
|
6558
6574
|
parameters: {
|
|
6559
|
-
/*
|
|
6575
|
+
/* !!!! */
|
|
6560
6576
|
},
|
|
6561
6577
|
};
|
|
6562
6578
|
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
@@ -6591,16 +6607,6 @@ async function getKnowledgeForTask(options) {
|
|
|
6591
6607
|
return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
|
|
6592
6608
|
// <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
|
|
6593
6609
|
}
|
|
6594
|
-
// TODO: !!!!!! Annotate + to new file
|
|
6595
|
-
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
6596
|
-
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
6597
|
-
throw new TypeError('Embedding vectors must have the same length');
|
|
6598
|
-
}
|
|
6599
|
-
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
6600
|
-
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
6601
|
-
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
6602
|
-
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
6603
|
-
}
|
|
6604
6610
|
/**
|
|
6605
6611
|
* TODO: !!!! Verify if this is working
|
|
6606
6612
|
* TODO: [♨] Implement Better - use keyword search
|
|
@@ -7103,6 +7109,22 @@ function createPipelineExecutor(options) {
|
|
|
7103
7109
|
cacheDirname,
|
|
7104
7110
|
intermediateFilesStrategy,
|
|
7105
7111
|
isAutoInstalled,
|
|
7112
|
+
}).catch((error) => {
|
|
7113
|
+
assertsError(error);
|
|
7114
|
+
return exportJson({
|
|
7115
|
+
name: 'pipelineExecutorResult',
|
|
7116
|
+
message: `Unuccessful PipelineExecutorResult, last catch`,
|
|
7117
|
+
order: [],
|
|
7118
|
+
value: {
|
|
7119
|
+
isSuccessful: false,
|
|
7120
|
+
errors: [serializeError(error)],
|
|
7121
|
+
warnings: [],
|
|
7122
|
+
usage: UNCERTAIN_USAGE,
|
|
7123
|
+
executionReport: null,
|
|
7124
|
+
outputParameters: {},
|
|
7125
|
+
preparedPipeline,
|
|
7126
|
+
},
|
|
7127
|
+
});
|
|
7106
7128
|
});
|
|
7107
7129
|
};
|
|
7108
7130
|
const pipelineExecutor = (inputParameters) => createTask({
|
|
@@ -8622,14 +8644,14 @@ const foreachCommandParser = {
|
|
|
8622
8644
|
`));
|
|
8623
8645
|
// <- TODO: [🏢] List all supported format names
|
|
8624
8646
|
}
|
|
8625
|
-
const
|
|
8626
|
-
if (
|
|
8647
|
+
const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(subformatName));
|
|
8648
|
+
if (subvalueParser === undefined) {
|
|
8627
8649
|
throw new ParseError(spaceTrim((block) => `
|
|
8628
8650
|
Unsupported subformat name "${subformatName}" for format "${formatName}"
|
|
8629
8651
|
|
|
8630
8652
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
8631
|
-
${block(formatDefinition.
|
|
8632
|
-
.map((
|
|
8653
|
+
${block(formatDefinition.subvalueParsers
|
|
8654
|
+
.map((subvalueParser) => subvalueParser.subvalueName)
|
|
8633
8655
|
.map((subvalueName) => `- ${subvalueName}`)
|
|
8634
8656
|
.join('\n'))}
|
|
8635
8657
|
`));
|
|
@@ -13255,10 +13277,10 @@ function $initializeRunCommand(program) {
|
|
|
13255
13277
|
console.info(colors.gray('--- Detailed Result ---'));
|
|
13256
13278
|
console.info({ isSuccessful, errors, warnings, outputParameters, executionReport });
|
|
13257
13279
|
}
|
|
13258
|
-
if (saveReport && saveReport.endsWith('.json')) {
|
|
13280
|
+
if (executionReport !== null && saveReport && saveReport.endsWith('.json')) {
|
|
13259
13281
|
await writeFile(saveReport, JSON.stringify(executionReport, null, 4) + '\n', 'utf-8');
|
|
13260
13282
|
}
|
|
13261
|
-
else if (saveReport && saveReport.endsWith('.md')) {
|
|
13283
|
+
else if (executionReport !== null && saveReport && saveReport.endsWith('.md')) {
|
|
13262
13284
|
const executionReportString = executionReportJsonToString(executionReport);
|
|
13263
13285
|
await writeFile(saveReport, executionReportString, 'utf-8');
|
|
13264
13286
|
}
|