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