@promptbook/openai 0.50.0-16 → 0.50.0-18

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/umd/index.umd.js CHANGED
@@ -87,8 +87,363 @@
87
87
  } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
88
88
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
89
89
  }
90
+ }
91
+
92
+ function __read(o, n) {
93
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
94
+ if (!m) return o;
95
+ var i = m.call(o), r, ar = [], e;
96
+ try {
97
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
98
+ }
99
+ catch (error) { e = { error: error }; }
100
+ finally {
101
+ try {
102
+ if (r && !r.done && (m = i["return"])) m.call(i);
103
+ }
104
+ finally { if (e) throw e.error; }
105
+ }
106
+ return ar;
107
+ }
108
+
109
+ /**
110
+ * Function computeUsage will create price per one token based on the string value found on openai page
111
+ *
112
+ * @private within the library, used only as internal helper for `OPENAI_MODELS`
113
+ */
114
+ function computeUsage(value) {
115
+ var _a = __read(value.split(' / '), 2), price = _a[0], tokens = _a[1];
116
+ return parseFloat(price.replace('$', '')) / parseFloat(tokens.replace('M tokens', '')) / 1000000;
90
117
  }
91
118
 
119
+ /**
120
+ * List of available OpenAI models with pricing
121
+ *
122
+ * Note: Done at 2024-05-20
123
+ *
124
+ * @see https://platform.openai.com/docs/models/
125
+ * @see https://openai.com/api/pricing/
126
+ */
127
+ var OPENAI_MODELS = [
128
+ /*/
129
+ {
130
+ modelTitle: 'dall-e-3',
131
+ modelName: 'dall-e-3',
132
+ },
133
+ /**/
134
+ /*/
135
+ {
136
+ modelTitle: 'whisper-1',
137
+ modelName: 'whisper-1',
138
+ },
139
+ /**/
140
+ /**/
141
+ {
142
+ modelVariant: 'COMPLETION',
143
+ modelTitle: 'davinci-002',
144
+ modelName: 'davinci-002',
145
+ pricing: {
146
+ prompt: computeUsage("$2.00 / 1M tokens"),
147
+ output: computeUsage("$2.00 / 1M tokens"), // <- not sure
148
+ },
149
+ },
150
+ /**/
151
+ /*/
152
+ {
153
+ modelTitle: 'dall-e-2',
154
+ modelName: 'dall-e-2',
155
+ },
156
+ /**/
157
+ /**/
158
+ {
159
+ modelVariant: 'CHAT',
160
+ modelTitle: 'gpt-3.5-turbo-16k',
161
+ modelName: 'gpt-3.5-turbo-16k',
162
+ pricing: {
163
+ prompt: computeUsage("$3.00 / 1M tokens"),
164
+ output: computeUsage("$4.00 / 1M tokens"),
165
+ },
166
+ },
167
+ /**/
168
+ /*/
169
+ {
170
+ modelTitle: 'tts-1-hd-1106',
171
+ modelName: 'tts-1-hd-1106',
172
+ },
173
+ /**/
174
+ /*/
175
+ {
176
+ modelTitle: 'tts-1-hd',
177
+ modelName: 'tts-1-hd',
178
+ },
179
+ /**/
180
+ /**/
181
+ {
182
+ modelVariant: 'CHAT',
183
+ modelTitle: 'gpt-4',
184
+ modelName: 'gpt-4',
185
+ pricing: {
186
+ prompt: computeUsage("$30.00 / 1M tokens"),
187
+ output: computeUsage("$60.00 / 1M tokens"),
188
+ },
189
+ },
190
+ /**/
191
+ /**/
192
+ {
193
+ modelVariant: 'CHAT',
194
+ modelTitle: 'gpt-4-32k',
195
+ modelName: 'gpt-4-32k',
196
+ pricing: {
197
+ prompt: computeUsage("$60.00 / 1M tokens"),
198
+ output: computeUsage("$120.00 / 1M tokens"),
199
+ },
200
+ },
201
+ /**/
202
+ /*/
203
+ {
204
+ modelVariant: 'CHAT',
205
+ modelTitle: 'gpt-4-0613',
206
+ modelName: 'gpt-4-0613',
207
+ pricing: {
208
+ prompt: computeUsage(` / 1M tokens`),
209
+ output: computeUsage(` / 1M tokens`),
210
+ },
211
+ },
212
+ /**/
213
+ /**/
214
+ {
215
+ modelVariant: 'CHAT',
216
+ modelTitle: 'gpt-4-turbo-2024-04-09',
217
+ modelName: 'gpt-4-turbo-2024-04-09',
218
+ pricing: {
219
+ prompt: computeUsage("$10.00 / 1M tokens"),
220
+ output: computeUsage("$30.00 / 1M tokens"),
221
+ },
222
+ },
223
+ /**/
224
+ /**/
225
+ {
226
+ modelVariant: 'CHAT',
227
+ modelTitle: 'gpt-3.5-turbo-1106',
228
+ modelName: 'gpt-3.5-turbo-1106',
229
+ pricing: {
230
+ prompt: computeUsage("$1.00 / 1M tokens"),
231
+ output: computeUsage("$2.00 / 1M tokens"),
232
+ },
233
+ },
234
+ /**/
235
+ /**/
236
+ {
237
+ modelVariant: 'CHAT',
238
+ modelTitle: 'gpt-4-turbo',
239
+ modelName: 'gpt-4-turbo',
240
+ pricing: {
241
+ prompt: computeUsage("$10.00 / 1M tokens"),
242
+ output: computeUsage("$30.00 / 1M tokens"),
243
+ },
244
+ },
245
+ /**/
246
+ /**/
247
+ {
248
+ modelVariant: 'COMPLETION',
249
+ modelTitle: 'gpt-3.5-turbo-instruct-0914',
250
+ modelName: 'gpt-3.5-turbo-instruct-0914',
251
+ pricing: {
252
+ prompt: computeUsage("$1.50 / 1M tokens"),
253
+ output: computeUsage("$2.00 / 1M tokens"), // <- For gpt-3.5-turbo-instruct
254
+ },
255
+ },
256
+ /**/
257
+ /**/
258
+ {
259
+ modelVariant: 'COMPLETION',
260
+ modelTitle: 'gpt-3.5-turbo-instruct',
261
+ modelName: 'gpt-3.5-turbo-instruct',
262
+ pricing: {
263
+ prompt: computeUsage("$1.50 / 1M tokens"),
264
+ output: computeUsage("$2.00 / 1M tokens"),
265
+ },
266
+ },
267
+ /**/
268
+ /*/
269
+ {
270
+ modelTitle: 'tts-1',
271
+ modelName: 'tts-1',
272
+ },
273
+ /**/
274
+ /**/
275
+ {
276
+ modelVariant: 'CHAT',
277
+ modelTitle: 'gpt-3.5-turbo',
278
+ modelName: 'gpt-3.5-turbo',
279
+ pricing: {
280
+ prompt: computeUsage("$3.00 / 1M tokens"),
281
+ output: computeUsage("$6.00 / 1M tokens"), // <- Not sure, refer to gpt-3.5-turbo in Fine-tuning models
282
+ },
283
+ },
284
+ /**/
285
+ /**/
286
+ {
287
+ modelVariant: 'CHAT',
288
+ modelTitle: 'gpt-3.5-turbo-0301',
289
+ modelName: 'gpt-3.5-turbo-0301',
290
+ pricing: {
291
+ prompt: computeUsage("$1.50 / 1M tokens"),
292
+ output: computeUsage("$2.00 / 1M tokens"),
293
+ },
294
+ },
295
+ /**/
296
+ /**/
297
+ {
298
+ modelVariant: 'COMPLETION',
299
+ modelTitle: 'babbage-002',
300
+ modelName: 'babbage-002',
301
+ pricing: {
302
+ prompt: computeUsage("$0.40 / 1M tokens"),
303
+ output: computeUsage("$0.40 / 1M tokens"), // <- Not sure
304
+ },
305
+ },
306
+ /**/
307
+ /**/
308
+ {
309
+ modelVariant: 'CHAT',
310
+ modelTitle: 'gpt-4-1106-preview',
311
+ modelName: 'gpt-4-1106-preview',
312
+ pricing: {
313
+ prompt: computeUsage("$10.00 / 1M tokens"),
314
+ output: computeUsage("$30.00 / 1M tokens"),
315
+ },
316
+ },
317
+ /**/
318
+ /**/
319
+ {
320
+ modelVariant: 'CHAT',
321
+ modelTitle: 'gpt-4-0125-preview',
322
+ modelName: 'gpt-4-0125-preview',
323
+ pricing: {
324
+ prompt: computeUsage("$10.00 / 1M tokens"),
325
+ output: computeUsage("$30.00 / 1M tokens"),
326
+ },
327
+ },
328
+ /**/
329
+ /*/
330
+ {
331
+ modelTitle: 'tts-1-1106',
332
+ modelName: 'tts-1-1106',
333
+ },
334
+ /**/
335
+ /**/
336
+ {
337
+ modelVariant: 'CHAT',
338
+ modelTitle: 'gpt-3.5-turbo-0125',
339
+ modelName: 'gpt-3.5-turbo-0125',
340
+ pricing: {
341
+ prompt: computeUsage("$0.50 / 1M tokens"),
342
+ output: computeUsage("$1.50 / 1M tokens"),
343
+ },
344
+ },
345
+ /**/
346
+ /**/
347
+ {
348
+ modelVariant: 'CHAT',
349
+ modelTitle: 'gpt-4-turbo-preview',
350
+ modelName: 'gpt-4-turbo-preview',
351
+ pricing: {
352
+ prompt: computeUsage("$10.00 / 1M tokens"),
353
+ output: computeUsage("$30.00 / 1M tokens"), // <- Not sure, just for gpt-4-turbo
354
+ },
355
+ },
356
+ /**/
357
+ /*/
358
+ {
359
+ modelTitle: 'text-embedding-3-large',
360
+ modelName: 'text-embedding-3-large',
361
+ },
362
+ /**/
363
+ /*/
364
+ {
365
+ modelTitle: 'text-embedding-3-small',
366
+ modelName: 'text-embedding-3-small',
367
+ },
368
+ /**/
369
+ /**/
370
+ {
371
+ modelVariant: 'CHAT',
372
+ modelTitle: 'gpt-3.5-turbo-0613',
373
+ modelName: 'gpt-3.5-turbo-0613',
374
+ pricing: {
375
+ prompt: computeUsage("$1.50 / 1M tokens"),
376
+ output: computeUsage("$2.00 / 1M tokens"),
377
+ },
378
+ },
379
+ /**/
380
+ /*/
381
+ {
382
+ modelTitle: 'text-embedding-ada-002',
383
+ modelName: 'text-embedding-ada-002',
384
+ },
385
+ /**/
386
+ /*/
387
+ {
388
+ modelVariant: 'CHAT',
389
+ modelTitle: 'gpt-4-1106-vision-preview',
390
+ modelName: 'gpt-4-1106-vision-preview',
391
+ },
392
+ /**/
393
+ /*/
394
+ {
395
+ modelTitle: 'gpt-4-vision-preview',
396
+ modelName: 'gpt-4-vision-preview',
397
+ pricing: {
398
+ prompt: computeUsage(`$10.00 / 1M tokens`),
399
+ output: computeUsage(`$30.00 / 1M tokens`),
400
+ },
401
+ },
402
+ /**/
403
+ /**/
404
+ {
405
+ modelVariant: 'CHAT',
406
+ modelTitle: 'gpt-4o-2024-05-13',
407
+ modelName: 'gpt-4o-2024-05-13',
408
+ pricing: {
409
+ prompt: computeUsage("$5.00 / 1M tokens"),
410
+ output: computeUsage("$15.00 / 1M tokens"),
411
+ },
412
+ },
413
+ /**/
414
+ /**/
415
+ {
416
+ modelVariant: 'CHAT',
417
+ modelTitle: 'gpt-4o',
418
+ modelName: 'gpt-4o',
419
+ pricing: {
420
+ prompt: computeUsage("$5.00 / 1M tokens"),
421
+ output: computeUsage("$15.00 / 1M tokens"),
422
+ },
423
+ },
424
+ /**/
425
+ /**/
426
+ {
427
+ modelVariant: 'CHAT',
428
+ modelTitle: 'gpt-3.5-turbo-16k-0613',
429
+ modelName: 'gpt-3.5-turbo-16k-0613',
430
+ pricing: {
431
+ prompt: computeUsage("$3.00 / 1M tokens"),
432
+ output: computeUsage("$4.00 / 1M tokens"),
433
+ },
434
+ },
435
+ /**/
436
+ ];
437
+ /**
438
+ * TODO: [🧠] Some mechanism to propagate unsureness
439
+ * TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
440
+ * @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
441
+ * @see https://openai.com/api/pricing/
442
+ * @see /other/playground/playground.ts
443
+ * TODO: [🍓] Make better
444
+ * TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
445
+ */
446
+
92
447
  /**
93
448
  * This error indicates errors during the execution of the promptbook
94
449
  */
@@ -130,33 +485,13 @@
130
485
  }
131
486
  var inputTokens = rawResponse.usage.prompt_tokens;
132
487
  var outputTokens = rawResponse.usage.completion_tokens;
133
- // TODO: !!!! [🕚] Make this list dynamic
134
- var pricePerThousandTokens = {
135
- 'gpt-3.5-turbo-0613': {
136
- prompt: 0.0015,
137
- completion: 0.002,
138
- },
139
- 'gpt-4-0613': {
140
- // TODO: Not sure if this is correct
141
- prompt: 0.01,
142
- completion: 0.03,
143
- },
144
- 'gpt-3.5-turbo-instruct': {
145
- prompt: 0.0015,
146
- completion: 0.002,
147
- },
148
- 'gpt-4-0125-preview': {
149
- prompt: 0.01,
150
- completion: 0.03,
151
- },
152
- }[rawResponse.model];
153
- // TODO: !!! Retrieve dynamically
488
+ var modelInfo = OPENAI_MODELS.find(function (model) { return model.modelName === rawResponse.model; });
154
489
  var price;
155
- if (pricePerThousandTokens === undefined) {
490
+ if (modelInfo === undefined || modelInfo.pricing === undefined) {
156
491
  price = 'UNKNOWN';
157
492
  }
158
493
  else {
159
- price = (inputTokens * pricePerThousandTokens.prompt + outputTokens * pricePerThousandTokens.completion) / 1000;
494
+ price = inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output;
160
495
  }
161
496
  return {
162
497
  price: price,
@@ -164,9 +499,6 @@
164
499
  outputTokens: outputTokens,
165
500
  };
166
501
  }
167
- /**
168
- * TODO: [🍓] Make better
169
- */
170
502
 
171
503
  /**
172
504
  * Execution Tools for calling OpenAI API.
@@ -347,226 +679,7 @@
347
679
  console.log({ models });
348
680
  console.log(models.data);
349
681
  */
350
- return [
351
- // Note: Done at 2024-05-15
352
- // TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
353
- // @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
354
- // @see https://openai.com/api/pricing/
355
- // @see /other/playground/playground.ts
356
- /*/
357
- {
358
- modelTitle: 'dall-e-3',
359
- modelName: 'dall-e-3',
360
- },
361
- /**/
362
- /*/
363
- {
364
- modelTitle: 'whisper-1',
365
- modelName: 'whisper-1',
366
- },
367
- /**/
368
- /**/
369
- {
370
- modelVariant: 'COMPLETION',
371
- modelTitle: 'davinci-002',
372
- modelName: 'davinci-002',
373
- },
374
- /**/
375
- /*/
376
- {
377
- modelTitle: 'dall-e-2',
378
- modelName: 'dall-e-2',
379
- },
380
- /**/
381
- /**/
382
- {
383
- modelVariant: 'CHAT',
384
- modelTitle: 'gpt-3.5-turbo-16k',
385
- modelName: 'gpt-3.5-turbo-16k',
386
- },
387
- /**/
388
- /*/
389
- {
390
- modelTitle: 'tts-1-hd-1106',
391
- modelName: 'tts-1-hd-1106',
392
- },
393
- /**/
394
- /*/
395
- {
396
- modelTitle: 'tts-1-hd',
397
- modelName: 'tts-1-hd',
398
- },
399
- /**/
400
- /**/
401
- {
402
- modelVariant: 'CHAT',
403
- modelTitle: 'gpt-4',
404
- modelName: 'gpt-4',
405
- },
406
- /**/
407
- /**/
408
- {
409
- modelVariant: 'CHAT',
410
- modelTitle: 'gpt-4-0613',
411
- modelName: 'gpt-4-0613',
412
- },
413
- /**/
414
- /**/
415
- {
416
- modelVariant: 'CHAT',
417
- modelTitle: 'gpt-4-turbo-2024-04-09',
418
- modelName: 'gpt-4-turbo-2024-04-09',
419
- },
420
- /**/
421
- /**/
422
- {
423
- modelVariant: 'CHAT',
424
- modelTitle: 'gpt-3.5-turbo-1106',
425
- modelName: 'gpt-3.5-turbo-1106',
426
- },
427
- /**/
428
- /**/
429
- {
430
- modelVariant: 'CHAT',
431
- modelTitle: 'gpt-4-turbo',
432
- modelName: 'gpt-4-turbo',
433
- },
434
- /**/
435
- /**/
436
- {
437
- modelVariant: 'COMPLETION',
438
- modelTitle: 'gpt-3.5-turbo-instruct-0914',
439
- modelName: 'gpt-3.5-turbo-instruct-0914',
440
- },
441
- /**/
442
- /**/
443
- {
444
- modelVariant: 'COMPLETION',
445
- modelTitle: 'gpt-3.5-turbo-instruct',
446
- modelName: 'gpt-3.5-turbo-instruct',
447
- },
448
- /**/
449
- /*/
450
- {
451
- modelTitle: 'tts-1',
452
- modelName: 'tts-1',
453
- },
454
- /**/
455
- /**/
456
- {
457
- modelVariant: 'CHAT',
458
- modelTitle: 'gpt-3.5-turbo',
459
- modelName: 'gpt-3.5-turbo',
460
- },
461
- /**/
462
- /**/
463
- {
464
- modelVariant: 'CHAT',
465
- modelTitle: 'gpt-3.5-turbo-0301',
466
- modelName: 'gpt-3.5-turbo-0301',
467
- },
468
- /**/
469
- /**/
470
- {
471
- modelVariant: 'COMPLETION',
472
- modelTitle: 'babbage-002',
473
- modelName: 'babbage-002',
474
- },
475
- /**/
476
- /**/
477
- {
478
- modelVariant: 'CHAT',
479
- modelTitle: 'gpt-4-1106-preview',
480
- modelName: 'gpt-4-1106-preview',
481
- },
482
- /**/
483
- /**/
484
- {
485
- modelVariant: 'CHAT',
486
- modelTitle: 'gpt-4-0125-preview',
487
- modelName: 'gpt-4-0125-preview',
488
- },
489
- /**/
490
- /*/
491
- {
492
- modelTitle: 'tts-1-1106',
493
- modelName: 'tts-1-1106',
494
- },
495
- /**/
496
- /**/
497
- {
498
- modelVariant: 'CHAT',
499
- modelTitle: 'gpt-3.5-turbo-0125',
500
- modelName: 'gpt-3.5-turbo-0125',
501
- },
502
- /**/
503
- /**/
504
- {
505
- modelVariant: 'CHAT',
506
- modelTitle: 'gpt-4-turbo-preview',
507
- modelName: 'gpt-4-turbo-preview',
508
- },
509
- /**/
510
- /*/
511
- {
512
- modelTitle: 'text-embedding-3-large',
513
- modelName: 'text-embedding-3-large',
514
- },
515
- /**/
516
- /*/
517
- {
518
- modelTitle: 'text-embedding-3-small',
519
- modelName: 'text-embedding-3-small',
520
- },
521
- /**/
522
- /**/
523
- {
524
- modelVariant: 'CHAT',
525
- modelTitle: 'gpt-3.5-turbo-0613',
526
- modelName: 'gpt-3.5-turbo-0613',
527
- },
528
- /**/
529
- /*/
530
- {
531
- modelTitle: 'text-embedding-ada-002',
532
- modelName: 'text-embedding-ada-002',
533
- },
534
- /**/
535
- /*/
536
- {
537
- modelVariant: 'CHAT',
538
- modelTitle: 'gpt-4-1106-vision-preview',
539
- modelName: 'gpt-4-1106-vision-preview',
540
- },
541
- /**/
542
- /*/
543
- {
544
- modelTitle: 'gpt-4-vision-preview',
545
- modelName: 'gpt-4-vision-preview',
546
- },
547
- /**/
548
- /**/
549
- {
550
- modelVariant: 'CHAT',
551
- modelTitle: 'gpt-4o-2024-05-13',
552
- modelName: 'gpt-4o-2024-05-13',
553
- },
554
- /**/
555
- /**/
556
- {
557
- modelVariant: 'CHAT',
558
- modelTitle: 'gpt-4o',
559
- modelName: 'gpt-4o',
560
- },
561
- /**/
562
- /**/
563
- {
564
- modelVariant: 'CHAT',
565
- modelTitle: 'gpt-3.5-turbo-16k-0613',
566
- modelName: 'gpt-3.5-turbo-16k-0613',
567
- },
568
- /**/
569
- ];
682
+ return OPENAI_MODELS;
570
683
  };
571
684
  return OpenAiExecutionTools;
572
685
  }());
@@ -576,6 +689,7 @@
576
689
  * TODO: Maybe make custom OpenaiError
577
690
  */
578
691
 
692
+ exports.OPENAI_MODELS = OPENAI_MODELS;
579
693
  exports.OpenAiExecutionTools = OpenAiExecutionTools;
580
694
 
581
695
  Object.defineProperty(exports, '__esModule', { value: true });