ask-llm-providers 0.6.1 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 915a6861e0cbc8cdddcc9f1b9f936d9f95896943f1307f199dfe604b8f4d527c
4
- data.tar.gz: 9f667d8f56d4e1265314c4dfdeaebbefbab7dae0a74724dc31ac79074decf3ef
3
+ metadata.gz: 48397005f7c0a96ae277cc4542f716c389000bb958ef060e474efa763f3cb2e7
4
+ data.tar.gz: ad14c0674e82ff5ee6572ee16c2c2c2731222b846ac1ea10e3ed51b59eb453cd
5
5
  SHA512:
6
- metadata.gz: 528d7105a625887f249e0fe7a0f0dad3469e47f73cfad59d02d85613cdecb287d9277c007cc50b1fc574053fc44ac27b6fa198cf3221ec0de8881dca2be65b33
7
- data.tar.gz: b6d3e1dc25804a7808e7cfa45ec2ff7f9542ca43fad5336a7131c7dd18930264badcf9575f0ee993781f7ced64cd9dfa496a8e14851b4f73e60fa0db4f1c780f
6
+ metadata.gz: 05db1db4749217a513b85be42e0b7492466d657ea1c90f50b5fe3bacec83745555d95440c77ffe6df90a356584b99f4f3619645a99d1eb8bf73103aed4c39e94
7
+ data.tar.gz: adbb4b2e782d488a87aae1b7c1ba9478dfc9e083c013f701f78984a28fe49c081f42f254197ed071c03a6f31820ecc10de35ef101d97d26e806a5b21d9765074
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [0.7.0] — 2026-07-17
2
+
3
+ ### Added
4
+
5
+ - **`Ask::LLM::Sources::ModelsDev`** — fetches model data from `models.dev` API and writes enriched per-provider JSON files with pricing, capabilities, and modalities. Run `rake models:update` before each release to keep bundled model data current.
6
+ - **`Ask::LLM::CostCalculator`** — calculates LLM API costs from model pricing data. Supports input, output, cache read/write, and reasoning tokens.
7
+
8
+ ### Changed
9
+
10
+ - **Model coverage expanded** — from 62 to 289 models across 10 providers, with 284 (98%) having full pricing data. Generated from models.dev API instead of hand-written.
11
+ - **`build_model_info` now deep-symbolizes pricing keys** — pricing hashes loaded from JSON now use symbol keys (`:text_tokens`, `:standard`, `:input_per_million`) matching the format produced by `ModelsDevParser` in ask-core.
12
+ - **`build_model_info` handles date parsing safely** — `Date.parse` failures no longer silently destroy the entire model entry via a broad `rescue Date::Error`. Invalid dates are gracefully set to `nil` via `safe_parse_date`.
13
+
14
+ ### Fixed
15
+
16
+ - **Pricing data loss bug** — `rescue Date::Error` in `build_model_info` was catching exceptions from the entire method body, including date parsing and pricing construction. When any model had an unparseable date, its ModelInfo was created with only `id` and `provider`, silently discarding pricing, capabilities, modalities, and all other fields.
17
+ - **Pricing key inconsistency** — pricing loaded from JSON had string keys while pricing from `ModelsDevParser` (ask-core) had symbol keys. Both formats now consistently use symbol keys.
18
+
1
19
  ## [0.6.1] — 2026-07-17
2
20
 
3
21
  ### Added
@@ -35,6 +35,8 @@ module Ask
35
35
  true
36
36
  end
37
37
 
38
+
39
+
38
40
  # Like load! but also fetches model lists from configured providers'
39
41
  # list_models() APIs. Unknown models are added with minimal metadata.
40
42
  def refresh!
@@ -112,9 +114,12 @@ module Ask
112
114
  # Register all accumulated entries into Ask::ModelCatalog.
113
115
  # Also registers alias entries so models can be found by alias name.
114
116
  def register_all
117
+ catalog = Ask::ModelCatalog.instance
118
+ catalog.instance_variable_set(:@models, [])
119
+
115
120
  @entries.each do |entry|
116
121
  info = build_model_info(entry)
117
- Ask::ModelCatalog.instance.register(info)
122
+ catalog.register(info)
118
123
  end
119
124
 
120
125
  register_alias_entries
@@ -142,6 +147,13 @@ module Ask
142
147
  hash.transform_keys { |k| k.respond_to?(:to_sym) ? k.to_sym : k }
143
148
  end
144
149
 
150
+ def deep_symbolize_keys(hash)
151
+ hash.each_with_object({}) { |(k, v), h|
152
+ hk = k.respond_to?(:to_sym) ? k.to_sym : k
153
+ h[hk] = v.is_a?(Hash) ? deep_symbolize_keys(v) : v
154
+ }
155
+ end
156
+
145
157
  def add_entry(entry)
146
158
  key = entry_key(entry)
147
159
  return if @model_keys.include?(key)
@@ -170,8 +182,16 @@ module Ask
170
182
 
171
183
  def build_model_info(entry)
172
184
  e = entry.transform_keys(&:to_sym)
173
- modalities = e[:modalities]
174
- modalities = symbolize_keys(modalities) if modalities
185
+
186
+ modalities = symbolize_keys(e[:modalities]) if e[:modalities]
187
+
188
+ pricing = {}
189
+ if e[:pricing] && e[:pricing].any?
190
+ deep_symbolize_keys(e[:pricing]).each { |k, v| pricing[k] = v }
191
+ end
192
+
193
+ knowledge_cutoff = safe_parse_date(e[:knowledge_cutoff])
194
+ created_at = safe_parse_date(e[:created_at])
175
195
 
176
196
  Ask::ModelInfo.new(
177
197
  id: e[:id],
@@ -182,13 +202,19 @@ module Ask
182
202
  context_window: e[:context_window],
183
203
  max_output_tokens: e[:max_output_tokens],
184
204
  modalities: modalities || { input: %w[text], output: %w[text] },
185
- pricing: e[:pricing] || {},
186
- knowledge_cutoff: e[:knowledge_cutoff] ? Date.parse(e[:knowledge_cutoff].to_s) : nil,
187
- created_at: e[:created_at] ? Date.parse(e[:created_at].to_s) : nil,
205
+ pricing: pricing,
206
+ knowledge_cutoff: knowledge_cutoff,
207
+ created_at: created_at,
188
208
  metadata: (e[:metadata] || {}).merge(source: e[:metadata]&.dig("source") || "bundled")
189
209
  )
190
- rescue Date::Error
191
- Ask::ModelInfo.new(id: e[:id], provider: e[:provider])
210
+ end
211
+
212
+ def safe_parse_date(value)
213
+ return nil if value.nil?
214
+ return value if value.is_a?(Date)
215
+ Date.parse(value.to_s)
216
+ rescue ArgumentError
217
+ nil
192
218
  end
193
219
  end
194
220
  end
@@ -1,19 +1,51 @@
1
1
  [
2
2
  {
3
- "id": "claude-sonnet-4-5",
4
- "name": "Claude Sonnet 4.5",
5
- "family": "claude_sonnet",
3
+ "id": "claude-fable-5",
4
+ "name": "Claude Fable 5",
5
+ "provider": "anthropic",
6
+ "family": "claude-fable",
7
+ "context_window": 1000000,
8
+ "max_output_tokens": 128000,
9
+ "capabilities": [
10
+ "function_calling",
11
+ "structured_output",
12
+ "reasoning",
13
+ "vision"
14
+ ],
15
+ "modalities": {
16
+ "input": [
17
+ "text",
18
+ "image",
19
+ "pdf"
20
+ ],
21
+ "output": [
22
+ "text"
23
+ ]
24
+ },
25
+ "pricing": {
26
+ "text_tokens": {
27
+ "standard": {
28
+ "input_per_million": 10,
29
+ "output_per_million": 50,
30
+ "cache_read_input_per_million": 1,
31
+ "cache_write_input_per_million": 12.5
32
+ }
33
+ }
34
+ },
35
+ "created_at": "2026-06-07"
36
+ },
37
+ {
38
+ "id": "claude-haiku-4-5-20251001",
39
+ "name": "Claude Haiku 4.5",
40
+ "provider": "anthropic",
41
+ "family": "claude-haiku",
6
42
  "context_window": 200000,
7
43
  "max_output_tokens": 64000,
8
44
  "capabilities": [
9
45
  "function_calling",
10
- "streaming",
11
46
  "structured_output",
12
- "vision",
13
47
  "reasoning",
14
- "prompt_caching",
15
- "tool_choice",
16
- "parallel_tool_calls"
48
+ "vision"
17
49
  ],
18
50
  "modalities": {
19
51
  "input": [
@@ -25,23 +57,31 @@
25
57
  "text"
26
58
  ]
27
59
  },
28
- "provider": "anthropic"
60
+ "pricing": {
61
+ "text_tokens": {
62
+ "standard": {
63
+ "input_per_million": 1,
64
+ "output_per_million": 5,
65
+ "cache_read_input_per_million": 0.1,
66
+ "cache_write_input_per_million": 1.25
67
+ }
68
+ }
69
+ },
70
+ "knowledge_cutoff": "2025-02-28",
71
+ "created_at": "2025-10-15"
29
72
  },
30
73
  {
31
- "id": "claude-sonnet-4",
32
- "name": "Claude Sonnet 4",
33
- "family": "claude_sonnet",
74
+ "id": "claude-haiku-4-5",
75
+ "name": "Claude Haiku 4.5 (latest)",
76
+ "provider": "anthropic",
77
+ "family": "claude-haiku",
34
78
  "context_window": 200000,
35
79
  "max_output_tokens": 64000,
36
80
  "capabilities": [
37
81
  "function_calling",
38
- "streaming",
39
82
  "structured_output",
40
- "vision",
41
83
  "reasoning",
42
- "prompt_caching",
43
- "tool_choice",
44
- "parallel_tool_calls"
84
+ "vision"
45
85
  ],
46
86
  "modalities": {
47
87
  "input": [
@@ -53,23 +93,31 @@
53
93
  "text"
54
94
  ]
55
95
  },
56
- "provider": "anthropic"
96
+ "pricing": {
97
+ "text_tokens": {
98
+ "standard": {
99
+ "input_per_million": 1,
100
+ "output_per_million": 5,
101
+ "cache_read_input_per_million": 0.1,
102
+ "cache_write_input_per_million": 1.25
103
+ }
104
+ }
105
+ },
106
+ "knowledge_cutoff": "2025-02-28",
107
+ "created_at": "2025-10-15"
57
108
  },
58
109
  {
59
- "id": "claude-4-opus",
60
- "name": "Claude Opus 4",
61
- "family": "claude_opus",
110
+ "id": "claude-opus-4-1-20250805",
111
+ "name": "Claude Opus 4.1",
112
+ "provider": "anthropic",
113
+ "family": "claude-opus",
62
114
  "context_window": 200000,
63
- "max_output_tokens": 64000,
115
+ "max_output_tokens": 32000,
64
116
  "capabilities": [
65
117
  "function_calling",
66
- "streaming",
67
118
  "structured_output",
68
- "vision",
69
119
  "reasoning",
70
- "prompt_caching",
71
- "tool_choice",
72
- "parallel_tool_calls"
120
+ "vision"
73
121
  ],
74
122
  "modalities": {
75
123
  "input": [
@@ -81,23 +129,31 @@
81
129
  "text"
82
130
  ]
83
131
  },
84
- "provider": "anthropic"
132
+ "pricing": {
133
+ "text_tokens": {
134
+ "standard": {
135
+ "input_per_million": 15,
136
+ "output_per_million": 75,
137
+ "cache_read_input_per_million": 1.5,
138
+ "cache_write_input_per_million": 18.75
139
+ }
140
+ }
141
+ },
142
+ "knowledge_cutoff": "2025-03-31",
143
+ "created_at": "2025-08-05"
85
144
  },
86
145
  {
87
- "id": "claude-haiku-4-5",
88
- "name": "Claude Haiku 4.5",
89
- "family": "claude_haiku",
146
+ "id": "claude-opus-4-1",
147
+ "name": "Claude Opus 4.1 (latest)",
148
+ "provider": "anthropic",
149
+ "family": "claude-opus",
90
150
  "context_window": 200000,
91
- "max_output_tokens": 64000,
151
+ "max_output_tokens": 32000,
92
152
  "capabilities": [
93
153
  "function_calling",
94
- "streaming",
95
154
  "structured_output",
96
- "vision",
97
155
  "reasoning",
98
- "prompt_caching",
99
- "tool_choice",
100
- "parallel_tool_calls"
156
+ "vision"
101
157
  ],
102
158
  "modalities": {
103
159
  "input": [
@@ -109,23 +165,31 @@
109
165
  "text"
110
166
  ]
111
167
  },
112
- "provider": "anthropic"
168
+ "pricing": {
169
+ "text_tokens": {
170
+ "standard": {
171
+ "input_per_million": 15,
172
+ "output_per_million": 75,
173
+ "cache_read_input_per_million": 1.5,
174
+ "cache_write_input_per_million": 18.75
175
+ }
176
+ }
177
+ },
178
+ "knowledge_cutoff": "2025-03-31",
179
+ "created_at": "2025-08-05"
113
180
  },
114
181
  {
115
- "id": "claude-opus-4-5",
182
+ "id": "claude-opus-4-5-20251101",
116
183
  "name": "Claude Opus 4.5",
117
- "family": "claude_opus",
184
+ "provider": "anthropic",
185
+ "family": "claude-opus",
118
186
  "context_window": 200000,
119
187
  "max_output_tokens": 64000,
120
188
  "capabilities": [
121
189
  "function_calling",
122
- "streaming",
123
190
  "structured_output",
124
- "vision",
125
191
  "reasoning",
126
- "prompt_caching",
127
- "tool_choice",
128
- "parallel_tool_calls"
192
+ "vision"
129
193
  ],
130
194
  "modalities": {
131
195
  "input": [
@@ -137,52 +201,305 @@
137
201
  "text"
138
202
  ]
139
203
  },
140
- "provider": "anthropic"
204
+ "pricing": {
205
+ "text_tokens": {
206
+ "standard": {
207
+ "input_per_million": 5,
208
+ "output_per_million": 25,
209
+ "cache_read_input_per_million": 0.5,
210
+ "cache_write_input_per_million": 6.25
211
+ }
212
+ }
213
+ },
214
+ "knowledge_cutoff": "2025-05",
215
+ "created_at": "2025-11-24"
141
216
  },
142
217
  {
143
- "id": "claude-3.5-sonnet",
144
- "name": "Claude 3.5 Sonnet",
145
- "family": "claude_sonnet",
218
+ "id": "claude-opus-4-5",
219
+ "name": "Claude Opus 4.5 (latest)",
220
+ "provider": "anthropic",
221
+ "family": "claude-opus",
146
222
  "context_window": 200000,
147
- "max_output_tokens": 8192,
223
+ "max_output_tokens": 64000,
148
224
  "capabilities": [
149
225
  "function_calling",
150
- "streaming",
151
- "vision",
152
- "reasoning"
226
+ "structured_output",
227
+ "reasoning",
228
+ "vision"
153
229
  ],
154
230
  "modalities": {
155
231
  "input": [
156
232
  "text",
157
- "image"
233
+ "image",
234
+ "pdf"
158
235
  ],
159
236
  "output": [
160
237
  "text"
161
238
  ]
162
239
  },
163
- "provider": "anthropic"
240
+ "pricing": {
241
+ "text_tokens": {
242
+ "standard": {
243
+ "input_per_million": 5,
244
+ "output_per_million": 25,
245
+ "cache_read_input_per_million": 0.5,
246
+ "cache_write_input_per_million": 6.25
247
+ }
248
+ }
249
+ },
250
+ "knowledge_cutoff": "2025-05",
251
+ "created_at": "2025-11-24"
164
252
  },
165
253
  {
166
- "id": "claude-3.5-haiku",
167
- "name": "Claude 3.5 Haiku",
168
- "family": "claude_haiku",
169
- "context_window": 200000,
170
- "max_output_tokens": 8192,
254
+ "id": "claude-opus-4-6",
255
+ "name": "Claude Opus 4.6",
256
+ "provider": "anthropic",
257
+ "family": "claude-opus",
258
+ "context_window": 1000000,
259
+ "max_output_tokens": 128000,
171
260
  "capabilities": [
172
261
  "function_calling",
173
- "streaming",
174
- "vision",
175
- "reasoning"
262
+ "structured_output",
263
+ "reasoning",
264
+ "vision"
176
265
  ],
177
266
  "modalities": {
178
267
  "input": [
179
268
  "text",
180
- "image"
269
+ "image",
270
+ "pdf"
181
271
  ],
182
272
  "output": [
183
273
  "text"
184
274
  ]
185
275
  },
186
- "provider": "anthropic"
276
+ "pricing": {
277
+ "text_tokens": {
278
+ "standard": {
279
+ "input_per_million": 5,
280
+ "output_per_million": 25,
281
+ "cache_read_input_per_million": 0.5,
282
+ "cache_write_input_per_million": 6.25
283
+ }
284
+ }
285
+ },
286
+ "knowledge_cutoff": "2025-05-31",
287
+ "created_at": "2026-02-04"
288
+ },
289
+ {
290
+ "id": "claude-opus-4-7",
291
+ "name": "Claude Opus 4.7",
292
+ "provider": "anthropic",
293
+ "family": "claude-opus",
294
+ "context_window": 1000000,
295
+ "max_output_tokens": 128000,
296
+ "capabilities": [
297
+ "function_calling",
298
+ "structured_output",
299
+ "reasoning",
300
+ "vision"
301
+ ],
302
+ "modalities": {
303
+ "input": [
304
+ "text",
305
+ "image",
306
+ "pdf"
307
+ ],
308
+ "output": [
309
+ "text"
310
+ ]
311
+ },
312
+ "pricing": {
313
+ "text_tokens": {
314
+ "standard": {
315
+ "input_per_million": 5,
316
+ "output_per_million": 25,
317
+ "cache_read_input_per_million": 0.5,
318
+ "cache_write_input_per_million": 6.25
319
+ }
320
+ }
321
+ },
322
+ "knowledge_cutoff": "2026-01-31",
323
+ "created_at": "2026-04-14"
324
+ },
325
+ {
326
+ "id": "claude-opus-4-8",
327
+ "name": "Claude Opus 4.8",
328
+ "provider": "anthropic",
329
+ "family": "claude-opus",
330
+ "context_window": 1000000,
331
+ "max_output_tokens": 128000,
332
+ "capabilities": [
333
+ "function_calling",
334
+ "structured_output",
335
+ "reasoning",
336
+ "vision"
337
+ ],
338
+ "modalities": {
339
+ "input": [
340
+ "text",
341
+ "image",
342
+ "pdf"
343
+ ],
344
+ "output": [
345
+ "text"
346
+ ]
347
+ },
348
+ "pricing": {
349
+ "text_tokens": {
350
+ "standard": {
351
+ "input_per_million": 5,
352
+ "output_per_million": 25,
353
+ "cache_read_input_per_million": 0.5,
354
+ "cache_write_input_per_million": 6.25
355
+ }
356
+ }
357
+ },
358
+ "knowledge_cutoff": "2026-01",
359
+ "created_at": "2026-05-28"
360
+ },
361
+ {
362
+ "id": "claude-sonnet-4-5-20250929",
363
+ "name": "Claude Sonnet 4.5",
364
+ "provider": "anthropic",
365
+ "family": "claude-sonnet",
366
+ "context_window": 1000000,
367
+ "max_output_tokens": 64000,
368
+ "capabilities": [
369
+ "function_calling",
370
+ "structured_output",
371
+ "reasoning",
372
+ "vision"
373
+ ],
374
+ "modalities": {
375
+ "input": [
376
+ "text",
377
+ "image",
378
+ "pdf"
379
+ ],
380
+ "output": [
381
+ "text"
382
+ ]
383
+ },
384
+ "pricing": {
385
+ "text_tokens": {
386
+ "standard": {
387
+ "input_per_million": 3,
388
+ "output_per_million": 15,
389
+ "cache_read_input_per_million": 0.3,
390
+ "cache_write_input_per_million": 3.75
391
+ }
392
+ }
393
+ },
394
+ "knowledge_cutoff": "2025-07-31",
395
+ "created_at": "2025-09-29"
396
+ },
397
+ {
398
+ "id": "claude-sonnet-4-5",
399
+ "name": "Claude Sonnet 4.5 (latest)",
400
+ "provider": "anthropic",
401
+ "family": "claude-sonnet",
402
+ "context_window": 1000000,
403
+ "max_output_tokens": 64000,
404
+ "capabilities": [
405
+ "function_calling",
406
+ "structured_output",
407
+ "reasoning",
408
+ "vision"
409
+ ],
410
+ "modalities": {
411
+ "input": [
412
+ "text",
413
+ "image",
414
+ "pdf"
415
+ ],
416
+ "output": [
417
+ "text"
418
+ ]
419
+ },
420
+ "pricing": {
421
+ "text_tokens": {
422
+ "standard": {
423
+ "input_per_million": 3,
424
+ "output_per_million": 15,
425
+ "cache_read_input_per_million": 0.3,
426
+ "cache_write_input_per_million": 3.75
427
+ }
428
+ }
429
+ },
430
+ "knowledge_cutoff": "2025-07-31",
431
+ "created_at": "2025-09-29"
432
+ },
433
+ {
434
+ "id": "claude-sonnet-4-6",
435
+ "name": "Claude Sonnet 4.6",
436
+ "provider": "anthropic",
437
+ "family": "claude-sonnet",
438
+ "context_window": 1000000,
439
+ "max_output_tokens": 128000,
440
+ "capabilities": [
441
+ "function_calling",
442
+ "structured_output",
443
+ "reasoning",
444
+ "vision"
445
+ ],
446
+ "modalities": {
447
+ "input": [
448
+ "text",
449
+ "image",
450
+ "pdf"
451
+ ],
452
+ "output": [
453
+ "text"
454
+ ]
455
+ },
456
+ "pricing": {
457
+ "text_tokens": {
458
+ "standard": {
459
+ "input_per_million": 3,
460
+ "output_per_million": 15,
461
+ "cache_read_input_per_million": 0.3,
462
+ "cache_write_input_per_million": 3.75
463
+ }
464
+ }
465
+ },
466
+ "knowledge_cutoff": "2025-08-31",
467
+ "created_at": "2026-02-17"
468
+ },
469
+ {
470
+ "id": "claude-sonnet-5",
471
+ "name": "Claude Sonnet 5",
472
+ "provider": "anthropic",
473
+ "family": "claude-sonnet",
474
+ "context_window": 1000000,
475
+ "max_output_tokens": 128000,
476
+ "capabilities": [
477
+ "function_calling",
478
+ "structured_output",
479
+ "reasoning",
480
+ "vision"
481
+ ],
482
+ "modalities": {
483
+ "input": [
484
+ "text",
485
+ "image",
486
+ "pdf"
487
+ ],
488
+ "output": [
489
+ "text"
490
+ ]
491
+ },
492
+ "pricing": {
493
+ "text_tokens": {
494
+ "standard": {
495
+ "input_per_million": 2,
496
+ "output_per_million": 10,
497
+ "cache_read_input_per_million": 0.2,
498
+ "cache_write_input_per_million": 2.5
499
+ }
500
+ }
501
+ },
502
+ "knowledge_cutoff": "2026-01-31",
503
+ "created_at": "2026-06-29"
187
504
  }
188
505
  ]