@promptbook/remote-server 0.8.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 +5 -0
- package/esm/index.es.js +160 -0
- package/esm/index.es.js.map +1 -0
- package/esm/typings/_packages/core.index.d.ts +17 -0
- package/esm/typings/_packages/execute-javascript.index.d.ts +3 -0
- package/esm/typings/_packages/openai.index.d.ts +3 -0
- package/esm/typings/_packages/remote-client.index.d.ts +4 -0
- package/esm/typings/_packages/remote-server.index.d.ts +3 -0
- package/esm/typings/_packages/types.index.d.ts +20 -0
- package/esm/typings/_packages/utils.index.d.ts +6 -0
- package/esm/typings/_packages/wizzard.index.d.ts +2 -0
- package/esm/typings/classes/PromptTemplatePipeline.d.ts +68 -0
- package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +55 -0
- package/esm/typings/config.d.ts +10 -0
- package/esm/typings/conversion/_importPtp.d.ts +12 -0
- package/esm/typings/conversion/parseCommand.d.ts +6 -0
- package/esm/typings/conversion/parseCommand.test.d.ts +1 -0
- package/esm/typings/conversion/promptTemplatePipelineStringToJson.d.ts +12 -0
- package/esm/typings/conversion/promptTemplatePipelineStringToJson.test.d.ts +1 -0
- package/esm/typings/conversion/validatePromptTemplatePipelineJson.d.ts +26 -0
- package/esm/typings/conversion/validatePromptTemplatePipelineJson.test.d.ts +1 -0
- package/esm/typings/execution/CommonExecutionToolsOptions.d.ts +6 -0
- package/esm/typings/execution/ExecutionTools.d.ts +25 -0
- package/esm/typings/execution/NaturalExecutionTools.d.ts +22 -0
- package/esm/typings/execution/PromptResult.d.ts +38 -0
- package/esm/typings/execution/PtpExecutor.d.ts +19 -0
- package/esm/typings/execution/ScriptExecutionTools.d.ts +34 -0
- package/esm/typings/execution/UserInterfaceTools.d.ts +30 -0
- package/esm/typings/execution/createPtpExecutor.d.ts +18 -0
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
- package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +27 -0
- package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +16 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/createRemoteServer.d.ts +16 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Error.d.ts +3 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Progress.d.ts +4 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Request.d.ts +6 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Response.d.ts +4 -0
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +20 -0
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +19 -0
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
- package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
- package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +4 -0
- package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
- package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
- package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
- package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
- package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
- package/esm/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
- package/esm/typings/types/Command.d.ts +65 -0
- package/esm/typings/types/ExecutionTypes.d.ts +13 -0
- package/esm/typings/types/ModelRequirements.d.ts +28 -0
- package/esm/typings/types/Parameters.d.ts +14 -0
- package/esm/typings/types/Prompt.d.ts +35 -0
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +82 -0
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateParameterJson.d.ts +23 -0
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +56 -0
- package/esm/typings/types/PromptTemplatePipelineString.d.ts +14 -0
- package/esm/typings/types/ScriptLanguage.d.ts +9 -0
- package/esm/typings/types/TaskProgress.d.ts +12 -0
- package/esm/typings/types/typeAliasEmoji.d.ts +9 -0
- package/esm/typings/types/typeAliases.d.ts +477 -0
- package/esm/typings/utils/emojis.d.ts +16 -0
- package/esm/typings/utils/just.d.ts +10 -0
- package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
- package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
- package/esm/typings/utils/markdown/extractBlocksFromMarkdown.d.ts +13 -0
- package/esm/typings/utils/markdown/extractBlocksFromMarkdown.test.d.ts +1 -0
- package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +16 -0
- package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
- package/esm/typings/utils/markdown/removeContentComments.d.ts +8 -0
- package/esm/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
- package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
- package/esm/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
- package/esm/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
- package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
- package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
- package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
- package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
- package/esm/typings/utils/removeEmojis.d.ts +7 -0
- package/esm/typings/utils/removeEmojis.test.d.ts +1 -0
- package/esm/typings/utils/removeQuotes.d.ts +13 -0
- package/esm/typings/utils/removeQuotes.test.d.ts +1 -0
- package/esm/typings/utils/replaceParameters.d.ts +16 -0
- package/esm/typings/utils/replaceParameters.test.d.ts +1 -0
- package/esm/typings/utils/unwrapResult.d.ts +13 -0
- package/esm/typings/utils/unwrapResult.test.d.ts +1 -0
- package/esm/typings/wizzard/Wizzard.d.ts +1 -0
- package/esm/typings/wizzard/sample.d.ts +5 -0
- package/package.json +46 -0
- package/umd/index.umd.js +171 -0
- package/umd/index.umd.js.map +1 -0
- package/umd/typings/_packages/core.index.d.ts +17 -0
- package/umd/typings/_packages/execute-javascript.index.d.ts +3 -0
- package/umd/typings/_packages/openai.index.d.ts +3 -0
- package/umd/typings/_packages/remote-client.index.d.ts +4 -0
- package/umd/typings/_packages/remote-server.index.d.ts +3 -0
- package/umd/typings/_packages/types.index.d.ts +20 -0
- package/umd/typings/_packages/utils.index.d.ts +6 -0
- package/umd/typings/_packages/wizzard.index.d.ts +2 -0
- package/umd/typings/classes/PromptTemplatePipeline.d.ts +68 -0
- package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +55 -0
- package/umd/typings/config.d.ts +10 -0
- package/umd/typings/conversion/_importPtp.d.ts +12 -0
- package/umd/typings/conversion/parseCommand.d.ts +6 -0
- package/umd/typings/conversion/parseCommand.test.d.ts +1 -0
- package/umd/typings/conversion/promptTemplatePipelineStringToJson.d.ts +12 -0
- package/umd/typings/conversion/promptTemplatePipelineStringToJson.test.d.ts +1 -0
- package/umd/typings/conversion/validatePromptTemplatePipelineJson.d.ts +26 -0
- package/umd/typings/conversion/validatePromptTemplatePipelineJson.test.d.ts +1 -0
- package/umd/typings/execution/CommonExecutionToolsOptions.d.ts +6 -0
- package/umd/typings/execution/ExecutionTools.d.ts +25 -0
- package/umd/typings/execution/NaturalExecutionTools.d.ts +22 -0
- package/umd/typings/execution/PromptResult.d.ts +38 -0
- package/umd/typings/execution/PtpExecutor.d.ts +19 -0
- package/umd/typings/execution/ScriptExecutionTools.d.ts +34 -0
- package/umd/typings/execution/UserInterfaceTools.d.ts +30 -0
- package/umd/typings/execution/createPtpExecutor.d.ts +18 -0
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
- package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +27 -0
- package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +16 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/createRemoteServer.d.ts +16 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Error.d.ts +3 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Progress.d.ts +4 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Request.d.ts +6 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Response.d.ts +4 -0
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +20 -0
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +19 -0
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
- package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
- package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +4 -0
- package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
- package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
- package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
- package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
- package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
- package/umd/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
- package/umd/typings/types/Command.d.ts +65 -0
- package/umd/typings/types/ExecutionTypes.d.ts +13 -0
- package/umd/typings/types/ModelRequirements.d.ts +28 -0
- package/umd/typings/types/Parameters.d.ts +14 -0
- package/umd/typings/types/Prompt.d.ts +35 -0
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +82 -0
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateParameterJson.d.ts +23 -0
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +56 -0
- package/umd/typings/types/PromptTemplatePipelineString.d.ts +14 -0
- package/umd/typings/types/ScriptLanguage.d.ts +9 -0
- package/umd/typings/types/TaskProgress.d.ts +12 -0
- package/umd/typings/types/typeAliasEmoji.d.ts +9 -0
- package/umd/typings/types/typeAliases.d.ts +477 -0
- package/umd/typings/utils/emojis.d.ts +16 -0
- package/umd/typings/utils/just.d.ts +10 -0
- package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
- package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
- package/umd/typings/utils/markdown/extractBlocksFromMarkdown.d.ts +13 -0
- package/umd/typings/utils/markdown/extractBlocksFromMarkdown.test.d.ts +1 -0
- package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +16 -0
- package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
- package/umd/typings/utils/markdown/removeContentComments.d.ts +8 -0
- package/umd/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
- package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
- package/umd/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
- package/umd/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
- package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
- package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
- package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
- package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
- package/umd/typings/utils/removeEmojis.d.ts +7 -0
- package/umd/typings/utils/removeEmojis.test.d.ts +1 -0
- package/umd/typings/utils/removeQuotes.d.ts +13 -0
- package/umd/typings/utils/removeQuotes.test.d.ts +1 -0
- package/umd/typings/utils/replaceParameters.d.ts +16 -0
- package/umd/typings/utils/replaceParameters.test.d.ts +1 -0
- package/umd/typings/utils/unwrapResult.d.ts +13 -0
- package/umd/typings/utils/unwrapResult.test.d.ts +1 -0
- package/umd/typings/wizzard/Wizzard.d.ts +1 -0
- package/umd/typings/wizzard/sample.d.ts +5 -0
package/README.md
ADDED
package/esm/index.es.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { Server } from 'socket.io';
|
|
4
|
+
import spaceTrim from 'spacetrim';
|
|
5
|
+
|
|
6
|
+
/*! *****************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function __generator(thisArg, body) {
|
|
32
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
33
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
34
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
|
+
function step(op) {
|
|
36
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
+
while (_) try {
|
|
38
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
39
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
|
+
switch (op[0]) {
|
|
41
|
+
case 0: case 1: t = op; break;
|
|
42
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
43
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
44
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
45
|
+
default:
|
|
46
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
47
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
48
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
49
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
50
|
+
if (t[2]) _.ops.pop();
|
|
51
|
+
_.trys.pop(); continue;
|
|
52
|
+
}
|
|
53
|
+
op = body.call(thisArg, _);
|
|
54
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
55
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
|
|
61
|
+
*
|
|
62
|
+
* You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
|
|
63
|
+
* This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
|
|
64
|
+
*
|
|
65
|
+
* @see https://github.com/webgptorg/promptbook#remote-server
|
|
66
|
+
*/
|
|
67
|
+
function createRemoteServer(options) {
|
|
68
|
+
var _this = this;
|
|
69
|
+
var port = options.port, /* [🎛] ptpLibrary, */ createNaturalExecutionTools = options.createNaturalExecutionTools, isVerbose = options.isVerbose;
|
|
70
|
+
var httpServer = http.createServer({}, function (request, response) {
|
|
71
|
+
var _a;
|
|
72
|
+
if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
response.write(spaceTrim("\n Server for processing PTP requests is running\n\n For more information look at:\n https://github.com/webgptorg/promptbook\n\n "));
|
|
76
|
+
response.end();
|
|
77
|
+
});
|
|
78
|
+
var server = new Server(httpServer, {
|
|
79
|
+
path: '/ptp/socket.io',
|
|
80
|
+
transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
|
|
81
|
+
cors: {
|
|
82
|
+
origin: '*',
|
|
83
|
+
methods: ['GET', 'POST'],
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
server.on('connection', function (socket) {
|
|
87
|
+
console.log(chalk.gray("Client connected"), socket.id);
|
|
88
|
+
socket.on('request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
89
|
+
var prompt, clientId, executionToolsForClient, promptResult, _a, error_1;
|
|
90
|
+
return __generator(this, function (_b) {
|
|
91
|
+
switch (_b.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
prompt = request.prompt, clientId = request.clientId;
|
|
94
|
+
// TODO: !! Validate here clientId (pass validator as dependency)
|
|
95
|
+
if (isVerbose) {
|
|
96
|
+
console.info(chalk.bgGray("Prompt:"), chalk.gray(JSON.stringify(request, null, 4)));
|
|
97
|
+
}
|
|
98
|
+
_b.label = 1;
|
|
99
|
+
case 1:
|
|
100
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
101
|
+
executionToolsForClient = createNaturalExecutionTools(clientId);
|
|
102
|
+
promptResult = void 0;
|
|
103
|
+
_a = prompt.modelRequirements.variant;
|
|
104
|
+
switch (_a) {
|
|
105
|
+
case 'CHAT': return [3 /*break*/, 2];
|
|
106
|
+
case 'COMPLETION': return [3 /*break*/, 4];
|
|
107
|
+
}
|
|
108
|
+
return [3 /*break*/, 6];
|
|
109
|
+
case 2: return [4 /*yield*/, executionToolsForClient.gptChat(prompt)];
|
|
110
|
+
case 3:
|
|
111
|
+
promptResult = _b.sent();
|
|
112
|
+
return [3 /*break*/, 7];
|
|
113
|
+
case 4: return [4 /*yield*/, executionToolsForClient.gptComplete(prompt)];
|
|
114
|
+
case 5:
|
|
115
|
+
promptResult = _b.sent();
|
|
116
|
+
return [3 /*break*/, 7];
|
|
117
|
+
case 6: throw new Error("Unknown model variant \"".concat(prompt.modelRequirements.variant, "\""));
|
|
118
|
+
case 7:
|
|
119
|
+
if (isVerbose) {
|
|
120
|
+
console.info(chalk.bgGreen("PromptResult:"), chalk.green(JSON.stringify(promptResult, null, 4)));
|
|
121
|
+
}
|
|
122
|
+
socket.emit('response', { promptResult: promptResult });
|
|
123
|
+
return [3 /*break*/, 10];
|
|
124
|
+
case 8:
|
|
125
|
+
error_1 = _b.sent();
|
|
126
|
+
if (!(error_1 instanceof Error)) {
|
|
127
|
+
throw error_1;
|
|
128
|
+
}
|
|
129
|
+
socket.emit('error', { errorMessage: error_1.message });
|
|
130
|
+
return [3 /*break*/, 10];
|
|
131
|
+
case 9:
|
|
132
|
+
socket.disconnect();
|
|
133
|
+
return [7 /*endfinally*/];
|
|
134
|
+
case 10: return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}); });
|
|
138
|
+
socket.on('disconnect', function () {
|
|
139
|
+
// TODO: Destroy here executionToolsForClient
|
|
140
|
+
if (isVerbose) {
|
|
141
|
+
console.info(chalk.gray("Client disconnected"), socket.id);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
httpServer.listen(port);
|
|
146
|
+
// Note: We want to log this also in non-verbose mode
|
|
147
|
+
console.info(chalk.bgGreen("PTP server listening on port ".concat(port)));
|
|
148
|
+
if (isVerbose) {
|
|
149
|
+
console.info(chalk.green("Verbose mode is enabled"));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* TODO: Handle progress - support streaming
|
|
154
|
+
* TODO: [🤹♂️] Do not hang up immediately but wait until client closes OR timeout
|
|
155
|
+
* TODO: [🤹♂️] Timeout on chat to free up resources
|
|
156
|
+
* TODO: [🃏] Pass here some security token to prevent DDoS
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
export { createRemoteServer };
|
|
160
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../../../node_modules/tslib/tslib.es6.js","../../../src/execution/plugins/natural-execution-tools/remote/createRemoteServer.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuDA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAChH,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,EAAE,UAAU,OAAO,EAAE,MAAM,EAAE;AAC/D,QAAQ,SAAS,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACnG,QAAQ,SAAS,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACtG,QAAQ,SAAS,IAAI,C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CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;yBACpG;wBAED,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,YAAY,cAAA,EAA0B,CAAC,CAAC;;;;wBAElE,IAAI,EAAE,OAAK,YAAY,KAAK,CAAC,EAAE;4BAC3B,MAAM,OAAK,CAAC;yBACf;wBAED,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,OAAK,CAAC,OAAO,EAAuB,CAAC,CAAC;;;wBAE3E,MAAM,CAAC,UAAU,EAAE,CAAC;;;;;aAE3B,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE;;YAEpB,IAAI,SAAS,EAAE;gBACX,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;aAC9D;SACJ,CAAC,CAAC;KACN,CAAC,CAAC;IAEH,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;;IAGxB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,uCAAgC,IAAI,CAAE,CAAC,CAAC,CAAC;IACpE,IAAI,SAAS,EAAE;QACX,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAC;KACxD;AACL,CAAC;AAED;;;;;;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
|
|
2
|
+
import { PromptTemplatePipelineLibrary } from '../classes/PromptTemplatePipelineLibrary';
|
|
3
|
+
import { PTP_VERSION } from '../config';
|
|
4
|
+
import { promptTemplatePipelineStringToJson } from '../conversion/promptTemplatePipelineStringToJson';
|
|
5
|
+
import { validatePromptTemplatePipelineJson } from '../conversion/validatePromptTemplatePipelineJson';
|
|
6
|
+
import { createPtpExecutor } from '../execution/createPtpExecutor';
|
|
7
|
+
import { MockedEchoNaturalExecutionTools } from '../execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools';
|
|
8
|
+
import { CallbackInterfaceTools } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools';
|
|
9
|
+
import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions';
|
|
10
|
+
import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
|
|
11
|
+
import { ExecutionTypes } from '../types/ExecutionTypes';
|
|
12
|
+
export { ExecutionTypes, PTP_VERSION, PromptTemplatePipeline, PromptTemplatePipelineLibrary };
|
|
13
|
+
export { SimplePromptInterfaceTools };
|
|
14
|
+
export { promptTemplatePipelineStringToJson, validatePromptTemplatePipelineJson };
|
|
15
|
+
export { MockedEchoNaturalExecutionTools };
|
|
16
|
+
export { createPtpExecutor };
|
|
17
|
+
export { CallbackInterfaceTools, CallbackInterfaceToolsOptions };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { JavascriptEvalExecutionTools } from '../execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools';
|
|
2
|
+
import { JavascriptExecutionTools } from '../execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools';
|
|
3
|
+
export { JavascriptEvalExecutionTools, JavascriptExecutionTools };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { OpenAiExecutionTools } from '../execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools';
|
|
2
|
+
import { OpenAiExecutionToolsOptions } from '../execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions';
|
|
3
|
+
export { OpenAiExecutionTools, OpenAiExecutionToolsOptions };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RemoteServerOptions } from '../execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions';
|
|
2
|
+
import { RemoteNaturalExecutionTools } from '../execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools';
|
|
3
|
+
import { RemoteNaturalExecutionToolsOptions } from '../execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions';
|
|
4
|
+
export { RemoteNaturalExecutionTools, RemoteNaturalExecutionToolsOptions, RemoteServerOptions };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRemoteServer } from '../execution/plugins/natural-execution-tools/remote/createRemoteServer';
|
|
2
|
+
import { RemoteServerOptions } from '../execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions';
|
|
3
|
+
export { createRemoteServer, RemoteServerOptions };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommonExecutionToolsOptions } from '../execution/CommonExecutionToolsOptions';
|
|
2
|
+
import { ExecutionTools } from '../execution/ExecutionTools';
|
|
3
|
+
import { NaturalExecutionTools } from '../execution/NaturalExecutionTools';
|
|
4
|
+
import { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult } from '../execution/PromptResult';
|
|
5
|
+
import { PtpExecutor } from '../execution/PtpExecutor';
|
|
6
|
+
import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
|
|
7
|
+
import { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
|
|
8
|
+
import { ExecutionType } from '../types/ExecutionTypes';
|
|
9
|
+
import { ModelRequirements, ModelVariant } from '../types/ModelRequirements';
|
|
10
|
+
import { Parameters } from '../types/Parameters';
|
|
11
|
+
import { Prompt } from '../types/Prompt';
|
|
12
|
+
import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
|
|
13
|
+
import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
|
|
14
|
+
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
15
|
+
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
16
|
+
import { ScriptLanguage } from '../types/ScriptLanguage';
|
|
17
|
+
import { DoneTaskProgress, PendingTaskProgress, TaskProgress } from '../types/TaskProgress';
|
|
18
|
+
import { string_char_emoji } from '../types/typeAliasEmoji';
|
|
19
|
+
import { ILicense, IPersonProfile, IRepository, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_cursor, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_image_prompt, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_midjourney_prompt, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptp_url, string_ptp_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_wallpaper_id, string_xml, uuid, uuid_first_segment } from '../types/typeAliases';
|
|
20
|
+
export { CommonExecutionToolsOptions, DoneTaskProgress, ExecutionTools, ExecutionType, ILicense, IPersonProfile, IRepository, ModelRequirements, ModelVariant, NaturalExecutionTools, Parameters, PendingTaskProgress, Prompt, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, PromptTemplatePipelineJson, PromptTemplatePipelineString, PtpExecutor, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_char_emoji, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_cursor, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_image_prompt, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_midjourney_prompt, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptp_url, string_ptp_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_wallpaper_id, string_xml, uuid, uuid_first_segment, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { removeContentComments } from '../utils/markdown/removeContentComments';
|
|
2
|
+
import { removeMarkdownFormatting } from '../utils/markdown/removeMarkdownFormatting';
|
|
3
|
+
import { removeEmojis } from '../utils/removeEmojis';
|
|
4
|
+
import { removeQuotes } from '../utils/removeQuotes';
|
|
5
|
+
import { unwrapResult } from '../utils/unwrapResult';
|
|
6
|
+
export { removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, unwrapResult };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { string_name } from '.././types/typeAliases';
|
|
2
|
+
import { PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
|
|
3
|
+
import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
|
|
4
|
+
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
5
|
+
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
6
|
+
/**
|
|
7
|
+
* Prompt template pipeline is the **core concept of this library**.
|
|
8
|
+
* It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
|
|
9
|
+
*
|
|
10
|
+
* It can have 3 formats:
|
|
11
|
+
* - **.ptp.md file** in custom markdown format described above
|
|
12
|
+
* - **JSON** format, parsed from the .ptp.md file
|
|
13
|
+
* - _(this)_ **Object** which is created from JSON format and bound with tools around (but not the execution logic)
|
|
14
|
+
*
|
|
15
|
+
* @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
|
|
16
|
+
*/
|
|
17
|
+
export declare class PromptTemplatePipeline {
|
|
18
|
+
readonly ptpUrl: URL | null;
|
|
19
|
+
readonly parameters: Record<string_name, PromptTemplateParameterJson>;
|
|
20
|
+
readonly promptTemplates: Array<PromptTemplateJson>;
|
|
21
|
+
/**
|
|
22
|
+
* Constructs PromptTemplatePipeline from any source
|
|
23
|
+
*
|
|
24
|
+
* Note: During the construction syntax and logic of source is validated
|
|
25
|
+
*
|
|
26
|
+
* @param source content of .ptp.md or .ptp.json file
|
|
27
|
+
* @returns PromptTemplatePipeline
|
|
28
|
+
*/
|
|
29
|
+
static fromSource(ptpSource: PromptTemplatePipelineString | PromptTemplatePipelineJson): PromptTemplatePipeline;
|
|
30
|
+
/**
|
|
31
|
+
* Constructs PromptTemplatePipeline from markdown source
|
|
32
|
+
*
|
|
33
|
+
* Note: During the construction syntax and logic of source is validated
|
|
34
|
+
*
|
|
35
|
+
* @param ptpString content of .ptp.md file
|
|
36
|
+
* @returns PromptTemplatePipeline
|
|
37
|
+
*/
|
|
38
|
+
static fromString(ptpString: PromptTemplatePipelineString): PromptTemplatePipeline;
|
|
39
|
+
/**
|
|
40
|
+
* Constructs PromptTemplatePipeline from JSON source
|
|
41
|
+
*
|
|
42
|
+
* Note: During the construction the source is logic validated
|
|
43
|
+
*
|
|
44
|
+
* @param ptpjson content of .ptp.json file parsed into JSON
|
|
45
|
+
* @returns PromptTemplatePipeline
|
|
46
|
+
*/
|
|
47
|
+
static fromJson(ptpjson: PromptTemplatePipelineJson): PromptTemplatePipeline;
|
|
48
|
+
private constructor();
|
|
49
|
+
/**
|
|
50
|
+
* Returns the first prompt template in the pipeline
|
|
51
|
+
*/
|
|
52
|
+
get entryPromptTemplate(): PromptTemplateJson;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the parameter that is the result of given prompt template
|
|
55
|
+
*/
|
|
56
|
+
getResultingParameter(promptTemplateName: string_name): PromptTemplateParameterJson;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the following prompt template in the pipeline or null if there is no following prompt template and this is the last one
|
|
59
|
+
*/
|
|
60
|
+
getFollowingPromptTemplate(promptTemplateName: string_name): PromptTemplateJson | null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
|
|
64
|
+
* TODO: !! [👐] Make parameters and promptTemplates private WHEN split between interface and class
|
|
65
|
+
* TODO: !! Add generic type for entry and result parameters
|
|
66
|
+
* TODO: Can be Array elegantly typed such as it must have at least one element?
|
|
67
|
+
* TODO: [🧠] Each PromptTemplatePipeline should have its unique hash to be able to compare them and execute on server ONLY the desired ones
|
|
68
|
+
*/
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { string_name } from '.././types/typeAliases';
|
|
2
|
+
import { ExecutionTools } from '../execution/ExecutionTools';
|
|
3
|
+
import { PtpExecutor } from '../execution/PtpExecutor';
|
|
4
|
+
import { Prompt } from '../types/Prompt';
|
|
5
|
+
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
6
|
+
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
7
|
+
import { PromptTemplatePipeline } from './PromptTemplatePipeline';
|
|
8
|
+
/**
|
|
9
|
+
* Library of prompt template pipelines that groups together prompt template pipelines for an application. This is a very thin wrapper around the Array / Set of prompt template pipelines.
|
|
10
|
+
*
|
|
11
|
+
* Prompt Template Pipeline library is a useful helper in execution, it can be shared between execution and consumer parts of the app and make common knowledge about prompt template pipelines.
|
|
12
|
+
*
|
|
13
|
+
* It allows to create executor functions from prompt template pipelines in the library.
|
|
14
|
+
*
|
|
15
|
+
* @see https://github.com/webgptorg/promptbook#prompt-template-pipeline-library
|
|
16
|
+
*/
|
|
17
|
+
export declare class PromptTemplatePipelineLibrary {
|
|
18
|
+
readonly promptTemplatePipelines: Record<string_name, PromptTemplatePipeline>;
|
|
19
|
+
/**
|
|
20
|
+
* Constructs PromptTemplatePipeline from any sources
|
|
21
|
+
*
|
|
22
|
+
* Note: During the construction syntax and logic of all sources are validated
|
|
23
|
+
* Note: You can combine .ptp.md and .ptp.json files BUT it is not recommended
|
|
24
|
+
*
|
|
25
|
+
* @param ptpSources contents of .ptp.md or .ptp.json files
|
|
26
|
+
* @returns PromptTemplatePipelineLibrary
|
|
27
|
+
*/
|
|
28
|
+
static fromSources(ptpSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>): PromptTemplatePipelineLibrary;
|
|
29
|
+
private constructor();
|
|
30
|
+
/**
|
|
31
|
+
* Gets prompt template pipeline by name
|
|
32
|
+
*/
|
|
33
|
+
getPtp(name: string_name): PromptTemplatePipeline;
|
|
34
|
+
/**
|
|
35
|
+
* Checks whether prompt is in the library
|
|
36
|
+
*/
|
|
37
|
+
isPromptInLibrary(prompt: Prompt): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Gets executor function for given prompt template pipeline
|
|
40
|
+
*/
|
|
41
|
+
createExecutor(name: string_name, tools: ExecutionTools): PtpExecutor;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
|
|
45
|
+
* TODO: !! [👐] Make promptTemplatePipelines private WHEN split between interface and class
|
|
46
|
+
* TODO: [🧠] Maybe isPromptInLibrary should be separate utility function
|
|
47
|
+
* TODO: [🧠] Maybe createExecutor should be separate utility function
|
|
48
|
+
* TODO: Static method fromDirectory
|
|
49
|
+
* TODO: [🤜] Add generic type for entry and result parameters
|
|
50
|
+
* TODO: [🧠] Is it better to ptpLibrary.executePtp('writeXyz',{...}) OR ptpLibrary.createExecutor('writeXyz')({...}) OR createExecutor(ptpLibrary.getPtp('writeXyz'))
|
|
51
|
+
* TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes PromptTemplatePipelineLibrary+PtpLibraryExecutor (maybe it was better?)
|
|
52
|
+
* TODO: [🧠] Is it better to pass tools into getExecutor or into constructor
|
|
53
|
+
* Maybe it is not a good idea to cache executors when they are can be created with different tools
|
|
54
|
+
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
55
|
+
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModelRequirements } from './types/ModelRequirements';
|
|
2
|
+
import { string_version } from './types/typeAliases';
|
|
3
|
+
/**
|
|
4
|
+
* The version of the PTP
|
|
5
|
+
*/
|
|
6
|
+
export declare const PTP_VERSION: string_version;
|
|
7
|
+
/**
|
|
8
|
+
* Default model requirements for the pipeline
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_MODEL_REQUIREMENTS: ModelRequirements;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
2
|
+
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
3
|
+
/**
|
|
4
|
+
* Import the text file
|
|
5
|
+
*
|
|
6
|
+
* Note: Using here custom import to work in jest tests
|
|
7
|
+
* Note: Using sync version is 💩 in the production code, but it's ok here in tests
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export declare function importPtp(path: `${string}.ptp.md`): PromptTemplatePipelineString;
|
|
12
|
+
export declare function importPtp(path: `${string}.ptp.json`): PromptTemplatePipelineJson;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
2
|
+
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
|
|
3
|
+
/**
|
|
4
|
+
* Parse prompt template pipeline from string format to JSON format
|
|
5
|
+
*
|
|
6
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
7
|
+
*/
|
|
8
|
+
export declare function promptTemplatePipelineStringToJson(promptTemplatePipelineString: PromptTemplatePipelineString): PromptTemplatePipelineJson;
|
|
9
|
+
/**
|
|
10
|
+
* TODO: Report here line/column of error
|
|
11
|
+
* TODO: Use spaceTrim more effectively
|
|
12
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
|
|
2
|
+
/**
|
|
3
|
+
* Validates PromptTemplatePipelineJson if it is logically valid.
|
|
4
|
+
*
|
|
5
|
+
* It checks:
|
|
6
|
+
* - if it has correct parameters dependency
|
|
7
|
+
*
|
|
8
|
+
* It does NOT check:
|
|
9
|
+
* - if it is valid json
|
|
10
|
+
* - if it is meaningful
|
|
11
|
+
*
|
|
12
|
+
* @param ptp valid or invalid PromptTemplatePipelineJson
|
|
13
|
+
* @throws {Error} if invalid
|
|
14
|
+
*/
|
|
15
|
+
export declare function validatePromptTemplatePipelineJson(ptp: PromptTemplatePipelineJson): void;
|
|
16
|
+
/**
|
|
17
|
+
* TODO: [🧠] Work with ptpVersion
|
|
18
|
+
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
19
|
+
* > /**
|
|
20
|
+
* > * Validates PromptTemplatePipelineJson if it is logically valid.
|
|
21
|
+
* > *
|
|
22
|
+
* > * It checks:
|
|
23
|
+
* > * - it has a valid structure
|
|
24
|
+
* > * - ...
|
|
25
|
+
* > ex port function validatePromptTemplatePipelineJson(ptp: unknown): asserts ptp is PromptTemplatePipelineJson {
|
|
26
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NaturalExecutionTools } from './NaturalExecutionTools';
|
|
2
|
+
import { ScriptExecutionTools } from './ScriptExecutionTools';
|
|
3
|
+
import { UserInterfaceTools } from './UserInterfaceTools';
|
|
4
|
+
/**
|
|
5
|
+
* All the tools needed to execute prompts (template pipelines).
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/webgptorg/promptbook#execution-tools
|
|
8
|
+
*/
|
|
9
|
+
export interface ExecutionTools {
|
|
10
|
+
/**
|
|
11
|
+
* Tools for executing prompts to large language models like GPT-4
|
|
12
|
+
*/
|
|
13
|
+
natural: NaturalExecutionTools;
|
|
14
|
+
/**
|
|
15
|
+
* Tools for executing scripts
|
|
16
|
+
*
|
|
17
|
+
* Note: You can pass multiple ScriptExecutionTools, they will be tried one by one until one of them supports the script
|
|
18
|
+
* If none of them supports the script, an error is thrown
|
|
19
|
+
*/
|
|
20
|
+
script: Array<ScriptExecutionTools>;
|
|
21
|
+
/**
|
|
22
|
+
* Tools for interacting with the user
|
|
23
|
+
*/
|
|
24
|
+
userInterface: UserInterfaceTools;
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Prompt } from '../types/Prompt';
|
|
2
|
+
import { PromptChatResult, PromptCompletionResult } from './PromptResult';
|
|
3
|
+
/**
|
|
4
|
+
* Vontainer for all the tools needed to execute prompts to large language models like GPT-4
|
|
5
|
+
* On its interface it exposes common methods for prompt execution.
|
|
6
|
+
* Inside (in constructor) it calls OpenAI, Azure, GPU, proxy, cache, logging,...
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/webgptorg/promptbook#natural-execution-tools
|
|
9
|
+
*/
|
|
10
|
+
export interface NaturalExecutionTools {
|
|
11
|
+
/**
|
|
12
|
+
* Use a chat model
|
|
13
|
+
*/
|
|
14
|
+
gptChat(prompt: Prompt): Promise<PromptChatResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Use a completion model
|
|
17
|
+
*/
|
|
18
|
+
gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* TODO: [🧠] Should or should not there be a word "GPT" in both gptComplete and gptChat
|
|
22
|
+
*/
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { string_model_name } from '.././types/typeAliases';
|
|
2
|
+
/**
|
|
3
|
+
* Prompt result is the simplest concept of execution.
|
|
4
|
+
* It is the result of executing one prompt _(NOT a template)_.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/webgptorg/promptbook#prompt-result
|
|
7
|
+
*/
|
|
8
|
+
export type PromptResult = PromptCompletionResult | PromptChatResult;
|
|
9
|
+
/**
|
|
10
|
+
* Prompt completion result
|
|
11
|
+
* It contains only the following text NOT the whole completion
|
|
12
|
+
*/
|
|
13
|
+
export type PromptCompletionResult = PromptCommonResult;
|
|
14
|
+
/**
|
|
15
|
+
* Prompt chat result
|
|
16
|
+
*/
|
|
17
|
+
export interface PromptChatResult extends PromptCommonResult {
|
|
18
|
+
}
|
|
19
|
+
export interface PromptCommonResult {
|
|
20
|
+
/**
|
|
21
|
+
* Exact text response from the model
|
|
22
|
+
*/
|
|
23
|
+
readonly content: string;
|
|
24
|
+
/**
|
|
25
|
+
* Name of the model used to generate the response
|
|
26
|
+
*/
|
|
27
|
+
readonly model: string_model_name;
|
|
28
|
+
/**
|
|
29
|
+
* Raw response from the model
|
|
30
|
+
*/
|
|
31
|
+
readonly rawResponse: object;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* TODO: [🧠] Should here be link to the prompt?
|
|
35
|
+
* TODO: [🧠] Maybe type raw properly - not onject but OpenAI.result.whatever
|
|
36
|
+
* TODO: [🧠] Maybe remove redundant raw.choices.text
|
|
37
|
+
* TODO: Log raw even if prompt failed - log the raw error
|
|
38
|
+
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Promisable } from 'type-fest';
|
|
2
|
+
import { string_name } from '.././types/typeAliases';
|
|
3
|
+
import { TaskProgress } from '../types/TaskProgress';
|
|
4
|
+
/**
|
|
5
|
+
* Executor is a simple async function that takes input parameters and returns result parameters _(along with all intermediate parameters and input parameters = it extends input object)_.
|
|
6
|
+
* Executor is made by combining execution tools and prompt template pipeline library.
|
|
7
|
+
*
|
|
8
|
+
* It can be done in two ways:
|
|
9
|
+
* - From `PromptTemplatePipelineLibrary.getExecutor` method
|
|
10
|
+
* - `createPtpExecutor` utility function
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/webgptorg/promptbook#executor
|
|
13
|
+
*/
|
|
14
|
+
export interface PtpExecutor {
|
|
15
|
+
(inputParameters: Record<string_name, string>, onProgress: (taskProgress: TaskProgress) => Promisable<void>): Promise<Record<string_name, string>>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* TODO: [🧠] Should this file be in /execution or /types folder?
|
|
19
|
+
*/
|