@promptbook/cli 0.77.0-3 → 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/esm/index.es.js +408 -347
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +11 -0
- 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/openai/register-configuration.d.ts +1 -1
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +8 -0
- package/package.json +1 -1
- package/umd/index.umd.js +408 -347
- package/umd/index.umd.js.map +1 -1
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.77.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
|
*
|
|
@@ -4733,218 +5023,79 @@ function createPipelineExecutor(options) {
|
|
|
4733
5023
|
})];
|
|
4734
5024
|
});
|
|
4735
5025
|
}); };
|
|
4736
|
-
return pipelineExecutor;
|
|
4737
|
-
}
|
|
4738
|
-
/**
|
|
4739
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4740
|
-
*/
|
|
4741
|
-
|
|
4742
|
-
/**
|
|
4743
|
-
* Prepares the persona for the pipeline
|
|
4744
|
-
*
|
|
4745
|
-
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
4746
|
-
* @public exported from `@promptbook/core`
|
|
4747
|
-
*/
|
|
4748
|
-
function preparePersona(personaDescription, tools, options) {
|
|
4749
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
4750
|
-
var _a, isVerbose, collection, preparePersonaExecutor, _b, _llms, llmTools, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
4751
|
-
var _c;
|
|
4752
|
-
return __generator(this, function (_d) {
|
|
4753
|
-
switch (_d.label) {
|
|
4754
|
-
case 0:
|
|
4755
|
-
_a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
|
|
4756
|
-
if (tools === undefined || tools.llm === undefined) {
|
|
4757
|
-
throw new MissingToolsError('LLM tools are required for preparing persona');
|
|
4758
|
-
}
|
|
4759
|
-
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
4760
|
-
_b = createPipelineExecutor;
|
|
4761
|
-
_c = {};
|
|
4762
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book.md')];
|
|
4763
|
-
case 1:
|
|
4764
|
-
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
4765
|
-
_c.tools = tools,
|
|
4766
|
-
_c)]);
|
|
4767
|
-
_llms = arrayableToArray(tools.llm);
|
|
4768
|
-
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
4769
|
-
return [4 /*yield*/, llmTools.listModels()];
|
|
4770
|
-
case 2:
|
|
4771
|
-
availableModels = _d.sent();
|
|
4772
|
-
availableModelNames = availableModels
|
|
4773
|
-
.filter(function (_a) {
|
|
4774
|
-
var modelVariant = _a.modelVariant;
|
|
4775
|
-
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;
|
|
5026
|
+
return pipelineExecutor;
|
|
4877
5027
|
}
|
|
4878
5028
|
/**
|
|
4879
|
-
* TODO:
|
|
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
|
|
5029
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4885
5030
|
*/
|
|
4886
5031
|
|
|
4887
5032
|
/**
|
|
4888
|
-
*
|
|
5033
|
+
* Prepares the persona for the pipeline
|
|
4889
5034
|
*
|
|
4890
|
-
* @
|
|
4891
|
-
* @
|
|
4892
|
-
* @example 'hello_world'
|
|
4893
|
-
* @example 'i_love_promptbook'
|
|
4894
|
-
* @public exported from `@promptbook/utils`
|
|
5035
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
5036
|
+
* @public exported from `@promptbook/core`
|
|
4895
5037
|
*/
|
|
4896
|
-
function
|
|
4897
|
-
return
|
|
5038
|
+
function preparePersona(personaDescription, tools, options) {
|
|
5039
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5040
|
+
var _a, isVerbose, collection, preparePersonaExecutor, _b, _llms, llmTools, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
5041
|
+
var _c;
|
|
5042
|
+
return __generator(this, function (_d) {
|
|
5043
|
+
switch (_d.label) {
|
|
5044
|
+
case 0:
|
|
5045
|
+
_a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
|
|
5046
|
+
if (tools === undefined || tools.llm === undefined) {
|
|
5047
|
+
throw new MissingToolsError('LLM tools are required for preparing persona');
|
|
5048
|
+
}
|
|
5049
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
5050
|
+
_b = createPipelineExecutor;
|
|
5051
|
+
_c = {};
|
|
5052
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book.md')];
|
|
5053
|
+
case 1:
|
|
5054
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
5055
|
+
_c.tools = tools,
|
|
5056
|
+
_c)]);
|
|
5057
|
+
_llms = arrayableToArray(tools.llm);
|
|
5058
|
+
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
5059
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
5060
|
+
case 2:
|
|
5061
|
+
availableModels = _d.sent();
|
|
5062
|
+
availableModelNames = availableModels
|
|
5063
|
+
.filter(function (_a) {
|
|
5064
|
+
var modelVariant = _a.modelVariant;
|
|
5065
|
+
return modelVariant === 'CHAT';
|
|
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
|
+
});
|
|
4898
5092
|
}
|
|
4899
|
-
|
|
4900
5093
|
/**
|
|
4901
|
-
*
|
|
4902
|
-
*
|
|
4903
|
-
*
|
|
4904
|
-
*
|
|
4905
|
-
* @private internal utility, exported are only signleton instances of this class
|
|
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
|
|
4906
5098
|
*/
|
|
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
|
-
}());
|
|
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,15 @@ 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
|
+
|
|
13469
13515
|
/**
|
|
13470
13516
|
* Registration of LLM provider metadata
|
|
13471
13517
|
*
|
|
@@ -13478,6 +13524,7 @@ var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
13478
13524
|
title: 'Google Gemini',
|
|
13479
13525
|
packageName: '@promptbook/google',
|
|
13480
13526
|
className: 'GoogleExecutionTools',
|
|
13527
|
+
envVariables: ['GOOGLE_GENERATIVE_AI_API_KEY'],
|
|
13481
13528
|
getBoilerplateConfiguration: function () {
|
|
13482
13529
|
return {
|
|
13483
13530
|
title: 'Google Gemini (boilerplate)',
|
|
@@ -13492,14 +13539,20 @@ var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
13492
13539
|
};
|
|
13493
13540
|
},
|
|
13494
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
|
+
}
|
|
13495
13548
|
// Note: Note using `process.env` BUT `env` to pass in the environment variables dynamically
|
|
13496
|
-
if (typeof env.
|
|
13549
|
+
if (typeof env.GOOGLE_GENERATIVE_AI_API_KEY === 'string') {
|
|
13497
13550
|
return {
|
|
13498
13551
|
title: 'Google Gemini (from env)',
|
|
13499
13552
|
packageName: '@promptbook/google',
|
|
13500
13553
|
className: 'GoogleExecutionTools',
|
|
13501
13554
|
options: {
|
|
13502
|
-
apiKey: env.
|
|
13555
|
+
apiKey: env.GOOGLE_GENERATIVE_AI_API_KEY,
|
|
13503
13556
|
},
|
|
13504
13557
|
};
|
|
13505
13558
|
}
|
|
@@ -13634,6 +13687,10 @@ function createExecutionToolsFromVercelProvider(options) {
|
|
|
13634
13687
|
* @public exported from `@promptbook/google`
|
|
13635
13688
|
*/
|
|
13636
13689
|
var createGoogleExecutionTools = Object.assign(function (options) {
|
|
13690
|
+
if ($isRunningInJest()) {
|
|
13691
|
+
// Note: [🔘]
|
|
13692
|
+
throw new Error('GoogleExecutionTools are not supported in Jest environment');
|
|
13693
|
+
}
|
|
13637
13694
|
// Note: [🔘] There is a compatibility when using import from '@ai-sdk/google'
|
|
13638
13695
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
13639
13696
|
var createGoogleGenerativeAI = require('@ai-sdk/google').createGoogleGenerativeAI;
|
|
@@ -13694,6 +13751,7 @@ var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
13694
13751
|
title: 'Open AI',
|
|
13695
13752
|
packageName: '@promptbook/openai',
|
|
13696
13753
|
className: 'OpenAiExecutionTools',
|
|
13754
|
+
envVariables: ['OPENAI_API_KEY'],
|
|
13697
13755
|
getBoilerplateConfiguration: function () {
|
|
13698
13756
|
return {
|
|
13699
13757
|
title: 'Open AI (boilerplate)',
|
|
@@ -13731,6 +13789,9 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
13731
13789
|
title: 'Open AI Assistant',
|
|
13732
13790
|
packageName: '@promptbook/openai',
|
|
13733
13791
|
className: 'OpenAiAssistantExecutionTools',
|
|
13792
|
+
envVariables: [
|
|
13793
|
+
/* TODO: 'OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID' */
|
|
13794
|
+
],
|
|
13734
13795
|
getBoilerplateConfiguration: function () {
|
|
13735
13796
|
return {
|
|
13736
13797
|
title: 'Open AI Assistant (boilerplate)',
|