@promptbook/vercel 0.76.0 → 0.77.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.
- package/README.md +5 -1
- package/esm/index.es.js +673 -2
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/_packages/google.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/vercel.index.d.ts +4 -0
- package/esm/typings/src/execution/AvailableModel.d.ts +5 -1
- package/esm/typings/src/execution/CommonToolsOptions.d.ts +9 -0
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/GoogleExecutionToolsOptions.d.ts +12 -0
- package/esm/typings/src/llm-providers/google/createGoogleExecutionTools.d.ts +18 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +13 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +14 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -10
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/vercel/VercelExecutionToolsOptions.d.ts +22 -0
- package/esm/typings/src/llm-providers/vercel/VercelProvider.d.ts +13 -0
- package/esm/typings/src/llm-providers/vercel/createExecutionToolsFromVercelProvider.d.ts +8 -0
- package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +6 -0
- package/esm/typings/src/utils/{$currentDate.d.ts → $getCurrentDate.d.ts} +1 -1
- package/package.json +6 -2
- package/umd/index.umd.js +701 -27
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/_packages/gemini.index.d.ts +0 -2
- package/esm/typings/src/utils/getCurrentIsoDate.d.ts +0 -7
package/esm/index.es.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import colors from 'colors';
|
|
2
|
+
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
3
|
+
|
|
1
4
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
2
5
|
/**
|
|
3
6
|
* The version of the Book language
|
|
@@ -10,11 +13,679 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
10
13
|
*
|
|
11
14
|
* @see https://github.com/webgptorg/promptbook
|
|
12
15
|
*/
|
|
13
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
16
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.77.0-2';
|
|
14
17
|
/**
|
|
15
18
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
16
19
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
17
20
|
*/
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
/*! *****************************************************************************
|
|
23
|
+
Copyright (c) Microsoft Corporation.
|
|
24
|
+
|
|
25
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
26
|
+
purpose with or without fee is hereby granted.
|
|
27
|
+
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
29
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
30
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
31
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
32
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
33
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
34
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
35
|
+
***************************************************************************** */
|
|
36
|
+
/* global Reflect, Promise */
|
|
37
|
+
|
|
38
|
+
var extendStatics = function(d, b) {
|
|
39
|
+
extendStatics = Object.setPrototypeOf ||
|
|
40
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
41
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
42
|
+
return extendStatics(d, b);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function __extends(d, b) {
|
|
46
|
+
if (typeof b !== "function" && b !== null)
|
|
47
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
48
|
+
extendStatics(d, b);
|
|
49
|
+
function __() { this.constructor = d; }
|
|
50
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var __assign = function() {
|
|
54
|
+
__assign = Object.assign || function __assign(t) {
|
|
55
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
56
|
+
s = arguments[i];
|
|
57
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
};
|
|
61
|
+
return __assign.apply(this, arguments);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
65
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
66
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
67
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
68
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
69
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
70
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function __generator(thisArg, body) {
|
|
75
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
76
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
77
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
78
|
+
function step(op) {
|
|
79
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
80
|
+
while (_) try {
|
|
81
|
+
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;
|
|
82
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
83
|
+
switch (op[0]) {
|
|
84
|
+
case 0: case 1: t = op; break;
|
|
85
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
86
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
87
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
88
|
+
default:
|
|
89
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
90
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
91
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
92
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
93
|
+
if (t[2]) _.ops.pop();
|
|
94
|
+
_.trys.pop(); continue;
|
|
95
|
+
}
|
|
96
|
+
op = body.call(thisArg, _);
|
|
97
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
98
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function __values(o) {
|
|
103
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
104
|
+
if (m) return m.call(o);
|
|
105
|
+
if (o && typeof o.length === "number") return {
|
|
106
|
+
next: function () {
|
|
107
|
+
if (o && i >= o.length) o = void 0;
|
|
108
|
+
return { value: o && o[i++], done: !o };
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function __read(o, n) {
|
|
115
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
116
|
+
if (!m) return o;
|
|
117
|
+
var i = m.call(o), r, ar = [], e;
|
|
118
|
+
try {
|
|
119
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
120
|
+
}
|
|
121
|
+
catch (error) { e = { error: error }; }
|
|
122
|
+
finally {
|
|
123
|
+
try {
|
|
124
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
125
|
+
}
|
|
126
|
+
finally { if (e) throw e.error; }
|
|
127
|
+
}
|
|
128
|
+
return ar;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function __spreadArray(to, from, pack) {
|
|
132
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
133
|
+
if (ar || !(i in from)) {
|
|
134
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
135
|
+
ar[i] = from[i];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* This error indicates errors during the execution of the pipeline
|
|
143
|
+
*
|
|
144
|
+
* @public exported from `@promptbook/core`
|
|
145
|
+
*/
|
|
146
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
147
|
+
__extends(PipelineExecutionError, _super);
|
|
148
|
+
function PipelineExecutionError(message) {
|
|
149
|
+
var _this = _super.call(this, message) || this;
|
|
150
|
+
_this.name = 'PipelineExecutionError';
|
|
151
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
152
|
+
return _this;
|
|
153
|
+
}
|
|
154
|
+
return PipelineExecutionError;
|
|
155
|
+
}(Error));
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @@@
|
|
159
|
+
*
|
|
160
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
161
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
162
|
+
*
|
|
163
|
+
* @returns The same object as the input, but deeply frozen
|
|
164
|
+
* @public exported from `@promptbook/utils`
|
|
165
|
+
*/
|
|
166
|
+
function $deepFreeze(objectValue) {
|
|
167
|
+
var e_1, _a;
|
|
168
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
169
|
+
try {
|
|
170
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
171
|
+
var propertyName = propertyNames_1_1.value;
|
|
172
|
+
var value = objectValue[propertyName];
|
|
173
|
+
if (value && typeof value === 'object') {
|
|
174
|
+
$deepFreeze(value);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
179
|
+
finally {
|
|
180
|
+
try {
|
|
181
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
182
|
+
}
|
|
183
|
+
finally { if (e_1) throw e_1.error; }
|
|
184
|
+
}
|
|
185
|
+
return Object.freeze(objectValue);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Represents the usage with no resources consumed
|
|
193
|
+
*
|
|
194
|
+
* @public exported from `@promptbook/core`
|
|
195
|
+
*/
|
|
196
|
+
$deepFreeze({
|
|
197
|
+
price: { value: 0 },
|
|
198
|
+
input: {
|
|
199
|
+
tokensCount: { value: 0 },
|
|
200
|
+
charactersCount: { value: 0 },
|
|
201
|
+
wordsCount: { value: 0 },
|
|
202
|
+
sentencesCount: { value: 0 },
|
|
203
|
+
linesCount: { value: 0 },
|
|
204
|
+
paragraphsCount: { value: 0 },
|
|
205
|
+
pagesCount: { value: 0 },
|
|
206
|
+
},
|
|
207
|
+
output: {
|
|
208
|
+
tokensCount: { value: 0 },
|
|
209
|
+
charactersCount: { value: 0 },
|
|
210
|
+
wordsCount: { value: 0 },
|
|
211
|
+
sentencesCount: { value: 0 },
|
|
212
|
+
linesCount: { value: 0 },
|
|
213
|
+
paragraphsCount: { value: 0 },
|
|
214
|
+
pagesCount: { value: 0 },
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
/**
|
|
218
|
+
* Represents the usage with unknown resources consumed
|
|
219
|
+
*
|
|
220
|
+
* @public exported from `@promptbook/core`
|
|
221
|
+
*/
|
|
222
|
+
var UNCERTAIN_USAGE = $deepFreeze({
|
|
223
|
+
price: { value: 0, isUncertain: true },
|
|
224
|
+
input: {
|
|
225
|
+
tokensCount: { value: 0, isUncertain: true },
|
|
226
|
+
charactersCount: { value: 0, isUncertain: true },
|
|
227
|
+
wordsCount: { value: 0, isUncertain: true },
|
|
228
|
+
sentencesCount: { value: 0, isUncertain: true },
|
|
229
|
+
linesCount: { value: 0, isUncertain: true },
|
|
230
|
+
paragraphsCount: { value: 0, isUncertain: true },
|
|
231
|
+
pagesCount: { value: 0, isUncertain: true },
|
|
232
|
+
},
|
|
233
|
+
output: {
|
|
234
|
+
tokensCount: { value: 0, isUncertain: true },
|
|
235
|
+
charactersCount: { value: 0, isUncertain: true },
|
|
236
|
+
wordsCount: { value: 0, isUncertain: true },
|
|
237
|
+
sentencesCount: { value: 0, isUncertain: true },
|
|
238
|
+
linesCount: { value: 0, isUncertain: true },
|
|
239
|
+
paragraphsCount: { value: 0, isUncertain: true },
|
|
240
|
+
pagesCount: { value: 0, isUncertain: true },
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
/**
|
|
244
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Simple wrapper `new Date().toISOString()`
|
|
249
|
+
*
|
|
250
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
|
251
|
+
*
|
|
252
|
+
* @returns string_date branded type
|
|
253
|
+
* @public exported from `@promptbook/utils`
|
|
254
|
+
*/
|
|
255
|
+
function $getCurrentDate() {
|
|
256
|
+
return new Date().toISOString();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
261
|
+
*
|
|
262
|
+
* @public exported from `@promptbook/core`
|
|
263
|
+
*/
|
|
264
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
265
|
+
__extends(UnexpectedError, _super);
|
|
266
|
+
function UnexpectedError(message) {
|
|
267
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
268
|
+
_this.name = 'UnexpectedError';
|
|
269
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
270
|
+
return _this;
|
|
271
|
+
}
|
|
272
|
+
return UnexpectedError;
|
|
273
|
+
}(Error));
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
277
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
278
|
+
*
|
|
279
|
+
* - Almost all primitives are serializable BUT:
|
|
280
|
+
* - `undefined` is not serializable
|
|
281
|
+
* - `NaN` is not serializable
|
|
282
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
283
|
+
* - Functions are not serializable
|
|
284
|
+
* - Circular references are not serializable
|
|
285
|
+
* - `Date` objects are not serializable
|
|
286
|
+
* - `Map` and `Set` objects are not serializable
|
|
287
|
+
* - `RegExp` objects are not serializable
|
|
288
|
+
* - `Error` objects are not serializable
|
|
289
|
+
* - `Symbol` objects are not serializable
|
|
290
|
+
* - And much more...
|
|
291
|
+
*
|
|
292
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
293
|
+
* @public exported from `@promptbook/utils`
|
|
294
|
+
*/
|
|
295
|
+
function checkSerializableAsJson(name, value) {
|
|
296
|
+
var e_1, _a;
|
|
297
|
+
if (value === undefined) {
|
|
298
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
299
|
+
}
|
|
300
|
+
else if (value === null) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
else if (typeof value === 'boolean') {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
else if (typeof value === 'string') {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
else if (typeof value === 'symbol') {
|
|
313
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
314
|
+
}
|
|
315
|
+
else if (typeof value === 'function') {
|
|
316
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
317
|
+
}
|
|
318
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
319
|
+
for (var i = 0; i < value.length; i++) {
|
|
320
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else if (typeof value === 'object') {
|
|
324
|
+
if (value instanceof Date) {
|
|
325
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
326
|
+
}
|
|
327
|
+
else if (value instanceof Map) {
|
|
328
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
329
|
+
}
|
|
330
|
+
else if (value instanceof Set) {
|
|
331
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
332
|
+
}
|
|
333
|
+
else if (value instanceof RegExp) {
|
|
334
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
335
|
+
}
|
|
336
|
+
else if (value instanceof Error) {
|
|
337
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
try {
|
|
341
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
342
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
343
|
+
if (subValue === undefined) {
|
|
344
|
+
// Note: undefined in object is serializable - it is just omited
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
351
|
+
finally {
|
|
352
|
+
try {
|
|
353
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
354
|
+
}
|
|
355
|
+
finally { if (e_1) throw e_1.error; }
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
if (!(error instanceof Error)) {
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
365
|
+
}
|
|
366
|
+
/*
|
|
367
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
368
|
+
const seen = new Set();
|
|
369
|
+
const stack = [{ value }];
|
|
370
|
+
while (stack.length > 0) {
|
|
371
|
+
const { value } = stack.pop()!;
|
|
372
|
+
if (typeof value === 'object' && value !== null) {
|
|
373
|
+
if (seen.has(value)) {
|
|
374
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
375
|
+
}
|
|
376
|
+
seen.add(value);
|
|
377
|
+
if (Array.isArray(value)) {
|
|
378
|
+
stack.push(...value.map((value) => ({ value })));
|
|
379
|
+
} else {
|
|
380
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
*/
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
394
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
395
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
396
|
+
*/
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @@@
|
|
400
|
+
* @@@
|
|
401
|
+
*
|
|
402
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
403
|
+
*
|
|
404
|
+
* @param name - Name of the object for debugging purposes
|
|
405
|
+
* @param objectValue - Object to be deeply frozen
|
|
406
|
+
* @returns The same object as the input, but deeply frozen
|
|
407
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
408
|
+
*/
|
|
409
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
410
|
+
checkSerializableAsJson(name, objectValue);
|
|
411
|
+
return $deepFreeze(objectValue);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
415
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
416
|
+
*/
|
|
417
|
+
|
|
418
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
419
|
+
/**
|
|
420
|
+
* The maximum number of iterations for a loops
|
|
421
|
+
*
|
|
422
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
423
|
+
*/
|
|
424
|
+
var LOOP_LIMIT = 1000;
|
|
425
|
+
/**
|
|
426
|
+
* Nonce which is used for replacing things in strings
|
|
427
|
+
*
|
|
428
|
+
* @private within the repository
|
|
429
|
+
*/
|
|
430
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
431
|
+
/**
|
|
432
|
+
* The names of the parameters that are reserved for special purposes
|
|
433
|
+
*
|
|
434
|
+
* @public exported from `@promptbook/core`
|
|
435
|
+
*/
|
|
436
|
+
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
437
|
+
'content',
|
|
438
|
+
'context',
|
|
439
|
+
'knowledge',
|
|
440
|
+
'examples',
|
|
441
|
+
'modelName',
|
|
442
|
+
'currentDate',
|
|
443
|
+
// <- TODO: list here all command names
|
|
444
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
445
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
446
|
+
]);
|
|
447
|
+
/**
|
|
448
|
+
* @@@
|
|
449
|
+
*
|
|
450
|
+
* @private within the repository
|
|
451
|
+
*/
|
|
452
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
453
|
+
/**
|
|
454
|
+
* @@@
|
|
455
|
+
*
|
|
456
|
+
* @private within the repository
|
|
457
|
+
*/
|
|
458
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
459
|
+
// <- TODO: [🧜♂️]
|
|
460
|
+
/**
|
|
461
|
+
* @@@
|
|
462
|
+
*
|
|
463
|
+
* @public exported from `@promptbook/core`
|
|
464
|
+
*/
|
|
465
|
+
Object.freeze({
|
|
466
|
+
delimiter: ',',
|
|
467
|
+
quoteChar: '"',
|
|
468
|
+
newline: '\n',
|
|
469
|
+
skipEmptyLines: true,
|
|
470
|
+
});
|
|
471
|
+
/**
|
|
472
|
+
* TODO: Extract `constants.ts` from `config.ts`
|
|
473
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
474
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* This error type indicates that some limit was reached
|
|
479
|
+
*
|
|
480
|
+
* @public exported from `@promptbook/core`
|
|
481
|
+
*/
|
|
482
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
483
|
+
__extends(LimitReachedError, _super);
|
|
484
|
+
function LimitReachedError(message) {
|
|
485
|
+
var _this = _super.call(this, message) || this;
|
|
486
|
+
_this.name = 'LimitReachedError';
|
|
487
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
488
|
+
return _this;
|
|
489
|
+
}
|
|
490
|
+
return LimitReachedError;
|
|
491
|
+
}(Error));
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Replaces parameters in template with values from parameters object
|
|
495
|
+
*
|
|
496
|
+
* @param template the template with parameters in {curly} braces
|
|
497
|
+
* @param parameters the object with parameters
|
|
498
|
+
* @returns the template with replaced parameters
|
|
499
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
500
|
+
* @public exported from `@promptbook/utils`
|
|
501
|
+
*/
|
|
502
|
+
function replaceParameters(template, parameters) {
|
|
503
|
+
var e_1, _a;
|
|
504
|
+
try {
|
|
505
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
506
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
507
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
508
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
509
|
+
}
|
|
510
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
511
|
+
// TODO: [🍵]
|
|
512
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
517
|
+
finally {
|
|
518
|
+
try {
|
|
519
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
520
|
+
}
|
|
521
|
+
finally { if (e_1) throw e_1.error; }
|
|
522
|
+
}
|
|
523
|
+
var replacedTemplates = template;
|
|
524
|
+
var match;
|
|
525
|
+
var loopLimit = LOOP_LIMIT;
|
|
526
|
+
var _loop_1 = function () {
|
|
527
|
+
if (loopLimit-- < 0) {
|
|
528
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
529
|
+
}
|
|
530
|
+
var precol = match.groups.precol;
|
|
531
|
+
var parameterName = match.groups.parameterName;
|
|
532
|
+
if (parameterName === '') {
|
|
533
|
+
return "continue";
|
|
534
|
+
}
|
|
535
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
536
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
537
|
+
}
|
|
538
|
+
if (parameters[parameterName] === undefined) {
|
|
539
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
540
|
+
}
|
|
541
|
+
var parameterValue = parameters[parameterName];
|
|
542
|
+
if (parameterValue === undefined) {
|
|
543
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
544
|
+
}
|
|
545
|
+
parameterValue = parameterValue.toString();
|
|
546
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
547
|
+
parameterValue = parameterValue
|
|
548
|
+
.split('\n')
|
|
549
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
550
|
+
.join('\n');
|
|
551
|
+
}
|
|
552
|
+
replacedTemplates =
|
|
553
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
554
|
+
parameterValue +
|
|
555
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
556
|
+
};
|
|
557
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
558
|
+
.exec(replacedTemplates))) {
|
|
559
|
+
_loop_1();
|
|
560
|
+
}
|
|
561
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
562
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
563
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
564
|
+
}
|
|
565
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
566
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
567
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
568
|
+
}
|
|
569
|
+
return replacedTemplates;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* !!!!!!
|
|
574
|
+
*
|
|
575
|
+
* @public exported from `@promptbook/vercel`
|
|
576
|
+
*/
|
|
577
|
+
function createExecutionToolsFromVercelProvider(options) {
|
|
578
|
+
var vercelProvider = options.vercelProvider, availableModels = options.availableModels, userId = options.userId, _a = options.additionalChatSettings, additionalChatSettings = _a === void 0 ? {} : _a;
|
|
579
|
+
return {
|
|
580
|
+
title: '!!!',
|
|
581
|
+
description: "!!! (through Vercel)",
|
|
582
|
+
checkConfiguration: function () {
|
|
583
|
+
// TODO: !!!!!!
|
|
584
|
+
return Promise.resolve();
|
|
585
|
+
},
|
|
586
|
+
listModels: function () {
|
|
587
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
588
|
+
return __generator(this, function (_a) {
|
|
589
|
+
return [2 /*return*/, availableModels];
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
},
|
|
593
|
+
callChatModel: function (prompt) {
|
|
594
|
+
var _a;
|
|
595
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
596
|
+
var content, parameters, modelRequirements, modelName, model, rawPromptContent, rawRequest, start, rawResponse, complete, usage;
|
|
597
|
+
return __generator(this, function (_b) {
|
|
598
|
+
switch (_b.label) {
|
|
599
|
+
case 0:
|
|
600
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
601
|
+
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
602
|
+
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
603
|
+
}
|
|
604
|
+
modelName = modelRequirements.modelName ||
|
|
605
|
+
((_a = availableModels.find(function (_a) {
|
|
606
|
+
var modelVariant = _a.modelVariant;
|
|
607
|
+
return modelVariant === 'CHAT';
|
|
608
|
+
})) === null || _a === void 0 ? void 0 : _a.modelName);
|
|
609
|
+
if (!modelName) {
|
|
610
|
+
throw new PipelineExecutionError(spaceTrim$1("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
|
|
611
|
+
}
|
|
612
|
+
return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
|
|
613
|
+
case 1:
|
|
614
|
+
model = _b.sent();
|
|
615
|
+
rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
|
|
616
|
+
rawRequest = {
|
|
617
|
+
// <- TODO: [☂]
|
|
618
|
+
inputFormat: 'messages',
|
|
619
|
+
mode: {
|
|
620
|
+
type: 'regular',
|
|
621
|
+
tools: [
|
|
622
|
+
/* !!!!!! */
|
|
623
|
+
],
|
|
624
|
+
},
|
|
625
|
+
prompt: __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
|
|
626
|
+
? []
|
|
627
|
+
: [
|
|
628
|
+
{
|
|
629
|
+
role: 'system',
|
|
630
|
+
content: modelRequirements.systemMessage,
|
|
631
|
+
},
|
|
632
|
+
])), false), [
|
|
633
|
+
{
|
|
634
|
+
role: 'user',
|
|
635
|
+
content: [
|
|
636
|
+
{
|
|
637
|
+
type: 'text',
|
|
638
|
+
text: rawPromptContent,
|
|
639
|
+
},
|
|
640
|
+
],
|
|
641
|
+
},
|
|
642
|
+
], false),
|
|
643
|
+
};
|
|
644
|
+
start = $getCurrentDate();
|
|
645
|
+
if (options.isVerbose) {
|
|
646
|
+
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
647
|
+
}
|
|
648
|
+
return [4 /*yield*/, model.doGenerate(rawRequest)];
|
|
649
|
+
case 2:
|
|
650
|
+
rawResponse = _b.sent();
|
|
651
|
+
/*
|
|
652
|
+
TODO: !!!!!! Handle errors
|
|
653
|
+
.catch((error) => {
|
|
654
|
+
if (options.isVerbose) {
|
|
655
|
+
console.info(colors.bgRed('error'), error);
|
|
656
|
+
}
|
|
657
|
+
throw error;
|
|
658
|
+
});
|
|
659
|
+
*/
|
|
660
|
+
if (options.isVerbose) {
|
|
661
|
+
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
662
|
+
}
|
|
663
|
+
if (rawResponse.text === undefined) {
|
|
664
|
+
throw new PipelineExecutionError('No response message');
|
|
665
|
+
}
|
|
666
|
+
complete = $getCurrentDate();
|
|
667
|
+
usage = UNCERTAIN_USAGE;
|
|
668
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('createExecutionToolsFromVercelProvider ChatPromptResult', {
|
|
669
|
+
content: rawResponse.text,
|
|
670
|
+
modelName: modelName,
|
|
671
|
+
timing: {
|
|
672
|
+
start: start,
|
|
673
|
+
complete: complete,
|
|
674
|
+
},
|
|
675
|
+
usage: usage,
|
|
676
|
+
rawPromptContent: rawPromptContent,
|
|
677
|
+
rawRequest: rawRequest,
|
|
678
|
+
rawResponse: {
|
|
679
|
+
/* TODO: !!!!!! UnexpectedError: createExecutionToolsFromVercelProvider ChatPromptResult.rawResponse.response.timestamp is Date */
|
|
680
|
+
},
|
|
681
|
+
// <- [🗯]
|
|
682
|
+
})];
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
},
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION, createExecutionToolsFromVercelProvider };
|
|
20
691
|
//# sourceMappingURL=index.es.js.map
|