@promptbook/azure-openai 0.69.0 → 0.69.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/README.md +1 -1
- package/esm/index.es.js +282 -248
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +8 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -1
- package/package.json +3 -3
- package/umd/index.umd.js +282 -248
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
package/esm/index.es.js
CHANGED
|
@@ -6,7 +6,7 @@ import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
|
6
6
|
/**
|
|
7
7
|
* The version of the Promptbook library
|
|
8
8
|
*/
|
|
9
|
-
var PROMPTBOOK_VERSION = '0.69.
|
|
9
|
+
var PROMPTBOOK_VERSION = '0.69.1';
|
|
10
10
|
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
11
11
|
|
|
12
12
|
/*! *****************************************************************************
|
|
@@ -129,20 +129,38 @@ function __spreadArray(to, from, pack) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
132
|
+
* @@@
|
|
133
133
|
*
|
|
134
|
-
*
|
|
134
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
135
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
136
|
+
*
|
|
137
|
+
* @returns The same object as the input, but deeply frozen
|
|
138
|
+
* @public exported from `@promptbook/utils`
|
|
135
139
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
function $deepFreeze(objectValue) {
|
|
141
|
+
var e_1, _a;
|
|
142
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
143
|
+
try {
|
|
144
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
145
|
+
var propertyName = propertyNames_1_1.value;
|
|
146
|
+
var value = objectValue[propertyName];
|
|
147
|
+
if (value && typeof value === 'object') {
|
|
148
|
+
$deepFreeze(value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
143
151
|
}
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
153
|
+
finally {
|
|
154
|
+
try {
|
|
155
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
156
|
+
}
|
|
157
|
+
finally { if (e_1) throw e_1.error; }
|
|
158
|
+
}
|
|
159
|
+
return Object.freeze(objectValue);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
163
|
+
*/
|
|
146
164
|
|
|
147
165
|
/**
|
|
148
166
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
@@ -160,6 +178,228 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
160
178
|
return UnexpectedError;
|
|
161
179
|
}(Error));
|
|
162
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
183
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
184
|
+
*
|
|
185
|
+
* - Almost all primitives are serializable BUT:
|
|
186
|
+
* - `undefined` is not serializable
|
|
187
|
+
* - `NaN` is not serializable
|
|
188
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
189
|
+
* - Functions are not serializable
|
|
190
|
+
* - Circular references are not serializable
|
|
191
|
+
* - `Date` objects are not serializable
|
|
192
|
+
* - `Map` and `Set` objects are not serializable
|
|
193
|
+
* - `RegExp` objects are not serializable
|
|
194
|
+
* - `Error` objects are not serializable
|
|
195
|
+
* - `Symbol` objects are not serializable
|
|
196
|
+
* - And much more...
|
|
197
|
+
*
|
|
198
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
199
|
+
* @public exported from `@promptbook/utils`
|
|
200
|
+
*/
|
|
201
|
+
function checkSerializableAsJson(name, value) {
|
|
202
|
+
var e_1, _a;
|
|
203
|
+
if (value === undefined) {
|
|
204
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
205
|
+
}
|
|
206
|
+
else if (value === null) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
else if (typeof value === 'boolean') {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
else if (typeof value === 'string') {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
else if (typeof value === 'symbol') {
|
|
219
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
220
|
+
}
|
|
221
|
+
else if (typeof value === 'function') {
|
|
222
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
223
|
+
}
|
|
224
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
225
|
+
for (var i = 0; i < value.length; i++) {
|
|
226
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else if (typeof value === 'object') {
|
|
230
|
+
if (value instanceof Date) {
|
|
231
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
232
|
+
}
|
|
233
|
+
else if (value instanceof Map) {
|
|
234
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
235
|
+
}
|
|
236
|
+
else if (value instanceof Set) {
|
|
237
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
238
|
+
}
|
|
239
|
+
else if (value instanceof RegExp) {
|
|
240
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
241
|
+
}
|
|
242
|
+
else if (value instanceof Error) {
|
|
243
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
try {
|
|
247
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
248
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
249
|
+
if (subValue === undefined) {
|
|
250
|
+
// Note: undefined in object is serializable - it is just omited
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
257
|
+
finally {
|
|
258
|
+
try {
|
|
259
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
260
|
+
}
|
|
261
|
+
finally { if (e_1) throw e_1.error; }
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (!(error instanceof Error)) {
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
271
|
+
}
|
|
272
|
+
/*
|
|
273
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
274
|
+
const seen = new Set();
|
|
275
|
+
const stack = [{ value }];
|
|
276
|
+
while (stack.length > 0) {
|
|
277
|
+
const { value } = stack.pop()!;
|
|
278
|
+
if (typeof value === 'object' && value !== null) {
|
|
279
|
+
if (seen.has(value)) {
|
|
280
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
281
|
+
}
|
|
282
|
+
seen.add(value);
|
|
283
|
+
if (Array.isArray(value)) {
|
|
284
|
+
stack.push(...value.map((value) => ({ value })));
|
|
285
|
+
} else {
|
|
286
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
*/
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
300
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
301
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
302
|
+
*/
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @@@
|
|
306
|
+
* @@@
|
|
307
|
+
*
|
|
308
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
309
|
+
*
|
|
310
|
+
* @param name - Name of the object for debugging purposes
|
|
311
|
+
* @param objectValue - Object to be deeply frozen
|
|
312
|
+
* @returns The same object as the input, but deeply frozen
|
|
313
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
314
|
+
*/
|
|
315
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
316
|
+
checkSerializableAsJson(name, objectValue);
|
|
317
|
+
return $deepFreeze(objectValue);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
321
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
325
|
+
/**
|
|
326
|
+
* The maximum number of iterations for a loops
|
|
327
|
+
*
|
|
328
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
329
|
+
*/
|
|
330
|
+
var LOOP_LIMIT = 1000;
|
|
331
|
+
/**
|
|
332
|
+
* Timeout for the connections in milliseconds
|
|
333
|
+
*
|
|
334
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
335
|
+
*/
|
|
336
|
+
var CONNECTION_TIMEOUT_MS = 7 * 1000;
|
|
337
|
+
/**
|
|
338
|
+
* Nonce which is used for replacing things in strings
|
|
339
|
+
*
|
|
340
|
+
* @private within the repository
|
|
341
|
+
*/
|
|
342
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
343
|
+
/**
|
|
344
|
+
* The names of the parameters that are reserved for special purposes
|
|
345
|
+
*
|
|
346
|
+
* @public exported from `@promptbook/core`
|
|
347
|
+
*/
|
|
348
|
+
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
349
|
+
'content',
|
|
350
|
+
'context',
|
|
351
|
+
'knowledge',
|
|
352
|
+
'samples',
|
|
353
|
+
'modelName',
|
|
354
|
+
'currentDate',
|
|
355
|
+
// <- TODO: !!!!! list here all command names
|
|
356
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
357
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
358
|
+
]);
|
|
359
|
+
/**
|
|
360
|
+
* @@@
|
|
361
|
+
*
|
|
362
|
+
* @private within the repository
|
|
363
|
+
*/
|
|
364
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
365
|
+
/**
|
|
366
|
+
* @@@
|
|
367
|
+
*
|
|
368
|
+
* @private within the repository
|
|
369
|
+
*/
|
|
370
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
371
|
+
// <- TODO: [🧜♂️]
|
|
372
|
+
/**
|
|
373
|
+
* @@@
|
|
374
|
+
*
|
|
375
|
+
* @public exported from `@promptbook/core`
|
|
376
|
+
*/
|
|
377
|
+
Object.freeze({
|
|
378
|
+
delimiter: ',',
|
|
379
|
+
quoteChar: '"',
|
|
380
|
+
newline: '\n',
|
|
381
|
+
skipEmptyLines: true,
|
|
382
|
+
});
|
|
383
|
+
/**
|
|
384
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
385
|
+
*/
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* This error indicates errors during the execution of the pipeline
|
|
389
|
+
*
|
|
390
|
+
* @public exported from `@promptbook/core`
|
|
391
|
+
*/
|
|
392
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
393
|
+
__extends(PipelineExecutionError, _super);
|
|
394
|
+
function PipelineExecutionError(message) {
|
|
395
|
+
var _this = _super.call(this, message) || this;
|
|
396
|
+
_this.name = 'PipelineExecutionError';
|
|
397
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
398
|
+
return _this;
|
|
399
|
+
}
|
|
400
|
+
return PipelineExecutionError;
|
|
401
|
+
}(Error));
|
|
402
|
+
|
|
163
403
|
/**
|
|
164
404
|
* Counts number of characters in the text
|
|
165
405
|
*
|
|
@@ -539,240 +779,6 @@ function getCurrentIsoDate() {
|
|
|
539
779
|
return new Date().toISOString();
|
|
540
780
|
}
|
|
541
781
|
|
|
542
|
-
/**
|
|
543
|
-
* @@@
|
|
544
|
-
*
|
|
545
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
546
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
547
|
-
*
|
|
548
|
-
* @returns The same object as the input, but deeply frozen
|
|
549
|
-
* @public exported from `@promptbook/utils`
|
|
550
|
-
*/
|
|
551
|
-
function $deepFreeze(objectValue) {
|
|
552
|
-
var e_1, _a;
|
|
553
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
554
|
-
try {
|
|
555
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
556
|
-
var propertyName = propertyNames_1_1.value;
|
|
557
|
-
var value = objectValue[propertyName];
|
|
558
|
-
if (value && typeof value === 'object') {
|
|
559
|
-
$deepFreeze(value);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
564
|
-
finally {
|
|
565
|
-
try {
|
|
566
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
567
|
-
}
|
|
568
|
-
finally { if (e_1) throw e_1.error; }
|
|
569
|
-
}
|
|
570
|
-
return Object.freeze(objectValue);
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
574
|
-
*/
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* Checks if the value is [🚉] serializable as JSON
|
|
578
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
579
|
-
*
|
|
580
|
-
* - Almost all primitives are serializable BUT:
|
|
581
|
-
* - `undefined` is not serializable
|
|
582
|
-
* - `NaN` is not serializable
|
|
583
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
584
|
-
* - Functions are not serializable
|
|
585
|
-
* - Circular references are not serializable
|
|
586
|
-
* - `Date` objects are not serializable
|
|
587
|
-
* - `Map` and `Set` objects are not serializable
|
|
588
|
-
* - `RegExp` objects are not serializable
|
|
589
|
-
* - `Error` objects are not serializable
|
|
590
|
-
* - `Symbol` objects are not serializable
|
|
591
|
-
* - And much more...
|
|
592
|
-
*
|
|
593
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
594
|
-
* @public exported from `@promptbook/utils`
|
|
595
|
-
*/
|
|
596
|
-
function checkSerializableAsJson(name, value) {
|
|
597
|
-
var e_1, _a;
|
|
598
|
-
if (value === undefined) {
|
|
599
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
600
|
-
}
|
|
601
|
-
else if (value === null) {
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
else if (typeof value === 'boolean') {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
else if (typeof value === 'string') {
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
else if (typeof value === 'symbol') {
|
|
614
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
615
|
-
}
|
|
616
|
-
else if (typeof value === 'function') {
|
|
617
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
618
|
-
}
|
|
619
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
620
|
-
for (var i = 0; i < value.length; i++) {
|
|
621
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
else if (typeof value === 'object') {
|
|
625
|
-
if (value instanceof Date) {
|
|
626
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
627
|
-
}
|
|
628
|
-
else if (value instanceof Map) {
|
|
629
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
630
|
-
}
|
|
631
|
-
else if (value instanceof Set) {
|
|
632
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
633
|
-
}
|
|
634
|
-
else if (value instanceof RegExp) {
|
|
635
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
636
|
-
}
|
|
637
|
-
else if (value instanceof Error) {
|
|
638
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
639
|
-
}
|
|
640
|
-
else {
|
|
641
|
-
try {
|
|
642
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
643
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
644
|
-
if (subValue === undefined) {
|
|
645
|
-
// Note: undefined in object is serializable - it is just omited
|
|
646
|
-
continue;
|
|
647
|
-
}
|
|
648
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
652
|
-
finally {
|
|
653
|
-
try {
|
|
654
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
655
|
-
}
|
|
656
|
-
finally { if (e_1) throw e_1.error; }
|
|
657
|
-
}
|
|
658
|
-
try {
|
|
659
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
660
|
-
}
|
|
661
|
-
catch (error) {
|
|
662
|
-
if (!(error instanceof Error)) {
|
|
663
|
-
throw error;
|
|
664
|
-
}
|
|
665
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
666
|
-
}
|
|
667
|
-
/*
|
|
668
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
669
|
-
const seen = new Set();
|
|
670
|
-
const stack = [{ value }];
|
|
671
|
-
while (stack.length > 0) {
|
|
672
|
-
const { value } = stack.pop()!;
|
|
673
|
-
if (typeof value === 'object' && value !== null) {
|
|
674
|
-
if (seen.has(value)) {
|
|
675
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
676
|
-
}
|
|
677
|
-
seen.add(value);
|
|
678
|
-
if (Array.isArray(value)) {
|
|
679
|
-
stack.push(...value.map((value) => ({ value })));
|
|
680
|
-
} else {
|
|
681
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
*/
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
695
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
696
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
697
|
-
*/
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* @@@
|
|
701
|
-
* @@@
|
|
702
|
-
*
|
|
703
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
704
|
-
*
|
|
705
|
-
* @param name - Name of the object for debugging purposes
|
|
706
|
-
* @param objectValue - Object to be deeply frozen
|
|
707
|
-
* @returns The same object as the input, but deeply frozen
|
|
708
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
709
|
-
*/
|
|
710
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
711
|
-
checkSerializableAsJson(name, objectValue);
|
|
712
|
-
return $deepFreeze(objectValue);
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
716
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
717
|
-
*/
|
|
718
|
-
|
|
719
|
-
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
720
|
-
/**
|
|
721
|
-
* The maximum number of iterations for a loops
|
|
722
|
-
*
|
|
723
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
724
|
-
*/
|
|
725
|
-
var LOOP_LIMIT = 1000;
|
|
726
|
-
/**
|
|
727
|
-
* Nonce which is used for replacing things in strings
|
|
728
|
-
*
|
|
729
|
-
* @private within the repository
|
|
730
|
-
*/
|
|
731
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
732
|
-
/**
|
|
733
|
-
* The names of the parameters that are reserved for special purposes
|
|
734
|
-
*
|
|
735
|
-
* @public exported from `@promptbook/core`
|
|
736
|
-
*/
|
|
737
|
-
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
738
|
-
'content',
|
|
739
|
-
'context',
|
|
740
|
-
'knowledge',
|
|
741
|
-
'samples',
|
|
742
|
-
'modelName',
|
|
743
|
-
'currentDate',
|
|
744
|
-
// <- TODO: !!!!! list here all command names
|
|
745
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
746
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
747
|
-
]);
|
|
748
|
-
/**
|
|
749
|
-
* @@@
|
|
750
|
-
*
|
|
751
|
-
* @private within the repository
|
|
752
|
-
*/
|
|
753
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
754
|
-
/**
|
|
755
|
-
* @@@
|
|
756
|
-
*
|
|
757
|
-
* @private within the repository
|
|
758
|
-
*/
|
|
759
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
760
|
-
// <- TODO: [🧜♂️]
|
|
761
|
-
/**
|
|
762
|
-
* @@@
|
|
763
|
-
*
|
|
764
|
-
* @public exported from `@promptbook/core`
|
|
765
|
-
*/
|
|
766
|
-
Object.freeze({
|
|
767
|
-
delimiter: ',',
|
|
768
|
-
quoteChar: '"',
|
|
769
|
-
newline: '\n',
|
|
770
|
-
skipEmptyLines: true,
|
|
771
|
-
});
|
|
772
|
-
/**
|
|
773
|
-
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
774
|
-
*/
|
|
775
|
-
|
|
776
782
|
/**
|
|
777
783
|
* This error type indicates that some limit was reached
|
|
778
784
|
*
|
|
@@ -1359,6 +1365,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
1359
1365
|
var _a, _b;
|
|
1360
1366
|
return __awaiter(this, void 0, void 0, function () {
|
|
1361
1367
|
var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, messages, start, complete, rawRequest, rawResponse, resultContent, usage, error_1;
|
|
1368
|
+
var _this = this;
|
|
1362
1369
|
return __generator(this, function (_c) {
|
|
1363
1370
|
switch (_c.label) {
|
|
1364
1371
|
case 0:
|
|
@@ -1405,7 +1412,12 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
1405
1412
|
console.info(colors.bgWhite('messages'), JSON.stringify(messages, null, 4));
|
|
1406
1413
|
}
|
|
1407
1414
|
rawRequest = [modelName, messages, modelSettings];
|
|
1408
|
-
return [4 /*yield*/, client.getChatCompletions.apply(client, __spreadArray([], __read(rawRequest), false))
|
|
1415
|
+
return [4 /*yield*/, this.withTimeout(client.getChatCompletions.apply(client, __spreadArray([], __read(rawRequest), false))).catch(function (error) {
|
|
1416
|
+
if (_this.options.isVerbose) {
|
|
1417
|
+
console.info(colors.bgRed('error'), error);
|
|
1418
|
+
}
|
|
1419
|
+
throw error;
|
|
1420
|
+
})];
|
|
1409
1421
|
case 3:
|
|
1410
1422
|
rawResponse = _c.sent();
|
|
1411
1423
|
if (this.options.isVerbose) {
|
|
@@ -1457,6 +1469,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
1457
1469
|
var _a, _b;
|
|
1458
1470
|
return __awaiter(this, void 0, void 0, function () {
|
|
1459
1471
|
var content, parameters, modelRequirements, client, modelName, modelSettings, start, complete, rawPromptContent, rawRequest, rawResponse, resultContent, usage, error_2;
|
|
1472
|
+
var _this = this;
|
|
1460
1473
|
return __generator(this, function (_c) {
|
|
1461
1474
|
switch (_c.label) {
|
|
1462
1475
|
case 0:
|
|
@@ -1495,7 +1508,12 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
1495
1508
|
[rawPromptContent],
|
|
1496
1509
|
modelSettings,
|
|
1497
1510
|
];
|
|
1498
|
-
return [4 /*yield*/, client.getCompletions.apply(client, __spreadArray([], __read(rawRequest), false))
|
|
1511
|
+
return [4 /*yield*/, this.withTimeout(client.getCompletions.apply(client, __spreadArray([], __read(rawRequest), false))).catch(function (error) {
|
|
1512
|
+
if (_this.options.isVerbose) {
|
|
1513
|
+
console.info(colors.bgRed('error'), error);
|
|
1514
|
+
}
|
|
1515
|
+
throw error;
|
|
1516
|
+
})];
|
|
1499
1517
|
case 3:
|
|
1500
1518
|
rawResponse = _c.sent();
|
|
1501
1519
|
if (this.options.isVerbose) {
|
|
@@ -1538,6 +1556,22 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
1538
1556
|
});
|
|
1539
1557
|
};
|
|
1540
1558
|
// <- Note: [🤖] callXxxModel
|
|
1559
|
+
/**
|
|
1560
|
+
* Library `@azure/openai` has bug/weird behavior that it does not throw error but hangs forever
|
|
1561
|
+
*
|
|
1562
|
+
* This method wraps the promise with timeout
|
|
1563
|
+
*/
|
|
1564
|
+
AzureOpenAiExecutionTools.prototype.withTimeout = function (promise) {
|
|
1565
|
+
return new Promise(function (resolve, reject) {
|
|
1566
|
+
var timeout = setTimeout(function () {
|
|
1567
|
+
reject(new PipelineExecutionError('Timeout'));
|
|
1568
|
+
}, CONNECTION_TIMEOUT_MS);
|
|
1569
|
+
promise.then(function (result) {
|
|
1570
|
+
clearTimeout(timeout);
|
|
1571
|
+
resolve(result);
|
|
1572
|
+
}, reject);
|
|
1573
|
+
});
|
|
1574
|
+
};
|
|
1541
1575
|
/**
|
|
1542
1576
|
* Changes Azure error (which is not propper Error but object) to propper Error
|
|
1543
1577
|
*/
|