@promptbook/node 0.65.0 → 0.66.0-0
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 +86 -56
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +10 -8
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -0
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +2 -1
- package/esm/typings/src/utils/currentDate.d.ts +2 -0
- package/esm/typings/src/utils/deepFreeze.d.ts +2 -1
- package/esm/typings/src/utils/environment/getGlobalScope.d.ts +9 -0
- package/esm/typings/src/utils/environment/isRunningInBrowser.d.ts +8 -0
- package/esm/typings/src/utils/environment/isRunningInNode.d.ts +8 -0
- package/esm/typings/src/utils/environment/isRunningInWebWorker.d.ts +8 -0
- package/esm/typings/src/utils/files/isDirectoryExisting.d.ts +3 -1
- package/esm/typings/src/utils/files/isFileExisting.d.ts +3 -1
- package/esm/typings/src/utils/files/listAllFiles.d.ts +3 -1
- package/esm/typings/src/utils/random/randomSeed.d.ts +1 -0
- package/package.json +4 -4
- package/umd/index.umd.js +86 -56
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +0 -18
package/umd/index.umd.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
/**
|
|
38
38
|
* The version of the Promptbook library
|
|
39
39
|
*/
|
|
40
|
-
var PROMPTBOOK_VERSION = '0.65.0
|
|
40
|
+
var PROMPTBOOK_VERSION = '0.65.0';
|
|
41
41
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
42
42
|
|
|
43
43
|
/*! *****************************************************************************
|
|
@@ -162,12 +162,13 @@
|
|
|
162
162
|
/**
|
|
163
163
|
* @@@
|
|
164
164
|
*
|
|
165
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
165
166
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
166
167
|
*
|
|
167
168
|
* @returns The same object as the input, but deeply frozen
|
|
168
169
|
* @public exported from `@promptbook/utils`
|
|
169
170
|
*/
|
|
170
|
-
function deepFreeze(objectValue) {
|
|
171
|
+
function $deepFreeze(objectValue) {
|
|
171
172
|
var e_1, _a;
|
|
172
173
|
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
173
174
|
try {
|
|
@@ -175,7 +176,7 @@
|
|
|
175
176
|
var propertyName = propertyNames_1_1.value;
|
|
176
177
|
var value = objectValue[propertyName];
|
|
177
178
|
if (value && typeof value === 'object') {
|
|
178
|
-
deepFreeze(value);
|
|
179
|
+
$deepFreeze(value);
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
@@ -198,7 +199,7 @@
|
|
|
198
199
|
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
199
200
|
*/
|
|
200
201
|
function deepFreezeWithSameType(objectValue) {
|
|
201
|
-
return deepFreeze(objectValue);
|
|
202
|
+
return $deepFreeze(objectValue);
|
|
202
203
|
}
|
|
203
204
|
/**
|
|
204
205
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -246,7 +247,7 @@
|
|
|
246
247
|
*
|
|
247
248
|
* @public exported from `@promptbook/core`
|
|
248
249
|
*/
|
|
249
|
-
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
250
|
+
var RESERVED_PARAMETER_NAMES = $deepFreeze([
|
|
250
251
|
'content',
|
|
251
252
|
'context',
|
|
252
253
|
'knowledge',
|
|
@@ -544,7 +545,7 @@
|
|
|
544
545
|
*
|
|
545
546
|
* @public exported from `@promptbook/core`
|
|
546
547
|
*/
|
|
547
|
-
var ZERO_USAGE = deepFreeze({
|
|
548
|
+
var ZERO_USAGE = $deepFreeze({
|
|
548
549
|
price: { value: 0 },
|
|
549
550
|
input: {
|
|
550
551
|
tokensCount: { value: 0 },
|
|
@@ -712,7 +713,7 @@
|
|
|
712
713
|
});
|
|
713
714
|
}
|
|
714
715
|
|
|
715
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.0
|
|
716
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.65.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.65.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.65.0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
716
717
|
|
|
717
718
|
/**
|
|
718
719
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2817,20 +2818,20 @@
|
|
|
2817
2818
|
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
2818
2819
|
}
|
|
2819
2820
|
return [3 /*break*/, 14];
|
|
2820
|
-
case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
|
|
2821
|
+
case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
2821
2822
|
case 9:
|
|
2822
2823
|
chatResult = _u.sent();
|
|
2823
2824
|
// TODO: [🍬] Destroy chatThread
|
|
2824
2825
|
result = chatResult;
|
|
2825
2826
|
resultString = chatResult.content;
|
|
2826
2827
|
return [3 /*break*/, 15];
|
|
2827
|
-
case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
|
|
2828
|
+
case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
2828
2829
|
case 11:
|
|
2829
2830
|
completionResult = _u.sent();
|
|
2830
2831
|
result = completionResult;
|
|
2831
2832
|
resultString = completionResult.content;
|
|
2832
2833
|
return [3 /*break*/, 15];
|
|
2833
|
-
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
|
|
2834
|
+
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
2834
2835
|
case 13:
|
|
2835
2836
|
embeddingResult = _u.sent();
|
|
2836
2837
|
result = embeddingResult;
|
|
@@ -2858,7 +2859,7 @@
|
|
|
2858
2859
|
_u.label = 19;
|
|
2859
2860
|
case 19:
|
|
2860
2861
|
_u.trys.push([19, 21, , 22]);
|
|
2861
|
-
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2862
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
2862
2863
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2863
2864
|
script: preparedContent,
|
|
2864
2865
|
parameters: parameters,
|
|
@@ -2906,7 +2907,7 @@
|
|
|
2906
2907
|
if (tools.userInterface === undefined) {
|
|
2907
2908
|
throw new PipelineExecutionError('User interface tools are not available');
|
|
2908
2909
|
}
|
|
2909
|
-
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2910
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
2910
2911
|
promptTitle: currentTemplate.title,
|
|
2911
2912
|
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
2912
2913
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
@@ -3701,7 +3702,9 @@
|
|
|
3701
3702
|
promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3702
3703
|
// TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
3703
3704
|
TODO_USE(parameters);
|
|
3704
|
-
promptTemplatesPrepared = new Array(
|
|
3705
|
+
promptTemplatesPrepared = new Array(
|
|
3706
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
3707
|
+
promptTemplates.length);
|
|
3705
3708
|
return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3706
3709
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
3707
3710
|
return __generator(this, function (_a) {
|
|
@@ -3774,7 +3777,9 @@
|
|
|
3774
3777
|
// <- TODO: [🧊]
|
|
3775
3778
|
currentPreparation,
|
|
3776
3779
|
];
|
|
3777
|
-
preparedPersonas = new Array(
|
|
3780
|
+
preparedPersonas = new Array(
|
|
3781
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
3782
|
+
personas.length);
|
|
3778
3783
|
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3779
3784
|
var modelRequirements, preparedPersona;
|
|
3780
3785
|
return __generator(this, function (_a) {
|
|
@@ -5851,12 +5856,23 @@
|
|
|
5851
5856
|
return CollectionError;
|
|
5852
5857
|
}(Error));
|
|
5853
5858
|
|
|
5859
|
+
/**
|
|
5860
|
+
* Detects if the code is running in a Node.js environment
|
|
5861
|
+
*
|
|
5862
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
5863
|
+
*
|
|
5864
|
+
* @public exported from `@promptbook/utils`
|
|
5865
|
+
*/
|
|
5866
|
+
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
5867
|
+
|
|
5854
5868
|
/**
|
|
5855
5869
|
* Checks if the file exists
|
|
5856
5870
|
*
|
|
5871
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
5872
|
+
*
|
|
5857
5873
|
* @private within the repository
|
|
5858
5874
|
*/
|
|
5859
|
-
function isFileExisting(filePath) {
|
|
5875
|
+
function $isFileExisting(filePath) {
|
|
5860
5876
|
return __awaiter(this, void 0, void 0, function () {
|
|
5861
5877
|
var isReadAccessAllowed, isFile;
|
|
5862
5878
|
return __generator(this, function (_a) {
|
|
@@ -5888,9 +5904,11 @@
|
|
|
5888
5904
|
/**
|
|
5889
5905
|
* Checks if the directory exists
|
|
5890
5906
|
*
|
|
5907
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
5908
|
+
*
|
|
5891
5909
|
* @private within the repository
|
|
5892
5910
|
*/
|
|
5893
|
-
function isDirectoryExisting(directoryPath) {
|
|
5911
|
+
function $isDirectoryExisting(directoryPath) {
|
|
5894
5912
|
return __awaiter(this, void 0, void 0, function () {
|
|
5895
5913
|
var isReadAccessAllowed, isDirectory;
|
|
5896
5914
|
return __generator(this, function (_a) {
|
|
@@ -5923,18 +5941,20 @@
|
|
|
5923
5941
|
/**
|
|
5924
5942
|
* Reads all files in the directory
|
|
5925
5943
|
*
|
|
5944
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
5945
|
+
*
|
|
5926
5946
|
* @param path
|
|
5927
5947
|
* @param isRecursive
|
|
5928
5948
|
* @returns List of all files in the directory
|
|
5929
5949
|
* @private internal function of `createCollectionFromDirectory`
|
|
5930
5950
|
*/
|
|
5931
|
-
function listAllFiles(path, isRecursive) {
|
|
5951
|
+
function $listAllFiles(path, isRecursive) {
|
|
5932
5952
|
return __awaiter(this, void 0, void 0, function () {
|
|
5933
5953
|
var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
|
|
5934
5954
|
var e_1, _g;
|
|
5935
5955
|
return __generator(this, function (_h) {
|
|
5936
5956
|
switch (_h.label) {
|
|
5937
|
-
case 0: return [4 /*yield*/, isDirectoryExisting(path)];
|
|
5957
|
+
case 0: return [4 /*yield*/, $isDirectoryExisting(path)];
|
|
5938
5958
|
case 1:
|
|
5939
5959
|
if (!(_h.sent())) {
|
|
5940
5960
|
throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
|
|
@@ -5962,7 +5982,7 @@
|
|
|
5962
5982
|
_d = (_c = fileNames.push).apply;
|
|
5963
5983
|
_e = [fileNames];
|
|
5964
5984
|
_f = [[]];
|
|
5965
|
-
return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
|
|
5985
|
+
return [4 /*yield*/, $listAllFiles(subPath, isRecursive)];
|
|
5966
5986
|
case 5:
|
|
5967
5987
|
_d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
5968
5988
|
_h.label = 6;
|
|
@@ -5990,25 +6010,6 @@
|
|
|
5990
6010
|
* TODO: [🖇] What about symlinks?
|
|
5991
6011
|
*/
|
|
5992
6012
|
|
|
5993
|
-
/**
|
|
5994
|
-
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
5995
|
-
*
|
|
5996
|
-
* @public exported from `@promptbook/utils`
|
|
5997
|
-
*/
|
|
5998
|
-
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
5999
|
-
/**
|
|
6000
|
-
* Detects if the code is running in a Node.js environment
|
|
6001
|
-
*
|
|
6002
|
-
* @public exported from `@promptbook/utils`
|
|
6003
|
-
*/
|
|
6004
|
-
var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
6005
|
-
/**
|
|
6006
|
-
* Detects if the code is running in a web worker
|
|
6007
|
-
*
|
|
6008
|
-
* @public exported from `@promptbook/utils`
|
|
6009
|
-
*/
|
|
6010
|
-
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
6011
|
-
|
|
6012
6013
|
/**
|
|
6013
6014
|
* Constructs Promptbook from async sources
|
|
6014
6015
|
* It can be one of the following:
|
|
@@ -6113,11 +6114,11 @@
|
|
|
6113
6114
|
return __generator(this, function (_f) {
|
|
6114
6115
|
switch (_f.label) {
|
|
6115
6116
|
case 0:
|
|
6116
|
-
if (
|
|
6117
|
+
if (!$isRunningInNode()) {
|
|
6117
6118
|
throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
6118
6119
|
}
|
|
6119
6120
|
makedLibraryFilePath = path.join(path$1, "".concat(PIPELINE_COLLECTION_BASE_FILENAME, ".json"));
|
|
6120
|
-
return [4 /*yield*/, isFileExisting(makedLibraryFilePath)];
|
|
6121
|
+
return [4 /*yield*/, $isFileExisting(makedLibraryFilePath)];
|
|
6121
6122
|
case 1:
|
|
6122
6123
|
if (!(_f.sent())) {
|
|
6123
6124
|
console.info(colors__default["default"].yellow("Tip: Prebuild your pipeline collection (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"ptbk make\" to speed up the collection creation.")));
|
|
@@ -6137,7 +6138,7 @@
|
|
|
6137
6138
|
if (isVerbose) {
|
|
6138
6139
|
console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
|
|
6139
6140
|
}
|
|
6140
|
-
return [4 /*yield*/, listAllFiles(path$1, isRecursive)];
|
|
6141
|
+
return [4 /*yield*/, $listAllFiles(path$1, isRecursive)];
|
|
6141
6142
|
case 1:
|
|
6142
6143
|
fileNames = _b.sent();
|
|
6143
6144
|
// Note: First load all .ptbk.json and then .ptbk.md files
|
|
@@ -6315,7 +6316,7 @@
|
|
|
6315
6316
|
* @public exported from `@promptbook/node`
|
|
6316
6317
|
*/
|
|
6317
6318
|
function createLlmToolsFromConfigurationFromEnv() {
|
|
6318
|
-
if (
|
|
6319
|
+
if (!$isRunningInNode()) {
|
|
6319
6320
|
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
6320
6321
|
}
|
|
6321
6322
|
dotenv__namespace.config();
|
|
@@ -6386,7 +6387,9 @@
|
|
|
6386
6387
|
*/
|
|
6387
6388
|
RemoteLlmExecutionTools.prototype.makeConnection = function () {
|
|
6388
6389
|
var _this = this;
|
|
6389
|
-
return new Promise(
|
|
6390
|
+
return new Promise(
|
|
6391
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
6392
|
+
function (resolve, reject) {
|
|
6390
6393
|
var socket = socket_ioClient.io(_this.options.remoteUrl, {
|
|
6391
6394
|
path: _this.options.path,
|
|
6392
6395
|
// path: `${this.remoteUrl.pathname}/socket.io`,
|
|
@@ -6508,12 +6511,21 @@
|
|
|
6508
6511
|
/**
|
|
6509
6512
|
* List of available Anthropic Claude models with pricing
|
|
6510
6513
|
*
|
|
6511
|
-
* Note: Done at 2024-
|
|
6514
|
+
* Note: Done at 2024-08-16
|
|
6512
6515
|
*
|
|
6513
6516
|
* @see https://docs.anthropic.com/en/docs/models-overview
|
|
6514
6517
|
* @public exported from `@promptbook/anthropic-claude`
|
|
6515
6518
|
*/
|
|
6516
6519
|
var ANTHROPIC_CLAUDE_MODELS = [
|
|
6520
|
+
{
|
|
6521
|
+
modelVariant: 'CHAT',
|
|
6522
|
+
modelTitle: 'Claude 3.5 Sonnet',
|
|
6523
|
+
modelName: 'claude-3-5-sonnet-20240620',
|
|
6524
|
+
pricing: {
|
|
6525
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
6526
|
+
output: computeUsage("$15.00 / 1M tokens"),
|
|
6527
|
+
},
|
|
6528
|
+
},
|
|
6517
6529
|
{
|
|
6518
6530
|
modelVariant: 'CHAT',
|
|
6519
6531
|
modelTitle: 'Claude 3 Opus',
|
|
@@ -6575,7 +6587,7 @@
|
|
|
6575
6587
|
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
6576
6588
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
6577
6589
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
6578
|
-
* TODO: [
|
|
6590
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
6579
6591
|
*/
|
|
6580
6592
|
|
|
6581
6593
|
/**
|
|
@@ -6639,7 +6651,9 @@
|
|
|
6639
6651
|
var anthropicOptions = __assign({}, options);
|
|
6640
6652
|
delete anthropicOptions.isVerbose;
|
|
6641
6653
|
delete anthropicOptions.isProxied;
|
|
6642
|
-
this.client = new Anthropic__default["default"](
|
|
6654
|
+
this.client = new Anthropic__default["default"](
|
|
6655
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
6656
|
+
anthropicOptions);
|
|
6643
6657
|
}
|
|
6644
6658
|
Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
|
|
6645
6659
|
get: function () {
|
|
@@ -6660,7 +6674,7 @@
|
|
|
6660
6674
|
*/
|
|
6661
6675
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
6662
6676
|
return __awaiter(this, void 0, void 0, function () {
|
|
6663
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6677
|
+
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
6664
6678
|
return __generator(this, function (_a) {
|
|
6665
6679
|
switch (_a.label) {
|
|
6666
6680
|
case 0:
|
|
@@ -6706,11 +6720,16 @@
|
|
|
6706
6720
|
if (rawResponse.content.length > 1) {
|
|
6707
6721
|
throw new PipelineExecutionError('More than one content blocks from Anthropic Claude');
|
|
6708
6722
|
}
|
|
6709
|
-
|
|
6723
|
+
contentBlock = rawResponse.content[0];
|
|
6724
|
+
if (contentBlock.type !== 'text') {
|
|
6725
|
+
throw new PipelineExecutionError("Returned content is not \"text\" type but \"".concat(contentBlock.type, "\""));
|
|
6726
|
+
}
|
|
6727
|
+
console.log('!!!!!! rawResponse.usage', rawResponse.usage);
|
|
6728
|
+
resultContent = contentBlock.text;
|
|
6710
6729
|
// eslint-disable-next-line prefer-const
|
|
6711
6730
|
complete = getCurrentIsoDate();
|
|
6712
6731
|
usage = {
|
|
6713
|
-
price: { value: 0, isUncertain: true } /* <- TODO: [🐞] Compute usage */,
|
|
6732
|
+
price: { value: 0, isUncertain: true } /* <- TODO: [🐞] !!!!!! Compute usage */,
|
|
6714
6733
|
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
|
|
6715
6734
|
output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
|
|
6716
6735
|
};
|
|
@@ -6861,7 +6880,9 @@
|
|
|
6861
6880
|
},
|
|
6862
6881
|
], models: ANTHROPIC_CLAUDE_MODELS }));
|
|
6863
6882
|
}
|
|
6864
|
-
return new AnthropicClaudeExecutionTools(
|
|
6883
|
+
return new AnthropicClaudeExecutionTools(
|
|
6884
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
6885
|
+
options);
|
|
6865
6886
|
}
|
|
6866
6887
|
/**
|
|
6867
6888
|
* TODO: [🧠] !!!! Make anonymous this with all LLM providers
|
|
@@ -7210,7 +7231,8 @@
|
|
|
7210
7231
|
/**
|
|
7211
7232
|
* Note: [🤖] Add models of new variant
|
|
7212
7233
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
7213
|
-
* TODO: [
|
|
7234
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
7235
|
+
* TODO: [🎰][👮♀️] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
|
|
7214
7236
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
7215
7237
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
7216
7238
|
* @see https://openai.com/api/pricing/
|
|
@@ -7233,7 +7255,11 @@
|
|
|
7233
7255
|
*/
|
|
7234
7256
|
function AzureOpenAiExecutionTools(options) {
|
|
7235
7257
|
this.options = options;
|
|
7236
|
-
this.client = new openai.OpenAIClient(
|
|
7258
|
+
this.client = new openai.OpenAIClient(
|
|
7259
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
7260
|
+
"https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(
|
|
7261
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
7262
|
+
options.apiKey));
|
|
7237
7263
|
}
|
|
7238
7264
|
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
7239
7265
|
get: function () {
|
|
@@ -7816,7 +7842,11 @@
|
|
|
7816
7842
|
return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
|
|
7817
7843
|
},
|
|
7818
7844
|
createAnthropicClaudeExecutionTools: createAnthropicClaudeExecutionTools,
|
|
7819
|
-
createAzureOpenAiExecutionTools: function (options) {
|
|
7845
|
+
createAzureOpenAiExecutionTools: function (options) {
|
|
7846
|
+
return new AzureOpenAiExecutionTools(
|
|
7847
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
7848
|
+
options);
|
|
7849
|
+
},
|
|
7820
7850
|
// <- Note: [🦑] Add here new LLM provider
|
|
7821
7851
|
};
|
|
7822
7852
|
/**
|
|
@@ -7865,7 +7895,7 @@
|
|
|
7865
7895
|
*/
|
|
7866
7896
|
function createLlmToolsFromEnv(options) {
|
|
7867
7897
|
if (options === void 0) { options = {}; }
|
|
7868
|
-
if (
|
|
7898
|
+
if (!$isRunningInNode()) {
|
|
7869
7899
|
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
7870
7900
|
}
|
|
7871
7901
|
var configuration = createLlmToolsFromConfigurationFromEnv();
|
|
@@ -7925,7 +7955,7 @@
|
|
|
7925
7955
|
var FilesStorage = /** @class */ (function () {
|
|
7926
7956
|
function FilesStorage(options) {
|
|
7927
7957
|
this.options = options;
|
|
7928
|
-
if (
|
|
7958
|
+
if (!$isRunningInNode()) {
|
|
7929
7959
|
throw new EnvironmentMismatchError("FilesStorage works only in Node.js environment");
|
|
7930
7960
|
}
|
|
7931
7961
|
}
|
|
@@ -7948,7 +7978,7 @@
|
|
|
7948
7978
|
switch (_a.label) {
|
|
7949
7979
|
case 0:
|
|
7950
7980
|
filename = this.getFilenameForKey(key);
|
|
7951
|
-
return [4 /*yield*/, isFileExisting(filename)];
|
|
7981
|
+
return [4 /*yield*/, $isFileExisting(filename)];
|
|
7952
7982
|
case 1:
|
|
7953
7983
|
if (!(_a.sent())) {
|
|
7954
7984
|
return [2 /*return*/, null];
|