@promptbook/cli 0.65.0-7 → 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/README.md +4 -1
- package/esm/index.es.js +94 -57
- 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/AnthropicClaudeExecutionTools.d.ts +0 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -2
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +3 -2
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +1 -1
- 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/llm-providers/remote/RemoteLlmExecutionTools.d.ts +0 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +0 -3
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +0 -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 +3 -3
- package/umd/index.umd.js +94 -57
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +0 -18
package/README.md
CHANGED
|
@@ -63,7 +63,10 @@ const promptbook = await getPipelineCollection().getPipelineByUrl(
|
|
|
63
63
|
// ▶ Prepare tools
|
|
64
64
|
const tools = {
|
|
65
65
|
llm: createLlmToolsFromEnv(),
|
|
66
|
-
script: [
|
|
66
|
+
script: [
|
|
67
|
+
new JavascriptExecutionTools(),
|
|
68
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
69
|
+
],
|
|
67
70
|
};
|
|
68
71
|
|
|
69
72
|
// ▶ Create executor - the function that will execute the Pipeline
|
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ import glob from 'glob-promise';
|
|
|
20
20
|
/**
|
|
21
21
|
* The version of the Promptbook library
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_VERSION = '0.65.0
|
|
23
|
+
var PROMPTBOOK_VERSION = '0.65.0';
|
|
24
24
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
25
25
|
|
|
26
26
|
/*! *****************************************************************************
|
|
@@ -158,34 +158,25 @@ var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
|
158
158
|
return EnvironmentMismatchError;
|
|
159
159
|
}(Error));
|
|
160
160
|
|
|
161
|
-
/**
|
|
162
|
-
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
163
|
-
*
|
|
164
|
-
* @public exported from `@promptbook/utils`
|
|
165
|
-
*/
|
|
166
|
-
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
167
161
|
/**
|
|
168
162
|
* Detects if the code is running in a Node.js environment
|
|
169
163
|
*
|
|
170
|
-
*
|
|
171
|
-
*/
|
|
172
|
-
var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
173
|
-
/**
|
|
174
|
-
* Detects if the code is running in a web worker
|
|
164
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
175
165
|
*
|
|
176
166
|
* @public exported from `@promptbook/utils`
|
|
177
167
|
*/
|
|
178
|
-
new Function("\n try {\n
|
|
168
|
+
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
179
169
|
|
|
180
170
|
/**
|
|
181
171
|
* @@@
|
|
182
172
|
*
|
|
173
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
183
174
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
184
175
|
*
|
|
185
176
|
* @returns The same object as the input, but deeply frozen
|
|
186
177
|
* @public exported from `@promptbook/utils`
|
|
187
178
|
*/
|
|
188
|
-
function deepFreeze(objectValue) {
|
|
179
|
+
function $deepFreeze(objectValue) {
|
|
189
180
|
var e_1, _a;
|
|
190
181
|
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
191
182
|
try {
|
|
@@ -193,7 +184,7 @@ function deepFreeze(objectValue) {
|
|
|
193
184
|
var propertyName = propertyNames_1_1.value;
|
|
194
185
|
var value = objectValue[propertyName];
|
|
195
186
|
if (value && typeof value === 'object') {
|
|
196
|
-
deepFreeze(value);
|
|
187
|
+
$deepFreeze(value);
|
|
197
188
|
}
|
|
198
189
|
}
|
|
199
190
|
}
|
|
@@ -216,7 +207,7 @@ function deepFreeze(objectValue) {
|
|
|
216
207
|
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
217
208
|
*/
|
|
218
209
|
function deepFreezeWithSameType(objectValue) {
|
|
219
|
-
return deepFreeze(objectValue);
|
|
210
|
+
return $deepFreeze(objectValue);
|
|
220
211
|
}
|
|
221
212
|
/**
|
|
222
213
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -290,7 +281,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
290
281
|
*
|
|
291
282
|
* @public exported from `@promptbook/core`
|
|
292
283
|
*/
|
|
293
|
-
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
284
|
+
var RESERVED_PARAMETER_NAMES = $deepFreeze([
|
|
294
285
|
'content',
|
|
295
286
|
'context',
|
|
296
287
|
'knowledge',
|
|
@@ -673,7 +664,7 @@ function deepClone(objectValue) {
|
|
|
673
664
|
*
|
|
674
665
|
* @public exported from `@promptbook/core`
|
|
675
666
|
*/
|
|
676
|
-
var ZERO_USAGE = deepFreeze({
|
|
667
|
+
var ZERO_USAGE = $deepFreeze({
|
|
677
668
|
price: { value: 0 },
|
|
678
669
|
input: {
|
|
679
670
|
tokensCount: { value: 0 },
|
|
@@ -841,7 +832,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
841
832
|
});
|
|
842
833
|
}
|
|
843
834
|
|
|
844
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.0
|
|
835
|
+
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"}];
|
|
845
836
|
|
|
846
837
|
/**
|
|
847
838
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2946,20 +2937,20 @@ function createPipelineExecutor(options) {
|
|
|
2946
2937
|
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
2947
2938
|
}
|
|
2948
2939
|
return [3 /*break*/, 14];
|
|
2949
|
-
case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
|
|
2940
|
+
case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
2950
2941
|
case 9:
|
|
2951
2942
|
chatResult = _u.sent();
|
|
2952
2943
|
// TODO: [🍬] Destroy chatThread
|
|
2953
2944
|
result = chatResult;
|
|
2954
2945
|
resultString = chatResult.content;
|
|
2955
2946
|
return [3 /*break*/, 15];
|
|
2956
|
-
case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
|
|
2947
|
+
case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
2957
2948
|
case 11:
|
|
2958
2949
|
completionResult = _u.sent();
|
|
2959
2950
|
result = completionResult;
|
|
2960
2951
|
resultString = completionResult.content;
|
|
2961
2952
|
return [3 /*break*/, 15];
|
|
2962
|
-
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
|
|
2953
|
+
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
2963
2954
|
case 13:
|
|
2964
2955
|
embeddingResult = _u.sent();
|
|
2965
2956
|
result = embeddingResult;
|
|
@@ -2987,7 +2978,7 @@ function createPipelineExecutor(options) {
|
|
|
2987
2978
|
_u.label = 19;
|
|
2988
2979
|
case 19:
|
|
2989
2980
|
_u.trys.push([19, 21, , 22]);
|
|
2990
|
-
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2981
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
2991
2982
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2992
2983
|
script: preparedContent,
|
|
2993
2984
|
parameters: parameters,
|
|
@@ -3035,7 +3026,7 @@ function createPipelineExecutor(options) {
|
|
|
3035
3026
|
if (tools.userInterface === undefined) {
|
|
3036
3027
|
throw new PipelineExecutionError('User interface tools are not available');
|
|
3037
3028
|
}
|
|
3038
|
-
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
3029
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3039
3030
|
promptTitle: currentTemplate.title,
|
|
3040
3031
|
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3041
3032
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
@@ -3830,7 +3821,9 @@ function prepareTemplates(pipeline, options) {
|
|
|
3830
3821
|
promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3831
3822
|
// TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
3832
3823
|
TODO_USE(parameters);
|
|
3833
|
-
promptTemplatesPrepared = new Array(
|
|
3824
|
+
promptTemplatesPrepared = new Array(
|
|
3825
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
3826
|
+
promptTemplates.length);
|
|
3834
3827
|
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 () {
|
|
3835
3828
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
3836
3829
|
return __generator(this, function (_a) {
|
|
@@ -3903,7 +3896,9 @@ function preparePipeline(pipeline, options) {
|
|
|
3903
3896
|
// <- TODO: [🧊]
|
|
3904
3897
|
currentPreparation,
|
|
3905
3898
|
];
|
|
3906
|
-
preparedPersonas = new Array(
|
|
3899
|
+
preparedPersonas = new Array(
|
|
3900
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
3901
|
+
personas.length);
|
|
3907
3902
|
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 () {
|
|
3908
3903
|
var modelRequirements, preparedPersona;
|
|
3909
3904
|
return __generator(this, function (_a) {
|
|
@@ -5983,9 +5978,11 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
5983
5978
|
/**
|
|
5984
5979
|
* Checks if the file exists
|
|
5985
5980
|
*
|
|
5981
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
5982
|
+
*
|
|
5986
5983
|
* @private within the repository
|
|
5987
5984
|
*/
|
|
5988
|
-
function isFileExisting(filePath) {
|
|
5985
|
+
function $isFileExisting(filePath) {
|
|
5989
5986
|
return __awaiter(this, void 0, void 0, function () {
|
|
5990
5987
|
var isReadAccessAllowed, isFile;
|
|
5991
5988
|
return __generator(this, function (_a) {
|
|
@@ -6017,9 +6014,11 @@ function isFileExisting(filePath) {
|
|
|
6017
6014
|
/**
|
|
6018
6015
|
* Checks if the directory exists
|
|
6019
6016
|
*
|
|
6017
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
6018
|
+
*
|
|
6020
6019
|
* @private within the repository
|
|
6021
6020
|
*/
|
|
6022
|
-
function isDirectoryExisting(directoryPath) {
|
|
6021
|
+
function $isDirectoryExisting(directoryPath) {
|
|
6023
6022
|
return __awaiter(this, void 0, void 0, function () {
|
|
6024
6023
|
var isReadAccessAllowed, isDirectory;
|
|
6025
6024
|
return __generator(this, function (_a) {
|
|
@@ -6052,18 +6051,20 @@ function isDirectoryExisting(directoryPath) {
|
|
|
6052
6051
|
/**
|
|
6053
6052
|
* Reads all files in the directory
|
|
6054
6053
|
*
|
|
6054
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
6055
|
+
*
|
|
6055
6056
|
* @param path
|
|
6056
6057
|
* @param isRecursive
|
|
6057
6058
|
* @returns List of all files in the directory
|
|
6058
6059
|
* @private internal function of `createCollectionFromDirectory`
|
|
6059
6060
|
*/
|
|
6060
|
-
function listAllFiles(path, isRecursive) {
|
|
6061
|
+
function $listAllFiles(path, isRecursive) {
|
|
6061
6062
|
return __awaiter(this, void 0, void 0, function () {
|
|
6062
6063
|
var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
|
|
6063
6064
|
var e_1, _g;
|
|
6064
6065
|
return __generator(this, function (_h) {
|
|
6065
6066
|
switch (_h.label) {
|
|
6066
|
-
case 0: return [4 /*yield*/, isDirectoryExisting(path)];
|
|
6067
|
+
case 0: return [4 /*yield*/, $isDirectoryExisting(path)];
|
|
6067
6068
|
case 1:
|
|
6068
6069
|
if (!(_h.sent())) {
|
|
6069
6070
|
throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
|
|
@@ -6091,7 +6092,7 @@ function listAllFiles(path, isRecursive) {
|
|
|
6091
6092
|
_d = (_c = fileNames.push).apply;
|
|
6092
6093
|
_e = [fileNames];
|
|
6093
6094
|
_f = [[]];
|
|
6094
|
-
return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
|
|
6095
|
+
return [4 /*yield*/, $listAllFiles(subPath, isRecursive)];
|
|
6095
6096
|
case 5:
|
|
6096
6097
|
_d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
6097
6098
|
_h.label = 6;
|
|
@@ -6223,11 +6224,11 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6223
6224
|
return __generator(this, function (_f) {
|
|
6224
6225
|
switch (_f.label) {
|
|
6225
6226
|
case 0:
|
|
6226
|
-
if (
|
|
6227
|
+
if (!$isRunningInNode()) {
|
|
6227
6228
|
throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
6228
6229
|
}
|
|
6229
6230
|
makedLibraryFilePath = join$1(path, "".concat(PIPELINE_COLLECTION_BASE_FILENAME, ".json"));
|
|
6230
|
-
return [4 /*yield*/, isFileExisting(makedLibraryFilePath)];
|
|
6231
|
+
return [4 /*yield*/, $isFileExisting(makedLibraryFilePath)];
|
|
6231
6232
|
case 1:
|
|
6232
6233
|
if (!(_f.sent())) {
|
|
6233
6234
|
console.info(colors.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.")));
|
|
@@ -6247,7 +6248,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6247
6248
|
if (isVerbose) {
|
|
6248
6249
|
console.info(colors.cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
|
|
6249
6250
|
}
|
|
6250
|
-
return [4 /*yield*/, listAllFiles(path, isRecursive)];
|
|
6251
|
+
return [4 /*yield*/, $listAllFiles(path, isRecursive)];
|
|
6251
6252
|
case 1:
|
|
6252
6253
|
fileNames = _b.sent();
|
|
6253
6254
|
// Note: First load all .ptbk.json and then .ptbk.md files
|
|
@@ -6482,7 +6483,7 @@ function nameToSubfolderPath(name) {
|
|
|
6482
6483
|
var FilesStorage = /** @class */ (function () {
|
|
6483
6484
|
function FilesStorage(options) {
|
|
6484
6485
|
this.options = options;
|
|
6485
|
-
if (
|
|
6486
|
+
if (!$isRunningInNode()) {
|
|
6486
6487
|
throw new EnvironmentMismatchError("FilesStorage works only in Node.js environment");
|
|
6487
6488
|
}
|
|
6488
6489
|
}
|
|
@@ -6505,7 +6506,7 @@ var FilesStorage = /** @class */ (function () {
|
|
|
6505
6506
|
switch (_a.label) {
|
|
6506
6507
|
case 0:
|
|
6507
6508
|
filename = this.getFilenameForKey(key);
|
|
6508
|
-
return [4 /*yield*/, isFileExisting(filename)];
|
|
6509
|
+
return [4 /*yield*/, $isFileExisting(filename)];
|
|
6509
6510
|
case 1:
|
|
6510
6511
|
if (!(_a.sent())) {
|
|
6511
6512
|
return [2 /*return*/, null];
|
|
@@ -6602,7 +6603,9 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
6602
6603
|
*/
|
|
6603
6604
|
RemoteLlmExecutionTools.prototype.makeConnection = function () {
|
|
6604
6605
|
var _this = this;
|
|
6605
|
-
return new Promise(
|
|
6606
|
+
return new Promise(
|
|
6607
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
6608
|
+
function (resolve, reject) {
|
|
6606
6609
|
var socket = io(_this.options.remoteUrl, {
|
|
6607
6610
|
path: _this.options.path,
|
|
6608
6611
|
// path: `${this.remoteUrl.pathname}/socket.io`,
|
|
@@ -6705,7 +6708,6 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
6705
6708
|
return RemoteLlmExecutionTools;
|
|
6706
6709
|
}());
|
|
6707
6710
|
/**
|
|
6708
|
-
* TODO: [🍜] !!!!!! Default remote remoteUrl and path for anonymous server
|
|
6709
6711
|
* TODO: [🍓] Allow to list compatible models with each variant
|
|
6710
6712
|
* TODO: [🗯] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
|
|
6711
6713
|
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
@@ -6725,12 +6727,21 @@ function computeUsage(value) {
|
|
|
6725
6727
|
/**
|
|
6726
6728
|
* List of available Anthropic Claude models with pricing
|
|
6727
6729
|
*
|
|
6728
|
-
* Note: Done at 2024-
|
|
6730
|
+
* Note: Done at 2024-08-16
|
|
6729
6731
|
*
|
|
6730
6732
|
* @see https://docs.anthropic.com/en/docs/models-overview
|
|
6731
6733
|
* @public exported from `@promptbook/anthropic-claude`
|
|
6732
6734
|
*/
|
|
6733
6735
|
var ANTHROPIC_CLAUDE_MODELS = [
|
|
6736
|
+
{
|
|
6737
|
+
modelVariant: 'CHAT',
|
|
6738
|
+
modelTitle: 'Claude 3.5 Sonnet',
|
|
6739
|
+
modelName: 'claude-3-5-sonnet-20240620',
|
|
6740
|
+
pricing: {
|
|
6741
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
6742
|
+
output: computeUsage("$15.00 / 1M tokens"),
|
|
6743
|
+
},
|
|
6744
|
+
},
|
|
6734
6745
|
{
|
|
6735
6746
|
modelVariant: 'CHAT',
|
|
6736
6747
|
modelTitle: 'Claude 3 Opus',
|
|
@@ -6792,7 +6803,7 @@ var ANTHROPIC_CLAUDE_MODELS = [
|
|
|
6792
6803
|
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
6793
6804
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
6794
6805
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
6795
|
-
* TODO: [
|
|
6806
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
6796
6807
|
*/
|
|
6797
6808
|
|
|
6798
6809
|
/**
|
|
@@ -6856,7 +6867,9 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6856
6867
|
var anthropicOptions = __assign({}, options);
|
|
6857
6868
|
delete anthropicOptions.isVerbose;
|
|
6858
6869
|
delete anthropicOptions.isProxied;
|
|
6859
|
-
this.client = new Anthropic(
|
|
6870
|
+
this.client = new Anthropic(
|
|
6871
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
6872
|
+
anthropicOptions);
|
|
6860
6873
|
}
|
|
6861
6874
|
Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
|
|
6862
6875
|
get: function () {
|
|
@@ -6877,7 +6890,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6877
6890
|
*/
|
|
6878
6891
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
6879
6892
|
return __awaiter(this, void 0, void 0, function () {
|
|
6880
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
6893
|
+
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
6881
6894
|
return __generator(this, function (_a) {
|
|
6882
6895
|
switch (_a.label) {
|
|
6883
6896
|
case 0:
|
|
@@ -6923,11 +6936,16 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6923
6936
|
if (rawResponse.content.length > 1) {
|
|
6924
6937
|
throw new PipelineExecutionError('More than one content blocks from Anthropic Claude');
|
|
6925
6938
|
}
|
|
6926
|
-
|
|
6939
|
+
contentBlock = rawResponse.content[0];
|
|
6940
|
+
if (contentBlock.type !== 'text') {
|
|
6941
|
+
throw new PipelineExecutionError("Returned content is not \"text\" type but \"".concat(contentBlock.type, "\""));
|
|
6942
|
+
}
|
|
6943
|
+
console.log('!!!!!! rawResponse.usage', rawResponse.usage);
|
|
6944
|
+
resultContent = contentBlock.text;
|
|
6927
6945
|
// eslint-disable-next-line prefer-const
|
|
6928
6946
|
complete = getCurrentIsoDate();
|
|
6929
6947
|
usage = {
|
|
6930
|
-
price: { value: 0, isUncertain: true } /* <- TODO: [🐞] Compute usage */,
|
|
6948
|
+
price: { value: 0, isUncertain: true } /* <- TODO: [🐞] !!!!!! Compute usage */,
|
|
6931
6949
|
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
|
|
6932
6950
|
output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
|
|
6933
6951
|
};
|
|
@@ -7058,7 +7076,6 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
7058
7076
|
* TODO: Maybe Create some common util for callChatModel and callCompletionModel
|
|
7059
7077
|
* TODO: Maybe make custom OpenaiError
|
|
7060
7078
|
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
7061
|
-
* TODO: [🍜] !!!!!! Auto use anonymous server in browser
|
|
7062
7079
|
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
7063
7080
|
* TODO: [📅] Maybe instead of `RemoteLlmExecutionToolsOptions` use `proxyWithAnonymousRemoteServer` (if implemented)
|
|
7064
7081
|
*/
|
|
@@ -7079,11 +7096,14 @@ function createAnthropicClaudeExecutionTools(options) {
|
|
|
7079
7096
|
},
|
|
7080
7097
|
], models: ANTHROPIC_CLAUDE_MODELS }));
|
|
7081
7098
|
}
|
|
7082
|
-
return new AnthropicClaudeExecutionTools(
|
|
7099
|
+
return new AnthropicClaudeExecutionTools(
|
|
7100
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
7101
|
+
options);
|
|
7083
7102
|
}
|
|
7084
7103
|
/**
|
|
7085
|
-
* TODO:
|
|
7086
|
-
* TODO:
|
|
7104
|
+
* TODO: [🧠] !!!! Make anonymous this with all LLM providers
|
|
7105
|
+
* TODO: [🧠] !!!! Maybe change all `new AnthropicClaudeExecutionTools` -> `createAnthropicClaudeExecutionTools` in manual
|
|
7106
|
+
* TODO: [🧠] Maybe auto-detect usage in browser and determine default value of `isProxied`
|
|
7087
7107
|
*/
|
|
7088
7108
|
|
|
7089
7109
|
/**
|
|
@@ -7427,7 +7447,8 @@ var OPENAI_MODELS = [
|
|
|
7427
7447
|
/**
|
|
7428
7448
|
* Note: [🤖] Add models of new variant
|
|
7429
7449
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
7430
|
-
* TODO: [
|
|
7450
|
+
* TODO: [🎰] Some mechanism to auto-update available models
|
|
7451
|
+
* TODO: [🎰][👮♀️] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
|
|
7431
7452
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
7432
7453
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
7433
7454
|
* @see https://openai.com/api/pricing/
|
|
@@ -7450,7 +7471,11 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7450
7471
|
*/
|
|
7451
7472
|
function AzureOpenAiExecutionTools(options) {
|
|
7452
7473
|
this.options = options;
|
|
7453
|
-
this.client = new OpenAIClient(
|
|
7474
|
+
this.client = new OpenAIClient(
|
|
7475
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
7476
|
+
"https://".concat(options.resourceName, ".openai.azure.com/"), new AzureKeyCredential(
|
|
7477
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
7478
|
+
options.apiKey));
|
|
7454
7479
|
}
|
|
7455
7480
|
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
7456
7481
|
get: function () {
|
|
@@ -8033,7 +8058,11 @@ var EXECUTION_TOOLS_CLASSES = {
|
|
|
8033
8058
|
return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
|
|
8034
8059
|
},
|
|
8035
8060
|
createAnthropicClaudeExecutionTools: createAnthropicClaudeExecutionTools,
|
|
8036
|
-
createAzureOpenAiExecutionTools: function (options) {
|
|
8061
|
+
createAzureOpenAiExecutionTools: function (options) {
|
|
8062
|
+
return new AzureOpenAiExecutionTools(
|
|
8063
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
8064
|
+
options);
|
|
8065
|
+
},
|
|
8037
8066
|
// <- Note: [🦑] Add here new LLM provider
|
|
8038
8067
|
};
|
|
8039
8068
|
/**
|
|
@@ -8079,7 +8108,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
8079
8108
|
* @public exported from `@promptbook/node`
|
|
8080
8109
|
*/
|
|
8081
8110
|
function createLlmToolsFromConfigurationFromEnv() {
|
|
8082
|
-
if (
|
|
8111
|
+
if (!$isRunningInNode()) {
|
|
8083
8112
|
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
8084
8113
|
}
|
|
8085
8114
|
dotenv.config();
|
|
@@ -8133,7 +8162,7 @@ function createLlmToolsFromConfigurationFromEnv() {
|
|
|
8133
8162
|
*/
|
|
8134
8163
|
function createLlmToolsFromEnv(options) {
|
|
8135
8164
|
if (options === void 0) { options = {}; }
|
|
8136
|
-
if (
|
|
8165
|
+
if (!$isRunningInNode()) {
|
|
8137
8166
|
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
8138
8167
|
}
|
|
8139
8168
|
var configuration = createLlmToolsFromConfigurationFromEnv();
|
|
@@ -8207,6 +8236,8 @@ var MemoryStorage = /** @class */ (function () {
|
|
|
8207
8236
|
/**
|
|
8208
8237
|
* Simple wrapper `new Date().toISOString()`
|
|
8209
8238
|
*
|
|
8239
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
|
8240
|
+
*
|
|
8210
8241
|
* @returns string_date branded type
|
|
8211
8242
|
* @public exported from `@promptbook/utils`
|
|
8212
8243
|
*/
|
|
@@ -8226,7 +8257,11 @@ function $currentDate() {
|
|
|
8226
8257
|
function cacheLlmTools(llmTools, options) {
|
|
8227
8258
|
var _this = this;
|
|
8228
8259
|
if (options === void 0) { options = {}; }
|
|
8229
|
-
var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a,
|
|
8260
|
+
var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a,
|
|
8261
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
8262
|
+
_b = options.isReloaded,
|
|
8263
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
8264
|
+
isReloaded = _b === void 0 ? false : _b;
|
|
8230
8265
|
var proxyTools = __assign(__assign({}, llmTools), {
|
|
8231
8266
|
// <- Note: [🥫]
|
|
8232
8267
|
get title() {
|
|
@@ -8331,14 +8366,16 @@ function cacheLlmTools(llmTools, options) {
|
|
|
8331
8366
|
* @private within the repository - for CLI utils
|
|
8332
8367
|
*/
|
|
8333
8368
|
function getLlmToolsForCli(options) {
|
|
8334
|
-
if (
|
|
8369
|
+
if (!$isRunningInNode()) {
|
|
8335
8370
|
throw new EnvironmentMismatchError('Function `getLlmToolsForTestingAndScriptsAndPlayground` works only in Node.js environment');
|
|
8336
8371
|
}
|
|
8337
8372
|
var _a = (options !== null && options !== void 0 ? options : {}).isCacheReloaded, isCacheReloaded = _a === void 0 ? false : _a;
|
|
8338
8373
|
return cacheLlmTools(countTotalUsage(
|
|
8339
8374
|
// <- Note: for example here we don`t want the [🌯]
|
|
8340
8375
|
createLlmToolsFromEnv()), {
|
|
8341
|
-
storage: new FilesStorage(
|
|
8376
|
+
storage: new FilesStorage(
|
|
8377
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
8378
|
+
{ cacheFolderPath: join$1(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
|
|
8342
8379
|
isReloaded: isCacheReloaded,
|
|
8343
8380
|
});
|
|
8344
8381
|
}
|
|
@@ -8831,7 +8868,7 @@ function promptbookCli() {
|
|
|
8831
8868
|
return __awaiter(this, void 0, void 0, function () {
|
|
8832
8869
|
var program;
|
|
8833
8870
|
return __generator(this, function (_a) {
|
|
8834
|
-
if (
|
|
8871
|
+
if (!$isRunningInNode()) {
|
|
8835
8872
|
throw new EnvironmentMismatchError(spaceTrim$1("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
|
|
8836
8873
|
}
|
|
8837
8874
|
program = new commander.Command();
|