@promptbook/cli 0.77.0-0 → 0.77.0-4
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 +1 -1
- package/esm/index.es.js +593 -316
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/_packages/google.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/vercel.index.d.ts +2 -0
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +11 -0
- package/esm/typings/src/execution/AvailableModel.d.ts +5 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +5 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/GoogleExecutionToolsOptions.d.ts +12 -0
- package/esm/typings/src/llm-providers/google/createGoogleExecutionTools.d.ts +18 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +13 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +14 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/vercel/VercelExecutionToolsOptions.d.ts +22 -0
- package/esm/typings/src/llm-providers/vercel/VercelProvider.d.ts +13 -0
- package/esm/typings/src/llm-providers/vercel/createExecutionToolsFromVercelProvider.d.ts +2 -5
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +8 -0
- package/package.json +2 -1
- package/umd/index.umd.js +595 -316
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/_packages/gemini.index.d.ts +0 -2
package/esm/index.es.js
CHANGED
|
@@ -37,7 +37,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
37
37
|
*
|
|
38
38
|
* @see https://github.com/webgptorg/promptbook
|
|
39
39
|
*/
|
|
40
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
40
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.77.0-3';
|
|
41
41
|
/**
|
|
42
42
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
43
43
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -660,6 +660,312 @@ function initializeHelloCommand(program) {
|
|
|
660
660
|
* Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
|
|
661
661
|
*/
|
|
662
662
|
|
|
663
|
+
/**
|
|
664
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
665
|
+
*
|
|
666
|
+
* @public exported from `@promptbook/core`
|
|
667
|
+
*/
|
|
668
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
669
|
+
__extends(NotYetImplementedError, _super);
|
|
670
|
+
function NotYetImplementedError(message) {
|
|
671
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
672
|
+
_this.name = 'NotYetImplementedError';
|
|
673
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
674
|
+
return _this;
|
|
675
|
+
}
|
|
676
|
+
return NotYetImplementedError;
|
|
677
|
+
}(Error));
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* @@@
|
|
681
|
+
*
|
|
682
|
+
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
683
|
+
*
|
|
684
|
+
* @private internal function of `$Register`
|
|
685
|
+
*/
|
|
686
|
+
function $getGlobalScope() {
|
|
687
|
+
return Function('return this')();
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* @@@
|
|
692
|
+
*
|
|
693
|
+
* @param text @@@
|
|
694
|
+
* @returns @@@
|
|
695
|
+
* @example 'HELLO_WORLD'
|
|
696
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
697
|
+
* @public exported from `@promptbook/utils`
|
|
698
|
+
*/
|
|
699
|
+
function normalizeTo_SCREAMING_CASE(text) {
|
|
700
|
+
var e_1, _a;
|
|
701
|
+
var charType;
|
|
702
|
+
var lastCharType = 'OTHER';
|
|
703
|
+
var normalizedName = '';
|
|
704
|
+
try {
|
|
705
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
706
|
+
var char = text_1_1.value;
|
|
707
|
+
var normalizedChar = void 0;
|
|
708
|
+
if (/^[a-z]$/.test(char)) {
|
|
709
|
+
charType = 'LOWERCASE';
|
|
710
|
+
normalizedChar = char.toUpperCase();
|
|
711
|
+
}
|
|
712
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
713
|
+
charType = 'UPPERCASE';
|
|
714
|
+
normalizedChar = char;
|
|
715
|
+
}
|
|
716
|
+
else if (/^[0-9]$/.test(char)) {
|
|
717
|
+
charType = 'NUMBER';
|
|
718
|
+
normalizedChar = char;
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
charType = 'OTHER';
|
|
722
|
+
normalizedChar = '_';
|
|
723
|
+
}
|
|
724
|
+
if (charType !== lastCharType &&
|
|
725
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
726
|
+
!(lastCharType === 'NUMBER') &&
|
|
727
|
+
!(charType === 'NUMBER')) {
|
|
728
|
+
normalizedName += '_';
|
|
729
|
+
}
|
|
730
|
+
normalizedName += normalizedChar;
|
|
731
|
+
lastCharType = charType;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
735
|
+
finally {
|
|
736
|
+
try {
|
|
737
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
738
|
+
}
|
|
739
|
+
finally { if (e_1) throw e_1.error; }
|
|
740
|
+
}
|
|
741
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
742
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
743
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
744
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
745
|
+
return normalizedName;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* TODO: Tests
|
|
749
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
750
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
751
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
752
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
753
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
754
|
+
*/
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* @@@
|
|
758
|
+
*
|
|
759
|
+
* @param text @@@
|
|
760
|
+
* @returns @@@
|
|
761
|
+
* @example 'hello_world'
|
|
762
|
+
* @example 'i_love_promptbook'
|
|
763
|
+
* @public exported from `@promptbook/utils`
|
|
764
|
+
*/
|
|
765
|
+
function normalizeTo_snake_case(text) {
|
|
766
|
+
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Register is @@@
|
|
771
|
+
*
|
|
772
|
+
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
773
|
+
*
|
|
774
|
+
* @private internal utility, exported are only signleton instances of this class
|
|
775
|
+
*/
|
|
776
|
+
var $Register = /** @class */ (function () {
|
|
777
|
+
function $Register(registerName) {
|
|
778
|
+
this.registerName = registerName;
|
|
779
|
+
var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
|
|
780
|
+
var globalScope = $getGlobalScope();
|
|
781
|
+
if (globalScope[storageName] === undefined) {
|
|
782
|
+
globalScope[storageName] = [];
|
|
783
|
+
}
|
|
784
|
+
else if (!Array.isArray(globalScope[storageName])) {
|
|
785
|
+
throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
|
|
786
|
+
}
|
|
787
|
+
this.storage = globalScope[storageName];
|
|
788
|
+
}
|
|
789
|
+
$Register.prototype.list = function () {
|
|
790
|
+
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
791
|
+
return this.storage;
|
|
792
|
+
};
|
|
793
|
+
$Register.prototype.register = function (registered) {
|
|
794
|
+
var packageName = registered.packageName, className = registered.className;
|
|
795
|
+
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
796
|
+
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
797
|
+
if (!existingRegistration) {
|
|
798
|
+
this.storage.push(registered);
|
|
799
|
+
}
|
|
800
|
+
else {
|
|
801
|
+
this.storage[existingRegistrationIndex] = registered;
|
|
802
|
+
}
|
|
803
|
+
return {
|
|
804
|
+
registerName: this.registerName,
|
|
805
|
+
packageName: packageName,
|
|
806
|
+
className: className,
|
|
807
|
+
get isDestroyed() {
|
|
808
|
+
return false;
|
|
809
|
+
},
|
|
810
|
+
destroy: function () {
|
|
811
|
+
throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
|
|
812
|
+
},
|
|
813
|
+
};
|
|
814
|
+
};
|
|
815
|
+
return $Register;
|
|
816
|
+
}());
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* @@@
|
|
820
|
+
*
|
|
821
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
822
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
823
|
+
* @public exported from `@promptbook/core`
|
|
824
|
+
*/
|
|
825
|
+
var $llmToolsMetadataRegister = new $Register('llm_tools_metadata');
|
|
826
|
+
/**
|
|
827
|
+
* TODO: [®] DRY Register logic
|
|
828
|
+
*/
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* @@@
|
|
832
|
+
*
|
|
833
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
834
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
835
|
+
* @public exported from `@promptbook/core`
|
|
836
|
+
*/
|
|
837
|
+
var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
838
|
+
/**
|
|
839
|
+
* TODO: [®] DRY Register logic
|
|
840
|
+
*/
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Creates a message with all registered LLM tools
|
|
844
|
+
*
|
|
845
|
+
* Note: This function is used to create a (error) message when there is no constructor for some LLM provider
|
|
846
|
+
*
|
|
847
|
+
* @private internal function of `createLlmToolsFromConfiguration` and `$provideLlmToolsFromEnv`
|
|
848
|
+
*/
|
|
849
|
+
function $registeredLlmToolsMessage() {
|
|
850
|
+
var e_1, _a, e_2, _b;
|
|
851
|
+
/**
|
|
852
|
+
* Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
|
|
853
|
+
*/
|
|
854
|
+
var all = [];
|
|
855
|
+
var _loop_1 = function (packageName, className, envVariables) {
|
|
856
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
857
|
+
return "continue";
|
|
858
|
+
}
|
|
859
|
+
all.push({ packageName: packageName, className: className, envVariables: envVariables });
|
|
860
|
+
};
|
|
861
|
+
try {
|
|
862
|
+
for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
863
|
+
var _e = _d.value, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
|
|
864
|
+
_loop_1(packageName, className, envVariables);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
868
|
+
finally {
|
|
869
|
+
try {
|
|
870
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
871
|
+
}
|
|
872
|
+
finally { if (e_1) throw e_1.error; }
|
|
873
|
+
}
|
|
874
|
+
var _loop_2 = function (packageName, className) {
|
|
875
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
876
|
+
return "continue";
|
|
877
|
+
}
|
|
878
|
+
all.push({ packageName: packageName, className: className });
|
|
879
|
+
};
|
|
880
|
+
try {
|
|
881
|
+
for (var _f = __values($llmToolsRegister.list()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
882
|
+
var _h = _g.value, packageName = _h.packageName, className = _h.className;
|
|
883
|
+
_loop_2(packageName, className);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
887
|
+
finally {
|
|
888
|
+
try {
|
|
889
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
890
|
+
}
|
|
891
|
+
finally { if (e_2) throw e_2.error; }
|
|
892
|
+
}
|
|
893
|
+
var metadata = all.map(function (metadata) {
|
|
894
|
+
var isMetadataAviailable = $llmToolsMetadataRegister
|
|
895
|
+
.list()
|
|
896
|
+
.find(function (_a) {
|
|
897
|
+
var packageName = _a.packageName, className = _a.className;
|
|
898
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
899
|
+
});
|
|
900
|
+
var isInstalled = $llmToolsRegister
|
|
901
|
+
.list()
|
|
902
|
+
.find(function (_a) {
|
|
903
|
+
var packageName = _a.packageName, className = _a.className;
|
|
904
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
905
|
+
});
|
|
906
|
+
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
|
|
907
|
+
});
|
|
908
|
+
if (metadata.length === 0) {
|
|
909
|
+
return "No LLM providers are available.";
|
|
910
|
+
}
|
|
911
|
+
return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
912
|
+
.map(function (_a, i) {
|
|
913
|
+
var packageName = _a.packageName, className = _a.className, envVariables = _a.envVariables, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
|
|
914
|
+
var more;
|
|
915
|
+
if (just(false)) {
|
|
916
|
+
more = '';
|
|
917
|
+
}
|
|
918
|
+
else if (!isMetadataAviailable && !isInstalled) {
|
|
919
|
+
// TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
|
|
920
|
+
more = "(not installed and no metadata, looks like a unexpected behavior)";
|
|
921
|
+
}
|
|
922
|
+
else if (isMetadataAviailable && !isInstalled) {
|
|
923
|
+
// TODO: [�][�]
|
|
924
|
+
more = "(not installed)";
|
|
925
|
+
}
|
|
926
|
+
else if (!isMetadataAviailable && isInstalled) {
|
|
927
|
+
more = "(no metadata, looks like a unexpected behavior)";
|
|
928
|
+
}
|
|
929
|
+
else if (isMetadataAviailable && isInstalled) {
|
|
930
|
+
more = "(installed)";
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
more = "(unknown state, looks like a unexpected behavior)";
|
|
934
|
+
}
|
|
935
|
+
var envVariablesMessage = '';
|
|
936
|
+
if (envVariables) {
|
|
937
|
+
envVariablesMessage = 'Configured by ' + envVariables.join(' + ');
|
|
938
|
+
}
|
|
939
|
+
return spaceTrim$1("\n ".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "`\n ").concat(more, "\n ").concat(envVariablesMessage, "\n "));
|
|
940
|
+
// <- TODO: !!!!!! Is this indented correctly?
|
|
941
|
+
})
|
|
942
|
+
.join('\n')), "\n "); });
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* TODO: [®] DRY Register logic
|
|
946
|
+
*/
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* Initializes `list-models` command for Promptbook CLI utilities
|
|
950
|
+
*
|
|
951
|
+
* @private internal function of `promptbookCli`
|
|
952
|
+
*/
|
|
953
|
+
function initializeListModelsCommand(program) {
|
|
954
|
+
var _this = this;
|
|
955
|
+
var listModelsCommand = program.command('list-models');
|
|
956
|
+
listModelsCommand.description(spaceTrim$1("\n List all available and configured LLM models\n "));
|
|
957
|
+
listModelsCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
958
|
+
return __generator(this, function (_a) {
|
|
959
|
+
console.info($registeredLlmToolsMessage());
|
|
960
|
+
return [2 /*return*/, process.exit(0)];
|
|
961
|
+
});
|
|
962
|
+
}); });
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
966
|
+
* Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
|
|
967
|
+
*/
|
|
968
|
+
|
|
663
969
|
/**
|
|
664
970
|
* Converts PipelineCollection to serialized JSON
|
|
665
971
|
*
|
|
@@ -2324,22 +2630,6 @@ var LimitReachedError = /** @class */ (function (_super) {
|
|
|
2324
2630
|
return LimitReachedError;
|
|
2325
2631
|
}(Error));
|
|
2326
2632
|
|
|
2327
|
-
/**
|
|
2328
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
2329
|
-
*
|
|
2330
|
-
* @public exported from `@promptbook/core`
|
|
2331
|
-
*/
|
|
2332
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
2333
|
-
__extends(NotYetImplementedError, _super);
|
|
2334
|
-
function NotYetImplementedError(message) {
|
|
2335
|
-
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
2336
|
-
_this.name = 'NotYetImplementedError';
|
|
2337
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
2338
|
-
return _this;
|
|
2339
|
-
}
|
|
2340
|
-
return NotYetImplementedError;
|
|
2341
|
-
}(Error));
|
|
2342
|
-
|
|
2343
2633
|
/**
|
|
2344
2634
|
* Index of all custom errors
|
|
2345
2635
|
*
|
|
@@ -4773,178 +5063,39 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
4773
5063
|
.filter(function (_a) {
|
|
4774
5064
|
var modelVariant = _a.modelVariant;
|
|
4775
5065
|
return modelVariant === 'CHAT';
|
|
4776
|
-
})
|
|
4777
|
-
.map(function (_a) {
|
|
4778
|
-
var modelName = _a.modelName;
|
|
4779
|
-
return modelName;
|
|
4780
|
-
})
|
|
4781
|
-
.join(',');
|
|
4782
|
-
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
4783
|
-
case 3:
|
|
4784
|
-
result = _d.sent();
|
|
4785
|
-
assertsExecutionSuccessful(result);
|
|
4786
|
-
outputParameters = result.outputParameters;
|
|
4787
|
-
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
4788
|
-
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
4789
|
-
if (isVerbose) {
|
|
4790
|
-
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
4791
|
-
}
|
|
4792
|
-
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
4793
|
-
return [2 /*return*/, {
|
|
4794
|
-
modelVariant: 'CHAT',
|
|
4795
|
-
modelName: modelName,
|
|
4796
|
-
systemMessage: systemMessage,
|
|
4797
|
-
temperature: temperature,
|
|
4798
|
-
}];
|
|
4799
|
-
}
|
|
4800
|
-
});
|
|
4801
|
-
});
|
|
4802
|
-
}
|
|
4803
|
-
/**
|
|
4804
|
-
* TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
|
|
4805
|
-
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
4806
|
-
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
4807
|
-
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
4808
|
-
*/
|
|
4809
|
-
|
|
4810
|
-
/**
|
|
4811
|
-
* @@@
|
|
4812
|
-
*
|
|
4813
|
-
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
4814
|
-
*
|
|
4815
|
-
* @private internal function of `$Register`
|
|
4816
|
-
*/
|
|
4817
|
-
function $getGlobalScope() {
|
|
4818
|
-
return Function('return this')();
|
|
4819
|
-
}
|
|
4820
|
-
|
|
4821
|
-
/**
|
|
4822
|
-
* @@@
|
|
4823
|
-
*
|
|
4824
|
-
* @param text @@@
|
|
4825
|
-
* @returns @@@
|
|
4826
|
-
* @example 'HELLO_WORLD'
|
|
4827
|
-
* @example 'I_LOVE_PROMPTBOOK'
|
|
4828
|
-
* @public exported from `@promptbook/utils`
|
|
4829
|
-
*/
|
|
4830
|
-
function normalizeTo_SCREAMING_CASE(text) {
|
|
4831
|
-
var e_1, _a;
|
|
4832
|
-
var charType;
|
|
4833
|
-
var lastCharType = 'OTHER';
|
|
4834
|
-
var normalizedName = '';
|
|
4835
|
-
try {
|
|
4836
|
-
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
4837
|
-
var char = text_1_1.value;
|
|
4838
|
-
var normalizedChar = void 0;
|
|
4839
|
-
if (/^[a-z]$/.test(char)) {
|
|
4840
|
-
charType = 'LOWERCASE';
|
|
4841
|
-
normalizedChar = char.toUpperCase();
|
|
4842
|
-
}
|
|
4843
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
4844
|
-
charType = 'UPPERCASE';
|
|
4845
|
-
normalizedChar = char;
|
|
4846
|
-
}
|
|
4847
|
-
else if (/^[0-9]$/.test(char)) {
|
|
4848
|
-
charType = 'NUMBER';
|
|
4849
|
-
normalizedChar = char;
|
|
4850
|
-
}
|
|
4851
|
-
else {
|
|
4852
|
-
charType = 'OTHER';
|
|
4853
|
-
normalizedChar = '_';
|
|
4854
|
-
}
|
|
4855
|
-
if (charType !== lastCharType &&
|
|
4856
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
4857
|
-
!(lastCharType === 'NUMBER') &&
|
|
4858
|
-
!(charType === 'NUMBER')) {
|
|
4859
|
-
normalizedName += '_';
|
|
4860
|
-
}
|
|
4861
|
-
normalizedName += normalizedChar;
|
|
4862
|
-
lastCharType = charType;
|
|
4863
|
-
}
|
|
4864
|
-
}
|
|
4865
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4866
|
-
finally {
|
|
4867
|
-
try {
|
|
4868
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
4869
|
-
}
|
|
4870
|
-
finally { if (e_1) throw e_1.error; }
|
|
4871
|
-
}
|
|
4872
|
-
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
4873
|
-
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
4874
|
-
normalizedName = normalizedName.replace(/^_/, '');
|
|
4875
|
-
normalizedName = normalizedName.replace(/_$/, '');
|
|
4876
|
-
return normalizedName;
|
|
4877
|
-
}
|
|
4878
|
-
/**
|
|
4879
|
-
* TODO: Tests
|
|
4880
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
4881
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
4882
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
4883
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
4884
|
-
* TODO: [🌺] Use some intermediate util splitWords
|
|
4885
|
-
*/
|
|
4886
|
-
|
|
4887
|
-
/**
|
|
4888
|
-
* @@@
|
|
4889
|
-
*
|
|
4890
|
-
* @param text @@@
|
|
4891
|
-
* @returns @@@
|
|
4892
|
-
* @example 'hello_world'
|
|
4893
|
-
* @example 'i_love_promptbook'
|
|
4894
|
-
* @public exported from `@promptbook/utils`
|
|
4895
|
-
*/
|
|
4896
|
-
function normalizeTo_snake_case(text) {
|
|
4897
|
-
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
4898
|
-
}
|
|
4899
|
-
|
|
4900
|
-
/**
|
|
4901
|
-
* Register is @@@
|
|
4902
|
-
*
|
|
4903
|
-
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
4904
|
-
*
|
|
4905
|
-
* @private internal utility, exported are only signleton instances of this class
|
|
4906
|
-
*/
|
|
4907
|
-
var $Register = /** @class */ (function () {
|
|
4908
|
-
function $Register(registerName) {
|
|
4909
|
-
this.registerName = registerName;
|
|
4910
|
-
var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
|
|
4911
|
-
var globalScope = $getGlobalScope();
|
|
4912
|
-
if (globalScope[storageName] === undefined) {
|
|
4913
|
-
globalScope[storageName] = [];
|
|
4914
|
-
}
|
|
4915
|
-
else if (!Array.isArray(globalScope[storageName])) {
|
|
4916
|
-
throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
|
|
4917
|
-
}
|
|
4918
|
-
this.storage = globalScope[storageName];
|
|
4919
|
-
}
|
|
4920
|
-
$Register.prototype.list = function () {
|
|
4921
|
-
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
4922
|
-
return this.storage;
|
|
4923
|
-
};
|
|
4924
|
-
$Register.prototype.register = function (registered) {
|
|
4925
|
-
var packageName = registered.packageName, className = registered.className;
|
|
4926
|
-
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
4927
|
-
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
4928
|
-
if (!existingRegistration) {
|
|
4929
|
-
this.storage.push(registered);
|
|
4930
|
-
}
|
|
4931
|
-
else {
|
|
4932
|
-
this.storage[existingRegistrationIndex] = registered;
|
|
4933
|
-
}
|
|
4934
|
-
return {
|
|
4935
|
-
registerName: this.registerName,
|
|
4936
|
-
packageName: packageName,
|
|
4937
|
-
className: className,
|
|
4938
|
-
get isDestroyed() {
|
|
4939
|
-
return false;
|
|
4940
|
-
},
|
|
4941
|
-
destroy: function () {
|
|
4942
|
-
throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
|
|
4943
|
-
},
|
|
4944
|
-
};
|
|
4945
|
-
};
|
|
4946
|
-
return $Register;
|
|
4947
|
-
}());
|
|
5066
|
+
})
|
|
5067
|
+
.map(function (_a) {
|
|
5068
|
+
var modelName = _a.modelName;
|
|
5069
|
+
return modelName;
|
|
5070
|
+
})
|
|
5071
|
+
.join(',');
|
|
5072
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
5073
|
+
case 3:
|
|
5074
|
+
result = _d.sent();
|
|
5075
|
+
assertsExecutionSuccessful(result);
|
|
5076
|
+
outputParameters = result.outputParameters;
|
|
5077
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
5078
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
5079
|
+
if (isVerbose) {
|
|
5080
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
5081
|
+
}
|
|
5082
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
5083
|
+
return [2 /*return*/, {
|
|
5084
|
+
modelVariant: 'CHAT',
|
|
5085
|
+
modelName: modelName,
|
|
5086
|
+
systemMessage: systemMessage,
|
|
5087
|
+
temperature: temperature,
|
|
5088
|
+
}];
|
|
5089
|
+
}
|
|
5090
|
+
});
|
|
5091
|
+
});
|
|
5092
|
+
}
|
|
5093
|
+
/**
|
|
5094
|
+
* TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
|
|
5095
|
+
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
5096
|
+
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
5097
|
+
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
5098
|
+
*/
|
|
4948
5099
|
|
|
4949
5100
|
/**
|
|
4950
5101
|
* @@@
|
|
@@ -9081,18 +9232,6 @@ function $provideExecutablesForNode(options) {
|
|
|
9081
9232
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9082
9233
|
*/
|
|
9083
9234
|
|
|
9084
|
-
/**
|
|
9085
|
-
* @@@
|
|
9086
|
-
*
|
|
9087
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
9088
|
-
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
9089
|
-
* @public exported from `@promptbook/core`
|
|
9090
|
-
*/
|
|
9091
|
-
var $llmToolsMetadataRegister = new $Register('llm_tools_metadata');
|
|
9092
|
-
/**
|
|
9093
|
-
* TODO: [®] DRY Register logic
|
|
9094
|
-
*/
|
|
9095
|
-
|
|
9096
9235
|
/**
|
|
9097
9236
|
* @@@
|
|
9098
9237
|
*
|
|
@@ -9101,6 +9240,7 @@ var $llmToolsMetadataRegister = new $Register('llm_tools_metadata');
|
|
|
9101
9240
|
* It looks for environment variables:
|
|
9102
9241
|
* - `process.env.OPENAI_API_KEY`
|
|
9103
9242
|
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9243
|
+
* - ...
|
|
9104
9244
|
*
|
|
9105
9245
|
* @returns @@@
|
|
9106
9246
|
* @public exported from `@promptbook/node`
|
|
@@ -9129,119 +9269,6 @@ function $provideLlmToolsConfigurationFromEnv() {
|
|
|
9129
9269
|
* TODO: [🧠] Maybe pass env as argument
|
|
9130
9270
|
* TODO: [®] DRY Register logic */
|
|
9131
9271
|
|
|
9132
|
-
/**
|
|
9133
|
-
* @@@
|
|
9134
|
-
*
|
|
9135
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
9136
|
-
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
9137
|
-
* @public exported from `@promptbook/core`
|
|
9138
|
-
*/
|
|
9139
|
-
var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
9140
|
-
/**
|
|
9141
|
-
* TODO: [®] DRY Register logic
|
|
9142
|
-
*/
|
|
9143
|
-
|
|
9144
|
-
/**
|
|
9145
|
-
* Creates a message with all registered LLM tools
|
|
9146
|
-
*
|
|
9147
|
-
* Note: This function is used to create a (error) message when there is no constructor for some LLM provider
|
|
9148
|
-
*
|
|
9149
|
-
* @private internal function of `createLlmToolsFromConfiguration` and `$provideLlmToolsFromEnv`
|
|
9150
|
-
*/
|
|
9151
|
-
function $registeredLlmToolsMessage() {
|
|
9152
|
-
var e_1, _a, e_2, _b;
|
|
9153
|
-
/**
|
|
9154
|
-
* Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
|
|
9155
|
-
*/
|
|
9156
|
-
var all = [];
|
|
9157
|
-
var _loop_1 = function (packageName, className) {
|
|
9158
|
-
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
9159
|
-
return "continue";
|
|
9160
|
-
}
|
|
9161
|
-
all.push({ packageName: packageName, className: className });
|
|
9162
|
-
};
|
|
9163
|
-
try {
|
|
9164
|
-
for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
9165
|
-
var _e = _d.value, packageName = _e.packageName, className = _e.className;
|
|
9166
|
-
_loop_1(packageName, className);
|
|
9167
|
-
}
|
|
9168
|
-
}
|
|
9169
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9170
|
-
finally {
|
|
9171
|
-
try {
|
|
9172
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
9173
|
-
}
|
|
9174
|
-
finally { if (e_1) throw e_1.error; }
|
|
9175
|
-
}
|
|
9176
|
-
var _loop_2 = function (packageName, className) {
|
|
9177
|
-
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
9178
|
-
return "continue";
|
|
9179
|
-
}
|
|
9180
|
-
all.push({ packageName: packageName, className: className });
|
|
9181
|
-
};
|
|
9182
|
-
try {
|
|
9183
|
-
for (var _f = __values($llmToolsRegister.list()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
9184
|
-
var _h = _g.value, packageName = _h.packageName, className = _h.className;
|
|
9185
|
-
_loop_2(packageName, className);
|
|
9186
|
-
}
|
|
9187
|
-
}
|
|
9188
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
9189
|
-
finally {
|
|
9190
|
-
try {
|
|
9191
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
9192
|
-
}
|
|
9193
|
-
finally { if (e_2) throw e_2.error; }
|
|
9194
|
-
}
|
|
9195
|
-
var metadata = all.map(function (metadata) {
|
|
9196
|
-
var isMetadataAviailable = $llmToolsMetadataRegister
|
|
9197
|
-
.list()
|
|
9198
|
-
.find(function (_a) {
|
|
9199
|
-
var packageName = _a.packageName, className = _a.className;
|
|
9200
|
-
return metadata.packageName === packageName && metadata.className === className;
|
|
9201
|
-
});
|
|
9202
|
-
var isInstalled = $llmToolsRegister
|
|
9203
|
-
.list()
|
|
9204
|
-
.find(function (_a) {
|
|
9205
|
-
var packageName = _a.packageName, className = _a.className;
|
|
9206
|
-
return metadata.packageName === packageName && metadata.className === className;
|
|
9207
|
-
});
|
|
9208
|
-
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
|
|
9209
|
-
});
|
|
9210
|
-
if (metadata.length === 0) {
|
|
9211
|
-
return "No LLM providers are available.";
|
|
9212
|
-
}
|
|
9213
|
-
return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
9214
|
-
.map(function (_a, i) {
|
|
9215
|
-
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
|
|
9216
|
-
var more;
|
|
9217
|
-
if (just(false)) {
|
|
9218
|
-
more = '';
|
|
9219
|
-
}
|
|
9220
|
-
else if (!isMetadataAviailable && !isInstalled) {
|
|
9221
|
-
// TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
|
|
9222
|
-
more = "(not installed and no metadata, looks like a unexpected behavior)";
|
|
9223
|
-
}
|
|
9224
|
-
else if (isMetadataAviailable && !isInstalled) {
|
|
9225
|
-
// TODO: [�][�]
|
|
9226
|
-
more = "(not installed)";
|
|
9227
|
-
}
|
|
9228
|
-
else if (!isMetadataAviailable && isInstalled) {
|
|
9229
|
-
more = "(no metadata, looks like a unexpected behavior)";
|
|
9230
|
-
}
|
|
9231
|
-
else if (isMetadataAviailable && isInstalled) {
|
|
9232
|
-
more = "(installed)";
|
|
9233
|
-
}
|
|
9234
|
-
else {
|
|
9235
|
-
more = "(unknown state, looks like a unexpected behavior)";
|
|
9236
|
-
}
|
|
9237
|
-
return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` ").concat(more);
|
|
9238
|
-
})
|
|
9239
|
-
.join('\n')), "\n "); });
|
|
9240
|
-
}
|
|
9241
|
-
/**
|
|
9242
|
-
* TODO: [®] DRY Register logic
|
|
9243
|
-
*/
|
|
9244
|
-
|
|
9245
9272
|
/**
|
|
9246
9273
|
* @@@
|
|
9247
9274
|
*
|
|
@@ -9287,6 +9314,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
9287
9314
|
* It looks for environment variables:
|
|
9288
9315
|
* - `process.env.OPENAI_API_KEY`
|
|
9289
9316
|
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9317
|
+
* - ...
|
|
9290
9318
|
*
|
|
9291
9319
|
* @returns @@@
|
|
9292
9320
|
* @public exported from `@promptbook/node`
|
|
@@ -11547,7 +11575,13 @@ function initializeRunCommand(program) {
|
|
|
11547
11575
|
if (!error.message.includes('No LLM tools')) {
|
|
11548
11576
|
throw error;
|
|
11549
11577
|
}
|
|
11550
|
-
console.error(colors.red(spaceTrim$1("\n
|
|
11578
|
+
console.error(colors.red(spaceTrim$1(function (block) { return "\n You need to configure LLM tools first\n\n \n 1) Create .env file at the root of your project\n 2) Configure API keys for LLM tools\n \n For example:\n ".concat(block($llmToolsMetadataRegister
|
|
11579
|
+
.list()
|
|
11580
|
+
.map(function (_a) {
|
|
11581
|
+
var title = _a.title, envVariables = _a.envVariables;
|
|
11582
|
+
return "- ".concat(envVariables.join(' + '), " (").concat(title, ")");
|
|
11583
|
+
})
|
|
11584
|
+
.join('\n')), "\n "); })));
|
|
11551
11585
|
return [2 /*return*/, process.exit(1)];
|
|
11552
11586
|
}
|
|
11553
11587
|
return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
|
|
@@ -11926,6 +11960,7 @@ function promptbookCli() {
|
|
|
11926
11960
|
initializeMakeCommand(program);
|
|
11927
11961
|
initializePrettifyCommand(program);
|
|
11928
11962
|
initializeTestCommand(program);
|
|
11963
|
+
initializeListModelsCommand(program);
|
|
11929
11964
|
program.parse(process.argv);
|
|
11930
11965
|
return [2 /*return*/];
|
|
11931
11966
|
});
|
|
@@ -11968,6 +12003,7 @@ var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
11968
12003
|
title: 'Anthropic Claude',
|
|
11969
12004
|
packageName: '@promptbook/anthropic-claude',
|
|
11970
12005
|
className: 'AnthropicClaudeExecutionTools',
|
|
12006
|
+
envVariables: ['ANTHROPIC_CLAUDE_API_KEY'],
|
|
11971
12007
|
getBoilerplateConfiguration: function () {
|
|
11972
12008
|
return {
|
|
11973
12009
|
title: 'Anthropic Claude (boilerplate)',
|
|
@@ -12687,6 +12723,7 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
12687
12723
|
title: 'Azure Open AI',
|
|
12688
12724
|
packageName: '@promptbook/azure-openai',
|
|
12689
12725
|
className: 'AzureOpenAiExecutionTools',
|
|
12726
|
+
envVariables: ['AZUREOPENAI_RESOURCE_NAME', 'AZUREOPENAI_DEPLOYMENT_NAME', 'AZUREOPENAI_API_KEY'],
|
|
12690
12727
|
getBoilerplateConfiguration: function () {
|
|
12691
12728
|
return {
|
|
12692
12729
|
title: 'Azure Open AI (boilerplate)',
|
|
@@ -13466,6 +13503,242 @@ var _AzureOpenAiRegistration = $llmToolsRegister.register(createAzureOpenAiExecu
|
|
|
13466
13503
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
13467
13504
|
*/
|
|
13468
13505
|
|
|
13506
|
+
/**
|
|
13507
|
+
* Detects if the code is running in jest environment
|
|
13508
|
+
*
|
|
13509
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
13510
|
+
*
|
|
13511
|
+
* @public exported from `@promptbook/utils`
|
|
13512
|
+
*/
|
|
13513
|
+
var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
|
|
13514
|
+
|
|
13515
|
+
/**
|
|
13516
|
+
* Registration of LLM provider metadata
|
|
13517
|
+
*
|
|
13518
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
13519
|
+
*
|
|
13520
|
+
* @public exported from `@promptbook/core`
|
|
13521
|
+
* @public exported from `@promptbook/cli`
|
|
13522
|
+
*/
|
|
13523
|
+
var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
13524
|
+
title: 'Google Gemini',
|
|
13525
|
+
packageName: '@promptbook/google',
|
|
13526
|
+
className: 'GoogleExecutionTools',
|
|
13527
|
+
envVariables: ['GOOGLE_GENERATIVE_AI_API_KEY'],
|
|
13528
|
+
getBoilerplateConfiguration: function () {
|
|
13529
|
+
return {
|
|
13530
|
+
title: 'Google Gemini (boilerplate)',
|
|
13531
|
+
packageName: '@promptbook/google',
|
|
13532
|
+
className: 'GoogleExecutionTools',
|
|
13533
|
+
options: {
|
|
13534
|
+
apiKey: 'sk-ant-api03-',
|
|
13535
|
+
isProxied: true,
|
|
13536
|
+
remoteUrl: DEFAULT_REMOTE_URL,
|
|
13537
|
+
path: DEFAULT_REMOTE_URL_PATH,
|
|
13538
|
+
},
|
|
13539
|
+
};
|
|
13540
|
+
},
|
|
13541
|
+
createConfigurationFromEnv: function (env) {
|
|
13542
|
+
if ($isRunningInJest()
|
|
13543
|
+
// <- TODO: Maybe check `env.JEST_WORKER_ID` directly here or pass `env` into `$isRunningInJest`
|
|
13544
|
+
) {
|
|
13545
|
+
// Note: [🔘] Gemini makes problems in Jest environment
|
|
13546
|
+
return null;
|
|
13547
|
+
}
|
|
13548
|
+
// Note: Note using `process.env` BUT `env` to pass in the environment variables dynamically
|
|
13549
|
+
if (typeof env.GOOGLE_GENERATIVE_AI_API_KEY === 'string') {
|
|
13550
|
+
return {
|
|
13551
|
+
title: 'Google Gemini (from env)',
|
|
13552
|
+
packageName: '@promptbook/google',
|
|
13553
|
+
className: 'GoogleExecutionTools',
|
|
13554
|
+
options: {
|
|
13555
|
+
apiKey: env.GOOGLE_GENERATIVE_AI_API_KEY,
|
|
13556
|
+
},
|
|
13557
|
+
};
|
|
13558
|
+
}
|
|
13559
|
+
return null;
|
|
13560
|
+
},
|
|
13561
|
+
});
|
|
13562
|
+
/**
|
|
13563
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
13564
|
+
*/
|
|
13565
|
+
|
|
13566
|
+
/**
|
|
13567
|
+
* !!!!!!
|
|
13568
|
+
*
|
|
13569
|
+
* @public exported from `@promptbook/vercel`
|
|
13570
|
+
*/
|
|
13571
|
+
function createExecutionToolsFromVercelProvider(options) {
|
|
13572
|
+
var vercelProvider = options.vercelProvider, availableModels = options.availableModels, userId = options.userId, _a = options.additionalChatSettings, additionalChatSettings = _a === void 0 ? {} : _a;
|
|
13573
|
+
return {
|
|
13574
|
+
title: '!!!',
|
|
13575
|
+
description: "!!! (through Vercel)",
|
|
13576
|
+
checkConfiguration: function () {
|
|
13577
|
+
// TODO: !!!!!!
|
|
13578
|
+
return Promise.resolve();
|
|
13579
|
+
},
|
|
13580
|
+
listModels: function () {
|
|
13581
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
13582
|
+
return __generator(this, function (_a) {
|
|
13583
|
+
return [2 /*return*/, availableModels];
|
|
13584
|
+
});
|
|
13585
|
+
});
|
|
13586
|
+
},
|
|
13587
|
+
callChatModel: function (prompt) {
|
|
13588
|
+
var _a;
|
|
13589
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
13590
|
+
var content, parameters, modelRequirements, modelName, model, rawPromptContent, rawRequest, start, rawResponse, complete, usage;
|
|
13591
|
+
return __generator(this, function (_b) {
|
|
13592
|
+
switch (_b.label) {
|
|
13593
|
+
case 0:
|
|
13594
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
13595
|
+
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
13596
|
+
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
13597
|
+
}
|
|
13598
|
+
modelName = modelRequirements.modelName ||
|
|
13599
|
+
((_a = availableModels.find(function (_a) {
|
|
13600
|
+
var modelVariant = _a.modelVariant;
|
|
13601
|
+
return modelVariant === 'CHAT';
|
|
13602
|
+
})) === null || _a === void 0 ? void 0 : _a.modelName);
|
|
13603
|
+
if (!modelName) {
|
|
13604
|
+
throw new PipelineExecutionError(spaceTrim$1("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
|
|
13605
|
+
}
|
|
13606
|
+
return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
|
|
13607
|
+
case 1:
|
|
13608
|
+
model = _b.sent();
|
|
13609
|
+
rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
|
|
13610
|
+
rawRequest = {
|
|
13611
|
+
// <- TODO: [☂]
|
|
13612
|
+
inputFormat: 'messages',
|
|
13613
|
+
mode: {
|
|
13614
|
+
type: 'regular',
|
|
13615
|
+
tools: [
|
|
13616
|
+
/* !!!!!! */
|
|
13617
|
+
],
|
|
13618
|
+
},
|
|
13619
|
+
prompt: __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
|
|
13620
|
+
? []
|
|
13621
|
+
: [
|
|
13622
|
+
{
|
|
13623
|
+
role: 'system',
|
|
13624
|
+
content: modelRequirements.systemMessage,
|
|
13625
|
+
},
|
|
13626
|
+
])), false), [
|
|
13627
|
+
{
|
|
13628
|
+
role: 'user',
|
|
13629
|
+
content: [
|
|
13630
|
+
{
|
|
13631
|
+
type: 'text',
|
|
13632
|
+
text: rawPromptContent,
|
|
13633
|
+
},
|
|
13634
|
+
],
|
|
13635
|
+
},
|
|
13636
|
+
], false),
|
|
13637
|
+
};
|
|
13638
|
+
start = $getCurrentDate();
|
|
13639
|
+
if (options.isVerbose) {
|
|
13640
|
+
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
13641
|
+
}
|
|
13642
|
+
return [4 /*yield*/, model.doGenerate(rawRequest)];
|
|
13643
|
+
case 2:
|
|
13644
|
+
rawResponse = _b.sent();
|
|
13645
|
+
/*
|
|
13646
|
+
TODO: !!!!!! Handle errors
|
|
13647
|
+
.catch((error) => {
|
|
13648
|
+
if (options.isVerbose) {
|
|
13649
|
+
console.info(colors.bgRed('error'), error);
|
|
13650
|
+
}
|
|
13651
|
+
throw error;
|
|
13652
|
+
});
|
|
13653
|
+
*/
|
|
13654
|
+
if (options.isVerbose) {
|
|
13655
|
+
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
13656
|
+
}
|
|
13657
|
+
if (rawResponse.text === undefined) {
|
|
13658
|
+
throw new PipelineExecutionError('No response message');
|
|
13659
|
+
}
|
|
13660
|
+
complete = $getCurrentDate();
|
|
13661
|
+
usage = UNCERTAIN_USAGE;
|
|
13662
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('createExecutionToolsFromVercelProvider ChatPromptResult', {
|
|
13663
|
+
content: rawResponse.text,
|
|
13664
|
+
modelName: modelName,
|
|
13665
|
+
timing: {
|
|
13666
|
+
start: start,
|
|
13667
|
+
complete: complete,
|
|
13668
|
+
},
|
|
13669
|
+
usage: usage,
|
|
13670
|
+
rawPromptContent: rawPromptContent,
|
|
13671
|
+
rawRequest: rawRequest,
|
|
13672
|
+
rawResponse: {
|
|
13673
|
+
/* TODO: !!!!!! UnexpectedError: createExecutionToolsFromVercelProvider ChatPromptResult.rawResponse.response.timestamp is Date */
|
|
13674
|
+
},
|
|
13675
|
+
// <- [🗯]
|
|
13676
|
+
})];
|
|
13677
|
+
}
|
|
13678
|
+
});
|
|
13679
|
+
});
|
|
13680
|
+
},
|
|
13681
|
+
};
|
|
13682
|
+
}
|
|
13683
|
+
|
|
13684
|
+
/**
|
|
13685
|
+
* Execution Tools for calling Google Gemini API.
|
|
13686
|
+
*
|
|
13687
|
+
* @public exported from `@promptbook/google`
|
|
13688
|
+
*/
|
|
13689
|
+
var createGoogleExecutionTools = Object.assign(function (options) {
|
|
13690
|
+
if ($isRunningInJest()) {
|
|
13691
|
+
// Note: [🔘]
|
|
13692
|
+
throw new Error('GoogleExecutionTools are not supported in Jest environment');
|
|
13693
|
+
}
|
|
13694
|
+
// Note: [🔘] There is a compatibility when using import from '@ai-sdk/google'
|
|
13695
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
13696
|
+
var createGoogleGenerativeAI = require('@ai-sdk/google').createGoogleGenerativeAI;
|
|
13697
|
+
var googleGeminiVercelProvider = createGoogleGenerativeAI(__assign({}, options));
|
|
13698
|
+
return createExecutionToolsFromVercelProvider(__assign({ vercelProvider: googleGeminiVercelProvider, availableModels: [
|
|
13699
|
+
// TODO: !!!!!! Maybe list models in same way as in other providers
|
|
13700
|
+
'gemini-1.5-flash',
|
|
13701
|
+
'gemini-1.5-flash-latest',
|
|
13702
|
+
'gemini-1.5-flash-001',
|
|
13703
|
+
'gemini-1.5-flash-002',
|
|
13704
|
+
'gemini-1.5-flash-exp-0827',
|
|
13705
|
+
'gemini-1.5-flash-8b',
|
|
13706
|
+
'gemini-1.5-flash-8b-latest',
|
|
13707
|
+
'gemini-1.5-flash-8b-exp-0924',
|
|
13708
|
+
'gemini-1.5-flash-8b-exp-0827',
|
|
13709
|
+
'gemini-1.5-pro-latest',
|
|
13710
|
+
'gemini-1.5-pro',
|
|
13711
|
+
'gemini-1.5-pro-001',
|
|
13712
|
+
'gemini-1.5-pro-002',
|
|
13713
|
+
'gemini-1.5-pro-exp-0827',
|
|
13714
|
+
'gemini-1.0-pro',
|
|
13715
|
+
].map(function (modelName) { return ({ modelName: modelName, modelVariant: 'CHAT' }); }) }, options));
|
|
13716
|
+
}, {
|
|
13717
|
+
packageName: '@promptbook/google',
|
|
13718
|
+
className: 'GoogleExecutionTools',
|
|
13719
|
+
});
|
|
13720
|
+
/**
|
|
13721
|
+
* TODO: [🧠][main] !!!! Make anonymous this with all LLM providers
|
|
13722
|
+
* TODO: [🧠][🧱][main] !!!! Maybe change all `new GoogleExecutionTools` -> `createGoogleExecutionTools` in manual
|
|
13723
|
+
* TODO: [🧠] Maybe auto-detect usage in browser and determine default value of `isProxied`
|
|
13724
|
+
* TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
|
|
13725
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
13726
|
+
*/
|
|
13727
|
+
|
|
13728
|
+
/**
|
|
13729
|
+
* Registration of LLM provider
|
|
13730
|
+
*
|
|
13731
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
13732
|
+
*
|
|
13733
|
+
* @public exported from `@promptbook/google`
|
|
13734
|
+
* @public exported from `@promptbook/cli`
|
|
13735
|
+
*/
|
|
13736
|
+
var _GoogleRegistration = $llmToolsRegister.register(createGoogleExecutionTools);
|
|
13737
|
+
/**
|
|
13738
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
13739
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
13740
|
+
*/
|
|
13741
|
+
|
|
13469
13742
|
/**
|
|
13470
13743
|
* Registration of LLM provider metadata
|
|
13471
13744
|
*
|
|
@@ -13478,6 +13751,7 @@ var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
13478
13751
|
title: 'Open AI',
|
|
13479
13752
|
packageName: '@promptbook/openai',
|
|
13480
13753
|
className: 'OpenAiExecutionTools',
|
|
13754
|
+
envVariables: ['OPENAI_API_KEY'],
|
|
13481
13755
|
getBoilerplateConfiguration: function () {
|
|
13482
13756
|
return {
|
|
13483
13757
|
title: 'Open AI (boilerplate)',
|
|
@@ -13515,6 +13789,9 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
13515
13789
|
title: 'Open AI Assistant',
|
|
13516
13790
|
packageName: '@promptbook/openai',
|
|
13517
13791
|
className: 'OpenAiAssistantExecutionTools',
|
|
13792
|
+
envVariables: [
|
|
13793
|
+
/* TODO: 'OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID' */
|
|
13794
|
+
],
|
|
13518
13795
|
getBoilerplateConfiguration: function () {
|
|
13519
13796
|
return {
|
|
13520
13797
|
title: 'Open AI Assistant (boilerplate)',
|
|
@@ -15369,5 +15646,5 @@ var _WebsiteScraperRegistration = $scrapersRegister.register(createWebsiteScrape
|
|
|
15369
15646
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15370
15647
|
*/
|
|
15371
15648
|
|
|
15372
|
-
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _DocumentScraperMetadataRegistration, _DocumentScraperRegistration, _LegacyDocumentScraperMetadataRegistration, _LegacyDocumentScraperRegistration, _MarkdownScraperMetadataRegistration, _MarkdownScraperRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration, _PdfScraperMetadataRegistration, _PdfScraperRegistration, _WebsiteScraperMetadataRegistration, _WebsiteScraperRegistration };
|
|
15649
|
+
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _DocumentScraperMetadataRegistration, _DocumentScraperRegistration, _GoogleMetadataRegistration, _GoogleRegistration, _LegacyDocumentScraperMetadataRegistration, _LegacyDocumentScraperRegistration, _MarkdownScraperMetadataRegistration, _MarkdownScraperRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration, _PdfScraperMetadataRegistration, _PdfScraperRegistration, _WebsiteScraperMetadataRegistration, _WebsiteScraperRegistration };
|
|
15373
15650
|
//# sourceMappingURL=index.es.js.map
|