@promptbook/openai 0.79.0 → 0.80.0-1
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 +618 -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 +8 -6
- package/esm/typings/src/_packages/types.index.d.ts +6 -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/getParserForCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
- package/esm/typings/src/config.d.ts +0 -25
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/{pipelineStringToJson.d.ts → compilePipeline.d.ts} +3 -3
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/{pipelineStringToJsonSync.d.ts → precompilePipeline.d.ts} +4 -3
- 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/prepare/unpreparePipeline.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 +618 -520
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
- /package/esm/typings/src/conversion/{pipelineStringToJson.test.d.ts → compilePipeline.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/{pipelineStringToJsonSync.test.d.ts → precompilePipeline.test.d.ts} +0 -0
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.80.0-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
|
|
@@ -228,7 +228,8 @@
|
|
|
228
228
|
}
|
|
229
229
|
finally { if (e_1) throw e_1.error; }
|
|
230
230
|
}
|
|
231
|
-
|
|
231
|
+
Object.freeze(objectValue);
|
|
232
|
+
return objectValue;
|
|
232
233
|
}
|
|
233
234
|
/**
|
|
234
235
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -329,24 +330,6 @@
|
|
|
329
330
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
330
331
|
*/
|
|
331
332
|
var LOOP_LIMIT = 1000;
|
|
332
|
-
/**
|
|
333
|
-
* Nonce which is used for replacing things in strings
|
|
334
|
-
*
|
|
335
|
-
* @private within the repository
|
|
336
|
-
*/
|
|
337
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
338
|
-
/**
|
|
339
|
-
* @@@
|
|
340
|
-
*
|
|
341
|
-
* @private within the repository
|
|
342
|
-
*/
|
|
343
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
344
|
-
/**
|
|
345
|
-
* @@@
|
|
346
|
-
*
|
|
347
|
-
* @private within the repository
|
|
348
|
-
*/
|
|
349
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
350
333
|
// <- TODO: [🧜♂️]
|
|
351
334
|
/**
|
|
352
335
|
* @@@
|
|
@@ -360,26 +343,21 @@
|
|
|
360
343
|
skipEmptyLines: true,
|
|
361
344
|
});
|
|
362
345
|
/**
|
|
363
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
364
346
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
365
347
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
366
348
|
*/
|
|
367
349
|
|
|
368
350
|
/**
|
|
369
|
-
*
|
|
351
|
+
* Orders JSON object by keys
|
|
370
352
|
*
|
|
371
|
-
* @
|
|
353
|
+
* @returns The same type of object as the input re-ordered
|
|
354
|
+
* @public exported from `@promptbook/utils`
|
|
372
355
|
*/
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
function
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
379
|
-
return _this;
|
|
380
|
-
}
|
|
381
|
-
return LimitReachedError;
|
|
382
|
-
}(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
|
+
}
|
|
383
361
|
|
|
384
362
|
/**
|
|
385
363
|
* Make error report URL for the given error
|
|
@@ -415,85 +393,6 @@
|
|
|
415
393
|
return UnexpectedError;
|
|
416
394
|
}(Error));
|
|
417
395
|
|
|
418
|
-
/**
|
|
419
|
-
* Replaces parameters in template with values from parameters object
|
|
420
|
-
*
|
|
421
|
-
* @param template the template with parameters in {curly} braces
|
|
422
|
-
* @param parameters the object with parameters
|
|
423
|
-
* @returns the template with replaced parameters
|
|
424
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
425
|
-
* @public exported from `@promptbook/utils`
|
|
426
|
-
*/
|
|
427
|
-
function replaceParameters(template, parameters) {
|
|
428
|
-
var e_1, _a;
|
|
429
|
-
try {
|
|
430
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
431
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
432
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
433
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
434
|
-
}
|
|
435
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
436
|
-
// TODO: [🍵]
|
|
437
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
442
|
-
finally {
|
|
443
|
-
try {
|
|
444
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
445
|
-
}
|
|
446
|
-
finally { if (e_1) throw e_1.error; }
|
|
447
|
-
}
|
|
448
|
-
var replacedTemplates = template;
|
|
449
|
-
var match;
|
|
450
|
-
var loopLimit = LOOP_LIMIT;
|
|
451
|
-
var _loop_1 = function () {
|
|
452
|
-
if (loopLimit-- < 0) {
|
|
453
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
454
|
-
}
|
|
455
|
-
var precol = match.groups.precol;
|
|
456
|
-
var parameterName = match.groups.parameterName;
|
|
457
|
-
if (parameterName === '') {
|
|
458
|
-
return "continue";
|
|
459
|
-
}
|
|
460
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
461
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
462
|
-
}
|
|
463
|
-
if (parameters[parameterName] === undefined) {
|
|
464
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
465
|
-
}
|
|
466
|
-
var parameterValue = parameters[parameterName];
|
|
467
|
-
if (parameterValue === undefined) {
|
|
468
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
469
|
-
}
|
|
470
|
-
parameterValue = parameterValue.toString();
|
|
471
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
472
|
-
parameterValue = parameterValue
|
|
473
|
-
.split('\n')
|
|
474
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
475
|
-
.join('\n');
|
|
476
|
-
}
|
|
477
|
-
replacedTemplates =
|
|
478
|
-
replacedTemplates.substring(0, match.index + precol.length) +
|
|
479
|
-
parameterValue +
|
|
480
|
-
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
481
|
-
};
|
|
482
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
483
|
-
.exec(replacedTemplates))) {
|
|
484
|
-
_loop_1();
|
|
485
|
-
}
|
|
486
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
487
|
-
if (/{\w+$/.test(replacedTemplates)) {
|
|
488
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
489
|
-
}
|
|
490
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
491
|
-
if (/^\w+}/.test(replacedTemplates)) {
|
|
492
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
493
|
-
}
|
|
494
|
-
return replacedTemplates;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
396
|
/**
|
|
498
397
|
* Checks if the value is [🚉] serializable as JSON
|
|
499
398
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -514,8 +413,9 @@
|
|
|
514
413
|
* @throws UnexpectedError if the value is not serializable as JSON
|
|
515
414
|
* @public exported from `@promptbook/utils`
|
|
516
415
|
*/
|
|
517
|
-
function checkSerializableAsJson(
|
|
416
|
+
function checkSerializableAsJson(options) {
|
|
518
417
|
var e_1, _a;
|
|
418
|
+
var value = options.value, name = options.name, message = options.message;
|
|
519
419
|
if (value === undefined) {
|
|
520
420
|
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
521
421
|
}
|
|
@@ -539,12 +439,12 @@
|
|
|
539
439
|
}
|
|
540
440
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
541
441
|
for (var i = 0; i < value.length; i++) {
|
|
542
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
442
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
543
443
|
}
|
|
544
444
|
}
|
|
545
445
|
else if (typeof value === 'object') {
|
|
546
446
|
if (value instanceof Date) {
|
|
547
|
-
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 "); }));
|
|
548
448
|
}
|
|
549
449
|
else if (value instanceof Map) {
|
|
550
450
|
throw new UnexpectedError("".concat(name, " is Map"));
|
|
@@ -556,7 +456,7 @@
|
|
|
556
456
|
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
557
457
|
}
|
|
558
458
|
else if (value instanceof Error) {
|
|
559
|
-
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 "); }));
|
|
560
460
|
}
|
|
561
461
|
else {
|
|
562
462
|
try {
|
|
@@ -566,7 +466,7 @@
|
|
|
566
466
|
// Note: undefined in object is serializable - it is just omited
|
|
567
467
|
continue;
|
|
568
468
|
}
|
|
569
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
469
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
570
470
|
}
|
|
571
471
|
}
|
|
572
472
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -583,7 +483,7 @@
|
|
|
583
483
|
if (!(error instanceof Error)) {
|
|
584
484
|
throw error;
|
|
585
485
|
}
|
|
586
|
-
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 "); }));
|
|
587
487
|
}
|
|
588
488
|
/*
|
|
589
489
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -608,35 +508,210 @@
|
|
|
608
508
|
}
|
|
609
509
|
}
|
|
610
510
|
else {
|
|
611
|
-
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 "); }));
|
|
612
512
|
}
|
|
613
513
|
}
|
|
614
514
|
/**
|
|
615
|
-
* TODO:
|
|
515
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
616
516
|
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
617
517
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
618
518
|
*/
|
|
619
519
|
|
|
620
520
|
/**
|
|
621
|
-
* @@@
|
|
622
521
|
* @@@
|
|
623
522
|
*
|
|
624
|
-
*
|
|
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
|
|
625
546
|
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
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`
|
|
630
556
|
*/
|
|
631
|
-
function
|
|
632
|
-
|
|
633
|
-
|
|
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;
|
|
634
573
|
}
|
|
635
574
|
/**
|
|
636
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
637
575
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
638
576
|
*/
|
|
639
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
|
+
|
|
640
715
|
/**
|
|
641
716
|
* Counts number of characters in the text
|
|
642
717
|
*
|
|
@@ -1044,381 +1119,384 @@
|
|
|
1044
1119
|
* @see https://openai.com/api/pricing/
|
|
1045
1120
|
* @public exported from `@promptbook/openai`
|
|
1046
1121
|
*/
|
|
1047
|
-
var OPENAI_MODELS =
|
|
1048
|
-
|
|
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
|
+
/*/
|
|
1049
1149
|
{
|
|
1050
|
-
modelTitle: 'dall-e-
|
|
1051
|
-
modelName: 'dall-e-
|
|
1150
|
+
modelTitle: 'dall-e-2',
|
|
1151
|
+
modelName: 'dall-e-2',
|
|
1052
1152
|
},
|
|
1053
1153
|
/**/
|
|
1054
|
-
|
|
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
|
+
/*/
|
|
1055
1166
|
{
|
|
1056
|
-
modelTitle: '
|
|
1057
|
-
modelName: '
|
|
1167
|
+
modelTitle: 'tts-1-hd-1106',
|
|
1168
|
+
modelName: 'tts-1-hd-1106',
|
|
1058
1169
|
},
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
},
|
|
1076
|
-
/**/
|
|
1077
|
-
/**/
|
|
1078
|
-
{
|
|
1079
|
-
modelVariant: 'CHAT',
|
|
1080
|
-
modelTitle: 'gpt-3.5-turbo-16k',
|
|
1081
|
-
modelName: 'gpt-3.5-turbo-16k',
|
|
1082
|
-
pricing: {
|
|
1083
|
-
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
1084
|
-
output: computeUsage("$4.00 / 1M tokens"),
|
|
1085
|
-
},
|
|
1086
|
-
},
|
|
1087
|
-
/**/
|
|
1088
|
-
/*/
|
|
1089
|
-
{
|
|
1090
|
-
modelTitle: 'tts-1-hd-1106',
|
|
1091
|
-
modelName: 'tts-1-hd-1106',
|
|
1092
|
-
},
|
|
1093
|
-
/**/
|
|
1094
|
-
/*/
|
|
1095
|
-
{
|
|
1096
|
-
modelTitle: 'tts-1-hd',
|
|
1097
|
-
modelName: 'tts-1-hd',
|
|
1098
|
-
},
|
|
1099
|
-
/**/
|
|
1100
|
-
/**/
|
|
1101
|
-
{
|
|
1102
|
-
modelVariant: 'CHAT',
|
|
1103
|
-
modelTitle: 'gpt-4',
|
|
1104
|
-
modelName: 'gpt-4',
|
|
1105
|
-
pricing: {
|
|
1106
|
-
prompt: computeUsage("$30.00 / 1M tokens"),
|
|
1107
|
-
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
|
+
},
|
|
1108
1186
|
},
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
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
|
+
},
|
|
1119
1197
|
},
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
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
|
+
},
|
|
1130
1208
|
},
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
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
|
+
},
|
|
1141
1219
|
},
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
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
|
+
},
|
|
1152
1230
|
},
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
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
|
+
},
|
|
1163
1241
|
},
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
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
|
+
},
|
|
1174
1252
|
},
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
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
|
+
},
|
|
1185
1263
|
},
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
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
|
+
},
|
|
1202
1280
|
},
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
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
|
+
},
|
|
1213
1291
|
},
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
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
|
+
},
|
|
1224
1302
|
},
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
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
|
+
},
|
|
1235
1313
|
},
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
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
|
+
},
|
|
1246
1324
|
},
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
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
|
+
},
|
|
1263
1341
|
},
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
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
|
+
},
|
|
1274
1352
|
},
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
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
|
+
},
|
|
1286
1364
|
},
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
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
|
+
},
|
|
1298
1376
|
},
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
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
|
+
},
|
|
1309
1387
|
},
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
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
|
+
},
|
|
1321
1399
|
},
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
modelName: 'gpt-4-1106-vision-preview',
|
|
1329
|
-
},
|
|
1330
|
-
/**/
|
|
1331
|
-
/*/
|
|
1332
|
-
{
|
|
1333
|
-
modelVariant: 'CHAT',
|
|
1334
|
-
modelTitle: 'gpt-4-vision-preview',
|
|
1335
|
-
modelName: 'gpt-4-vision-preview',
|
|
1336
|
-
pricing: {
|
|
1337
|
-
prompt: computeUsage(`$10.00 / 1M tokens`),
|
|
1338
|
-
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',
|
|
1339
1406
|
},
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
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
|
|
1350
1429
|
},
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
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
|
+
},
|
|
1362
1440
|
},
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
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
|
+
},
|
|
1373
1451
|
},
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
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
|
+
},
|
|
1385
1463
|
},
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
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
|
+
},
|
|
1396
1474
|
},
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
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
|
+
},
|
|
1407
1485
|
},
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
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
|
+
},
|
|
1418
1496
|
},
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1497
|
+
/**/
|
|
1498
|
+
],
|
|
1499
|
+
});
|
|
1422
1500
|
/**
|
|
1423
1501
|
* Note: [🤖] Add models of new variant
|
|
1424
1502
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
@@ -1634,18 +1712,23 @@
|
|
|
1634
1712
|
if (resultContent === null) {
|
|
1635
1713
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
1636
1714
|
}
|
|
1637
|
-
return [2 /*return*/,
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
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
|
+
// <- [🗯]
|
|
1643
1731
|
},
|
|
1644
|
-
usage: usage,
|
|
1645
|
-
rawPromptContent: rawPromptContent,
|
|
1646
|
-
rawRequest: rawRequest,
|
|
1647
|
-
rawResponse: rawResponse,
|
|
1648
|
-
// <- [🗯]
|
|
1649
1732
|
})];
|
|
1650
1733
|
}
|
|
1651
1734
|
});
|
|
@@ -1710,18 +1793,23 @@
|
|
|
1710
1793
|
// eslint-disable-next-line prefer-const
|
|
1711
1794
|
complete = $getCurrentDate();
|
|
1712
1795
|
usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
1713
|
-
return [2 /*return*/,
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
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
|
+
// <- [🗯]
|
|
1719
1812
|
},
|
|
1720
|
-
usage: usage,
|
|
1721
|
-
rawPromptContent: rawPromptContent,
|
|
1722
|
-
rawRequest: rawRequest,
|
|
1723
|
-
rawResponse: rawResponse,
|
|
1724
|
-
// <- [🗯]
|
|
1725
1813
|
})];
|
|
1726
1814
|
}
|
|
1727
1815
|
});
|
|
@@ -1778,18 +1866,23 @@
|
|
|
1778
1866
|
usage = computeOpenAiUsage(content || '', '',
|
|
1779
1867
|
// <- Note: Embedding does not have result content
|
|
1780
1868
|
rawResponse);
|
|
1781
|
-
return [2 /*return*/,
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
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
|
+
// <- [🗯]
|
|
1787
1885
|
},
|
|
1788
|
-
usage: usage,
|
|
1789
|
-
rawPromptContent: rawPromptContent,
|
|
1790
|
-
rawRequest: rawRequest,
|
|
1791
|
-
rawResponse: rawResponse,
|
|
1792
|
-
// <- [🗯]
|
|
1793
1886
|
})];
|
|
1794
1887
|
}
|
|
1795
1888
|
});
|
|
@@ -1985,20 +2078,25 @@
|
|
|
1985
2078
|
if (resultContent === null) {
|
|
1986
2079
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
1987
2080
|
}
|
|
1988
|
-
return [2 /*return*/,
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
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
|
+
// <- [🗯]
|
|
1996
2099
|
},
|
|
1997
|
-
usage: usage,
|
|
1998
|
-
rawPromptContent: rawPromptContent,
|
|
1999
|
-
rawRequest: rawRequest,
|
|
2000
|
-
rawResponse: rawResponse,
|
|
2001
|
-
// <- [🗯]
|
|
2002
2100
|
})];
|
|
2003
2101
|
}
|
|
2004
2102
|
});
|