@promptbook/remote-server 0.65.0 → 0.66.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/esm/index.es.js +255 -185
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -2
- package/esm/typings/src/_packages/utils.index.d.ts +10 -8
- package/esm/typings/src/config.d.ts +22 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +11 -5
- package/esm/typings/src/llm-providers/_common/config.d.ts +1 -6
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +18 -0
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.test.d.ts +4 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register1.d.ts +4 -0
- package/esm/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -0
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +5 -1
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +3 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +2 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +4 -1
- package/esm/typings/src/utils/currentDate.d.ts +2 -0
- package/esm/typings/src/utils/deepFreeze.d.ts +2 -1
- package/esm/typings/src/utils/environment/getGlobalScope.d.ts +12 -0
- package/esm/typings/src/utils/environment/isRunningInBrowser.d.ts +8 -0
- package/esm/typings/src/utils/environment/isRunningInNode.d.ts +8 -0
- package/esm/typings/src/utils/environment/isRunningInWebWorker.d.ts +8 -0
- package/esm/typings/src/utils/files/isDirectoryExisting.d.ts +3 -1
- package/esm/typings/src/utils/files/isFileExisting.d.ts +3 -1
- package/esm/typings/src/utils/files/listAllFiles.d.ts +3 -1
- package/esm/typings/src/utils/random/randomSeed.d.ts +1 -0
- package/package.json +4 -4
- package/umd/index.umd.js +255 -185
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +0 -18
package/umd/index.umd.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook library
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_VERSION = '0.
|
|
19
|
+
var PROMPTBOOK_VERSION = '0.66.0-0';
|
|
20
20
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
21
21
|
|
|
22
22
|
/*! *****************************************************************************
|
|
@@ -457,7 +457,9 @@
|
|
|
457
457
|
*/
|
|
458
458
|
RemoteLlmExecutionTools.prototype.makeConnection = function () {
|
|
459
459
|
var _this = this;
|
|
460
|
-
return new Promise(
|
|
460
|
+
return new Promise(
|
|
461
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
462
|
+
function (resolve, reject) {
|
|
461
463
|
var socket = socket_ioClient.io(_this.options.remoteUrl, {
|
|
462
464
|
path: _this.options.path,
|
|
463
465
|
// path: `${this.remoteUrl.pathname}/socket.io`,
|
|
@@ -579,12 +581,21 @@
|
|
|
579
581
|
/**
|
|
580
582
|
* List of available Anthropic Claude models with pricing
|
|
581
583
|
*
|
|
582
|
-
* Note: Done at 2024-
|
|
584
|
+
* Note: Done at 2024-08-16
|
|
583
585
|
*
|
|
584
586
|
* @see https://docs.anthropic.com/en/docs/models-overview
|
|
585
587
|
* @public exported from `@promptbook/anthropic-claude`
|
|
586
588
|
*/
|
|
587
589
|
var ANTHROPIC_CLAUDE_MODELS = [
|
|
590
|
+
{
|
|
591
|
+
modelVariant: 'CHAT',
|
|
592
|
+
modelTitle: 'Claude 3.5 Sonnet',
|
|
593
|
+
modelName: 'claude-3-5-sonnet-20240620',
|
|
594
|
+
pricing: {
|
|
595
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
596
|
+
output: computeUsage("$15.00 / 1M tokens"),
|
|
597
|
+
},
|
|
598
|
+
},
|
|
588
599
|
{
|
|
589
600
|
modelVariant: 'CHAT',
|
|
590
601
|
modelTitle: 'Claude 3 Opus',
|
|
@@ -646,8 +657,190 @@
|
|
|
646
657
|
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
647
658
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
648
659
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
649
|
-
* TODO: [
|
|
660
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
661
|
+
*/
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Get current date in ISO 8601 format
|
|
665
|
+
*
|
|
666
|
+
* @private internal utility
|
|
667
|
+
*/
|
|
668
|
+
function getCurrentIsoDate() {
|
|
669
|
+
return new Date().toISOString();
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* @@@
|
|
674
|
+
*
|
|
675
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
676
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
677
|
+
*
|
|
678
|
+
* @returns The same object as the input, but deeply frozen
|
|
679
|
+
* @public exported from `@promptbook/utils`
|
|
680
|
+
*/
|
|
681
|
+
function $deepFreeze(objectValue) {
|
|
682
|
+
var e_1, _a;
|
|
683
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
684
|
+
try {
|
|
685
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
686
|
+
var propertyName = propertyNames_1_1.value;
|
|
687
|
+
var value = objectValue[propertyName];
|
|
688
|
+
if (value && typeof value === 'object') {
|
|
689
|
+
$deepFreeze(value);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
694
|
+
finally {
|
|
695
|
+
try {
|
|
696
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
697
|
+
}
|
|
698
|
+
finally { if (e_1) throw e_1.error; }
|
|
699
|
+
}
|
|
700
|
+
return Object.freeze(objectValue);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
704
|
+
*/
|
|
705
|
+
|
|
706
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
707
|
+
/**
|
|
708
|
+
* The maximum number of iterations for a loops
|
|
709
|
+
*
|
|
710
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
711
|
+
*/
|
|
712
|
+
var LOOP_LIMIT = 1000;
|
|
713
|
+
/**
|
|
714
|
+
* Nonce which is used for replacing things in strings
|
|
715
|
+
*
|
|
716
|
+
* @private within the repository
|
|
717
|
+
*/
|
|
718
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
719
|
+
/**
|
|
720
|
+
* The names of the parameters that are reserved for special purposes
|
|
721
|
+
*
|
|
722
|
+
* @public exported from `@promptbook/core`
|
|
723
|
+
*/
|
|
724
|
+
$deepFreeze([
|
|
725
|
+
'content',
|
|
726
|
+
'context',
|
|
727
|
+
'knowledge',
|
|
728
|
+
'samples',
|
|
729
|
+
'modelName',
|
|
730
|
+
'currentDate',
|
|
731
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
732
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
733
|
+
]);
|
|
734
|
+
/**
|
|
735
|
+
* @@@
|
|
736
|
+
*
|
|
737
|
+
* @private within the repository
|
|
738
|
+
*/
|
|
739
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
740
|
+
/**
|
|
741
|
+
* @@@
|
|
742
|
+
*
|
|
743
|
+
* @private within the repository
|
|
744
|
+
*/
|
|
745
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
746
|
+
/**
|
|
747
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
748
|
+
*/
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* This error type indicates that some limit was reached
|
|
752
|
+
*
|
|
753
|
+
* @public exported from `@promptbook/core`
|
|
650
754
|
*/
|
|
755
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
756
|
+
__extends(LimitReachedError, _super);
|
|
757
|
+
function LimitReachedError(message) {
|
|
758
|
+
var _this = _super.call(this, message) || this;
|
|
759
|
+
_this.name = 'LimitReachedError';
|
|
760
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
761
|
+
return _this;
|
|
762
|
+
}
|
|
763
|
+
return LimitReachedError;
|
|
764
|
+
}(Error));
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Replaces parameters in template with values from parameters object
|
|
768
|
+
*
|
|
769
|
+
* @param template the template with parameters in {curly} braces
|
|
770
|
+
* @param parameters the object with parameters
|
|
771
|
+
* @returns the template with replaced parameters
|
|
772
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
773
|
+
* @public exported from `@promptbook/utils`
|
|
774
|
+
*/
|
|
775
|
+
function replaceParameters(template, parameters) {
|
|
776
|
+
var e_1, _a;
|
|
777
|
+
try {
|
|
778
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
779
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
780
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
781
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
782
|
+
}
|
|
783
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
784
|
+
// TODO: [🍵]
|
|
785
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
790
|
+
finally {
|
|
791
|
+
try {
|
|
792
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
793
|
+
}
|
|
794
|
+
finally { if (e_1) throw e_1.error; }
|
|
795
|
+
}
|
|
796
|
+
var replacedTemplate = template;
|
|
797
|
+
var match;
|
|
798
|
+
var loopLimit = LOOP_LIMIT;
|
|
799
|
+
var _loop_1 = function () {
|
|
800
|
+
if (loopLimit-- < 0) {
|
|
801
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
802
|
+
}
|
|
803
|
+
var precol = match.groups.precol;
|
|
804
|
+
var parameterName = match.groups.parameterName;
|
|
805
|
+
if (parameterName === '') {
|
|
806
|
+
return "continue";
|
|
807
|
+
}
|
|
808
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
809
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
810
|
+
}
|
|
811
|
+
if (parameters[parameterName] === undefined) {
|
|
812
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
813
|
+
}
|
|
814
|
+
var parameterValue = parameters[parameterName];
|
|
815
|
+
if (parameterValue === undefined) {
|
|
816
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
817
|
+
}
|
|
818
|
+
parameterValue = parameterValue.toString();
|
|
819
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
820
|
+
parameterValue = parameterValue
|
|
821
|
+
.split('\n')
|
|
822
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
823
|
+
.join('\n');
|
|
824
|
+
}
|
|
825
|
+
replacedTemplate =
|
|
826
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
827
|
+
parameterValue +
|
|
828
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
829
|
+
};
|
|
830
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
831
|
+
.exec(replacedTemplate))) {
|
|
832
|
+
_loop_1();
|
|
833
|
+
}
|
|
834
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
835
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
836
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
837
|
+
}
|
|
838
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
839
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
840
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
841
|
+
}
|
|
842
|
+
return replacedTemplate;
|
|
843
|
+
}
|
|
651
844
|
|
|
652
845
|
/**
|
|
653
846
|
* Counts number of characters in the text
|
|
@@ -1020,182 +1213,42 @@
|
|
|
1020
1213
|
}
|
|
1021
1214
|
|
|
1022
1215
|
/**
|
|
1023
|
-
*
|
|
1216
|
+
* Computes the usage of the Anthropic Claude API based on the response from Anthropic Claude
|
|
1024
1217
|
*
|
|
1025
|
-
* @
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
/**
|
|
1032
|
-
* @@@
|
|
1033
|
-
*
|
|
1034
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1035
|
-
*
|
|
1036
|
-
* @returns The same object as the input, but deeply frozen
|
|
1037
|
-
* @public exported from `@promptbook/utils`
|
|
1218
|
+
* @param promptContent The content of the prompt
|
|
1219
|
+
* @param resultContent The content of the result (for embedding prompts or failed prompts pass empty string)
|
|
1220
|
+
* @param rawResponse The raw response from Anthropic Claude API
|
|
1221
|
+
* @throws {PipelineExecutionError} If the usage is not defined in the response from Anthropic Claude
|
|
1222
|
+
* @private internal utility of `AnthropicClaudeExecutionTools`
|
|
1038
1223
|
*/
|
|
1039
|
-
function
|
|
1040
|
-
|
|
1041
|
-
var
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
var propertyName = propertyNames_1_1.value;
|
|
1045
|
-
var value = objectValue[propertyName];
|
|
1046
|
-
if (value && typeof value === 'object') {
|
|
1047
|
-
deepFreeze(value);
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1224
|
+
function computeAnthropicClaudeUsage(promptContent, // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
|
|
1225
|
+
resultContent, rawResponse) {
|
|
1226
|
+
var _a, _b;
|
|
1227
|
+
if (rawResponse.usage === undefined) {
|
|
1228
|
+
throw new PipelineExecutionError('The usage is not defined in the response from Anthropic Claude');
|
|
1050
1229
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
try {
|
|
1054
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1055
|
-
}
|
|
1056
|
-
finally { if (e_1) throw e_1.error; }
|
|
1230
|
+
if (((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.input_tokens) === undefined) {
|
|
1231
|
+
throw new PipelineExecutionError('In Anthropic Claude response `usage.prompt_tokens` not defined');
|
|
1057
1232
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
1065
|
-
/**
|
|
1066
|
-
* The maximum number of iterations for a loops
|
|
1067
|
-
*
|
|
1068
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
1069
|
-
*/
|
|
1070
|
-
var LOOP_LIMIT = 1000;
|
|
1071
|
-
/**
|
|
1072
|
-
* Nonce which is used for replacing things in strings
|
|
1073
|
-
*
|
|
1074
|
-
* @private within the repository
|
|
1075
|
-
*/
|
|
1076
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
1077
|
-
/**
|
|
1078
|
-
* The names of the parameters that are reserved for special purposes
|
|
1079
|
-
*
|
|
1080
|
-
* @public exported from `@promptbook/core`
|
|
1081
|
-
*/
|
|
1082
|
-
deepFreeze([
|
|
1083
|
-
'content',
|
|
1084
|
-
'context',
|
|
1085
|
-
'knowledge',
|
|
1086
|
-
'samples',
|
|
1087
|
-
'modelName',
|
|
1088
|
-
'currentDate',
|
|
1089
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
1090
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
1091
|
-
]);
|
|
1092
|
-
/**
|
|
1093
|
-
* @@@
|
|
1094
|
-
*
|
|
1095
|
-
* @private within the repository
|
|
1096
|
-
*/
|
|
1097
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
1098
|
-
/**
|
|
1099
|
-
* @@@
|
|
1100
|
-
*
|
|
1101
|
-
* @private within the repository
|
|
1102
|
-
*/
|
|
1103
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
1104
|
-
|
|
1105
|
-
/**
|
|
1106
|
-
* This error type indicates that some limit was reached
|
|
1107
|
-
*
|
|
1108
|
-
* @public exported from `@promptbook/core`
|
|
1109
|
-
*/
|
|
1110
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
1111
|
-
__extends(LimitReachedError, _super);
|
|
1112
|
-
function LimitReachedError(message) {
|
|
1113
|
-
var _this = _super.call(this, message) || this;
|
|
1114
|
-
_this.name = 'LimitReachedError';
|
|
1115
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
1116
|
-
return _this;
|
|
1117
|
-
}
|
|
1118
|
-
return LimitReachedError;
|
|
1119
|
-
}(Error));
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
* Replaces parameters in template with values from parameters object
|
|
1123
|
-
*
|
|
1124
|
-
* @param template the template with parameters in {curly} braces
|
|
1125
|
-
* @param parameters the object with parameters
|
|
1126
|
-
* @returns the template with replaced parameters
|
|
1127
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
1128
|
-
* @public exported from `@promptbook/utils`
|
|
1129
|
-
*/
|
|
1130
|
-
function replaceParameters(template, parameters) {
|
|
1131
|
-
var e_1, _a;
|
|
1132
|
-
try {
|
|
1133
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1134
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
1135
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
1136
|
-
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
1137
|
-
}
|
|
1138
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
1139
|
-
// TODO: [🍵]
|
|
1140
|
-
throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1233
|
+
var inputTokens = rawResponse.usage.input_tokens;
|
|
1234
|
+
var outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.output_tokens) || 0;
|
|
1235
|
+
var modelInfo = ANTHROPIC_CLAUDE_MODELS.find(function (model) { return model.modelName === rawResponse.model; });
|
|
1236
|
+
var price;
|
|
1237
|
+
if (modelInfo === undefined || modelInfo.pricing === undefined) {
|
|
1238
|
+
price = uncertainNumber();
|
|
1143
1239
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
try {
|
|
1147
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1148
|
-
}
|
|
1149
|
-
finally { if (e_1) throw e_1.error; }
|
|
1240
|
+
else {
|
|
1241
|
+
price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
|
|
1150
1242
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
if (loopLimit-- < 0) {
|
|
1156
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
1157
|
-
}
|
|
1158
|
-
var precol = match.groups.precol;
|
|
1159
|
-
var parameterName = match.groups.parameterName;
|
|
1160
|
-
if (parameterName === '') {
|
|
1161
|
-
return "continue";
|
|
1162
|
-
}
|
|
1163
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
1164
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
1165
|
-
}
|
|
1166
|
-
if (parameters[parameterName] === undefined) {
|
|
1167
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1168
|
-
}
|
|
1169
|
-
var parameterValue = parameters[parameterName];
|
|
1170
|
-
if (parameterValue === undefined) {
|
|
1171
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1172
|
-
}
|
|
1173
|
-
parameterValue = parameterValue.toString();
|
|
1174
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
1175
|
-
parameterValue = parameterValue
|
|
1176
|
-
.split('\n')
|
|
1177
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
1178
|
-
.join('\n');
|
|
1179
|
-
}
|
|
1180
|
-
replacedTemplate =
|
|
1181
|
-
replacedTemplate.substring(0, match.index + precol.length) +
|
|
1182
|
-
parameterValue +
|
|
1183
|
-
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
1243
|
+
return {
|
|
1244
|
+
price: price,
|
|
1245
|
+
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(promptContent)),
|
|
1246
|
+
output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
|
|
1184
1247
|
};
|
|
1185
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
1186
|
-
.exec(replacedTemplate))) {
|
|
1187
|
-
_loop_1();
|
|
1188
|
-
}
|
|
1189
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
1190
|
-
if (/{\w+$/.test(replacedTemplate)) {
|
|
1191
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
1192
|
-
}
|
|
1193
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
1194
|
-
if (/^\w+}/.test(replacedTemplate)) {
|
|
1195
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
1196
|
-
}
|
|
1197
|
-
return replacedTemplate;
|
|
1198
1248
|
}
|
|
1249
|
+
/**
|
|
1250
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
1251
|
+
*/
|
|
1199
1252
|
|
|
1200
1253
|
/**
|
|
1201
1254
|
* Execution Tools for calling Anthropic Claude API.
|
|
@@ -1217,6 +1270,7 @@
|
|
|
1217
1270
|
delete anthropicOptions.isVerbose;
|
|
1218
1271
|
delete anthropicOptions.isProxied;
|
|
1219
1272
|
this.client = new Anthropic__default["default"](anthropicOptions);
|
|
1273
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
1220
1274
|
}
|
|
1221
1275
|
Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
|
|
1222
1276
|
get: function () {
|
|
@@ -1237,7 +1291,7 @@
|
|
|
1237
1291
|
*/
|
|
1238
1292
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
1239
1293
|
return __awaiter(this, void 0, void 0, function () {
|
|
1240
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
1294
|
+
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
1241
1295
|
return __generator(this, function (_a) {
|
|
1242
1296
|
switch (_a.label) {
|
|
1243
1297
|
case 0:
|
|
@@ -1283,14 +1337,14 @@
|
|
|
1283
1337
|
if (rawResponse.content.length > 1) {
|
|
1284
1338
|
throw new PipelineExecutionError('More than one content blocks from Anthropic Claude');
|
|
1285
1339
|
}
|
|
1286
|
-
|
|
1340
|
+
contentBlock = rawResponse.content[0];
|
|
1341
|
+
if (contentBlock.type !== 'text') {
|
|
1342
|
+
throw new PipelineExecutionError("Returned content is not \"text\" type but \"".concat(contentBlock.type, "\""));
|
|
1343
|
+
}
|
|
1344
|
+
resultContent = contentBlock.text;
|
|
1287
1345
|
// eslint-disable-next-line prefer-const
|
|
1288
1346
|
complete = getCurrentIsoDate();
|
|
1289
|
-
usage =
|
|
1290
|
-
price: { value: 0, isUncertain: true } /* <- TODO: [🐞] Compute usage */,
|
|
1291
|
-
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
|
|
1292
|
-
output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
|
|
1293
|
-
};
|
|
1347
|
+
usage = computeAnthropicClaudeUsage(content, '', rawResponse);
|
|
1294
1348
|
return [2 /*return*/, {
|
|
1295
1349
|
content: resultContent,
|
|
1296
1350
|
modelName: rawResponse.model,
|
|
@@ -1438,7 +1492,9 @@
|
|
|
1438
1492
|
},
|
|
1439
1493
|
], models: ANTHROPIC_CLAUDE_MODELS }));
|
|
1440
1494
|
}
|
|
1441
|
-
return new AnthropicClaudeExecutionTools(
|
|
1495
|
+
return new AnthropicClaudeExecutionTools(
|
|
1496
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
1497
|
+
options);
|
|
1442
1498
|
}
|
|
1443
1499
|
/**
|
|
1444
1500
|
* TODO: [🧠] !!!! Make anonymous this with all LLM providers
|
|
@@ -1787,7 +1843,8 @@
|
|
|
1787
1843
|
/**
|
|
1788
1844
|
* Note: [🤖] Add models of new variant
|
|
1789
1845
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
1790
|
-
* TODO: [
|
|
1846
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
1847
|
+
* TODO: [🎰][👮♀️] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
|
|
1791
1848
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
1792
1849
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
1793
1850
|
* @see https://openai.com/api/pricing/
|
|
@@ -1810,7 +1867,10 @@
|
|
|
1810
1867
|
*/
|
|
1811
1868
|
function AzureOpenAiExecutionTools(options) {
|
|
1812
1869
|
this.options = options;
|
|
1813
|
-
this.client = new openai.OpenAIClient(
|
|
1870
|
+
this.client = new openai.OpenAIClient(
|
|
1871
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
1872
|
+
"https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(options.apiKey));
|
|
1873
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
1814
1874
|
}
|
|
1815
1875
|
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
1816
1876
|
get: function () {
|
|
@@ -2080,6 +2140,9 @@
|
|
|
2080
2140
|
output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
|
|
2081
2141
|
};
|
|
2082
2142
|
}
|
|
2143
|
+
/**
|
|
2144
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
2145
|
+
*/
|
|
2083
2146
|
|
|
2084
2147
|
/**
|
|
2085
2148
|
* Execution Tools for calling OpenAI API.
|
|
@@ -2100,6 +2163,7 @@
|
|
|
2100
2163
|
delete openAiOptions.isVerbose;
|
|
2101
2164
|
delete openAiOptions.user;
|
|
2102
2165
|
this.client = new OpenAI__default["default"](__assign({}, openAiOptions));
|
|
2166
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
2103
2167
|
}
|
|
2104
2168
|
Object.defineProperty(OpenAiExecutionTools.prototype, "title", {
|
|
2105
2169
|
get: function () {
|
|
@@ -2393,11 +2457,15 @@
|
|
|
2393
2457
|
return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
|
|
2394
2458
|
},
|
|
2395
2459
|
createAnthropicClaudeExecutionTools: createAnthropicClaudeExecutionTools,
|
|
2396
|
-
createAzureOpenAiExecutionTools: function (options) {
|
|
2460
|
+
createAzureOpenAiExecutionTools: function (options) {
|
|
2461
|
+
return new AzureOpenAiExecutionTools(
|
|
2462
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
2463
|
+
options);
|
|
2464
|
+
},
|
|
2397
2465
|
// <- Note: [🦑] Add here new LLM provider
|
|
2398
2466
|
};
|
|
2399
2467
|
/**
|
|
2400
|
-
* TODO:
|
|
2468
|
+
* TODO: !!!!!!! Make global register for this
|
|
2401
2469
|
* TODO: [🧠][🎌] Adding this should be responsibility of each provider package NOT this one central place
|
|
2402
2470
|
*/
|
|
2403
2471
|
|
|
@@ -2482,7 +2550,9 @@
|
|
|
2482
2550
|
}
|
|
2483
2551
|
});
|
|
2484
2552
|
}); });
|
|
2485
|
-
var server = new socket_io.Server(
|
|
2553
|
+
var server = new socket_io.Server(
|
|
2554
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
2555
|
+
httpServer, {
|
|
2486
2556
|
path: path,
|
|
2487
2557
|
transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
|
|
2488
2558
|
cors: {
|