@promptbook/azure-openai 0.77.1 → 0.78.2
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/esm/index.es.js +225 -203
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -8
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
- package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +223 -201
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
- /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
|
|
2
2
|
import colors from 'colors';
|
|
3
|
-
import spaceTrim
|
|
3
|
+
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
4
4
|
|
|
5
5
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
6
6
|
/**
|
|
@@ -14,7 +14,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
14
14
|
*
|
|
15
15
|
* @see https://github.com/webgptorg/promptbook
|
|
16
16
|
*/
|
|
17
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
17
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
18
18
|
/**
|
|
19
19
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
20
20
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -140,198 +140,25 @@ function __spreadArray(to, from, pack) {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
146
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
143
|
+
* Name for the Promptbook
|
|
147
144
|
*
|
|
148
|
-
*
|
|
149
|
-
* @public exported from `@promptbook/utils`
|
|
150
|
-
*/
|
|
151
|
-
function $deepFreeze(objectValue) {
|
|
152
|
-
var e_1, _a;
|
|
153
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
154
|
-
try {
|
|
155
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
156
|
-
var propertyName = propertyNames_1_1.value;
|
|
157
|
-
var value = objectValue[propertyName];
|
|
158
|
-
if (value && typeof value === 'object') {
|
|
159
|
-
$deepFreeze(value);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
164
|
-
finally {
|
|
165
|
-
try {
|
|
166
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
167
|
-
}
|
|
168
|
-
finally { if (e_1) throw e_1.error; }
|
|
169
|
-
}
|
|
170
|
-
return Object.freeze(objectValue);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
145
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
178
146
|
*
|
|
179
147
|
* @public exported from `@promptbook/core`
|
|
180
148
|
*/
|
|
181
|
-
var
|
|
182
|
-
__extends(UnexpectedError, _super);
|
|
183
|
-
function UnexpectedError(message) {
|
|
184
|
-
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;
|
|
185
|
-
_this.name = 'UnexpectedError';
|
|
186
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
187
|
-
return _this;
|
|
188
|
-
}
|
|
189
|
-
return UnexpectedError;
|
|
190
|
-
}(Error));
|
|
191
|
-
|
|
149
|
+
var NAME = "Promptbook";
|
|
192
150
|
/**
|
|
193
|
-
*
|
|
194
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
151
|
+
* Email of the responsible person
|
|
195
152
|
*
|
|
196
|
-
*
|
|
197
|
-
* - `undefined` is not serializable
|
|
198
|
-
* - `NaN` is not serializable
|
|
199
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
200
|
-
* - Functions are not serializable
|
|
201
|
-
* - Circular references are not serializable
|
|
202
|
-
* - `Date` objects are not serializable
|
|
203
|
-
* - `Map` and `Set` objects are not serializable
|
|
204
|
-
* - `RegExp` objects are not serializable
|
|
205
|
-
* - `Error` objects are not serializable
|
|
206
|
-
* - `Symbol` objects are not serializable
|
|
207
|
-
* - And much more...
|
|
208
|
-
*
|
|
209
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
210
|
-
* @public exported from `@promptbook/utils`
|
|
211
|
-
*/
|
|
212
|
-
function checkSerializableAsJson(name, value) {
|
|
213
|
-
var e_1, _a;
|
|
214
|
-
if (value === undefined) {
|
|
215
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
216
|
-
}
|
|
217
|
-
else if (value === null) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
else if (typeof value === 'boolean') {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
else if (typeof value === 'string') {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
else if (typeof value === 'symbol') {
|
|
230
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
231
|
-
}
|
|
232
|
-
else if (typeof value === 'function') {
|
|
233
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
234
|
-
}
|
|
235
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
236
|
-
for (var i = 0; i < value.length; i++) {
|
|
237
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
else if (typeof value === 'object') {
|
|
241
|
-
if (value instanceof Date) {
|
|
242
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
243
|
-
}
|
|
244
|
-
else if (value instanceof Map) {
|
|
245
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
246
|
-
}
|
|
247
|
-
else if (value instanceof Set) {
|
|
248
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
249
|
-
}
|
|
250
|
-
else if (value instanceof RegExp) {
|
|
251
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
252
|
-
}
|
|
253
|
-
else if (value instanceof Error) {
|
|
254
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
try {
|
|
258
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
259
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
260
|
-
if (subValue === undefined) {
|
|
261
|
-
// Note: undefined in object is serializable - it is just omited
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
268
|
-
finally {
|
|
269
|
-
try {
|
|
270
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
271
|
-
}
|
|
272
|
-
finally { if (e_1) throw e_1.error; }
|
|
273
|
-
}
|
|
274
|
-
try {
|
|
275
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
if (!(error instanceof Error)) {
|
|
279
|
-
throw error;
|
|
280
|
-
}
|
|
281
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
282
|
-
}
|
|
283
|
-
/*
|
|
284
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
285
|
-
const seen = new Set();
|
|
286
|
-
const stack = [{ value }];
|
|
287
|
-
while (stack.length > 0) {
|
|
288
|
-
const { value } = stack.pop()!;
|
|
289
|
-
if (typeof value === 'object' && value !== null) {
|
|
290
|
-
if (seen.has(value)) {
|
|
291
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
292
|
-
}
|
|
293
|
-
seen.add(value);
|
|
294
|
-
if (Array.isArray(value)) {
|
|
295
|
-
stack.push(...value.map((value) => ({ value })));
|
|
296
|
-
} else {
|
|
297
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
*/
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
311
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
312
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
153
|
+
* @public exported from `@promptbook/core`
|
|
313
154
|
*/
|
|
314
|
-
|
|
155
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
315
156
|
/**
|
|
316
|
-
*
|
|
317
|
-
* @@@
|
|
157
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
318
158
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* @param name - Name of the object for debugging purposes
|
|
322
|
-
* @param objectValue - Object to be deeply frozen
|
|
323
|
-
* @returns The same object as the input, but deeply frozen
|
|
324
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
325
|
-
*/
|
|
326
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
327
|
-
checkSerializableAsJson(name, objectValue);
|
|
328
|
-
return $deepFreeze(objectValue);
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
332
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
159
|
+
* @public exported from `@promptbook/core`
|
|
333
160
|
*/
|
|
334
|
-
|
|
161
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
335
162
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
336
163
|
/**
|
|
337
164
|
* The maximum number of iterations for a loops
|
|
@@ -351,22 +178,6 @@ var CONNECTION_TIMEOUT_MS = 7 * 1000;
|
|
|
351
178
|
* @private within the repository
|
|
352
179
|
*/
|
|
353
180
|
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
354
|
-
/**
|
|
355
|
-
* The names of the parameters that are reserved for special purposes
|
|
356
|
-
*
|
|
357
|
-
* @public exported from `@promptbook/core`
|
|
358
|
-
*/
|
|
359
|
-
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
360
|
-
'content',
|
|
361
|
-
'context',
|
|
362
|
-
'knowledge',
|
|
363
|
-
'examples',
|
|
364
|
-
'modelName',
|
|
365
|
-
'currentDate',
|
|
366
|
-
// <- TODO: list here all command names
|
|
367
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
368
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
369
|
-
]);
|
|
370
181
|
/**
|
|
371
182
|
* @@@
|
|
372
183
|
*
|
|
@@ -413,6 +224,40 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
413
224
|
return PipelineExecutionError;
|
|
414
225
|
}(Error));
|
|
415
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Make error report URL for the given error
|
|
229
|
+
*
|
|
230
|
+
* @private !!!!!!
|
|
231
|
+
*/
|
|
232
|
+
function getErrorReportUrl(error) {
|
|
233
|
+
var report = {
|
|
234
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
235
|
+
body: spaceTrim(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
236
|
+
};
|
|
237
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
238
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
239
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
240
|
+
reportUrl.searchParams.set('title', report.title);
|
|
241
|
+
reportUrl.searchParams.set('body', report.body);
|
|
242
|
+
return reportUrl;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
247
|
+
*
|
|
248
|
+
* @public exported from `@promptbook/core`
|
|
249
|
+
*/
|
|
250
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
251
|
+
__extends(UnexpectedError, _super);
|
|
252
|
+
function UnexpectedError(message) {
|
|
253
|
+
var _this = _super.call(this, spaceTrim$1(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 ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
254
|
+
_this.name = 'UnexpectedError';
|
|
255
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
256
|
+
return _this;
|
|
257
|
+
}
|
|
258
|
+
return UnexpectedError;
|
|
259
|
+
}(Error));
|
|
260
|
+
|
|
416
261
|
/**
|
|
417
262
|
* Counts number of characters in the text
|
|
418
263
|
*
|
|
@@ -908,6 +753,183 @@ function replaceParameters(template, parameters) {
|
|
|
908
753
|
return replacedTemplates;
|
|
909
754
|
}
|
|
910
755
|
|
|
756
|
+
/**
|
|
757
|
+
* @@@
|
|
758
|
+
*
|
|
759
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
760
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
761
|
+
*
|
|
762
|
+
* @returns The same object as the input, but deeply frozen
|
|
763
|
+
* @public exported from `@promptbook/utils`
|
|
764
|
+
*/
|
|
765
|
+
function $deepFreeze(objectValue) {
|
|
766
|
+
var e_1, _a;
|
|
767
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
768
|
+
try {
|
|
769
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
770
|
+
var propertyName = propertyNames_1_1.value;
|
|
771
|
+
var value = objectValue[propertyName];
|
|
772
|
+
if (value && typeof value === 'object') {
|
|
773
|
+
$deepFreeze(value);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
778
|
+
finally {
|
|
779
|
+
try {
|
|
780
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
781
|
+
}
|
|
782
|
+
finally { if (e_1) throw e_1.error; }
|
|
783
|
+
}
|
|
784
|
+
return Object.freeze(objectValue);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
792
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
793
|
+
*
|
|
794
|
+
* - Almost all primitives are serializable BUT:
|
|
795
|
+
* - `undefined` is not serializable
|
|
796
|
+
* - `NaN` is not serializable
|
|
797
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
798
|
+
* - Functions are not serializable
|
|
799
|
+
* - Circular references are not serializable
|
|
800
|
+
* - `Date` objects are not serializable
|
|
801
|
+
* - `Map` and `Set` objects are not serializable
|
|
802
|
+
* - `RegExp` objects are not serializable
|
|
803
|
+
* - `Error` objects are not serializable
|
|
804
|
+
* - `Symbol` objects are not serializable
|
|
805
|
+
* - And much more...
|
|
806
|
+
*
|
|
807
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
808
|
+
* @public exported from `@promptbook/utils`
|
|
809
|
+
*/
|
|
810
|
+
function checkSerializableAsJson(name, value) {
|
|
811
|
+
var e_1, _a;
|
|
812
|
+
if (value === undefined) {
|
|
813
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
814
|
+
}
|
|
815
|
+
else if (value === null) {
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
else if (typeof value === 'boolean') {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
else if (typeof value === 'string') {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
else if (typeof value === 'symbol') {
|
|
828
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
829
|
+
}
|
|
830
|
+
else if (typeof value === 'function') {
|
|
831
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
832
|
+
}
|
|
833
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
834
|
+
for (var i = 0; i < value.length; i++) {
|
|
835
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
else if (typeof value === 'object') {
|
|
839
|
+
if (value instanceof Date) {
|
|
840
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
841
|
+
}
|
|
842
|
+
else if (value instanceof Map) {
|
|
843
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
844
|
+
}
|
|
845
|
+
else if (value instanceof Set) {
|
|
846
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
847
|
+
}
|
|
848
|
+
else if (value instanceof RegExp) {
|
|
849
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
850
|
+
}
|
|
851
|
+
else if (value instanceof Error) {
|
|
852
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
try {
|
|
856
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
857
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
858
|
+
if (subValue === undefined) {
|
|
859
|
+
// Note: undefined in object is serializable - it is just omited
|
|
860
|
+
continue;
|
|
861
|
+
}
|
|
862
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
866
|
+
finally {
|
|
867
|
+
try {
|
|
868
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
869
|
+
}
|
|
870
|
+
finally { if (e_1) throw e_1.error; }
|
|
871
|
+
}
|
|
872
|
+
try {
|
|
873
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
874
|
+
}
|
|
875
|
+
catch (error) {
|
|
876
|
+
if (!(error instanceof Error)) {
|
|
877
|
+
throw error;
|
|
878
|
+
}
|
|
879
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
880
|
+
}
|
|
881
|
+
/*
|
|
882
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
883
|
+
const seen = new Set();
|
|
884
|
+
const stack = [{ value }];
|
|
885
|
+
while (stack.length > 0) {
|
|
886
|
+
const { value } = stack.pop()!;
|
|
887
|
+
if (typeof value === 'object' && value !== null) {
|
|
888
|
+
if (seen.has(value)) {
|
|
889
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
890
|
+
}
|
|
891
|
+
seen.add(value);
|
|
892
|
+
if (Array.isArray(value)) {
|
|
893
|
+
stack.push(...value.map((value) => ({ value })));
|
|
894
|
+
} else {
|
|
895
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
*/
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
909
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
910
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
911
|
+
*/
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* @@@
|
|
915
|
+
* @@@
|
|
916
|
+
*
|
|
917
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
918
|
+
*
|
|
919
|
+
* @param name - Name of the object for debugging purposes
|
|
920
|
+
* @param objectValue - Object to be deeply frozen
|
|
921
|
+
* @returns The same object as the input, but deeply frozen
|
|
922
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
923
|
+
*/
|
|
924
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
925
|
+
checkSerializableAsJson(name, objectValue);
|
|
926
|
+
return $deepFreeze(objectValue);
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
930
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
931
|
+
*/
|
|
932
|
+
|
|
911
933
|
/**
|
|
912
934
|
* Function computeUsage will create price per one token based on the string value found on openai page
|
|
913
935
|
*
|
|
@@ -1261,7 +1283,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
|
|
|
1261
1283
|
modelVariant: 'CHAT',
|
|
1262
1284
|
modelTitle: 'o1-preview-2024-09-12',
|
|
1263
1285
|
modelName: 'o1-preview-2024-09-12',
|
|
1264
|
-
// <- TODO: [
|
|
1286
|
+
// <- TODO: [💩] Some better system to organize theese date suffixes and versions
|
|
1265
1287
|
pricing: {
|
|
1266
1288
|
prompt: computeUsage("$15.00 / 1M tokens"),
|
|
1267
1289
|
output: computeUsage("$60.00 / 1M tokens"),
|
|
@@ -1311,7 +1333,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
|
|
|
1311
1333
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
1312
1334
|
* @see https://openai.com/api/pricing/
|
|
1313
1335
|
* @see /other/playground/playground.ts
|
|
1314
|
-
* TODO: [🍓] Make better
|
|
1336
|
+
* TODO: [🍓][💩] Make better
|
|
1315
1337
|
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
1316
1338
|
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
1317
1339
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1653,7 +1675,7 @@ var createAzureOpenAiExecutionTools = Object.assign(function (options) {
|
|
|
1653
1675
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1654
1676
|
__extends(NotYetImplementedError, _super);
|
|
1655
1677
|
function NotYetImplementedError(message) {
|
|
1656
|
-
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
1678
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
1657
1679
|
_this.name = 'NotYetImplementedError';
|
|
1658
1680
|
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1659
1681
|
return _this;
|