llm.rb 11.3.1 → 12.0.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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +242 -1
  3. data/LICENSE +92 -17
  4. data/README.md +204 -623
  5. data/data/anthropic.json +433 -249
  6. data/data/bedrock.json +2097 -1055
  7. data/data/deepinfra.json +993 -0
  8. data/data/deepseek.json +53 -28
  9. data/data/google.json +389 -771
  10. data/data/openai.json +1053 -771
  11. data/data/xai.json +133 -292
  12. data/data/zai.json +249 -141
  13. data/lib/llm/active_record/acts_as_agent.rb +3 -41
  14. data/lib/llm/active_record/acts_as_llm.rb +18 -0
  15. data/lib/llm/active_record.rb +3 -3
  16. data/lib/llm/context.rb +9 -5
  17. data/lib/llm/contract/completion.rb +2 -2
  18. data/lib/llm/provider.rb +2 -2
  19. data/lib/llm/providers/deepinfra/audio.rb +66 -0
  20. data/lib/llm/providers/deepinfra/images.rb +90 -0
  21. data/lib/llm/providers/deepinfra/response_adapter.rb +36 -0
  22. data/lib/llm/providers/deepinfra.rb +100 -0
  23. data/lib/llm/providers/deepseek/images.rb +109 -0
  24. data/lib/llm/providers/deepseek/request_adapter.rb +32 -0
  25. data/lib/llm/providers/deepseek/response_adapter/image.rb +9 -0
  26. data/lib/llm/providers/deepseek/response_adapter.rb +29 -0
  27. data/lib/llm/providers/deepseek.rb +4 -2
  28. data/lib/llm/providers/google/request_adapter.rb +22 -5
  29. data/lib/llm/providers/google.rb +4 -4
  30. data/lib/llm/providers/openai/audio.rb +6 -2
  31. data/lib/llm/providers/openai/images.rb +9 -50
  32. data/lib/llm/providers/openai/request_adapter/respond.rb +38 -4
  33. data/lib/llm/providers/openai/response_adapter/audio.rb +5 -1
  34. data/lib/llm/providers/openai/response_adapter/completion.rb +1 -1
  35. data/lib/llm/providers/openai/response_adapter/image.rb +0 -4
  36. data/lib/llm/providers/openai/responses.rb +1 -0
  37. data/lib/llm/providers/openai/stream_parser.rb +5 -6
  38. data/lib/llm/providers/openai.rb +2 -2
  39. data/lib/llm/providers/xai/images.rb +49 -26
  40. data/lib/llm/providers/xai.rb +2 -2
  41. data/lib/llm/response.rb +10 -0
  42. data/lib/llm/schema/leaf.rb +7 -1
  43. data/lib/llm/schema/renderer.rb +121 -0
  44. data/lib/llm/schema.rb +30 -0
  45. data/lib/llm/sequel/agent.rb +2 -43
  46. data/lib/llm/sequel/plugin.rb +25 -7
  47. data/lib/llm/tracer/telemetry.rb +4 -6
  48. data/lib/llm/tracer.rb +9 -21
  49. data/lib/llm/transport/execution.rb +16 -1
  50. data/lib/llm/transport/net_http_adapter.rb +1 -1
  51. data/lib/llm/uridata.rb +16 -0
  52. data/lib/llm/version.rb +1 -1
  53. data/lib/llm.rb +9 -0
  54. data/llm.gemspec +5 -18
  55. data/resources/deepdive.md +798 -264
  56. metadata +15 -18
  57. data/lib/llm/tracer/langsmith.rb +0 -144
data/data/zai.json CHANGED
@@ -8,20 +8,25 @@
8
8
  "name": "Z.AI",
9
9
  "doc": "https://docs.z.ai/guides/overview/pricing",
10
10
  "models": {
11
- "glm-5.1": {
12
- "id": "glm-5.1",
13
- "name": "GLM-5.1",
11
+ "glm-4.7": {
12
+ "id": "glm-4.7",
13
+ "name": "GLM-4.7",
14
14
  "family": "glm",
15
15
  "attachment": false,
16
16
  "reasoning": true,
17
+ "reasoning_options": [
18
+ {
19
+ "type": "toggle"
20
+ }
21
+ ],
17
22
  "tool_call": true,
18
23
  "interleaved": {
19
24
  "field": "reasoning_content"
20
25
  },
21
- "structured_output": true,
22
26
  "temperature": true,
23
- "release_date": "2026-03-27",
24
- "last_updated": "2026-03-27",
27
+ "knowledge": "2025-04",
28
+ "release_date": "2025-12-22",
29
+ "last_updated": "2025-12-22",
25
30
  "modalities": {
26
31
  "input": [
27
32
  "text"
@@ -30,51 +35,87 @@
30
35
  "text"
31
36
  ]
32
37
  },
33
- "open_weights": false,
38
+ "open_weights": true,
34
39
  "limit": {
35
- "context": 200000,
40
+ "context": 204800,
36
41
  "output": 131072
37
42
  },
38
43
  "cost": {
39
- "input": 1.4,
40
- "output": 4.4,
41
- "cache_read": 0.26,
44
+ "input": 0.6,
45
+ "output": 2.2,
46
+ "cache_read": 0.11,
42
47
  "cache_write": 0
43
48
  }
44
49
  },
45
- "glm-5v-turbo": {
46
- "id": "glm-5v-turbo",
47
- "name": "GLM-5V-Turbo",
50
+ "glm-4.5v": {
51
+ "id": "glm-4.5v",
52
+ "name": "GLM-4.5V",
48
53
  "family": "glm",
49
54
  "attachment": true,
50
55
  "reasoning": true,
56
+ "reasoning_options": [
57
+ {
58
+ "type": "toggle"
59
+ }
60
+ ],
51
61
  "tool_call": true,
52
- "interleaved": {
53
- "field": "reasoning_content"
54
- },
55
62
  "temperature": true,
56
- "release_date": "2026-04-01",
57
- "last_updated": "2026-04-01",
63
+ "knowledge": "2025-04",
64
+ "release_date": "2025-08-11",
65
+ "last_updated": "2025-08-11",
58
66
  "modalities": {
59
67
  "input": [
60
68
  "text",
61
69
  "image",
62
- "video",
63
- "pdf"
70
+ "video"
64
71
  ],
65
72
  "output": [
66
73
  "text"
67
74
  ]
68
75
  },
69
- "open_weights": false,
76
+ "open_weights": true,
70
77
  "limit": {
71
- "context": 200000,
72
- "output": 131072
78
+ "context": 64000,
79
+ "output": 16384
73
80
  },
74
81
  "cost": {
75
- "input": 1.2,
76
- "output": 4,
77
- "cache_read": 0.24,
82
+ "input": 0.6,
83
+ "output": 1.8
84
+ }
85
+ },
86
+ "glm-4.5": {
87
+ "id": "glm-4.5",
88
+ "name": "GLM-4.5",
89
+ "family": "glm",
90
+ "attachment": false,
91
+ "reasoning": true,
92
+ "reasoning_options": [
93
+ {
94
+ "type": "toggle"
95
+ }
96
+ ],
97
+ "tool_call": true,
98
+ "temperature": true,
99
+ "knowledge": "2025-04",
100
+ "release_date": "2025-07-28",
101
+ "last_updated": "2025-07-28",
102
+ "modalities": {
103
+ "input": [
104
+ "text"
105
+ ],
106
+ "output": [
107
+ "text"
108
+ ]
109
+ },
110
+ "open_weights": true,
111
+ "limit": {
112
+ "context": 131072,
113
+ "output": 98304
114
+ },
115
+ "cost": {
116
+ "input": 0.6,
117
+ "output": 2.2,
118
+ "cache_read": 0.11,
78
119
  "cache_write": 0
79
120
  }
80
121
  },
@@ -84,6 +125,11 @@
84
125
  "family": "glm-flash",
85
126
  "attachment": false,
86
127
  "reasoning": true,
128
+ "reasoning_options": [
129
+ {
130
+ "type": "toggle"
131
+ }
132
+ ],
87
133
  "tool_call": true,
88
134
  "temperature": true,
89
135
  "knowledge": "2025-04",
@@ -109,17 +155,25 @@
109
155
  "cache_write": 0
110
156
  }
111
157
  },
112
- "glm-4.5-air": {
113
- "id": "glm-4.5-air",
114
- "name": "GLM-4.5-Air",
115
- "family": "glm-air",
158
+ "glm-5.1": {
159
+ "id": "glm-5.1",
160
+ "name": "GLM-5.1",
161
+ "family": "glm",
116
162
  "attachment": false,
117
163
  "reasoning": true,
164
+ "reasoning_options": [
165
+ {
166
+ "type": "toggle"
167
+ }
168
+ ],
118
169
  "tool_call": true,
170
+ "interleaved": {
171
+ "field": "reasoning_content"
172
+ },
173
+ "structured_output": true,
119
174
  "temperature": true,
120
- "knowledge": "2025-04",
121
- "release_date": "2025-07-28",
122
- "last_updated": "2025-07-28",
175
+ "release_date": "2026-04-07",
176
+ "last_updated": "2026-04-07",
123
177
  "modalities": {
124
178
  "input": [
125
179
  "text"
@@ -130,32 +184,35 @@
130
184
  },
131
185
  "open_weights": true,
132
186
  "limit": {
133
- "context": 131072,
134
- "output": 98304
187
+ "context": 200000,
188
+ "output": 131072
135
189
  },
136
190
  "cost": {
137
- "input": 0.2,
138
- "output": 1.1,
139
- "cache_read": 0.03,
191
+ "input": 1.4,
192
+ "output": 4.4,
193
+ "cache_read": 0.26,
140
194
  "cache_write": 0
141
195
  }
142
196
  },
143
- "glm-4.5v": {
144
- "id": "glm-4.5v",
145
- "name": "GLM-4.5V",
197
+ "glm-4.6": {
198
+ "id": "glm-4.6",
199
+ "name": "GLM-4.6",
146
200
  "family": "glm",
147
- "attachment": true,
201
+ "attachment": false,
148
202
  "reasoning": true,
203
+ "reasoning_options": [
204
+ {
205
+ "type": "toggle"
206
+ }
207
+ ],
149
208
  "tool_call": true,
150
209
  "temperature": true,
151
210
  "knowledge": "2025-04",
152
- "release_date": "2025-08-11",
153
- "last_updated": "2025-08-11",
211
+ "release_date": "2025-09-30",
212
+ "last_updated": "2025-09-30",
154
213
  "modalities": {
155
214
  "input": [
156
- "text",
157
- "image",
158
- "video"
215
+ "text"
159
216
  ],
160
217
  "output": [
161
218
  "text"
@@ -163,25 +220,39 @@
163
220
  },
164
221
  "open_weights": true,
165
222
  "limit": {
166
- "context": 64000,
167
- "output": 16384
223
+ "context": 204800,
224
+ "output": 131072
168
225
  },
169
226
  "cost": {
170
227
  "input": 0.6,
171
- "output": 1.8
228
+ "output": 2.2,
229
+ "cache_read": 0.11,
230
+ "cache_write": 0
172
231
  }
173
232
  },
174
- "glm-4.7-flash": {
175
- "id": "glm-4.7-flash",
176
- "name": "GLM-4.7-Flash",
177
- "family": "glm-flash",
233
+ "glm-5.2": {
234
+ "id": "glm-5.2",
235
+ "name": "GLM-5.2",
236
+ "family": "glm",
178
237
  "attachment": false,
179
238
  "reasoning": true,
239
+ "reasoning_options": [
240
+ {
241
+ "type": "effort",
242
+ "values": [
243
+ "high",
244
+ "max"
245
+ ]
246
+ }
247
+ ],
180
248
  "tool_call": true,
249
+ "interleaved": {
250
+ "field": "reasoning_content"
251
+ },
252
+ "structured_output": true,
181
253
  "temperature": true,
182
- "knowledge": "2025-04",
183
- "release_date": "2026-01-19",
184
- "last_updated": "2026-01-19",
254
+ "release_date": "2026-06-13",
255
+ "last_updated": "2026-06-13",
185
256
  "modalities": {
186
257
  "input": [
187
258
  "text"
@@ -192,30 +263,37 @@
192
263
  },
193
264
  "open_weights": true,
194
265
  "limit": {
195
- "context": 200000,
266
+ "context": 1000000,
196
267
  "output": 131072
197
268
  },
198
269
  "cost": {
199
- "input": 0,
200
- "output": 0,
201
- "cache_read": 0,
270
+ "input": 1.4,
271
+ "output": 4.4,
272
+ "cache_read": 0.26,
202
273
  "cache_write": 0
203
274
  }
204
275
  },
205
- "glm-4.6": {
206
- "id": "glm-4.6",
207
- "name": "GLM-4.6",
276
+ "glm-4.6v": {
277
+ "id": "glm-4.6v",
278
+ "name": "GLM-4.6V",
208
279
  "family": "glm",
209
- "attachment": false,
280
+ "attachment": true,
210
281
  "reasoning": true,
282
+ "reasoning_options": [
283
+ {
284
+ "type": "toggle"
285
+ }
286
+ ],
211
287
  "tool_call": true,
212
288
  "temperature": true,
213
289
  "knowledge": "2025-04",
214
- "release_date": "2025-09-30",
215
- "last_updated": "2025-09-30",
290
+ "release_date": "2025-12-08",
291
+ "last_updated": "2025-12-08",
216
292
  "modalities": {
217
293
  "input": [
218
- "text"
294
+ "text",
295
+ "image",
296
+ "video"
219
297
  ],
220
298
  "output": [
221
299
  "text"
@@ -223,53 +301,66 @@
223
301
  },
224
302
  "open_weights": true,
225
303
  "limit": {
226
- "context": 204800,
227
- "output": 131072
304
+ "context": 128000,
305
+ "output": 32768
228
306
  },
229
307
  "cost": {
230
- "input": 0.6,
231
- "output": 2.2,
232
- "cache_read": 0.11,
233
- "cache_write": 0
308
+ "input": 0.3,
309
+ "output": 0.9
234
310
  }
235
311
  },
236
- "glm-4.5": {
237
- "id": "glm-4.5",
238
- "name": "GLM-4.5",
312
+ "glm-5v-turbo": {
313
+ "id": "glm-5v-turbo",
314
+ "name": "GLM-5V-Turbo",
239
315
  "family": "glm",
240
- "attachment": false,
316
+ "attachment": true,
241
317
  "reasoning": true,
318
+ "reasoning_options": [
319
+ {
320
+ "type": "toggle"
321
+ }
322
+ ],
242
323
  "tool_call": true,
324
+ "interleaved": {
325
+ "field": "reasoning_content"
326
+ },
243
327
  "temperature": true,
244
- "knowledge": "2025-04",
245
- "release_date": "2025-07-28",
246
- "last_updated": "2025-07-28",
328
+ "release_date": "2026-04-01",
329
+ "last_updated": "2026-04-01",
247
330
  "modalities": {
248
331
  "input": [
249
- "text"
332
+ "text",
333
+ "image",
334
+ "video",
335
+ "pdf"
250
336
  ],
251
337
  "output": [
252
338
  "text"
253
339
  ]
254
340
  },
255
- "open_weights": true,
341
+ "open_weights": false,
256
342
  "limit": {
257
- "context": 131072,
258
- "output": 98304
343
+ "context": 200000,
344
+ "output": 131072
259
345
  },
260
346
  "cost": {
261
- "input": 0.6,
262
- "output": 2.2,
263
- "cache_read": 0.11,
347
+ "input": 1.2,
348
+ "output": 4,
349
+ "cache_read": 0.24,
264
350
  "cache_write": 0
265
351
  }
266
352
  },
267
- "glm-4.5-flash": {
268
- "id": "glm-4.5-flash",
269
- "name": "GLM-4.5-Flash",
270
- "family": "glm-flash",
353
+ "glm-4.5-air": {
354
+ "id": "glm-4.5-air",
355
+ "name": "GLM-4.5-Air",
356
+ "family": "glm-air",
271
357
  "attachment": false,
272
358
  "reasoning": true,
359
+ "reasoning_options": [
360
+ {
361
+ "type": "toggle"
362
+ }
363
+ ],
273
364
  "tool_call": true,
274
365
  "temperature": true,
275
366
  "knowledge": "2025-04",
@@ -289,26 +380,28 @@
289
380
  "output": 98304
290
381
  },
291
382
  "cost": {
292
- "input": 0,
293
- "output": 0,
294
- "cache_read": 0,
383
+ "input": 0.2,
384
+ "output": 1.1,
385
+ "cache_read": 0.03,
295
386
  "cache_write": 0
296
387
  }
297
388
  },
298
- "glm-5-turbo": {
299
- "id": "glm-5-turbo",
300
- "name": "GLM-5-Turbo",
301
- "family": "glm",
389
+ "glm-4.7-flash": {
390
+ "id": "glm-4.7-flash",
391
+ "name": "GLM-4.7-Flash",
392
+ "family": "glm-flash",
302
393
  "attachment": false,
303
394
  "reasoning": true,
395
+ "reasoning_options": [
396
+ {
397
+ "type": "toggle"
398
+ }
399
+ ],
304
400
  "tool_call": true,
305
- "interleaved": {
306
- "field": "reasoning_content"
307
- },
308
- "structured_output": true,
309
401
  "temperature": true,
310
- "release_date": "2026-03-16",
311
- "last_updated": "2026-03-16",
402
+ "knowledge": "2025-04",
403
+ "release_date": "2026-01-19",
404
+ "last_updated": "2026-01-19",
312
405
  "modalities": {
313
406
  "input": [
314
407
  "text"
@@ -317,32 +410,34 @@
317
410
  "text"
318
411
  ]
319
412
  },
320
- "open_weights": false,
413
+ "open_weights": true,
321
414
  "limit": {
322
415
  "context": 200000,
323
416
  "output": 131072
324
417
  },
325
418
  "cost": {
326
- "input": 1.2,
327
- "output": 4,
328
- "cache_read": 0.24,
419
+ "input": 0,
420
+ "output": 0,
421
+ "cache_read": 0,
329
422
  "cache_write": 0
330
423
  }
331
424
  },
332
- "glm-4.7": {
333
- "id": "glm-4.7",
334
- "name": "GLM-4.7",
335
- "family": "glm",
425
+ "glm-4.5-flash": {
426
+ "id": "glm-4.5-flash",
427
+ "name": "GLM-4.5-Flash",
428
+ "family": "glm-flash",
336
429
  "attachment": false,
337
430
  "reasoning": true,
431
+ "reasoning_options": [
432
+ {
433
+ "type": "toggle"
434
+ }
435
+ ],
338
436
  "tool_call": true,
339
- "interleaved": {
340
- "field": "reasoning_content"
341
- },
342
437
  "temperature": true,
343
438
  "knowledge": "2025-04",
344
- "release_date": "2025-12-22",
345
- "last_updated": "2025-12-22",
439
+ "release_date": "2025-07-28",
440
+ "last_updated": "2025-07-28",
346
441
  "modalities": {
347
442
  "input": [
348
443
  "text"
@@ -353,13 +448,13 @@
353
448
  },
354
449
  "open_weights": true,
355
450
  "limit": {
356
- "context": 204800,
357
- "output": 131072
451
+ "context": 131072,
452
+ "output": 98304
358
453
  },
359
454
  "cost": {
360
- "input": 0.6,
361
- "output": 2.2,
362
- "cache_read": 0.11,
455
+ "input": 0,
456
+ "output": 0,
457
+ "cache_read": 0,
363
458
  "cache_write": 0
364
459
  }
365
460
  },
@@ -369,13 +464,18 @@
369
464
  "family": "glm",
370
465
  "attachment": false,
371
466
  "reasoning": true,
467
+ "reasoning_options": [
468
+ {
469
+ "type": "toggle"
470
+ }
471
+ ],
372
472
  "tool_call": true,
373
473
  "interleaved": {
374
474
  "field": "reasoning_content"
375
475
  },
376
476
  "temperature": true,
377
- "release_date": "2026-02-11",
378
- "last_updated": "2026-02-11",
477
+ "release_date": "2026-02-12",
478
+ "last_updated": "2026-02-12",
379
479
  "modalities": {
380
480
  "input": [
381
481
  "text"
@@ -396,35 +496,43 @@
396
496
  "cache_write": 0
397
497
  }
398
498
  },
399
- "glm-4.6v": {
400
- "id": "glm-4.6v",
401
- "name": "GLM-4.6V",
499
+ "glm-5-turbo": {
500
+ "id": "glm-5-turbo",
501
+ "name": "GLM-5-Turbo",
402
502
  "family": "glm",
403
- "attachment": true,
503
+ "attachment": false,
404
504
  "reasoning": true,
505
+ "reasoning_options": [
506
+ {
507
+ "type": "toggle"
508
+ }
509
+ ],
405
510
  "tool_call": true,
511
+ "interleaved": {
512
+ "field": "reasoning_content"
513
+ },
514
+ "structured_output": true,
406
515
  "temperature": true,
407
- "knowledge": "2025-04",
408
- "release_date": "2025-12-08",
409
- "last_updated": "2025-12-08",
516
+ "release_date": "2026-03-16",
517
+ "last_updated": "2026-03-16",
410
518
  "modalities": {
411
519
  "input": [
412
- "text",
413
- "image",
414
- "video"
520
+ "text"
415
521
  ],
416
522
  "output": [
417
523
  "text"
418
524
  ]
419
525
  },
420
- "open_weights": true,
526
+ "open_weights": false,
421
527
  "limit": {
422
- "context": 128000,
423
- "output": 32768
528
+ "context": 200000,
529
+ "output": 131072
424
530
  },
425
531
  "cost": {
426
- "input": 0.3,
427
- "output": 0.9
532
+ "input": 1.2,
533
+ "output": 4,
534
+ "cache_read": 0.24,
535
+ "cache_write": 0
428
536
  }
429
537
  }
430
538
  }
@@ -17,46 +17,6 @@ module LLM::ActiveRecord
17
17
  # class and forwarded to an internal agent subclass.
18
18
  module ActsAsAgent
19
19
  module ClassMethods
20
- def model(model = nil, &block)
21
- return agent.model if model.nil? && !block
22
- agent.model(model, &block)
23
- end
24
-
25
- def tools(*tools, &block)
26
- return agent.tools if tools.empty? && !block
27
- agent.tools(*tools, &block)
28
- end
29
-
30
- def skills(*skills, &block)
31
- return agent.skills if skills.empty? && !block
32
- agent.skills(*skills, &block)
33
- end
34
-
35
- def schema(schema = nil, &block)
36
- return agent.schema if schema.nil? && !block
37
- agent.schema(schema, &block)
38
- end
39
-
40
- def instructions(instructions = nil)
41
- return agent.instructions if instructions.nil?
42
- agent.instructions(instructions)
43
- end
44
-
45
- def concurrency(concurrency = nil)
46
- return agent.concurrency if concurrency.nil?
47
- agent.concurrency(concurrency)
48
- end
49
-
50
- def confirm(*tool_names, &block)
51
- return agent.confirm if tool_names.empty? && !block
52
- agent.confirm(*tool_names, &block)
53
- end
54
-
55
- def tracer(tracer = nil, &block)
56
- return agent.tracer if tracer.nil? && !block
57
- agent.tracer(tracer, &block)
58
- end
59
-
60
20
  def agent
61
21
  @agent ||= Class.new(LLM::Agent)
62
22
  end
@@ -92,13 +52,15 @@ module LLM::ActiveRecord
92
52
  # Evaluated in the model class after the wrapper is installed, so agent
93
53
  # DSL methods such as `model`, `tools`, `schema`, `instructions`, and
94
54
  # `concurrency` can be configured inline.
55
+ # @yieldparam [LLM::Agent] agent
56
+ # Yields an instance of {LLM::Agent LLM::Agent}.
95
57
  # @return [void]
96
58
  def acts_as_agent(options = EMPTY_HASH, &block)
97
59
  options = DEFAULTS.merge(options)
98
60
  class_attribute :llm_plugin_options, instance_accessor: false, default: DEFAULTS unless respond_to?(:llm_plugin_options)
99
61
  self.llm_plugin_options = options.freeze
100
62
  extend Hooks
101
- class_exec(&block) if block
63
+ block_given? ? class_exec(agent, &block) : nil
102
64
  end
103
65
 
104
66
  module InstanceMethods