@promptbook/cli 0.85.0-8 → 0.85.0-9
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.
|
@@ -8,7 +8,6 @@ import type { Command as Program } from 'commander';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function $initializeAboutCommand(program: Program): void;
|
|
10
10
|
/**
|
|
11
|
-
* TODO: !!! Test this in `deno`
|
|
12
11
|
* TODO: [🗽] Unite branding and make single place for it
|
|
13
12
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
14
13
|
* Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
|
|
@@ -11,8 +11,7 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): IDestroyable;
|
|
13
13
|
/**
|
|
14
|
-
* TODO:
|
|
15
|
-
* TODO: !!!!!!! Allow to pass tokem here
|
|
14
|
+
* TODO: !! Add CORS and security - probbably via `helmet`
|
|
16
15
|
* TODO: [👩🏾🤝🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
|
|
17
16
|
* TODO: Split this file into multiple functions - handler for each request
|
|
18
17
|
* TODO: Maybe use `$exportJson`
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
* @generated
|
|
54
54
|
* @see https://github.com/webgptorg/promptbook
|
|
55
55
|
*/
|
|
56
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-
|
|
56
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-8';
|
|
57
57
|
/**
|
|
58
58
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
59
59
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -543,7 +543,6 @@
|
|
|
543
543
|
}); });
|
|
544
544
|
}
|
|
545
545
|
/**
|
|
546
|
-
* TODO: !!! Test this in `deno`
|
|
547
546
|
* TODO: [🗽] Unite branding and make single place for it
|
|
548
547
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
549
548
|
* Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
|
|
@@ -4930,18 +4929,16 @@
|
|
|
4930
4929
|
*/
|
|
4931
4930
|
function createTask(options) {
|
|
4932
4931
|
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
4933
|
-
var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO:
|
|
4932
|
+
var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
|
|
4934
4933
|
var partialResultSubject = new rxjs.BehaviorSubject({});
|
|
4935
4934
|
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
4936
4935
|
partialResultSubject.next(newOngoingResult);
|
|
4937
4936
|
});
|
|
4938
4937
|
finalResultPromise
|
|
4939
4938
|
.catch(function (error) {
|
|
4940
|
-
// console.error('!!!!! Task failed:', error);
|
|
4941
4939
|
partialResultSubject.error(error);
|
|
4942
4940
|
})
|
|
4943
4941
|
.then(function (value) {
|
|
4944
|
-
// console.error('!!!!! Task finished:', value);
|
|
4945
4942
|
if (value) {
|
|
4946
4943
|
try {
|
|
4947
4944
|
assertsTaskSuccessful(value);
|
|
@@ -4963,9 +4960,7 @@
|
|
|
4963
4960
|
return [4 /*yield*/, finalResultPromise];
|
|
4964
4961
|
case 1:
|
|
4965
4962
|
finalResult = _b.sent();
|
|
4966
|
-
console.error('!!!!! finalResult:', finalResult);
|
|
4967
4963
|
if (isCrashedOnError) {
|
|
4968
|
-
console.error('!!!!! isCrashedOnError:', finalResult);
|
|
4969
4964
|
assertsTaskSuccessful(finalResult);
|
|
4970
4965
|
}
|
|
4971
4966
|
return [2 /*return*/, finalResult];
|
|
@@ -13806,6 +13801,57 @@
|
|
|
13806
13801
|
.filter(function (part) { return part !== ''; })
|
|
13807
13802
|
.join('/');
|
|
13808
13803
|
var startupDate = new Date();
|
|
13804
|
+
function getExecutionToolsFromIdentification(identification) {
|
|
13805
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
13806
|
+
var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
|
|
13807
|
+
var _a;
|
|
13808
|
+
return __generator(this, function (_b) {
|
|
13809
|
+
switch (_b.label) {
|
|
13810
|
+
case 0:
|
|
13811
|
+
if (identification === null || identification === undefined) {
|
|
13812
|
+
throw new Error("Identification is not provided");
|
|
13813
|
+
}
|
|
13814
|
+
isAnonymous = identification.isAnonymous;
|
|
13815
|
+
if (isAnonymous === true && !isAnonymousModeAllowed) {
|
|
13816
|
+
throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
13817
|
+
}
|
|
13818
|
+
if (isAnonymous === false && !isApplicationModeAllowed) {
|
|
13819
|
+
throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
13820
|
+
}
|
|
13821
|
+
if (!(isAnonymous === true)) return [3 /*break*/, 1];
|
|
13822
|
+
llmToolsConfiguration = identification.llmToolsConfiguration;
|
|
13823
|
+
llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
|
|
13824
|
+
return [3 /*break*/, 4];
|
|
13825
|
+
case 1:
|
|
13826
|
+
if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
|
|
13827
|
+
appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
|
|
13828
|
+
return [4 /*yield*/, createLlmExecutionTools({
|
|
13829
|
+
appId: appId,
|
|
13830
|
+
userId: userId,
|
|
13831
|
+
customOptions: customOptions,
|
|
13832
|
+
})];
|
|
13833
|
+
case 2:
|
|
13834
|
+
llm = _b.sent();
|
|
13835
|
+
return [3 /*break*/, 4];
|
|
13836
|
+
case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
|
|
13837
|
+
case 4:
|
|
13838
|
+
fs = $provideFilesystemForNode();
|
|
13839
|
+
return [4 /*yield*/, $provideExecutablesForNode()];
|
|
13840
|
+
case 5:
|
|
13841
|
+
executables = _b.sent();
|
|
13842
|
+
_a = {
|
|
13843
|
+
llm: llm,
|
|
13844
|
+
fs: fs
|
|
13845
|
+
};
|
|
13846
|
+
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
|
|
13847
|
+
case 6:
|
|
13848
|
+
tools = (_a.scrapers = _b.sent(),
|
|
13849
|
+
_a);
|
|
13850
|
+
return [2 /*return*/, tools];
|
|
13851
|
+
}
|
|
13852
|
+
});
|
|
13853
|
+
});
|
|
13854
|
+
}
|
|
13809
13855
|
var app = express__default["default"]();
|
|
13810
13856
|
app.use(express__default["default"].json());
|
|
13811
13857
|
app.use(function (request, response, next) {
|
|
@@ -13899,13 +13945,12 @@
|
|
|
13899
13945
|
});
|
|
13900
13946
|
}); });
|
|
13901
13947
|
app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
13902
|
-
var
|
|
13903
|
-
var _a;
|
|
13948
|
+
var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_1;
|
|
13904
13949
|
return __generator(this, function (_b) {
|
|
13905
13950
|
switch (_b.label) {
|
|
13906
13951
|
case 0:
|
|
13907
|
-
_b.trys.push([0,
|
|
13908
|
-
|
|
13952
|
+
_b.trys.push([0, 4, , 5]);
|
|
13953
|
+
_a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
|
|
13909
13954
|
pipelineUrl = request.body.pipelineUrl || request.body.book;
|
|
13910
13955
|
return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
|
|
13911
13956
|
case 1:
|
|
@@ -13914,43 +13959,27 @@
|
|
|
13914
13959
|
response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
|
|
13915
13960
|
return [2 /*return*/];
|
|
13916
13961
|
}
|
|
13917
|
-
return [4 /*yield*/,
|
|
13918
|
-
appId: '!!!!',
|
|
13919
|
-
userId: '!!!!',
|
|
13920
|
-
customOptions: {},
|
|
13921
|
-
})];
|
|
13962
|
+
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
13922
13963
|
case 2:
|
|
13923
|
-
|
|
13924
|
-
fs = $provideFilesystemForNode();
|
|
13925
|
-
return [4 /*yield*/, $provideExecutablesForNode()];
|
|
13926
|
-
case 3:
|
|
13927
|
-
executables = _b.sent();
|
|
13928
|
-
_a = {
|
|
13929
|
-
llm: llm,
|
|
13930
|
-
fs: fs
|
|
13931
|
-
};
|
|
13932
|
-
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
|
|
13933
|
-
case 4:
|
|
13934
|
-
tools = (_a.scrapers = _b.sent(),
|
|
13935
|
-
_a);
|
|
13964
|
+
tools = _b.sent();
|
|
13936
13965
|
pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
|
|
13937
13966
|
executionTask = pipelineExecutor(inputParameters);
|
|
13938
13967
|
runningExecutionTasks.push(executionTask);
|
|
13939
13968
|
return [4 /*yield*/, waitasecond.forTime(10)];
|
|
13940
|
-
case
|
|
13969
|
+
case 3:
|
|
13941
13970
|
_b.sent();
|
|
13942
13971
|
// <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
|
|
13943
13972
|
// <- TODO: Put this into configuration
|
|
13944
13973
|
response.send(executionTask);
|
|
13945
|
-
return [3 /*break*/,
|
|
13946
|
-
case
|
|
13974
|
+
return [3 /*break*/, 5];
|
|
13975
|
+
case 4:
|
|
13947
13976
|
error_1 = _b.sent();
|
|
13948
13977
|
if (!(error_1 instanceof Error)) {
|
|
13949
13978
|
throw error_1;
|
|
13950
13979
|
}
|
|
13951
13980
|
response.status(400).send({ error: serializeError(error_1) });
|
|
13952
|
-
return [3 /*break*/,
|
|
13953
|
-
case
|
|
13981
|
+
return [3 /*break*/, 5];
|
|
13982
|
+
case 5: return [2 /*return*/];
|
|
13954
13983
|
}
|
|
13955
13984
|
});
|
|
13956
13985
|
}); });
|
|
@@ -13967,55 +13996,9 @@
|
|
|
13967
13996
|
if (isVerbose) {
|
|
13968
13997
|
console.info(colors__default["default"].gray("Client connected"), socket.id);
|
|
13969
13998
|
}
|
|
13970
|
-
var getExecutionToolsFromIdentification = function (identification) { return __awaiter(_this, void 0, void 0, function () {
|
|
13971
|
-
var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
|
|
13972
|
-
var _a;
|
|
13973
|
-
return __generator(this, function (_b) {
|
|
13974
|
-
switch (_b.label) {
|
|
13975
|
-
case 0:
|
|
13976
|
-
isAnonymous = identification.isAnonymous;
|
|
13977
|
-
if (isAnonymous === true && !isAnonymousModeAllowed) {
|
|
13978
|
-
throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
13979
|
-
}
|
|
13980
|
-
if (isAnonymous === false && !isApplicationModeAllowed) {
|
|
13981
|
-
throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
13982
|
-
}
|
|
13983
|
-
if (!(isAnonymous === true)) return [3 /*break*/, 1];
|
|
13984
|
-
llmToolsConfiguration = identification.llmToolsConfiguration;
|
|
13985
|
-
llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
|
|
13986
|
-
return [3 /*break*/, 4];
|
|
13987
|
-
case 1:
|
|
13988
|
-
if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
|
|
13989
|
-
appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
|
|
13990
|
-
return [4 /*yield*/, createLlmExecutionTools({
|
|
13991
|
-
appId: appId,
|
|
13992
|
-
userId: userId,
|
|
13993
|
-
customOptions: customOptions,
|
|
13994
|
-
})];
|
|
13995
|
-
case 2:
|
|
13996
|
-
llm = _b.sent();
|
|
13997
|
-
return [3 /*break*/, 4];
|
|
13998
|
-
case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
|
|
13999
|
-
case 4:
|
|
14000
|
-
fs = $provideFilesystemForNode();
|
|
14001
|
-
return [4 /*yield*/, $provideExecutablesForNode()];
|
|
14002
|
-
case 5:
|
|
14003
|
-
executables = _b.sent();
|
|
14004
|
-
_a = {
|
|
14005
|
-
llm: llm,
|
|
14006
|
-
fs: fs
|
|
14007
|
-
};
|
|
14008
|
-
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
|
|
14009
|
-
case 6:
|
|
14010
|
-
tools = (_a.scrapers = _b.sent(),
|
|
14011
|
-
_a);
|
|
14012
|
-
return [2 /*return*/, tools];
|
|
14013
|
-
}
|
|
14014
|
-
});
|
|
14015
|
-
}); };
|
|
14016
13999
|
// -----------
|
|
14017
14000
|
socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
14018
|
-
var identification, prompt,
|
|
14001
|
+
var identification, prompt, tools, llm, _a, promptResult, _b, error_2;
|
|
14019
14002
|
return __generator(this, function (_c) {
|
|
14020
14003
|
switch (_c.label) {
|
|
14021
14004
|
case 0:
|
|
@@ -14028,8 +14011,8 @@
|
|
|
14028
14011
|
_c.trys.push([1, 13, 14, 15]);
|
|
14029
14012
|
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
14030
14013
|
case 2:
|
|
14031
|
-
|
|
14032
|
-
llm =
|
|
14014
|
+
tools = _c.sent();
|
|
14015
|
+
llm = tools.llm;
|
|
14033
14016
|
_a = identification.isAnonymous === false &&
|
|
14034
14017
|
collection !== null;
|
|
14035
14018
|
if (!_a) return [3 /*break*/, 4];
|
|
@@ -14100,7 +14083,7 @@
|
|
|
14100
14083
|
// -----------
|
|
14101
14084
|
// TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
14102
14085
|
socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
14103
|
-
var identification,
|
|
14086
|
+
var identification, tools, llm, models, error_3;
|
|
14104
14087
|
return __generator(this, function (_a) {
|
|
14105
14088
|
switch (_a.label) {
|
|
14106
14089
|
case 0:
|
|
@@ -14113,8 +14096,8 @@
|
|
|
14113
14096
|
_a.trys.push([1, 4, 5, 6]);
|
|
14114
14097
|
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
14115
14098
|
case 2:
|
|
14116
|
-
|
|
14117
|
-
llm =
|
|
14099
|
+
tools = _a.sent();
|
|
14100
|
+
llm = tools.llm;
|
|
14118
14101
|
return [4 /*yield*/, llm.listModels()];
|
|
14119
14102
|
case 3:
|
|
14120
14103
|
models = _a.sent();
|
|
@@ -14137,7 +14120,7 @@
|
|
|
14137
14120
|
// -----------
|
|
14138
14121
|
// TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
14139
14122
|
socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
14140
|
-
var identification, pipeline,
|
|
14123
|
+
var identification, pipeline, tools, preparedPipeline, error_4;
|
|
14141
14124
|
return __generator(this, function (_a) {
|
|
14142
14125
|
switch (_a.label) {
|
|
14143
14126
|
case 0:
|
|
@@ -14150,8 +14133,8 @@
|
|
|
14150
14133
|
_a.trys.push([1, 4, 5, 6]);
|
|
14151
14134
|
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
14152
14135
|
case 2:
|
|
14153
|
-
|
|
14154
|
-
return [4 /*yield*/, preparePipeline(pipeline,
|
|
14136
|
+
tools = _a.sent();
|
|
14137
|
+
return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
|
|
14155
14138
|
case 3:
|
|
14156
14139
|
preparedPipeline = _a.sent();
|
|
14157
14140
|
socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
|
|
@@ -14200,8 +14183,7 @@
|
|
|
14200
14183
|
};
|
|
14201
14184
|
}
|
|
14202
14185
|
/**
|
|
14203
|
-
* TODO:
|
|
14204
|
-
* TODO: !!!!!!! Allow to pass tokem here
|
|
14186
|
+
* TODO: !! Add CORS and security - probbably via `helmet`
|
|
14205
14187
|
* TODO: [👩🏾🤝🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
|
|
14206
14188
|
* TODO: Split this file into multiple functions - handler for each request
|
|
14207
14189
|
* TODO: Maybe use `$exportJson`
|
|
@@ -15540,7 +15522,7 @@
|
|
|
15540
15522
|
pricing: {
|
|
15541
15523
|
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
15542
15524
|
output: computeUsage("$12.00 / 1M tokens"),
|
|
15543
|
-
// <- TODO:
|
|
15525
|
+
// <- TODO: !! Unsure, check the pricing
|
|
15544
15526
|
},
|
|
15545
15527
|
},
|
|
15546
15528
|
/**/
|
|
@@ -15552,7 +15534,7 @@
|
|
|
15552
15534
|
pricing: {
|
|
15553
15535
|
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
15554
15536
|
output: computeUsage("$12.00 / 1M tokens"),
|
|
15555
|
-
// <- TODO:
|
|
15537
|
+
// <- TODO: !! Unsure, check the pricing
|
|
15556
15538
|
},
|
|
15557
15539
|
},
|
|
15558
15540
|
/**/
|