@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/esm/index.es.js
CHANGED
|
@@ -11,7 +11,7 @@ import OpenAI from 'openai';
|
|
|
11
11
|
/**
|
|
12
12
|
* The version of the Promptbook library
|
|
13
13
|
*/
|
|
14
|
-
var PROMPTBOOK_VERSION = '0.
|
|
14
|
+
var PROMPTBOOK_VERSION = '0.66.0-0';
|
|
15
15
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
16
16
|
|
|
17
17
|
/*! *****************************************************************************
|
|
@@ -452,7 +452,9 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
452
452
|
*/
|
|
453
453
|
RemoteLlmExecutionTools.prototype.makeConnection = function () {
|
|
454
454
|
var _this = this;
|
|
455
|
-
return new Promise(
|
|
455
|
+
return new Promise(
|
|
456
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
457
|
+
function (resolve, reject) {
|
|
456
458
|
var socket = io(_this.options.remoteUrl, {
|
|
457
459
|
path: _this.options.path,
|
|
458
460
|
// path: `${this.remoteUrl.pathname}/socket.io`,
|
|
@@ -574,12 +576,21 @@ function computeUsage(value) {
|
|
|
574
576
|
/**
|
|
575
577
|
* List of available Anthropic Claude models with pricing
|
|
576
578
|
*
|
|
577
|
-
* Note: Done at 2024-
|
|
579
|
+
* Note: Done at 2024-08-16
|
|
578
580
|
*
|
|
579
581
|
* @see https://docs.anthropic.com/en/docs/models-overview
|
|
580
582
|
* @public exported from `@promptbook/anthropic-claude`
|
|
581
583
|
*/
|
|
582
584
|
var ANTHROPIC_CLAUDE_MODELS = [
|
|
585
|
+
{
|
|
586
|
+
modelVariant: 'CHAT',
|
|
587
|
+
modelTitle: 'Claude 3.5 Sonnet',
|
|
588
|
+
modelName: 'claude-3-5-sonnet-20240620',
|
|
589
|
+
pricing: {
|
|
590
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
591
|
+
output: computeUsage("$15.00 / 1M tokens"),
|
|
592
|
+
},
|
|
593
|
+
},
|
|
583
594
|
{
|
|
584
595
|
modelVariant: 'CHAT',
|
|
585
596
|
modelTitle: 'Claude 3 Opus',
|
|
@@ -641,8 +652,190 @@ var ANTHROPIC_CLAUDE_MODELS = [
|
|
|
641
652
|
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
642
653
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
643
654
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
644
|
-
* TODO: [
|
|
655
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
656
|
+
*/
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Get current date in ISO 8601 format
|
|
660
|
+
*
|
|
661
|
+
* @private internal utility
|
|
662
|
+
*/
|
|
663
|
+
function getCurrentIsoDate() {
|
|
664
|
+
return new Date().toISOString();
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* @@@
|
|
669
|
+
*
|
|
670
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
671
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
672
|
+
*
|
|
673
|
+
* @returns The same object as the input, but deeply frozen
|
|
674
|
+
* @public exported from `@promptbook/utils`
|
|
675
|
+
*/
|
|
676
|
+
function $deepFreeze(objectValue) {
|
|
677
|
+
var e_1, _a;
|
|
678
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
679
|
+
try {
|
|
680
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
681
|
+
var propertyName = propertyNames_1_1.value;
|
|
682
|
+
var value = objectValue[propertyName];
|
|
683
|
+
if (value && typeof value === 'object') {
|
|
684
|
+
$deepFreeze(value);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
689
|
+
finally {
|
|
690
|
+
try {
|
|
691
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
692
|
+
}
|
|
693
|
+
finally { if (e_1) throw e_1.error; }
|
|
694
|
+
}
|
|
695
|
+
return Object.freeze(objectValue);
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
699
|
+
*/
|
|
700
|
+
|
|
701
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
702
|
+
/**
|
|
703
|
+
* The maximum number of iterations for a loops
|
|
704
|
+
*
|
|
705
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
706
|
+
*/
|
|
707
|
+
var LOOP_LIMIT = 1000;
|
|
708
|
+
/**
|
|
709
|
+
* Nonce which is used for replacing things in strings
|
|
710
|
+
*
|
|
711
|
+
* @private within the repository
|
|
712
|
+
*/
|
|
713
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
714
|
+
/**
|
|
715
|
+
* The names of the parameters that are reserved for special purposes
|
|
716
|
+
*
|
|
717
|
+
* @public exported from `@promptbook/core`
|
|
718
|
+
*/
|
|
719
|
+
$deepFreeze([
|
|
720
|
+
'content',
|
|
721
|
+
'context',
|
|
722
|
+
'knowledge',
|
|
723
|
+
'samples',
|
|
724
|
+
'modelName',
|
|
725
|
+
'currentDate',
|
|
726
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
727
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
728
|
+
]);
|
|
729
|
+
/**
|
|
730
|
+
* @@@
|
|
731
|
+
*
|
|
732
|
+
* @private within the repository
|
|
733
|
+
*/
|
|
734
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
735
|
+
/**
|
|
736
|
+
* @@@
|
|
737
|
+
*
|
|
738
|
+
* @private within the repository
|
|
739
|
+
*/
|
|
740
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
741
|
+
/**
|
|
742
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
743
|
+
*/
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* This error type indicates that some limit was reached
|
|
747
|
+
*
|
|
748
|
+
* @public exported from `@promptbook/core`
|
|
645
749
|
*/
|
|
750
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
751
|
+
__extends(LimitReachedError, _super);
|
|
752
|
+
function LimitReachedError(message) {
|
|
753
|
+
var _this = _super.call(this, message) || this;
|
|
754
|
+
_this.name = 'LimitReachedError';
|
|
755
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
756
|
+
return _this;
|
|
757
|
+
}
|
|
758
|
+
return LimitReachedError;
|
|
759
|
+
}(Error));
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Replaces parameters in template with values from parameters object
|
|
763
|
+
*
|
|
764
|
+
* @param template the template with parameters in {curly} braces
|
|
765
|
+
* @param parameters the object with parameters
|
|
766
|
+
* @returns the template with replaced parameters
|
|
767
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
768
|
+
* @public exported from `@promptbook/utils`
|
|
769
|
+
*/
|
|
770
|
+
function replaceParameters(template, parameters) {
|
|
771
|
+
var e_1, _a;
|
|
772
|
+
try {
|
|
773
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
774
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
775
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
776
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
777
|
+
}
|
|
778
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
779
|
+
// TODO: [🍵]
|
|
780
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
785
|
+
finally {
|
|
786
|
+
try {
|
|
787
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
788
|
+
}
|
|
789
|
+
finally { if (e_1) throw e_1.error; }
|
|
790
|
+
}
|
|
791
|
+
var replacedTemplate = template;
|
|
792
|
+
var match;
|
|
793
|
+
var loopLimit = LOOP_LIMIT;
|
|
794
|
+
var _loop_1 = function () {
|
|
795
|
+
if (loopLimit-- < 0) {
|
|
796
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
797
|
+
}
|
|
798
|
+
var precol = match.groups.precol;
|
|
799
|
+
var parameterName = match.groups.parameterName;
|
|
800
|
+
if (parameterName === '') {
|
|
801
|
+
return "continue";
|
|
802
|
+
}
|
|
803
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
804
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
805
|
+
}
|
|
806
|
+
if (parameters[parameterName] === undefined) {
|
|
807
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
808
|
+
}
|
|
809
|
+
var parameterValue = parameters[parameterName];
|
|
810
|
+
if (parameterValue === undefined) {
|
|
811
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
812
|
+
}
|
|
813
|
+
parameterValue = parameterValue.toString();
|
|
814
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
815
|
+
parameterValue = parameterValue
|
|
816
|
+
.split('\n')
|
|
817
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
818
|
+
.join('\n');
|
|
819
|
+
}
|
|
820
|
+
replacedTemplate =
|
|
821
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
822
|
+
parameterValue +
|
|
823
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
824
|
+
};
|
|
825
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
826
|
+
.exec(replacedTemplate))) {
|
|
827
|
+
_loop_1();
|
|
828
|
+
}
|
|
829
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
830
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
831
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
832
|
+
}
|
|
833
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
834
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
835
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
836
|
+
}
|
|
837
|
+
return replacedTemplate;
|
|
838
|
+
}
|
|
646
839
|
|
|
647
840
|
/**
|
|
648
841
|
* Counts number of characters in the text
|
|
@@ -1015,182 +1208,42 @@ function uncertainNumber(value) {
|
|
|
1015
1208
|
}
|
|
1016
1209
|
|
|
1017
1210
|
/**
|
|
1018
|
-
*
|
|
1211
|
+
* Computes the usage of the Anthropic Claude API based on the response from Anthropic Claude
|
|
1019
1212
|
*
|
|
1020
|
-
* @
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
/**
|
|
1027
|
-
* @@@
|
|
1028
|
-
*
|
|
1029
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1030
|
-
*
|
|
1031
|
-
* @returns The same object as the input, but deeply frozen
|
|
1032
|
-
* @public exported from `@promptbook/utils`
|
|
1213
|
+
* @param promptContent The content of the prompt
|
|
1214
|
+
* @param resultContent The content of the result (for embedding prompts or failed prompts pass empty string)
|
|
1215
|
+
* @param rawResponse The raw response from Anthropic Claude API
|
|
1216
|
+
* @throws {PipelineExecutionError} If the usage is not defined in the response from Anthropic Claude
|
|
1217
|
+
* @private internal utility of `AnthropicClaudeExecutionTools`
|
|
1033
1218
|
*/
|
|
1034
|
-
function
|
|
1035
|
-
|
|
1036
|
-
var
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
var propertyName = propertyNames_1_1.value;
|
|
1040
|
-
var value = objectValue[propertyName];
|
|
1041
|
-
if (value && typeof value === 'object') {
|
|
1042
|
-
deepFreeze(value);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1219
|
+
function computeAnthropicClaudeUsage(promptContent, // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
|
|
1220
|
+
resultContent, rawResponse) {
|
|
1221
|
+
var _a, _b;
|
|
1222
|
+
if (rawResponse.usage === undefined) {
|
|
1223
|
+
throw new PipelineExecutionError('The usage is not defined in the response from Anthropic Claude');
|
|
1045
1224
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
try {
|
|
1049
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1050
|
-
}
|
|
1051
|
-
finally { if (e_1) throw e_1.error; }
|
|
1225
|
+
if (((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.input_tokens) === undefined) {
|
|
1226
|
+
throw new PipelineExecutionError('In Anthropic Claude response `usage.prompt_tokens` not defined');
|
|
1052
1227
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
1060
|
-
/**
|
|
1061
|
-
* The maximum number of iterations for a loops
|
|
1062
|
-
*
|
|
1063
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
1064
|
-
*/
|
|
1065
|
-
var LOOP_LIMIT = 1000;
|
|
1066
|
-
/**
|
|
1067
|
-
* Nonce which is used for replacing things in strings
|
|
1068
|
-
*
|
|
1069
|
-
* @private within the repository
|
|
1070
|
-
*/
|
|
1071
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
1072
|
-
/**
|
|
1073
|
-
* The names of the parameters that are reserved for special purposes
|
|
1074
|
-
*
|
|
1075
|
-
* @public exported from `@promptbook/core`
|
|
1076
|
-
*/
|
|
1077
|
-
deepFreeze([
|
|
1078
|
-
'content',
|
|
1079
|
-
'context',
|
|
1080
|
-
'knowledge',
|
|
1081
|
-
'samples',
|
|
1082
|
-
'modelName',
|
|
1083
|
-
'currentDate',
|
|
1084
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
1085
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
1086
|
-
]);
|
|
1087
|
-
/**
|
|
1088
|
-
* @@@
|
|
1089
|
-
*
|
|
1090
|
-
* @private within the repository
|
|
1091
|
-
*/
|
|
1092
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
1093
|
-
/**
|
|
1094
|
-
* @@@
|
|
1095
|
-
*
|
|
1096
|
-
* @private within the repository
|
|
1097
|
-
*/
|
|
1098
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
1099
|
-
|
|
1100
|
-
/**
|
|
1101
|
-
* This error type indicates that some limit was reached
|
|
1102
|
-
*
|
|
1103
|
-
* @public exported from `@promptbook/core`
|
|
1104
|
-
*/
|
|
1105
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
1106
|
-
__extends(LimitReachedError, _super);
|
|
1107
|
-
function LimitReachedError(message) {
|
|
1108
|
-
var _this = _super.call(this, message) || this;
|
|
1109
|
-
_this.name = 'LimitReachedError';
|
|
1110
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
1111
|
-
return _this;
|
|
1112
|
-
}
|
|
1113
|
-
return LimitReachedError;
|
|
1114
|
-
}(Error));
|
|
1115
|
-
|
|
1116
|
-
/**
|
|
1117
|
-
* Replaces parameters in template with values from parameters object
|
|
1118
|
-
*
|
|
1119
|
-
* @param template the template with parameters in {curly} braces
|
|
1120
|
-
* @param parameters the object with parameters
|
|
1121
|
-
* @returns the template with replaced parameters
|
|
1122
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
1123
|
-
* @public exported from `@promptbook/utils`
|
|
1124
|
-
*/
|
|
1125
|
-
function replaceParameters(template, parameters) {
|
|
1126
|
-
var e_1, _a;
|
|
1127
|
-
try {
|
|
1128
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1129
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
1130
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
1131
|
-
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
1132
|
-
}
|
|
1133
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
1134
|
-
// TODO: [🍵]
|
|
1135
|
-
throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1228
|
+
var inputTokens = rawResponse.usage.input_tokens;
|
|
1229
|
+
var outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.output_tokens) || 0;
|
|
1230
|
+
var modelInfo = ANTHROPIC_CLAUDE_MODELS.find(function (model) { return model.modelName === rawResponse.model; });
|
|
1231
|
+
var price;
|
|
1232
|
+
if (modelInfo === undefined || modelInfo.pricing === undefined) {
|
|
1233
|
+
price = uncertainNumber();
|
|
1138
1234
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
try {
|
|
1142
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1143
|
-
}
|
|
1144
|
-
finally { if (e_1) throw e_1.error; }
|
|
1235
|
+
else {
|
|
1236
|
+
price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
|
|
1145
1237
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
if (loopLimit-- < 0) {
|
|
1151
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
1152
|
-
}
|
|
1153
|
-
var precol = match.groups.precol;
|
|
1154
|
-
var parameterName = match.groups.parameterName;
|
|
1155
|
-
if (parameterName === '') {
|
|
1156
|
-
return "continue";
|
|
1157
|
-
}
|
|
1158
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
1159
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
1160
|
-
}
|
|
1161
|
-
if (parameters[parameterName] === undefined) {
|
|
1162
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1163
|
-
}
|
|
1164
|
-
var parameterValue = parameters[parameterName];
|
|
1165
|
-
if (parameterValue === undefined) {
|
|
1166
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1167
|
-
}
|
|
1168
|
-
parameterValue = parameterValue.toString();
|
|
1169
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
1170
|
-
parameterValue = parameterValue
|
|
1171
|
-
.split('\n')
|
|
1172
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
1173
|
-
.join('\n');
|
|
1174
|
-
}
|
|
1175
|
-
replacedTemplate =
|
|
1176
|
-
replacedTemplate.substring(0, match.index + precol.length) +
|
|
1177
|
-
parameterValue +
|
|
1178
|
-
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
1238
|
+
return {
|
|
1239
|
+
price: price,
|
|
1240
|
+
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(promptContent)),
|
|
1241
|
+
output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
|
|
1179
1242
|
};
|
|
1180
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
1181
|
-
.exec(replacedTemplate))) {
|
|
1182
|
-
_loop_1();
|
|
1183
|
-
}
|
|
1184
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
1185
|
-
if (/{\w+$/.test(replacedTemplate)) {
|
|
1186
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
1187
|
-
}
|
|
1188
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
1189
|
-
if (/^\w+}/.test(replacedTemplate)) {
|
|
1190
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
1191
|
-
}
|
|
1192
|
-
return replacedTemplate;
|
|
1193
1243
|
}
|
|
1244
|
+
/**
|
|
1245
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
1246
|
+
*/
|
|
1194
1247
|
|
|
1195
1248
|
/**
|
|
1196
1249
|
* Execution Tools for calling Anthropic Claude API.
|
|
@@ -1212,6 +1265,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
1212
1265
|
delete anthropicOptions.isVerbose;
|
|
1213
1266
|
delete anthropicOptions.isProxied;
|
|
1214
1267
|
this.client = new Anthropic(anthropicOptions);
|
|
1268
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
1215
1269
|
}
|
|
1216
1270
|
Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
|
|
1217
1271
|
get: function () {
|
|
@@ -1232,7 +1286,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
1232
1286
|
*/
|
|
1233
1287
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
1234
1288
|
return __awaiter(this, void 0, void 0, function () {
|
|
1235
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
1289
|
+
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
1236
1290
|
return __generator(this, function (_a) {
|
|
1237
1291
|
switch (_a.label) {
|
|
1238
1292
|
case 0:
|
|
@@ -1278,14 +1332,14 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
1278
1332
|
if (rawResponse.content.length > 1) {
|
|
1279
1333
|
throw new PipelineExecutionError('More than one content blocks from Anthropic Claude');
|
|
1280
1334
|
}
|
|
1281
|
-
|
|
1335
|
+
contentBlock = rawResponse.content[0];
|
|
1336
|
+
if (contentBlock.type !== 'text') {
|
|
1337
|
+
throw new PipelineExecutionError("Returned content is not \"text\" type but \"".concat(contentBlock.type, "\""));
|
|
1338
|
+
}
|
|
1339
|
+
resultContent = contentBlock.text;
|
|
1282
1340
|
// eslint-disable-next-line prefer-const
|
|
1283
1341
|
complete = getCurrentIsoDate();
|
|
1284
|
-
usage =
|
|
1285
|
-
price: { value: 0, isUncertain: true } /* <- TODO: [🐞] Compute usage */,
|
|
1286
|
-
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
|
|
1287
|
-
output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
|
|
1288
|
-
};
|
|
1342
|
+
usage = computeAnthropicClaudeUsage(content, '', rawResponse);
|
|
1289
1343
|
return [2 /*return*/, {
|
|
1290
1344
|
content: resultContent,
|
|
1291
1345
|
modelName: rawResponse.model,
|
|
@@ -1433,7 +1487,9 @@ function createAnthropicClaudeExecutionTools(options) {
|
|
|
1433
1487
|
},
|
|
1434
1488
|
], models: ANTHROPIC_CLAUDE_MODELS }));
|
|
1435
1489
|
}
|
|
1436
|
-
return new AnthropicClaudeExecutionTools(
|
|
1490
|
+
return new AnthropicClaudeExecutionTools(
|
|
1491
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
1492
|
+
options);
|
|
1437
1493
|
}
|
|
1438
1494
|
/**
|
|
1439
1495
|
* TODO: [🧠] !!!! Make anonymous this with all LLM providers
|
|
@@ -1782,7 +1838,8 @@ var OPENAI_MODELS = [
|
|
|
1782
1838
|
/**
|
|
1783
1839
|
* Note: [🤖] Add models of new variant
|
|
1784
1840
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
1785
|
-
* TODO: [
|
|
1841
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
1842
|
+
* TODO: [🎰][👮♀️] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
|
|
1786
1843
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
1787
1844
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
1788
1845
|
* @see https://openai.com/api/pricing/
|
|
@@ -1805,7 +1862,10 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
1805
1862
|
*/
|
|
1806
1863
|
function AzureOpenAiExecutionTools(options) {
|
|
1807
1864
|
this.options = options;
|
|
1808
|
-
this.client = new OpenAIClient(
|
|
1865
|
+
this.client = new OpenAIClient(
|
|
1866
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
1867
|
+
"https://".concat(options.resourceName, ".openai.azure.com/"), new AzureKeyCredential(options.apiKey));
|
|
1868
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
1809
1869
|
}
|
|
1810
1870
|
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
1811
1871
|
get: function () {
|
|
@@ -2075,6 +2135,9 @@ resultContent, rawResponse) {
|
|
|
2075
2135
|
output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
|
|
2076
2136
|
};
|
|
2077
2137
|
}
|
|
2138
|
+
/**
|
|
2139
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
2140
|
+
*/
|
|
2078
2141
|
|
|
2079
2142
|
/**
|
|
2080
2143
|
* Execution Tools for calling OpenAI API.
|
|
@@ -2095,6 +2158,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
2095
2158
|
delete openAiOptions.isVerbose;
|
|
2096
2159
|
delete openAiOptions.user;
|
|
2097
2160
|
this.client = new OpenAI(__assign({}, openAiOptions));
|
|
2161
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
2098
2162
|
}
|
|
2099
2163
|
Object.defineProperty(OpenAiExecutionTools.prototype, "title", {
|
|
2100
2164
|
get: function () {
|
|
@@ -2388,11 +2452,15 @@ var EXECUTION_TOOLS_CLASSES = {
|
|
|
2388
2452
|
return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
|
|
2389
2453
|
},
|
|
2390
2454
|
createAnthropicClaudeExecutionTools: createAnthropicClaudeExecutionTools,
|
|
2391
|
-
createAzureOpenAiExecutionTools: function (options) {
|
|
2455
|
+
createAzureOpenAiExecutionTools: function (options) {
|
|
2456
|
+
return new AzureOpenAiExecutionTools(
|
|
2457
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
2458
|
+
options);
|
|
2459
|
+
},
|
|
2392
2460
|
// <- Note: [🦑] Add here new LLM provider
|
|
2393
2461
|
};
|
|
2394
2462
|
/**
|
|
2395
|
-
* TODO:
|
|
2463
|
+
* TODO: !!!!!!! Make global register for this
|
|
2396
2464
|
* TODO: [🧠][🎌] Adding this should be responsibility of each provider package NOT this one central place
|
|
2397
2465
|
*/
|
|
2398
2466
|
|
|
@@ -2477,7 +2545,9 @@ function startRemoteServer(options) {
|
|
|
2477
2545
|
}
|
|
2478
2546
|
});
|
|
2479
2547
|
}); });
|
|
2480
|
-
var server = new Server(
|
|
2548
|
+
var server = new Server(
|
|
2549
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
2550
|
+
httpServer, {
|
|
2481
2551
|
path: path,
|
|
2482
2552
|
transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
|
|
2483
2553
|
cors: {
|