@promptbook/core 0.52.0-2 → 0.52.0-3

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.
@@ -0,0 +1,35 @@
1
+ import type { Prompt } from '../../../../types/Prompt';
2
+ import type { AvailableModel, LlmExecutionTools } from '../../../LlmExecutionTools';
3
+ import type { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
4
+ /**
5
+ * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
6
+ *
7
+ * @see https://github.com/webgptorg/promptbook#multiple-server
8
+ */
9
+ export declare class MultipleLlmExecutionTools implements LlmExecutionTools {
10
+ /**
11
+ * Array of execution tools in order of priority
12
+ */
13
+ private llmExecutionTools;
14
+ /**
15
+ * Gets array of execution tools in order of priority
16
+ */
17
+ constructor(...llmExecutionTools: Array<LlmExecutionTools>);
18
+ /**
19
+ * Calls the best available chat model
20
+ */
21
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
22
+ /**
23
+ * Calls the best available completion model
24
+ */
25
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
26
+ /**
27
+ * Calls the best available model
28
+ */
29
+ private gptCommon;
30
+ /**
31
+ * List all available models that can be used
32
+ * This liost is a combination of all available models from all execution tools
33
+ */
34
+ listModels(): Promise<Array<AvailableModel>>;
35
+ }
@@ -0,0 +1,23 @@
1
+ import type { client_id, string_uri } from '../../../../types/typeAliases';
2
+ import type { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ /**
4
+ * Options for MultipleLlmExecutionTools
5
+ */
6
+ export type MultipleLlmExecutionToolsOptions = CommonExecutionToolsOptions & {
7
+ /**
8
+ * URL of the multiple PROMPTBOOK server
9
+ * On this server will be connected to the socket.io server
10
+ */
11
+ readonly multipleUrl: URL;
12
+ /**
13
+ * Path for the Socket.io server to listen
14
+ *
15
+ * @default '/socket.io'
16
+ * @example '/promptbook/socket.io'
17
+ */
18
+ readonly path: string_uri;
19
+ /**
20
+ * Your client ID
21
+ */
22
+ readonly clientId: client_id;
23
+ };
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ts-node
2
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.52.0-2",
3
+ "version": "0.52.0-3",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -453,7 +453,7 @@
453
453
  /**
454
454
  * The version of the Promptbook library
455
455
  */
456
- var PROMPTBOOK_VERSION = '0.52.0-1';
456
+ var PROMPTBOOK_VERSION = '0.52.0-2';
457
457
 
458
458
  /**
459
459
  * Parses the template and returns the list of all parameter names
@@ -3132,8 +3132,140 @@
3132
3132
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3133
3133
  */
3134
3134
 
3135
+ /**
3136
+ * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
3137
+ *
3138
+ * @see https://github.com/webgptorg/promptbook#multiple-server
3139
+ */
3140
+ var MultipleLlmExecutionTools = /** @class */ (function () {
3141
+ /**
3142
+ * Gets array of execution tools in order of priority
3143
+ */
3144
+ function MultipleLlmExecutionTools() {
3145
+ var llmExecutionTools = [];
3146
+ for (var _i = 0; _i < arguments.length; _i++) {
3147
+ llmExecutionTools[_i] = arguments[_i];
3148
+ }
3149
+ this.llmExecutionTools = llmExecutionTools;
3150
+ }
3151
+ /**
3152
+ * Calls the best available chat model
3153
+ */
3154
+ MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
3155
+ return this.gptCommon(prompt);
3156
+ };
3157
+ /**
3158
+ * Calls the best available completion model
3159
+ */
3160
+ MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
3161
+ return this.gptCommon(prompt);
3162
+ };
3163
+ /**
3164
+ * Calls the best available model
3165
+ */
3166
+ MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
3167
+ return __awaiter(this, void 0, void 0, function () {
3168
+ var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
3169
+ var e_1, _c;
3170
+ return __generator(this, function (_d) {
3171
+ switch (_d.label) {
3172
+ case 0:
3173
+ errors = [];
3174
+ _d.label = 1;
3175
+ case 1:
3176
+ _d.trys.push([1, 11, 12, 13]);
3177
+ _a = __values(this.llmExecutionTools), _b = _a.next();
3178
+ _d.label = 2;
3179
+ case 2:
3180
+ if (!!_b.done) return [3 /*break*/, 10];
3181
+ llmExecutionTools = _b.value;
3182
+ _d.label = 3;
3183
+ case 3:
3184
+ _d.trys.push([3, 8, , 9]);
3185
+ if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
3186
+ return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
3187
+ case 4: return [2 /*return*/, _d.sent()];
3188
+ case 5:
3189
+ if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
3190
+ return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
3191
+ case 6: return [2 /*return*/, _d.sent()];
3192
+ case 7: return [3 /*break*/, 9];
3193
+ case 8:
3194
+ error_1 = _d.sent();
3195
+ if (!(error_1 instanceof Error)) {
3196
+ throw error_1;
3197
+ }
3198
+ errors.push(error_1);
3199
+ return [3 /*break*/, 9];
3200
+ case 9:
3201
+ _b = _a.next();
3202
+ return [3 /*break*/, 2];
3203
+ case 10: return [3 /*break*/, 13];
3204
+ case 11:
3205
+ e_1_1 = _d.sent();
3206
+ e_1 = { error: e_1_1 };
3207
+ return [3 /*break*/, 13];
3208
+ case 12:
3209
+ try {
3210
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3211
+ }
3212
+ finally { if (e_1) throw e_1.error; }
3213
+ return [7 /*endfinally*/];
3214
+ case 13: throw new Error(spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n \n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n \n "); }));
3215
+ }
3216
+ });
3217
+ });
3218
+ };
3219
+ /**
3220
+ * List all available models that can be used
3221
+ * This liost is a combination of all available models from all execution tools
3222
+ */
3223
+ MultipleLlmExecutionTools.prototype.listModels = function () {
3224
+ return __awaiter(this, void 0, void 0, function () {
3225
+ var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
3226
+ var e_2, _c;
3227
+ return __generator(this, function (_d) {
3228
+ switch (_d.label) {
3229
+ case 0:
3230
+ availableModels = [];
3231
+ _d.label = 1;
3232
+ case 1:
3233
+ _d.trys.push([1, 6, 7, 8]);
3234
+ _a = __values(this.llmExecutionTools), _b = _a.next();
3235
+ _d.label = 2;
3236
+ case 2:
3237
+ if (!!_b.done) return [3 /*break*/, 5];
3238
+ llmExecutionTools = _b.value;
3239
+ return [4 /*yield*/, llmExecutionTools.listModels()];
3240
+ case 3:
3241
+ models = _d.sent();
3242
+ availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
3243
+ _d.label = 4;
3244
+ case 4:
3245
+ _b = _a.next();
3246
+ return [3 /*break*/, 2];
3247
+ case 5: return [3 /*break*/, 8];
3248
+ case 6:
3249
+ e_2_1 = _d.sent();
3250
+ e_2 = { error: e_2_1 };
3251
+ return [3 /*break*/, 8];
3252
+ case 7:
3253
+ try {
3254
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3255
+ }
3256
+ finally { if (e_2) throw e_2.error; }
3257
+ return [7 /*endfinally*/];
3258
+ case 8: return [2 /*return*/, availableModels];
3259
+ }
3260
+ });
3261
+ });
3262
+ };
3263
+ return MultipleLlmExecutionTools;
3264
+ }());
3265
+
3135
3266
  exports.CallbackInterfaceTools = CallbackInterfaceTools;
3136
3267
  exports.ExecutionTypes = ExecutionTypes;
3268
+ exports.MultipleLlmExecutionTools = MultipleLlmExecutionTools;
3137
3269
  exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
3138
3270
  exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
3139
3271
  exports.SimplePromptbookLibrary = SimplePromptbookLibrary;