@promptbook/openai 0.78.4 → 0.80.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 +4 -0
- package/esm/index.es.js +621 -520
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -2
- package/esm/typings/src/config.d.ts +0 -25
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +6 -1
- package/esm/typings/src/formfactors/index.d.ts +12 -2
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +6 -1
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
- package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
- package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
- package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
- package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
- package/package.json +2 -2
- package/umd/index.umd.js +621 -520
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
package/umd/index.umd.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.79.0';
|
|
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
|
|
@@ -198,7 +198,7 @@
|
|
|
198
198
|
}(Error));
|
|
199
199
|
|
|
200
200
|
/**
|
|
201
|
-
*
|
|
201
|
+
* Freezes the given object and all its nested objects recursively
|
|
202
202
|
*
|
|
203
203
|
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
204
204
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
@@ -208,6 +208,9 @@
|
|
|
208
208
|
*/
|
|
209
209
|
function $deepFreeze(objectValue) {
|
|
210
210
|
var e_1, _a;
|
|
211
|
+
if (Array.isArray(objectValue)) {
|
|
212
|
+
return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
|
|
213
|
+
}
|
|
211
214
|
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
212
215
|
try {
|
|
213
216
|
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
@@ -225,7 +228,8 @@
|
|
|
225
228
|
}
|
|
226
229
|
finally { if (e_1) throw e_1.error; }
|
|
227
230
|
}
|
|
228
|
-
|
|
231
|
+
Object.freeze(objectValue);
|
|
232
|
+
return objectValue;
|
|
229
233
|
}
|
|
230
234
|
/**
|
|
231
235
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -326,24 +330,6 @@
|
|
|
326
330
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
327
331
|
*/
|
|
328
332
|
var LOOP_LIMIT = 1000;
|
|
329
|
-
/**
|
|
330
|
-
* Nonce which is used for replacing things in strings
|
|
331
|
-
*
|
|
332
|
-
* @private within the repository
|
|
333
|
-
*/
|
|
334
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
335
|
-
/**
|
|
336
|
-
* @@@
|
|
337
|
-
*
|
|
338
|
-
* @private within the repository
|
|
339
|
-
*/
|
|
340
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
341
|
-
/**
|
|
342
|
-
* @@@
|
|
343
|
-
*
|
|
344
|
-
* @private within the repository
|
|
345
|
-
*/
|
|
346
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
347
333
|
// <- TODO: [🧜♂️]
|
|
348
334
|
/**
|
|
349
335
|
* @@@
|
|
@@ -357,26 +343,21 @@
|
|
|
357
343
|
skipEmptyLines: true,
|
|
358
344
|
});
|
|
359
345
|
/**
|
|
360
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
361
346
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
362
347
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
363
348
|
*/
|
|
364
349
|
|
|
365
350
|
/**
|
|
366
|
-
*
|
|
351
|
+
* Orders JSON object by keys
|
|
367
352
|
*
|
|
368
|
-
* @
|
|
353
|
+
* @returns The same type of object as the input re-ordered
|
|
354
|
+
* @public exported from `@promptbook/utils`
|
|
369
355
|
*/
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
function
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
376
|
-
return _this;
|
|
377
|
-
}
|
|
378
|
-
return LimitReachedError;
|
|
379
|
-
}(Error));
|
|
356
|
+
function orderJson(options) {
|
|
357
|
+
var value = options.value, order = options.order;
|
|
358
|
+
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
|
|
359
|
+
return orderedValue;
|
|
360
|
+
}
|
|
380
361
|
|
|
381
362
|
/**
|
|
382
363
|
* Make error report URL for the given error
|
|
@@ -412,85 +393,6 @@
|
|
|
412
393
|
return UnexpectedError;
|
|
413
394
|
}(Error));
|
|
414
395
|
|
|
415
|
-
/**
|
|
416
|
-
* Replaces parameters in template with values from parameters object
|
|
417
|
-
*
|
|
418
|
-
* @param template the template with parameters in {curly} braces
|
|
419
|
-
* @param parameters the object with parameters
|
|
420
|
-
* @returns the template with replaced parameters
|
|
421
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
422
|
-
* @public exported from `@promptbook/utils`
|
|
423
|
-
*/
|
|
424
|
-
function replaceParameters(template, parameters) {
|
|
425
|
-
var e_1, _a;
|
|
426
|
-
try {
|
|
427
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
428
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
429
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
430
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
431
|
-
}
|
|
432
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
433
|
-
// TODO: [🍵]
|
|
434
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
439
|
-
finally {
|
|
440
|
-
try {
|
|
441
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
442
|
-
}
|
|
443
|
-
finally { if (e_1) throw e_1.error; }
|
|
444
|
-
}
|
|
445
|
-
var replacedTemplates = template;
|
|
446
|
-
var match;
|
|
447
|
-
var loopLimit = LOOP_LIMIT;
|
|
448
|
-
var _loop_1 = function () {
|
|
449
|
-
if (loopLimit-- < 0) {
|
|
450
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
451
|
-
}
|
|
452
|
-
var precol = match.groups.precol;
|
|
453
|
-
var parameterName = match.groups.parameterName;
|
|
454
|
-
if (parameterName === '') {
|
|
455
|
-
return "continue";
|
|
456
|
-
}
|
|
457
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
458
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
459
|
-
}
|
|
460
|
-
if (parameters[parameterName] === undefined) {
|
|
461
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
462
|
-
}
|
|
463
|
-
var parameterValue = parameters[parameterName];
|
|
464
|
-
if (parameterValue === undefined) {
|
|
465
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
466
|
-
}
|
|
467
|
-
parameterValue = parameterValue.toString();
|
|
468
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
469
|
-
parameterValue = parameterValue
|
|
470
|
-
.split('\n')
|
|
471
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
472
|
-
.join('\n');
|
|
473
|
-
}
|
|
474
|
-
replacedTemplates =
|
|
475
|
-
replacedTemplates.substring(0, match.index + precol.length) +
|
|
476
|
-
parameterValue +
|
|
477
|
-
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
478
|
-
};
|
|
479
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
480
|
-
.exec(replacedTemplates))) {
|
|
481
|
-
_loop_1();
|
|
482
|
-
}
|
|
483
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
484
|
-
if (/{\w+$/.test(replacedTemplates)) {
|
|
485
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
486
|
-
}
|
|
487
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
488
|
-
if (/^\w+}/.test(replacedTemplates)) {
|
|
489
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
490
|
-
}
|
|
491
|
-
return replacedTemplates;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
396
|
/**
|
|
495
397
|
* Checks if the value is [🚉] serializable as JSON
|
|
496
398
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -511,8 +413,9 @@
|
|
|
511
413
|
* @throws UnexpectedError if the value is not serializable as JSON
|
|
512
414
|
* @public exported from `@promptbook/utils`
|
|
513
415
|
*/
|
|
514
|
-
function checkSerializableAsJson(
|
|
416
|
+
function checkSerializableAsJson(options) {
|
|
515
417
|
var e_1, _a;
|
|
418
|
+
var value = options.value, name = options.name, message = options.message;
|
|
516
419
|
if (value === undefined) {
|
|
517
420
|
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
518
421
|
}
|
|
@@ -536,12 +439,12 @@
|
|
|
536
439
|
}
|
|
537
440
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
538
441
|
for (var i = 0; i < value.length; i++) {
|
|
539
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
442
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
540
443
|
}
|
|
541
444
|
}
|
|
542
445
|
else if (typeof value === 'object') {
|
|
543
446
|
if (value instanceof Date) {
|
|
544
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n
|
|
447
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
545
448
|
}
|
|
546
449
|
else if (value instanceof Map) {
|
|
547
450
|
throw new UnexpectedError("".concat(name, " is Map"));
|
|
@@ -553,7 +456,7 @@
|
|
|
553
456
|
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
554
457
|
}
|
|
555
458
|
else if (value instanceof Error) {
|
|
556
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n
|
|
459
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
|
|
557
460
|
}
|
|
558
461
|
else {
|
|
559
462
|
try {
|
|
@@ -563,7 +466,7 @@
|
|
|
563
466
|
// Note: undefined in object is serializable - it is just omited
|
|
564
467
|
continue;
|
|
565
468
|
}
|
|
566
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
469
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
567
470
|
}
|
|
568
471
|
}
|
|
569
472
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -580,7 +483,7 @@
|
|
|
580
483
|
if (!(error instanceof Error)) {
|
|
581
484
|
throw error;
|
|
582
485
|
}
|
|
583
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
486
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
584
487
|
}
|
|
585
488
|
/*
|
|
586
489
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -605,35 +508,210 @@
|
|
|
605
508
|
}
|
|
606
509
|
}
|
|
607
510
|
else {
|
|
608
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
511
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
609
512
|
}
|
|
610
513
|
}
|
|
611
514
|
/**
|
|
612
|
-
* TODO:
|
|
515
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
613
516
|
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
614
517
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
615
518
|
*/
|
|
616
519
|
|
|
617
520
|
/**
|
|
618
|
-
* @@@
|
|
619
521
|
* @@@
|
|
620
522
|
*
|
|
621
|
-
*
|
|
523
|
+
* @public exported from `@promptbook/utils`
|
|
524
|
+
*/
|
|
525
|
+
function deepClone(objectValue) {
|
|
526
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
527
|
+
/*
|
|
528
|
+
!!!!!!!!
|
|
529
|
+
TODO: [🧠] Is there a better implementation?
|
|
530
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
531
|
+
> for (const propertyName of propertyNames) {
|
|
532
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
533
|
+
> if (value && typeof value === 'object') {
|
|
534
|
+
> deepClone(value);
|
|
535
|
+
> }
|
|
536
|
+
> }
|
|
537
|
+
> return Object.assign({}, objectValue);
|
|
538
|
+
*/
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
542
|
+
*/
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Utility to export a JSON object from a function
|
|
622
546
|
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
547
|
+
* 1) Checks if the value is serializable as JSON
|
|
548
|
+
* 2) Makes a deep clone of the object
|
|
549
|
+
* 2) Orders the object properties
|
|
550
|
+
* 2) Deeply freezes the cloned object
|
|
551
|
+
*
|
|
552
|
+
* Note: This function does not mutates the given object
|
|
553
|
+
*
|
|
554
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
555
|
+
* @public exported from `@promptbook/utils`
|
|
627
556
|
*/
|
|
628
|
-
function
|
|
629
|
-
|
|
630
|
-
|
|
557
|
+
function exportJson(options) {
|
|
558
|
+
var name = options.name, value = options.value, order = options.order, message = options.message;
|
|
559
|
+
checkSerializableAsJson({ name: name, value: value, message: message });
|
|
560
|
+
var orderedValue =
|
|
561
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
562
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
563
|
+
// @ts-ignore
|
|
564
|
+
order === undefined
|
|
565
|
+
? deepClone(value)
|
|
566
|
+
: orderJson({
|
|
567
|
+
value: value,
|
|
568
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
569
|
+
order: order,
|
|
570
|
+
});
|
|
571
|
+
$deepFreeze(orderedValue);
|
|
572
|
+
return orderedValue;
|
|
631
573
|
}
|
|
632
574
|
/**
|
|
633
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
634
575
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
635
576
|
*/
|
|
636
577
|
|
|
578
|
+
/**
|
|
579
|
+
* Nonce which is used for replacing things in strings
|
|
580
|
+
*
|
|
581
|
+
* @private within the repository
|
|
582
|
+
*/
|
|
583
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
584
|
+
/**
|
|
585
|
+
* @@@
|
|
586
|
+
*
|
|
587
|
+
* @private within the repository
|
|
588
|
+
*/
|
|
589
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
590
|
+
/**
|
|
591
|
+
* @@@
|
|
592
|
+
*
|
|
593
|
+
* @private within the repository
|
|
594
|
+
*/
|
|
595
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
596
|
+
/**
|
|
597
|
+
* The names of the parameters that are reserved for special purposes
|
|
598
|
+
*
|
|
599
|
+
* @public exported from `@promptbook/core`
|
|
600
|
+
*/
|
|
601
|
+
exportJson({
|
|
602
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
603
|
+
message: "The names of the parameters that are reserved for special purposes",
|
|
604
|
+
value: [
|
|
605
|
+
'content',
|
|
606
|
+
'context',
|
|
607
|
+
'knowledge',
|
|
608
|
+
'examples',
|
|
609
|
+
'modelName',
|
|
610
|
+
'currentDate',
|
|
611
|
+
// <- TODO: list here all command names
|
|
612
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
613
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
614
|
+
],
|
|
615
|
+
});
|
|
616
|
+
/**
|
|
617
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
618
|
+
*/
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* This error type indicates that some limit was reached
|
|
622
|
+
*
|
|
623
|
+
* @public exported from `@promptbook/core`
|
|
624
|
+
*/
|
|
625
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
626
|
+
__extends(LimitReachedError, _super);
|
|
627
|
+
function LimitReachedError(message) {
|
|
628
|
+
var _this = _super.call(this, message) || this;
|
|
629
|
+
_this.name = 'LimitReachedError';
|
|
630
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
631
|
+
return _this;
|
|
632
|
+
}
|
|
633
|
+
return LimitReachedError;
|
|
634
|
+
}(Error));
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Replaces parameters in template with values from parameters object
|
|
638
|
+
*
|
|
639
|
+
* @param template the template with parameters in {curly} braces
|
|
640
|
+
* @param parameters the object with parameters
|
|
641
|
+
* @returns the template with replaced parameters
|
|
642
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
643
|
+
* @public exported from `@promptbook/utils`
|
|
644
|
+
*/
|
|
645
|
+
function replaceParameters(template, parameters) {
|
|
646
|
+
var e_1, _a;
|
|
647
|
+
try {
|
|
648
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
649
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
650
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
651
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
652
|
+
}
|
|
653
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
654
|
+
// TODO: [🍵]
|
|
655
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
660
|
+
finally {
|
|
661
|
+
try {
|
|
662
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
663
|
+
}
|
|
664
|
+
finally { if (e_1) throw e_1.error; }
|
|
665
|
+
}
|
|
666
|
+
var replacedTemplates = template;
|
|
667
|
+
var match;
|
|
668
|
+
var loopLimit = LOOP_LIMIT;
|
|
669
|
+
var _loop_1 = function () {
|
|
670
|
+
if (loopLimit-- < 0) {
|
|
671
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
672
|
+
}
|
|
673
|
+
var precol = match.groups.precol;
|
|
674
|
+
var parameterName = match.groups.parameterName;
|
|
675
|
+
if (parameterName === '') {
|
|
676
|
+
return "continue";
|
|
677
|
+
}
|
|
678
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
679
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
680
|
+
}
|
|
681
|
+
if (parameters[parameterName] === undefined) {
|
|
682
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
683
|
+
}
|
|
684
|
+
var parameterValue = parameters[parameterName];
|
|
685
|
+
if (parameterValue === undefined) {
|
|
686
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
687
|
+
}
|
|
688
|
+
parameterValue = parameterValue.toString();
|
|
689
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
690
|
+
parameterValue = parameterValue
|
|
691
|
+
.split('\n')
|
|
692
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
693
|
+
.join('\n');
|
|
694
|
+
}
|
|
695
|
+
replacedTemplates =
|
|
696
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
697
|
+
parameterValue +
|
|
698
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
699
|
+
};
|
|
700
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
701
|
+
.exec(replacedTemplates))) {
|
|
702
|
+
_loop_1();
|
|
703
|
+
}
|
|
704
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
705
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
706
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
707
|
+
}
|
|
708
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
709
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
710
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
711
|
+
}
|
|
712
|
+
return replacedTemplates;
|
|
713
|
+
}
|
|
714
|
+
|
|
637
715
|
/**
|
|
638
716
|
* Counts number of characters in the text
|
|
639
717
|
*
|
|
@@ -1041,381 +1119,384 @@
|
|
|
1041
1119
|
* @see https://openai.com/api/pricing/
|
|
1042
1120
|
* @public exported from `@promptbook/openai`
|
|
1043
1121
|
*/
|
|
1044
|
-
var OPENAI_MODELS =
|
|
1045
|
-
|
|
1122
|
+
var OPENAI_MODELS = exportJson({
|
|
1123
|
+
name: 'OPENAI_MODELS',
|
|
1124
|
+
value: [
|
|
1125
|
+
/*/
|
|
1126
|
+
{
|
|
1127
|
+
modelTitle: 'dall-e-3',
|
|
1128
|
+
modelName: 'dall-e-3',
|
|
1129
|
+
},
|
|
1130
|
+
/**/
|
|
1131
|
+
/*/
|
|
1132
|
+
{
|
|
1133
|
+
modelTitle: 'whisper-1',
|
|
1134
|
+
modelName: 'whisper-1',
|
|
1135
|
+
},
|
|
1136
|
+
/**/
|
|
1137
|
+
/**/
|
|
1138
|
+
{
|
|
1139
|
+
modelVariant: 'COMPLETION',
|
|
1140
|
+
modelTitle: 'davinci-002',
|
|
1141
|
+
modelName: 'davinci-002',
|
|
1142
|
+
pricing: {
|
|
1143
|
+
prompt: computeUsage("$2.00 / 1M tokens"),
|
|
1144
|
+
output: computeUsage("$2.00 / 1M tokens"), // <- not sure
|
|
1145
|
+
},
|
|
1146
|
+
},
|
|
1147
|
+
/**/
|
|
1148
|
+
/*/
|
|
1046
1149
|
{
|
|
1047
|
-
modelTitle: 'dall-e-
|
|
1048
|
-
modelName: 'dall-e-
|
|
1150
|
+
modelTitle: 'dall-e-2',
|
|
1151
|
+
modelName: 'dall-e-2',
|
|
1049
1152
|
},
|
|
1050
1153
|
/**/
|
|
1051
|
-
|
|
1154
|
+
/**/
|
|
1155
|
+
{
|
|
1156
|
+
modelVariant: 'CHAT',
|
|
1157
|
+
modelTitle: 'gpt-3.5-turbo-16k',
|
|
1158
|
+
modelName: 'gpt-3.5-turbo-16k',
|
|
1159
|
+
pricing: {
|
|
1160
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
1161
|
+
output: computeUsage("$4.00 / 1M tokens"),
|
|
1162
|
+
},
|
|
1163
|
+
},
|
|
1164
|
+
/**/
|
|
1165
|
+
/*/
|
|
1052
1166
|
{
|
|
1053
|
-
modelTitle: '
|
|
1054
|
-
modelName: '
|
|
1167
|
+
modelTitle: 'tts-1-hd-1106',
|
|
1168
|
+
modelName: 'tts-1-hd-1106',
|
|
1055
1169
|
},
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
},
|
|
1073
|
-
/**/
|
|
1074
|
-
/**/
|
|
1075
|
-
{
|
|
1076
|
-
modelVariant: 'CHAT',
|
|
1077
|
-
modelTitle: 'gpt-3.5-turbo-16k',
|
|
1078
|
-
modelName: 'gpt-3.5-turbo-16k',
|
|
1079
|
-
pricing: {
|
|
1080
|
-
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
1081
|
-
output: computeUsage("$4.00 / 1M tokens"),
|
|
1082
|
-
},
|
|
1083
|
-
},
|
|
1084
|
-
/**/
|
|
1085
|
-
/*/
|
|
1086
|
-
{
|
|
1087
|
-
modelTitle: 'tts-1-hd-1106',
|
|
1088
|
-
modelName: 'tts-1-hd-1106',
|
|
1089
|
-
},
|
|
1090
|
-
/**/
|
|
1091
|
-
/*/
|
|
1092
|
-
{
|
|
1093
|
-
modelTitle: 'tts-1-hd',
|
|
1094
|
-
modelName: 'tts-1-hd',
|
|
1095
|
-
},
|
|
1096
|
-
/**/
|
|
1097
|
-
/**/
|
|
1098
|
-
{
|
|
1099
|
-
modelVariant: 'CHAT',
|
|
1100
|
-
modelTitle: 'gpt-4',
|
|
1101
|
-
modelName: 'gpt-4',
|
|
1102
|
-
pricing: {
|
|
1103
|
-
prompt: computeUsage("$30.00 / 1M tokens"),
|
|
1104
|
-
output: computeUsage("$60.00 / 1M tokens"),
|
|
1170
|
+
/**/
|
|
1171
|
+
/*/
|
|
1172
|
+
{
|
|
1173
|
+
modelTitle: 'tts-1-hd',
|
|
1174
|
+
modelName: 'tts-1-hd',
|
|
1175
|
+
},
|
|
1176
|
+
/**/
|
|
1177
|
+
/**/
|
|
1178
|
+
{
|
|
1179
|
+
modelVariant: 'CHAT',
|
|
1180
|
+
modelTitle: 'gpt-4',
|
|
1181
|
+
modelName: 'gpt-4',
|
|
1182
|
+
pricing: {
|
|
1183
|
+
prompt: computeUsage("$30.00 / 1M tokens"),
|
|
1184
|
+
output: computeUsage("$60.00 / 1M tokens"),
|
|
1185
|
+
},
|
|
1105
1186
|
},
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1187
|
+
/**/
|
|
1188
|
+
/**/
|
|
1189
|
+
{
|
|
1190
|
+
modelVariant: 'CHAT',
|
|
1191
|
+
modelTitle: 'gpt-4-32k',
|
|
1192
|
+
modelName: 'gpt-4-32k',
|
|
1193
|
+
pricing: {
|
|
1194
|
+
prompt: computeUsage("$60.00 / 1M tokens"),
|
|
1195
|
+
output: computeUsage("$120.00 / 1M tokens"),
|
|
1196
|
+
},
|
|
1116
1197
|
},
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1198
|
+
/**/
|
|
1199
|
+
/*/
|
|
1200
|
+
{
|
|
1201
|
+
modelVariant: 'CHAT',
|
|
1202
|
+
modelTitle: 'gpt-4-0613',
|
|
1203
|
+
modelName: 'gpt-4-0613',
|
|
1204
|
+
pricing: {
|
|
1205
|
+
prompt: computeUsage(` / 1M tokens`),
|
|
1206
|
+
output: computeUsage(` / 1M tokens`),
|
|
1207
|
+
},
|
|
1127
1208
|
},
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1209
|
+
/**/
|
|
1210
|
+
/**/
|
|
1211
|
+
{
|
|
1212
|
+
modelVariant: 'CHAT',
|
|
1213
|
+
modelTitle: 'gpt-4-turbo-2024-04-09',
|
|
1214
|
+
modelName: 'gpt-4-turbo-2024-04-09',
|
|
1215
|
+
pricing: {
|
|
1216
|
+
prompt: computeUsage("$10.00 / 1M tokens"),
|
|
1217
|
+
output: computeUsage("$30.00 / 1M tokens"),
|
|
1218
|
+
},
|
|
1138
1219
|
},
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1220
|
+
/**/
|
|
1221
|
+
/**/
|
|
1222
|
+
{
|
|
1223
|
+
modelVariant: 'CHAT',
|
|
1224
|
+
modelTitle: 'gpt-3.5-turbo-1106',
|
|
1225
|
+
modelName: 'gpt-3.5-turbo-1106',
|
|
1226
|
+
pricing: {
|
|
1227
|
+
prompt: computeUsage("$1.00 / 1M tokens"),
|
|
1228
|
+
output: computeUsage("$2.00 / 1M tokens"),
|
|
1229
|
+
},
|
|
1149
1230
|
},
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1231
|
+
/**/
|
|
1232
|
+
/**/
|
|
1233
|
+
{
|
|
1234
|
+
modelVariant: 'CHAT',
|
|
1235
|
+
modelTitle: 'gpt-4-turbo',
|
|
1236
|
+
modelName: 'gpt-4-turbo',
|
|
1237
|
+
pricing: {
|
|
1238
|
+
prompt: computeUsage("$10.00 / 1M tokens"),
|
|
1239
|
+
output: computeUsage("$30.00 / 1M tokens"),
|
|
1240
|
+
},
|
|
1160
1241
|
},
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1242
|
+
/**/
|
|
1243
|
+
/**/
|
|
1244
|
+
{
|
|
1245
|
+
modelVariant: 'COMPLETION',
|
|
1246
|
+
modelTitle: 'gpt-3.5-turbo-instruct-0914',
|
|
1247
|
+
modelName: 'gpt-3.5-turbo-instruct-0914',
|
|
1248
|
+
pricing: {
|
|
1249
|
+
prompt: computeUsage("$1.50 / 1M tokens"),
|
|
1250
|
+
output: computeUsage("$2.00 / 1M tokens"), // <- For gpt-3.5-turbo-instruct
|
|
1251
|
+
},
|
|
1171
1252
|
},
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1253
|
+
/**/
|
|
1254
|
+
/**/
|
|
1255
|
+
{
|
|
1256
|
+
modelVariant: 'COMPLETION',
|
|
1257
|
+
modelTitle: 'gpt-3.5-turbo-instruct',
|
|
1258
|
+
modelName: 'gpt-3.5-turbo-instruct',
|
|
1259
|
+
pricing: {
|
|
1260
|
+
prompt: computeUsage("$1.50 / 1M tokens"),
|
|
1261
|
+
output: computeUsage("$2.00 / 1M tokens"),
|
|
1262
|
+
},
|
|
1182
1263
|
},
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1264
|
+
/**/
|
|
1265
|
+
/*/
|
|
1266
|
+
{
|
|
1267
|
+
modelTitle: 'tts-1',
|
|
1268
|
+
modelName: 'tts-1',
|
|
1269
|
+
},
|
|
1270
|
+
/**/
|
|
1271
|
+
/**/
|
|
1272
|
+
{
|
|
1273
|
+
modelVariant: 'CHAT',
|
|
1274
|
+
modelTitle: 'gpt-3.5-turbo',
|
|
1275
|
+
modelName: 'gpt-3.5-turbo',
|
|
1276
|
+
pricing: {
|
|
1277
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
1278
|
+
output: computeUsage("$6.00 / 1M tokens"), // <- Not sure, refer to gpt-3.5-turbo in Fine-tuning models
|
|
1279
|
+
},
|
|
1199
1280
|
},
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1281
|
+
/**/
|
|
1282
|
+
/**/
|
|
1283
|
+
{
|
|
1284
|
+
modelVariant: 'CHAT',
|
|
1285
|
+
modelTitle: 'gpt-3.5-turbo-0301',
|
|
1286
|
+
modelName: 'gpt-3.5-turbo-0301',
|
|
1287
|
+
pricing: {
|
|
1288
|
+
prompt: computeUsage("$1.50 / 1M tokens"),
|
|
1289
|
+
output: computeUsage("$2.00 / 1M tokens"),
|
|
1290
|
+
},
|
|
1210
1291
|
},
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1292
|
+
/**/
|
|
1293
|
+
/**/
|
|
1294
|
+
{
|
|
1295
|
+
modelVariant: 'COMPLETION',
|
|
1296
|
+
modelTitle: 'babbage-002',
|
|
1297
|
+
modelName: 'babbage-002',
|
|
1298
|
+
pricing: {
|
|
1299
|
+
prompt: computeUsage("$0.40 / 1M tokens"),
|
|
1300
|
+
output: computeUsage("$0.40 / 1M tokens"), // <- Not sure
|
|
1301
|
+
},
|
|
1221
1302
|
},
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1303
|
+
/**/
|
|
1304
|
+
/**/
|
|
1305
|
+
{
|
|
1306
|
+
modelVariant: 'CHAT',
|
|
1307
|
+
modelTitle: 'gpt-4-1106-preview',
|
|
1308
|
+
modelName: 'gpt-4-1106-preview',
|
|
1309
|
+
pricing: {
|
|
1310
|
+
prompt: computeUsage("$10.00 / 1M tokens"),
|
|
1311
|
+
output: computeUsage("$30.00 / 1M tokens"),
|
|
1312
|
+
},
|
|
1232
1313
|
},
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1314
|
+
/**/
|
|
1315
|
+
/**/
|
|
1316
|
+
{
|
|
1317
|
+
modelVariant: 'CHAT',
|
|
1318
|
+
modelTitle: 'gpt-4-0125-preview',
|
|
1319
|
+
modelName: 'gpt-4-0125-preview',
|
|
1320
|
+
pricing: {
|
|
1321
|
+
prompt: computeUsage("$10.00 / 1M tokens"),
|
|
1322
|
+
output: computeUsage("$30.00 / 1M tokens"),
|
|
1323
|
+
},
|
|
1243
1324
|
},
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1325
|
+
/**/
|
|
1326
|
+
/*/
|
|
1327
|
+
{
|
|
1328
|
+
modelTitle: 'tts-1-1106',
|
|
1329
|
+
modelName: 'tts-1-1106',
|
|
1330
|
+
},
|
|
1331
|
+
/**/
|
|
1332
|
+
/**/
|
|
1333
|
+
{
|
|
1334
|
+
modelVariant: 'CHAT',
|
|
1335
|
+
modelTitle: 'gpt-3.5-turbo-0125',
|
|
1336
|
+
modelName: 'gpt-3.5-turbo-0125',
|
|
1337
|
+
pricing: {
|
|
1338
|
+
prompt: computeUsage("$0.50 / 1M tokens"),
|
|
1339
|
+
output: computeUsage("$1.50 / 1M tokens"),
|
|
1340
|
+
},
|
|
1260
1341
|
},
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1342
|
+
/**/
|
|
1343
|
+
/**/
|
|
1344
|
+
{
|
|
1345
|
+
modelVariant: 'CHAT',
|
|
1346
|
+
modelTitle: 'gpt-4-turbo-preview',
|
|
1347
|
+
modelName: 'gpt-4-turbo-preview',
|
|
1348
|
+
pricing: {
|
|
1349
|
+
prompt: computeUsage("$10.00 / 1M tokens"),
|
|
1350
|
+
output: computeUsage("$30.00 / 1M tokens"), // <- Not sure, just for gpt-4-turbo
|
|
1351
|
+
},
|
|
1271
1352
|
},
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1353
|
+
/**/
|
|
1354
|
+
/**/
|
|
1355
|
+
{
|
|
1356
|
+
modelVariant: 'EMBEDDING',
|
|
1357
|
+
modelTitle: 'text-embedding-3-large',
|
|
1358
|
+
modelName: 'text-embedding-3-large',
|
|
1359
|
+
pricing: {
|
|
1360
|
+
prompt: computeUsage("$0.13 / 1M tokens"),
|
|
1361
|
+
// TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
|
|
1362
|
+
output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
|
|
1363
|
+
},
|
|
1283
1364
|
},
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1365
|
+
/**/
|
|
1366
|
+
/**/
|
|
1367
|
+
{
|
|
1368
|
+
modelVariant: 'EMBEDDING',
|
|
1369
|
+
modelTitle: 'text-embedding-3-small',
|
|
1370
|
+
modelName: 'text-embedding-3-small',
|
|
1371
|
+
pricing: {
|
|
1372
|
+
prompt: computeUsage("$0.02 / 1M tokens"),
|
|
1373
|
+
// TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
|
|
1374
|
+
output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
|
|
1375
|
+
},
|
|
1295
1376
|
},
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1377
|
+
/**/
|
|
1378
|
+
/**/
|
|
1379
|
+
{
|
|
1380
|
+
modelVariant: 'CHAT',
|
|
1381
|
+
modelTitle: 'gpt-3.5-turbo-0613',
|
|
1382
|
+
modelName: 'gpt-3.5-turbo-0613',
|
|
1383
|
+
pricing: {
|
|
1384
|
+
prompt: computeUsage("$1.50 / 1M tokens"),
|
|
1385
|
+
output: computeUsage("$2.00 / 1M tokens"),
|
|
1386
|
+
},
|
|
1306
1387
|
},
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1388
|
+
/**/
|
|
1389
|
+
/**/
|
|
1390
|
+
{
|
|
1391
|
+
modelVariant: 'EMBEDDING',
|
|
1392
|
+
modelTitle: 'text-embedding-ada-002',
|
|
1393
|
+
modelName: 'text-embedding-ada-002',
|
|
1394
|
+
pricing: {
|
|
1395
|
+
prompt: computeUsage("$0.1 / 1M tokens"),
|
|
1396
|
+
// TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
|
|
1397
|
+
output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
|
|
1398
|
+
},
|
|
1318
1399
|
},
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
modelName: 'gpt-4-1106-vision-preview',
|
|
1326
|
-
},
|
|
1327
|
-
/**/
|
|
1328
|
-
/*/
|
|
1329
|
-
{
|
|
1330
|
-
modelVariant: 'CHAT',
|
|
1331
|
-
modelTitle: 'gpt-4-vision-preview',
|
|
1332
|
-
modelName: 'gpt-4-vision-preview',
|
|
1333
|
-
pricing: {
|
|
1334
|
-
prompt: computeUsage(`$10.00 / 1M tokens`),
|
|
1335
|
-
output: computeUsage(`$30.00 / 1M tokens`),
|
|
1400
|
+
/**/
|
|
1401
|
+
/*/
|
|
1402
|
+
{
|
|
1403
|
+
modelVariant: 'CHAT',
|
|
1404
|
+
modelTitle: 'gpt-4-1106-vision-preview',
|
|
1405
|
+
modelName: 'gpt-4-1106-vision-preview',
|
|
1336
1406
|
},
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1407
|
+
/**/
|
|
1408
|
+
/*/
|
|
1409
|
+
{
|
|
1410
|
+
modelVariant: 'CHAT',
|
|
1411
|
+
modelTitle: 'gpt-4-vision-preview',
|
|
1412
|
+
modelName: 'gpt-4-vision-preview',
|
|
1413
|
+
pricing: {
|
|
1414
|
+
prompt: computeUsage(`$10.00 / 1M tokens`),
|
|
1415
|
+
output: computeUsage(`$30.00 / 1M tokens`),
|
|
1416
|
+
},
|
|
1417
|
+
},
|
|
1418
|
+
/**/
|
|
1419
|
+
/**/
|
|
1420
|
+
{
|
|
1421
|
+
modelVariant: 'CHAT',
|
|
1422
|
+
modelTitle: 'gpt-4o-2024-05-13',
|
|
1423
|
+
modelName: 'gpt-4o-2024-05-13',
|
|
1424
|
+
pricing: {
|
|
1425
|
+
prompt: computeUsage("$5.00 / 1M tokens"),
|
|
1426
|
+
output: computeUsage("$15.00 / 1M tokens"),
|
|
1427
|
+
},
|
|
1428
|
+
//TODO: [main] !!! Add gpt-4o-mini-2024-07-18 and all others to be up to date
|
|
1347
1429
|
},
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
output: computeUsage("$15.00 / 1M tokens"),
|
|
1430
|
+
/**/
|
|
1431
|
+
/**/
|
|
1432
|
+
{
|
|
1433
|
+
modelVariant: 'CHAT',
|
|
1434
|
+
modelTitle: 'gpt-4o',
|
|
1435
|
+
modelName: 'gpt-4o',
|
|
1436
|
+
pricing: {
|
|
1437
|
+
prompt: computeUsage("$5.00 / 1M tokens"),
|
|
1438
|
+
output: computeUsage("$15.00 / 1M tokens"),
|
|
1439
|
+
},
|
|
1359
1440
|
},
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1441
|
+
/**/
|
|
1442
|
+
/**/
|
|
1443
|
+
{
|
|
1444
|
+
modelVariant: 'CHAT',
|
|
1445
|
+
modelTitle: 'o1-preview',
|
|
1446
|
+
modelName: 'o1-preview',
|
|
1447
|
+
pricing: {
|
|
1448
|
+
prompt: computeUsage("$15.00 / 1M tokens"),
|
|
1449
|
+
output: computeUsage("$60.00 / 1M tokens"),
|
|
1450
|
+
},
|
|
1370
1451
|
},
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1452
|
+
/**/
|
|
1453
|
+
/**/
|
|
1454
|
+
{
|
|
1455
|
+
modelVariant: 'CHAT',
|
|
1456
|
+
modelTitle: 'o1-preview-2024-09-12',
|
|
1457
|
+
modelName: 'o1-preview-2024-09-12',
|
|
1458
|
+
// <- TODO: [💩] Some better system to organize theese date suffixes and versions
|
|
1459
|
+
pricing: {
|
|
1460
|
+
prompt: computeUsage("$15.00 / 1M tokens"),
|
|
1461
|
+
output: computeUsage("$60.00 / 1M tokens"),
|
|
1462
|
+
},
|
|
1382
1463
|
},
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1464
|
+
/**/
|
|
1465
|
+
/**/
|
|
1466
|
+
{
|
|
1467
|
+
modelVariant: 'CHAT',
|
|
1468
|
+
modelTitle: 'o1-mini',
|
|
1469
|
+
modelName: 'o1-mini',
|
|
1470
|
+
pricing: {
|
|
1471
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
1472
|
+
output: computeUsage("$12.00 / 1M tokens"),
|
|
1473
|
+
},
|
|
1393
1474
|
},
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1475
|
+
/**/
|
|
1476
|
+
/**/
|
|
1477
|
+
{
|
|
1478
|
+
modelVariant: 'CHAT',
|
|
1479
|
+
modelTitle: 'o1-mini-2024-09-12',
|
|
1480
|
+
modelName: 'o1-mini-2024-09-12',
|
|
1481
|
+
pricing: {
|
|
1482
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
1483
|
+
output: computeUsage("$12.00 / 1M tokens"),
|
|
1484
|
+
},
|
|
1404
1485
|
},
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1486
|
+
/**/
|
|
1487
|
+
/**/
|
|
1488
|
+
{
|
|
1489
|
+
modelVariant: 'CHAT',
|
|
1490
|
+
modelTitle: 'gpt-3.5-turbo-16k-0613',
|
|
1491
|
+
modelName: 'gpt-3.5-turbo-16k-0613',
|
|
1492
|
+
pricing: {
|
|
1493
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
1494
|
+
output: computeUsage("$4.00 / 1M tokens"),
|
|
1495
|
+
},
|
|
1415
1496
|
},
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1497
|
+
/**/
|
|
1498
|
+
],
|
|
1499
|
+
});
|
|
1419
1500
|
/**
|
|
1420
1501
|
* Note: [🤖] Add models of new variant
|
|
1421
1502
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
@@ -1631,18 +1712,23 @@
|
|
|
1631
1712
|
if (resultContent === null) {
|
|
1632
1713
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
1633
1714
|
}
|
|
1634
|
-
return [2 /*return*/,
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1715
|
+
return [2 /*return*/, exportJson({
|
|
1716
|
+
name: 'promptResult',
|
|
1717
|
+
message: "Result of `OpenAiExecutionTools.callChatModel`",
|
|
1718
|
+
order: [],
|
|
1719
|
+
value: {
|
|
1720
|
+
content: resultContent,
|
|
1721
|
+
modelName: rawResponse.model || modelName,
|
|
1722
|
+
timing: {
|
|
1723
|
+
start: start,
|
|
1724
|
+
complete: complete,
|
|
1725
|
+
},
|
|
1726
|
+
usage: usage,
|
|
1727
|
+
rawPromptContent: rawPromptContent,
|
|
1728
|
+
rawRequest: rawRequest,
|
|
1729
|
+
rawResponse: rawResponse,
|
|
1730
|
+
// <- [🗯]
|
|
1640
1731
|
},
|
|
1641
|
-
usage: usage,
|
|
1642
|
-
rawPromptContent: rawPromptContent,
|
|
1643
|
-
rawRequest: rawRequest,
|
|
1644
|
-
rawResponse: rawResponse,
|
|
1645
|
-
// <- [🗯]
|
|
1646
1732
|
})];
|
|
1647
1733
|
}
|
|
1648
1734
|
});
|
|
@@ -1707,18 +1793,23 @@
|
|
|
1707
1793
|
// eslint-disable-next-line prefer-const
|
|
1708
1794
|
complete = $getCurrentDate();
|
|
1709
1795
|
usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
1710
|
-
return [2 /*return*/,
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1796
|
+
return [2 /*return*/, exportJson({
|
|
1797
|
+
name: 'promptResult',
|
|
1798
|
+
message: "Result of `OpenAiExecutionTools.callCompletionModel`",
|
|
1799
|
+
order: [],
|
|
1800
|
+
value: {
|
|
1801
|
+
content: resultContent,
|
|
1802
|
+
modelName: rawResponse.model || modelName,
|
|
1803
|
+
timing: {
|
|
1804
|
+
start: start,
|
|
1805
|
+
complete: complete,
|
|
1806
|
+
},
|
|
1807
|
+
usage: usage,
|
|
1808
|
+
rawPromptContent: rawPromptContent,
|
|
1809
|
+
rawRequest: rawRequest,
|
|
1810
|
+
rawResponse: rawResponse,
|
|
1811
|
+
// <- [🗯]
|
|
1716
1812
|
},
|
|
1717
|
-
usage: usage,
|
|
1718
|
-
rawPromptContent: rawPromptContent,
|
|
1719
|
-
rawRequest: rawRequest,
|
|
1720
|
-
rawResponse: rawResponse,
|
|
1721
|
-
// <- [🗯]
|
|
1722
1813
|
})];
|
|
1723
1814
|
}
|
|
1724
1815
|
});
|
|
@@ -1775,18 +1866,23 @@
|
|
|
1775
1866
|
usage = computeOpenAiUsage(content || '', '',
|
|
1776
1867
|
// <- Note: Embedding does not have result content
|
|
1777
1868
|
rawResponse);
|
|
1778
|
-
return [2 /*return*/,
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1869
|
+
return [2 /*return*/, exportJson({
|
|
1870
|
+
name: 'promptResult',
|
|
1871
|
+
message: "Result of `OpenAiExecutionTools.callEmbeddingModel`",
|
|
1872
|
+
order: [],
|
|
1873
|
+
value: {
|
|
1874
|
+
content: resultContent,
|
|
1875
|
+
modelName: rawResponse.model || modelName,
|
|
1876
|
+
timing: {
|
|
1877
|
+
start: start,
|
|
1878
|
+
complete: complete,
|
|
1879
|
+
},
|
|
1880
|
+
usage: usage,
|
|
1881
|
+
rawPromptContent: rawPromptContent,
|
|
1882
|
+
rawRequest: rawRequest,
|
|
1883
|
+
rawResponse: rawResponse,
|
|
1884
|
+
// <- [🗯]
|
|
1784
1885
|
},
|
|
1785
|
-
usage: usage,
|
|
1786
|
-
rawPromptContent: rawPromptContent,
|
|
1787
|
-
rawRequest: rawRequest,
|
|
1788
|
-
rawResponse: rawResponse,
|
|
1789
|
-
// <- [🗯]
|
|
1790
1886
|
})];
|
|
1791
1887
|
}
|
|
1792
1888
|
});
|
|
@@ -1982,20 +2078,25 @@
|
|
|
1982
2078
|
if (resultContent === null) {
|
|
1983
2079
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
1984
2080
|
}
|
|
1985
|
-
return [2 /*return*/,
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2081
|
+
return [2 /*return*/, exportJson({
|
|
2082
|
+
name: 'promptResult',
|
|
2083
|
+
message: "Result of `OpenAiAssistantExecutionTools.callChatModel`",
|
|
2084
|
+
order: [],
|
|
2085
|
+
value: {
|
|
2086
|
+
content: resultContent,
|
|
2087
|
+
modelName: 'assistant',
|
|
2088
|
+
// <- TODO: [🥘] Detect used model in assistant
|
|
2089
|
+
// ?> model: rawResponse.model || modelName,
|
|
2090
|
+
timing: {
|
|
2091
|
+
start: start,
|
|
2092
|
+
complete: complete,
|
|
2093
|
+
},
|
|
2094
|
+
usage: usage,
|
|
2095
|
+
rawPromptContent: rawPromptContent,
|
|
2096
|
+
rawRequest: rawRequest,
|
|
2097
|
+
rawResponse: rawResponse,
|
|
2098
|
+
// <- [🗯]
|
|
1993
2099
|
},
|
|
1994
|
-
usage: usage,
|
|
1995
|
-
rawPromptContent: rawPromptContent,
|
|
1996
|
-
rawRequest: rawRequest,
|
|
1997
|
-
rawResponse: rawResponse,
|
|
1998
|
-
// <- [🗯]
|
|
1999
2100
|
})];
|
|
2000
2101
|
}
|
|
2001
2102
|
});
|