aimodels 0.1.1 → 0.2.0

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/dist/index.js CHANGED
@@ -20,91 +20,602 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ creators: () => creators_default,
23
24
  models: () => models
24
25
  });
25
26
  module.exports = __toCommonJS(index_exports);
26
27
 
27
- // src/data/models.json
28
- var models_default = [
29
- {
30
- id: "gpt-4",
31
- name: "GPT-4",
32
- provider: "openai",
33
- contextWindow: 8192,
34
- capabilities: ["chat", "completion"],
35
- pricing: {
36
- input: 0.03,
37
- output: 0.06
38
- },
39
- released: "2023-03-14",
40
- parameters: 11e11
41
- },
42
- {
43
- id: "gpt-3.5-turbo",
44
- name: "GPT-3.5 Turbo",
45
- provider: "openai",
46
- contextWindow: 4096,
47
- capabilities: ["chat", "completion"],
48
- pricing: {
49
- input: 15e-4,
50
- output: 2e-3
51
- },
52
- released: "2022-11-30"
53
- },
54
- {
55
- id: "claude-2.1",
56
- name: "Claude 2.1",
57
- provider: "anthropic",
58
- contextWindow: 2e5,
59
- capabilities: ["chat", "completion"],
60
- pricing: {
61
- input: 8e-3,
62
- output: 0.024
63
- },
64
- released: "2023-11-21"
65
- },
66
- {
67
- id: "llama-2-70b",
68
- name: "Llama 2 70B",
69
- provider: "meta",
70
- contextWindow: 4096,
71
- capabilities: ["chat", "completion"],
72
- pricing: {
73
- input: 0,
74
- output: 0
75
- },
76
- released: "2023-07-18",
77
- license: "Llama 2 Community License",
78
- parameters: 7e10
79
- }
80
- ];
28
+ // src/types/models.ts
29
+ var ModelCollection = class _ModelCollection extends Array {
30
+ constructor(models2) {
31
+ super(...models2);
32
+ Object.setPrototypeOf(this, _ModelCollection.prototype);
33
+ }
34
+ can(...capabilities) {
35
+ return new _ModelCollection(
36
+ this.filter((model) => capabilities.every((cap) => model.can.includes(cap)))
37
+ );
38
+ }
39
+ know(...languages) {
40
+ return new _ModelCollection(
41
+ this.filter((model) => languages.every((lang) => model.languages?.includes(lang)))
42
+ );
43
+ }
44
+ // Override array methods to return ModelCollection
45
+ filter(predicate) {
46
+ return new _ModelCollection(super.filter(predicate));
47
+ }
48
+ slice(start, end) {
49
+ return new _ModelCollection(super.slice(start, end));
50
+ }
51
+ };
52
+
53
+ // src/data/models/openai.json
54
+ var openai_default = {
55
+ models: [
56
+ {
57
+ id: "whisper-1",
58
+ name: "Whisper-1",
59
+ license: "proprietary",
60
+ providers: [
61
+ "openai",
62
+ "azure"
63
+ ],
64
+ can: [
65
+ "sound-in",
66
+ "text-out"
67
+ ],
68
+ context: {
69
+ total: null,
70
+ maxOutput: null
71
+ }
72
+ },
73
+ {
74
+ id: "tts-1",
75
+ name: "TTS-1",
76
+ license: "proprietary",
77
+ providers: [
78
+ "openai",
79
+ "azure"
80
+ ],
81
+ can: [
82
+ "text-in",
83
+ "sound-out"
84
+ ],
85
+ context: {
86
+ total: null,
87
+ maxOutput: null
88
+ }
89
+ },
90
+ {
91
+ id: "tts-1-hd",
92
+ name: "TTS-1 HD",
93
+ license: "proprietary",
94
+ providers: [
95
+ "openai",
96
+ "azure"
97
+ ],
98
+ can: [
99
+ "text-in",
100
+ "sound-out"
101
+ ],
102
+ context: {
103
+ total: null,
104
+ maxOutput: null
105
+ }
106
+ },
107
+ {
108
+ id: "gpt-4o",
109
+ name: "GPT-4O",
110
+ license: "proprietary",
111
+ providers: [
112
+ "openai",
113
+ "azure"
114
+ ],
115
+ can: [
116
+ "chat",
117
+ "img-in",
118
+ "json-out",
119
+ "function-out"
120
+ ],
121
+ context: {
122
+ total: 128e3,
123
+ maxOutput: 16384
124
+ }
125
+ },
126
+ {
127
+ id: "gpt-4o-mini",
128
+ name: "GPT-4O Mini",
129
+ license: "proprietary",
130
+ providers: [
131
+ "openai",
132
+ "azure"
133
+ ],
134
+ can: [
135
+ "chat",
136
+ "img-in",
137
+ "json-out",
138
+ "function-out"
139
+ ],
140
+ context: {
141
+ total: 128e3,
142
+ maxOutput: 16384
143
+ }
144
+ },
145
+ {
146
+ id: "o1",
147
+ name: "OpenAI O1",
148
+ license: "proprietary",
149
+ providers: [
150
+ "openai",
151
+ "azure"
152
+ ],
153
+ can: [
154
+ "chat",
155
+ "img-in",
156
+ "json-out",
157
+ "function-out",
158
+ "reason"
159
+ ],
160
+ context: {
161
+ total: 2e5,
162
+ maxOutput: 1e5
163
+ }
164
+ },
165
+ {
166
+ id: "o1-mini",
167
+ name: "OpenAI O1 Mini",
168
+ license: "proprietary",
169
+ providers: [
170
+ "openai",
171
+ "azure"
172
+ ],
173
+ can: [
174
+ "chat",
175
+ "json-out",
176
+ "function-out",
177
+ "reason"
178
+ ],
179
+ context: {
180
+ total: 128e3,
181
+ maxOutput: 65536
182
+ }
183
+ },
184
+ {
185
+ id: "o3-mini",
186
+ name: "OpenAI O3 Mini",
187
+ license: "proprietary",
188
+ providers: [
189
+ "openai",
190
+ "azure"
191
+ ],
192
+ can: [
193
+ "chat",
194
+ "json-out",
195
+ "function-out",
196
+ "reason"
197
+ ],
198
+ context: {
199
+ total: 2e5,
200
+ maxOutput: 1e5
201
+ }
202
+ },
203
+ {
204
+ id: "gpt-4o-audio-preview",
205
+ name: "GPT-4O Audio",
206
+ license: "proprietary",
207
+ providers: [
208
+ "openai",
209
+ "azure"
210
+ ],
211
+ can: [
212
+ "chat",
213
+ "sound-in",
214
+ "json-out",
215
+ "function-out"
216
+ ],
217
+ context: {
218
+ total: 128e3,
219
+ maxOutput: 16384
220
+ }
221
+ },
222
+ {
223
+ id: "gpt-4o-realtime-preview",
224
+ name: "GPT-4O Realtime",
225
+ license: "proprietary",
226
+ providers: [
227
+ "openai",
228
+ "azure"
229
+ ],
230
+ can: [
231
+ "chat",
232
+ "sound-in",
233
+ "json-out",
234
+ "function-out"
235
+ ],
236
+ context: {
237
+ total: 128e3,
238
+ maxOutput: 4096
239
+ }
240
+ },
241
+ {
242
+ id: "dall-e-3",
243
+ name: "DALL-E 3",
244
+ license: "proprietary",
245
+ providers: [
246
+ "openai",
247
+ "azure"
248
+ ],
249
+ can: [
250
+ "img-out"
251
+ ],
252
+ context: {
253
+ maxOutput: 1,
254
+ sizes: [
255
+ "1024x1024",
256
+ "1024x1792",
257
+ "1792x1024"
258
+ ],
259
+ qualities: [
260
+ "standard",
261
+ "hd"
262
+ ]
263
+ }
264
+ }
265
+ ]
266
+ };
267
+
268
+ // src/data/models/anthropic.json
269
+ var anthropic_default = {
270
+ models: [
271
+ {
272
+ id: "claude-3-opus",
273
+ name: "Claude 3 Opus",
274
+ license: "proprietary",
275
+ providers: ["anthropic", "aws", "google"],
276
+ can: ["chat", "img-in", "json-out", "function-out"],
277
+ context: {
278
+ total: 2e5,
279
+ maxOutput: 4096
280
+ }
281
+ },
282
+ {
283
+ id: "claude-3-sonnet",
284
+ name: "Claude 3 Sonnet",
285
+ license: "proprietary",
286
+ providers: ["anthropic", "aws", "google"],
287
+ can: ["chat", "img-in", "json-out", "function-out"],
288
+ context: {
289
+ total: 2e5,
290
+ maxOutput: 4096
291
+ }
292
+ },
293
+ {
294
+ id: "claude-3-haiku",
295
+ name: "Claude 3 Haiku",
296
+ license: "proprietary",
297
+ providers: ["anthropic", "aws", "google"],
298
+ can: ["chat", "img-in", "json-out", "function-out"],
299
+ context: {
300
+ total: 2e5,
301
+ maxOutput: 4096
302
+ }
303
+ }
304
+ ]
305
+ };
306
+
307
+ // src/data/models/meta.json
308
+ var meta_default = {
309
+ models: [
310
+ {
311
+ id: "llama2-70b-4096",
312
+ name: "Llama 2 70B",
313
+ license: "llama-2-community",
314
+ providers: ["groq", "ollama"],
315
+ can: ["chat", "json-out", "function-out"],
316
+ context: {
317
+ total: 4096,
318
+ maxOutput: 4096
319
+ }
320
+ }
321
+ ]
322
+ };
323
+
324
+ // src/data/models/mistral.json
325
+ var mistral_default = {
326
+ models: [
327
+ {
328
+ id: "mixtral-8x7b-32768",
329
+ name: "Mixtral 8x7B",
330
+ license: "apache-2.0",
331
+ providers: ["groq"],
332
+ can: ["chat", "json-out", "function-out"],
333
+ context: {
334
+ total: 32768,
335
+ maxOutput: 4096
336
+ }
337
+ }
338
+ ]
339
+ };
340
+
341
+ // src/builders/models.ts
342
+ function buildAllModels() {
343
+ return [
344
+ ...openai_default.models,
345
+ ...anthropic_default.models,
346
+ ...meta_default.models,
347
+ ...mistral_default.models
348
+ ];
349
+ }
350
+
351
+ // src/data/providers/openai.json
352
+ var openai_default2 = {
353
+ id: "openai",
354
+ name: "OpenAI",
355
+ websiteUrl: "https://openai.com/",
356
+ apiUrl: "https://api.openai.com/v1",
357
+ defaultModel: "gpt-4o",
358
+ models: {
359
+ "gpt-4o": {
360
+ type: "token",
361
+ input: 20,
362
+ output: 80
363
+ },
364
+ "gpt-3.5-turbo": {
365
+ type: "token",
366
+ input: 5,
367
+ output: 20
368
+ },
369
+ "gpt-4o-vision": {
370
+ type: "token",
371
+ input: 15,
372
+ input_cached: 7.5,
373
+ output: 60
374
+ },
375
+ "o1-mini": {
376
+ type: "token",
377
+ input: 3,
378
+ input_cached: 1.5,
379
+ output: 15
380
+ },
381
+ "o3-mini": {
382
+ type: "token",
383
+ input: 3,
384
+ input_cached: 1.5,
385
+ output: 15
386
+ },
387
+ "gpt-4o-audio-preview": {
388
+ type: "token",
389
+ input: 20,
390
+ output: 80
391
+ },
392
+ "gpt-4o-vision-preview": {
393
+ type: "token",
394
+ input: 20,
395
+ output: 80
396
+ },
397
+ "whisper-1": {
398
+ type: "minute",
399
+ price: 6e-3
400
+ },
401
+ "tts-1": {
402
+ type: "character",
403
+ price: 15e-6
404
+ },
405
+ "tts-1-hd": {
406
+ type: "character",
407
+ price: 3e-5
408
+ },
409
+ "dall-e-2": {
410
+ type: "image",
411
+ price: 0.016,
412
+ size: "256x256",
413
+ unit: "per_image"
414
+ },
415
+ "dall-e-2-512": {
416
+ type: "image",
417
+ price: 0.018,
418
+ size: "512x512",
419
+ unit: "per_image"
420
+ },
421
+ "dall-e-2-1024": {
422
+ type: "image",
423
+ price: 0.02,
424
+ size: "1024x1024",
425
+ unit: "per_image"
426
+ },
427
+ "dall-e-3": {
428
+ type: "image",
429
+ price: 0.04,
430
+ size: "1024x1024",
431
+ unit: "per_image"
432
+ },
433
+ "dall-e-3-hd": {
434
+ type: "image",
435
+ price: 0.08,
436
+ size: "1024x1024",
437
+ unit: "per_image"
438
+ }
439
+ }
440
+ };
441
+
442
+ // src/data/providers/anthropic.json
443
+ var anthropic_default2 = {
444
+ id: "anthropic",
445
+ name: "Anthropic",
446
+ websiteUrl: "https://www.anthropic.com/",
447
+ apiUrl: "https://api.anthropic.com/v1",
448
+ defaultModel: "claude-3-sonnet",
449
+ models: {
450
+ "claude-3-opus": {
451
+ type: "token",
452
+ input: 15,
453
+ output: 75
454
+ },
455
+ "claude-3-sonnet": {
456
+ type: "token",
457
+ input: 3,
458
+ output: 15
459
+ },
460
+ "claude-3-haiku": {
461
+ type: "token",
462
+ input: 2.5,
463
+ output: 12.5
464
+ }
465
+ }
466
+ };
467
+
468
+ // src/data/providers/mistral.json
469
+ var mistral_default2 = {
470
+ id: "mistral",
471
+ name: "Mistral",
472
+ websiteUrl: "https://mistral.ai/",
473
+ apiUrl: "https://api.mistral.ai/v1",
474
+ defaultModel: "mixtral-8x7b-32768",
475
+ models: {
476
+ "mixtral-8x7b-32768": {
477
+ type: "token",
478
+ input: 0.7,
479
+ output: 0.7
480
+ },
481
+ "mistral-large-latest": {
482
+ type: "token",
483
+ input: 0.7,
484
+ output: 0.7
485
+ }
486
+ }
487
+ };
488
+
489
+ // src/builders/providers.ts
490
+ function isTokenPrice(price) {
491
+ return typeof price === "object" && price !== null && "type" in price && price.type === "token" && "input" in price && typeof price.input === "number" && "output" in price && typeof price.output === "number";
492
+ }
493
+ function isImagePrice(price) {
494
+ return typeof price === "object" && price !== null && "type" in price && price.type === "image" && "price" in price && typeof price.price === "number" && "size" in price && typeof price.size === "string" && "unit" in price && price.unit === "per_image";
495
+ }
496
+ function isCharacterPrice(price) {
497
+ return typeof price === "object" && price !== null && "type" in price && price.type === "character" && "price" in price && typeof price.price === "number";
498
+ }
499
+ function isMinutePrice(price) {
500
+ return typeof price === "object" && price !== null && "type" in price && price.type === "minute" && "price" in price && typeof price.price === "number";
501
+ }
502
+ function validateProvider(raw) {
503
+ if (typeof raw !== "object" || raw === null) {
504
+ throw new Error("Provider data must be an object");
505
+ }
506
+ const provider = raw;
507
+ if (typeof provider.id !== "string") {
508
+ throw new Error("Provider id must be a string");
509
+ }
510
+ if (typeof provider.name !== "string") {
511
+ throw new Error("Provider name must be a string");
512
+ }
513
+ if (typeof provider.websiteUrl !== "string") {
514
+ throw new Error("Provider websiteUrl must be a string");
515
+ }
516
+ if (typeof provider.apiUrl !== "string") {
517
+ throw new Error("Provider apiUrl must be a string");
518
+ }
519
+ if (typeof provider.models !== "object" || provider.models === null) {
520
+ throw new Error("Provider models must be an object");
521
+ }
522
+ const models2 = provider.models;
523
+ Object.values(models2).forEach((price) => {
524
+ if (!isTokenPrice(price) && !isImagePrice(price) && !isCharacterPrice(price) && !isMinutePrice(price)) {
525
+ throw new Error(`Invalid price data: ${JSON.stringify(price)}`);
526
+ }
527
+ });
528
+ return {
529
+ id: provider.id,
530
+ name: provider.name,
531
+ websiteUrl: provider.websiteUrl,
532
+ apiUrl: provider.apiUrl,
533
+ models: provider.models
534
+ };
535
+ }
536
+ function buildAllProviders() {
537
+ return [
538
+ validateProvider(openai_default2),
539
+ validateProvider(anthropic_default2),
540
+ validateProvider(mistral_default2)
541
+ ];
542
+ }
543
+ function buildProvidersData() {
544
+ return {
545
+ providers: buildAllProviders()
546
+ };
547
+ }
548
+
549
+ // src/data/creators.json
550
+ var creators_default = {
551
+ creators: {
552
+ openai: {
553
+ name: "OpenAI",
554
+ website: "https://openai.com"
555
+ },
556
+ anthropic: {
557
+ name: "Anthropic",
558
+ website: "https://anthropic.com"
559
+ },
560
+ meta: {
561
+ name: "Meta",
562
+ website: "https://ai.meta.com"
563
+ },
564
+ mistral: {
565
+ name: "Mistral AI",
566
+ website: "https://mistral.ai"
567
+ }
568
+ }
569
+ };
81
570
 
82
571
  // src/index.ts
83
- var aimodels = models_default;
572
+ var allModels = buildAllModels();
573
+ var providersData = buildProvidersData();
84
574
  var models = {
85
- all: aimodels,
575
+ all: new ModelCollection(allModels),
576
+ get creators() {
577
+ return Object.keys(creators_default.creators);
578
+ },
86
579
  get providers() {
87
- return [...new Set(aimodels.map((model) => model.provider))];
580
+ return providersData.providers.map((p) => p.id);
88
581
  },
89
- from(provider) {
90
- return aimodels.filter((model) => model.provider === provider);
582
+ fromCreator(creator) {
583
+ return new ModelCollection(
584
+ allModels.filter(
585
+ (model) => model.license.startsWith(creator) || // For open source models
586
+ providersData.providers.find((p) => p.id === creator)?.models[model.id]
587
+ // For proprietary models
588
+ )
589
+ );
590
+ },
591
+ fromProvider(provider) {
592
+ return new ModelCollection(
593
+ allModels.filter((model) => model.providers.includes(provider))
594
+ );
91
595
  },
92
596
  find(id) {
93
- return aimodels.find((model) => model.id === id);
597
+ return allModels.find((model) => model.id === id);
94
598
  },
95
- withCapability(capability) {
96
- return aimodels.filter((model) => model.capabilities.includes(capability));
599
+ can(...capabilities) {
600
+ return new ModelCollection(
601
+ allModels.filter(
602
+ (model) => capabilities.every((capability) => model.can.includes(capability))
603
+ )
604
+ );
97
605
  },
98
606
  withMinContext(tokens) {
99
- return aimodels.filter((model) => model.contextWindow >= tokens);
100
- },
101
- withMaxPrice(price) {
102
- return aimodels.filter(
103
- (model) => model.pricing.input <= price && model.pricing.output <= price
607
+ return new ModelCollection(
608
+ allModels.filter((model) => model.context.total >= tokens)
104
609
  );
610
+ },
611
+ getPrice(modelId, provider) {
612
+ const providerData = providersData.providers.find((p) => p.id === provider);
613
+ const price = providerData?.models[modelId];
614
+ return price?.type === "token" ? price : void 0;
105
615
  }
106
616
  };
107
617
  // Annotate the CommonJS export names for ESM import in node:
108
618
  0 && (module.exports = {
619
+ creators,
109
620
  models
110
621
  });