llm.rb 11.3.1 → 12.1.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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +354 -2
  3. data/LICENSE +93 -17
  4. data/README.md +226 -616
  5. data/data/anthropic.json +322 -426
  6. data/data/bedrock.json +2634 -1144
  7. data/data/deepinfra.json +1513 -0
  8. data/data/deepseek.json +57 -28
  9. data/data/google.json +411 -771
  10. data/data/openai.json +1104 -771
  11. data/data/xai.json +141 -292
  12. data/data/zai.json +263 -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/agent.rb +25 -1
  17. data/lib/llm/context.rb +17 -5
  18. data/lib/llm/contract/completion.rb +2 -2
  19. data/lib/llm/json_adapter.rb +29 -3
  20. data/lib/llm/provider.rb +3 -3
  21. data/lib/llm/providers/deepinfra/audio.rb +66 -0
  22. data/lib/llm/providers/deepinfra/images.rb +90 -0
  23. data/lib/llm/providers/deepinfra/response_adapter.rb +36 -0
  24. data/lib/llm/providers/deepinfra.rb +100 -0
  25. data/lib/llm/providers/deepseek/images.rb +109 -0
  26. data/lib/llm/providers/deepseek/request_adapter.rb +32 -0
  27. data/lib/llm/providers/deepseek/response_adapter/image.rb +9 -0
  28. data/lib/llm/providers/deepseek/response_adapter.rb +29 -0
  29. data/lib/llm/providers/deepseek.rb +4 -2
  30. data/lib/llm/providers/google/request_adapter.rb +22 -5
  31. data/lib/llm/providers/google.rb +4 -4
  32. data/lib/llm/providers/llamacpp.rb +5 -5
  33. data/lib/llm/providers/openai/audio.rb +6 -2
  34. data/lib/llm/providers/openai/images.rb +9 -50
  35. data/lib/llm/providers/openai/request_adapter/respond.rb +38 -4
  36. data/lib/llm/providers/openai/response_adapter/audio.rb +5 -1
  37. data/lib/llm/providers/openai/response_adapter/completion.rb +1 -1
  38. data/lib/llm/providers/openai/response_adapter/image.rb +0 -4
  39. data/lib/llm/providers/openai/responses.rb +1 -0
  40. data/lib/llm/providers/openai/stream_parser.rb +5 -6
  41. data/lib/llm/providers/openai.rb +2 -2
  42. data/lib/llm/providers/xai/images.rb +49 -26
  43. data/lib/llm/providers/xai.rb +2 -2
  44. data/lib/llm/repl/input.rb +64 -0
  45. data/lib/llm/repl/status.rb +30 -0
  46. data/lib/llm/repl/stream.rb +46 -0
  47. data/lib/llm/repl/transcript.rb +61 -0
  48. data/lib/llm/repl/window.rb +107 -0
  49. data/lib/llm/repl.rb +78 -0
  50. data/lib/llm/response.rb +10 -0
  51. data/lib/llm/schema/leaf.rb +7 -1
  52. data/lib/llm/schema/renderer.rb +121 -0
  53. data/lib/llm/schema.rb +30 -0
  54. data/lib/llm/sequel/agent.rb +2 -43
  55. data/lib/llm/sequel/plugin.rb +25 -7
  56. data/lib/llm/tools/chdir.rb +23 -0
  57. data/lib/llm/tools/git.rb +41 -0
  58. data/lib/llm/tools/mkdir.rb +32 -0
  59. data/lib/llm/tools/pwd.rb +20 -0
  60. data/lib/llm/tools/read_file.rb +40 -0
  61. data/lib/llm/tools/rg.rb +46 -0
  62. data/lib/llm/tools/shell.rb +48 -0
  63. data/lib/llm/tools/swap_text.rb +25 -0
  64. data/lib/llm/tools/write_file.rb +24 -0
  65. data/lib/llm/tools.rb +5 -0
  66. data/lib/llm/tracer/telemetry.rb +4 -6
  67. data/lib/llm/tracer.rb +9 -21
  68. data/lib/llm/transport/execution.rb +16 -1
  69. data/lib/llm/transport/net_http_adapter.rb +1 -1
  70. data/lib/llm/uridata.rb +16 -0
  71. data/lib/llm/version.rb +1 -1
  72. data/lib/llm.rb +9 -0
  73. data/llm.gemspec +5 -18
  74. data/resources/deepdive.md +829 -263
  75. metadata +31 -18
  76. data/lib/llm/tracer/langsmith.rb +0 -144
data/data/zai.json CHANGED
@@ -8,20 +8,26 @@
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
+ "description": "Mature GLM model for dependable coding, reasoning, and structured agent tasks",
14
15
  "family": "glm",
15
16
  "attachment": false,
16
17
  "reasoning": true,
18
+ "reasoning_options": [
19
+ {
20
+ "type": "toggle"
21
+ }
22
+ ],
17
23
  "tool_call": true,
18
24
  "interleaved": {
19
25
  "field": "reasoning_content"
20
26
  },
21
- "structured_output": true,
22
27
  "temperature": true,
23
- "release_date": "2026-03-27",
24
- "last_updated": "2026-03-27",
28
+ "knowledge": "2025-04",
29
+ "release_date": "2025-12-22",
30
+ "last_updated": "2025-12-22",
25
31
  "modalities": {
26
32
  "input": [
27
33
  "text"
@@ -30,60 +36,104 @@
30
36
  "text"
31
37
  ]
32
38
  },
33
- "open_weights": false,
39
+ "open_weights": true,
34
40
  "limit": {
35
- "context": 200000,
41
+ "context": 204800,
36
42
  "output": 131072
37
43
  },
38
44
  "cost": {
39
- "input": 1.4,
40
- "output": 4.4,
41
- "cache_read": 0.26,
45
+ "input": 0.6,
46
+ "output": 2.2,
47
+ "cache_read": 0.11,
42
48
  "cache_write": 0
43
49
  }
44
50
  },
45
- "glm-5v-turbo": {
46
- "id": "glm-5v-turbo",
47
- "name": "GLM-5V-Turbo",
51
+ "glm-4.5v": {
52
+ "id": "glm-4.5v",
53
+ "name": "GLM-4.5V",
54
+ "description": "GLM vision model for visual reasoning, documents, and multimodal agents",
48
55
  "family": "glm",
49
56
  "attachment": true,
50
57
  "reasoning": true,
58
+ "reasoning_options": [
59
+ {
60
+ "type": "toggle"
61
+ }
62
+ ],
51
63
  "tool_call": true,
52
- "interleaved": {
53
- "field": "reasoning_content"
54
- },
55
64
  "temperature": true,
56
- "release_date": "2026-04-01",
57
- "last_updated": "2026-04-01",
65
+ "knowledge": "2025-04",
66
+ "release_date": "2025-08-11",
67
+ "last_updated": "2025-08-11",
58
68
  "modalities": {
59
69
  "input": [
60
70
  "text",
61
71
  "image",
62
- "video",
63
- "pdf"
72
+ "video"
64
73
  ],
65
74
  "output": [
66
75
  "text"
67
76
  ]
68
77
  },
69
- "open_weights": false,
78
+ "open_weights": true,
70
79
  "limit": {
71
- "context": 200000,
72
- "output": 131072
80
+ "context": 64000,
81
+ "output": 16384
73
82
  },
74
83
  "cost": {
75
- "input": 1.2,
76
- "output": 4,
77
- "cache_read": 0.24,
84
+ "input": 0.6,
85
+ "output": 1.8
86
+ }
87
+ },
88
+ "glm-4.5": {
89
+ "id": "glm-4.5",
90
+ "name": "GLM-4.5",
91
+ "description": "Hybrid-reasoning GLM release that made the 4.5 line broadly useful",
92
+ "family": "glm",
93
+ "attachment": false,
94
+ "reasoning": true,
95
+ "reasoning_options": [
96
+ {
97
+ "type": "toggle"
98
+ }
99
+ ],
100
+ "tool_call": true,
101
+ "temperature": true,
102
+ "knowledge": "2025-04",
103
+ "release_date": "2025-07-28",
104
+ "last_updated": "2025-07-28",
105
+ "modalities": {
106
+ "input": [
107
+ "text"
108
+ ],
109
+ "output": [
110
+ "text"
111
+ ]
112
+ },
113
+ "open_weights": true,
114
+ "limit": {
115
+ "context": 131072,
116
+ "output": 98304
117
+ },
118
+ "cost": {
119
+ "input": 0.6,
120
+ "output": 2.2,
121
+ "cache_read": 0.11,
78
122
  "cache_write": 0
79
123
  }
80
124
  },
81
125
  "glm-4.7-flashx": {
82
126
  "id": "glm-4.7-flashx",
83
127
  "name": "GLM-4.7-FlashX",
128
+ "description": "Efficient GLM model for fast reasoning, coding, and agent workflows",
84
129
  "family": "glm-flash",
85
130
  "attachment": false,
86
131
  "reasoning": true,
132
+ "reasoning_options": [
133
+ {
134
+ "type": "toggle"
135
+ }
136
+ ],
87
137
  "tool_call": true,
88
138
  "temperature": true,
89
139
  "knowledge": "2025-04",
@@ -109,17 +159,26 @@
109
159
  "cache_write": 0
110
160
  }
111
161
  },
112
- "glm-4.5-air": {
113
- "id": "glm-4.5-air",
114
- "name": "GLM-4.5-Air",
115
- "family": "glm-air",
162
+ "glm-5.1": {
163
+ "id": "glm-5.1",
164
+ "name": "GLM-5.1",
165
+ "description": "Strong GLM coding model for agentic engineering, terminals, and repository generation",
166
+ "family": "glm",
116
167
  "attachment": false,
117
168
  "reasoning": true,
169
+ "reasoning_options": [
170
+ {
171
+ "type": "toggle"
172
+ }
173
+ ],
118
174
  "tool_call": true,
175
+ "interleaved": {
176
+ "field": "reasoning_content"
177
+ },
178
+ "structured_output": true,
119
179
  "temperature": true,
120
- "knowledge": "2025-04",
121
- "release_date": "2025-07-28",
122
- "last_updated": "2025-07-28",
180
+ "release_date": "2026-04-07",
181
+ "last_updated": "2026-04-07",
123
182
  "modalities": {
124
183
  "input": [
125
184
  "text"
@@ -130,32 +189,36 @@
130
189
  },
131
190
  "open_weights": true,
132
191
  "limit": {
133
- "context": 131072,
134
- "output": 98304
192
+ "context": 200000,
193
+ "output": 131072
135
194
  },
136
195
  "cost": {
137
- "input": 0.2,
138
- "output": 1.1,
139
- "cache_read": 0.03,
196
+ "input": 1.4,
197
+ "output": 4.4,
198
+ "cache_read": 0.26,
140
199
  "cache_write": 0
141
200
  }
142
201
  },
143
- "glm-4.5v": {
144
- "id": "glm-4.5v",
145
- "name": "GLM-4.5V",
202
+ "glm-4.6": {
203
+ "id": "glm-4.6",
204
+ "name": "GLM-4.6",
205
+ "description": "Late GLM-4 workhorse for coding agents, reasoning, and structured tasks",
146
206
  "family": "glm",
147
- "attachment": true,
207
+ "attachment": false,
148
208
  "reasoning": true,
209
+ "reasoning_options": [
210
+ {
211
+ "type": "toggle"
212
+ }
213
+ ],
149
214
  "tool_call": true,
150
215
  "temperature": true,
151
216
  "knowledge": "2025-04",
152
- "release_date": "2025-08-11",
153
- "last_updated": "2025-08-11",
217
+ "release_date": "2025-09-30",
218
+ "last_updated": "2025-09-30",
154
219
  "modalities": {
155
220
  "input": [
156
- "text",
157
- "image",
158
- "video"
221
+ "text"
159
222
  ],
160
223
  "output": [
161
224
  "text"
@@ -163,25 +226,40 @@
163
226
  },
164
227
  "open_weights": true,
165
228
  "limit": {
166
- "context": 64000,
167
- "output": 16384
229
+ "context": 204800,
230
+ "output": 131072
168
231
  },
169
232
  "cost": {
170
233
  "input": 0.6,
171
- "output": 1.8
234
+ "output": 2.2,
235
+ "cache_read": 0.11,
236
+ "cache_write": 0
172
237
  }
173
238
  },
174
- "glm-4.7-flash": {
175
- "id": "glm-4.7-flash",
176
- "name": "GLM-4.7-Flash",
177
- "family": "glm-flash",
239
+ "glm-5.2": {
240
+ "id": "glm-5.2",
241
+ "name": "GLM-5.2",
242
+ "description": "Open flagship GLM for long-horizon coding agents and million-token context work",
243
+ "family": "glm",
178
244
  "attachment": false,
179
245
  "reasoning": true,
246
+ "reasoning_options": [
247
+ {
248
+ "type": "effort",
249
+ "values": [
250
+ "high",
251
+ "max"
252
+ ]
253
+ }
254
+ ],
180
255
  "tool_call": true,
256
+ "interleaved": {
257
+ "field": "reasoning_content"
258
+ },
259
+ "structured_output": true,
181
260
  "temperature": true,
182
- "knowledge": "2025-04",
183
- "release_date": "2026-01-19",
184
- "last_updated": "2026-01-19",
261
+ "release_date": "2026-06-13",
262
+ "last_updated": "2026-06-13",
185
263
  "modalities": {
186
264
  "input": [
187
265
  "text"
@@ -192,30 +270,38 @@
192
270
  },
193
271
  "open_weights": true,
194
272
  "limit": {
195
- "context": 200000,
273
+ "context": 1000000,
196
274
  "output": 131072
197
275
  },
198
276
  "cost": {
199
- "input": 0,
200
- "output": 0,
201
- "cache_read": 0,
277
+ "input": 1.4,
278
+ "output": 4.4,
279
+ "cache_read": 0.26,
202
280
  "cache_write": 0
203
281
  }
204
282
  },
205
- "glm-4.6": {
206
- "id": "glm-4.6",
207
- "name": "GLM-4.6",
283
+ "glm-4.6v": {
284
+ "id": "glm-4.6v",
285
+ "name": "GLM-4.6V",
286
+ "description": "GLM vision model for visual reasoning, documents, and multimodal agents",
208
287
  "family": "glm",
209
- "attachment": false,
288
+ "attachment": true,
210
289
  "reasoning": true,
290
+ "reasoning_options": [
291
+ {
292
+ "type": "toggle"
293
+ }
294
+ ],
211
295
  "tool_call": true,
212
296
  "temperature": true,
213
297
  "knowledge": "2025-04",
214
- "release_date": "2025-09-30",
215
- "last_updated": "2025-09-30",
298
+ "release_date": "2025-12-08",
299
+ "last_updated": "2025-12-08",
216
300
  "modalities": {
217
301
  "input": [
218
- "text"
302
+ "text",
303
+ "image",
304
+ "video"
219
305
  ],
220
306
  "output": [
221
307
  "text"
@@ -223,53 +309,68 @@
223
309
  },
224
310
  "open_weights": true,
225
311
  "limit": {
226
- "context": 204800,
227
- "output": 131072
312
+ "context": 128000,
313
+ "output": 32768
228
314
  },
229
315
  "cost": {
230
- "input": 0.6,
231
- "output": 2.2,
232
- "cache_read": 0.11,
233
- "cache_write": 0
316
+ "input": 0.3,
317
+ "output": 0.9
234
318
  }
235
319
  },
236
- "glm-4.5": {
237
- "id": "glm-4.5",
238
- "name": "GLM-4.5",
320
+ "glm-5v-turbo": {
321
+ "id": "glm-5v-turbo",
322
+ "name": "GLM-5V-Turbo",
323
+ "description": "Fast GLM vision model for screenshots, documents, and multimodal agent tasks",
239
324
  "family": "glm",
240
- "attachment": false,
325
+ "attachment": true,
241
326
  "reasoning": true,
327
+ "reasoning_options": [
328
+ {
329
+ "type": "toggle"
330
+ }
331
+ ],
242
332
  "tool_call": true,
333
+ "interleaved": {
334
+ "field": "reasoning_content"
335
+ },
243
336
  "temperature": true,
244
- "knowledge": "2025-04",
245
- "release_date": "2025-07-28",
246
- "last_updated": "2025-07-28",
337
+ "release_date": "2026-04-01",
338
+ "last_updated": "2026-04-01",
247
339
  "modalities": {
248
340
  "input": [
249
- "text"
341
+ "text",
342
+ "image",
343
+ "video",
344
+ "pdf"
250
345
  ],
251
346
  "output": [
252
347
  "text"
253
348
  ]
254
349
  },
255
- "open_weights": true,
350
+ "open_weights": false,
256
351
  "limit": {
257
- "context": 131072,
258
- "output": 98304
352
+ "context": 200000,
353
+ "output": 131072
259
354
  },
260
355
  "cost": {
261
- "input": 0.6,
262
- "output": 2.2,
263
- "cache_read": 0.11,
356
+ "input": 1.2,
357
+ "output": 4,
358
+ "cache_read": 0.24,
264
359
  "cache_write": 0
265
360
  }
266
361
  },
267
- "glm-4.5-flash": {
268
- "id": "glm-4.5-flash",
269
- "name": "GLM-4.5-Flash",
270
- "family": "glm-flash",
362
+ "glm-4.5-air": {
363
+ "id": "glm-4.5-air",
364
+ "name": "GLM-4.5-Air",
365
+ "description": "Lighter GLM-4.5 variant for fast coding assistance and cheaper agents",
366
+ "family": "glm-air",
271
367
  "attachment": false,
272
368
  "reasoning": true,
369
+ "reasoning_options": [
370
+ {
371
+ "type": "toggle"
372
+ }
373
+ ],
273
374
  "tool_call": true,
274
375
  "temperature": true,
275
376
  "knowledge": "2025-04",
@@ -289,26 +390,29 @@
289
390
  "output": 98304
290
391
  },
291
392
  "cost": {
292
- "input": 0,
293
- "output": 0,
294
- "cache_read": 0,
393
+ "input": 0.2,
394
+ "output": 1.1,
395
+ "cache_read": 0.03,
295
396
  "cache_write": 0
296
397
  }
297
398
  },
298
- "glm-5-turbo": {
299
- "id": "glm-5-turbo",
300
- "name": "GLM-5-Turbo",
301
- "family": "glm",
399
+ "glm-4.7-flash": {
400
+ "id": "glm-4.7-flash",
401
+ "name": "GLM-4.7-Flash",
402
+ "description": "Budget GLM lane for fast coding help, routing, and everyday automation",
403
+ "family": "glm-flash",
302
404
  "attachment": false,
303
405
  "reasoning": true,
406
+ "reasoning_options": [
407
+ {
408
+ "type": "toggle"
409
+ }
410
+ ],
304
411
  "tool_call": true,
305
- "interleaved": {
306
- "field": "reasoning_content"
307
- },
308
- "structured_output": true,
309
412
  "temperature": true,
310
- "release_date": "2026-03-16",
311
- "last_updated": "2026-03-16",
413
+ "knowledge": "2025-04",
414
+ "release_date": "2026-01-19",
415
+ "last_updated": "2026-01-19",
312
416
  "modalities": {
313
417
  "input": [
314
418
  "text"
@@ -317,32 +421,35 @@
317
421
  "text"
318
422
  ]
319
423
  },
320
- "open_weights": false,
424
+ "open_weights": true,
321
425
  "limit": {
322
426
  "context": 200000,
323
427
  "output": 131072
324
428
  },
325
429
  "cost": {
326
- "input": 1.2,
327
- "output": 4,
328
- "cache_read": 0.24,
430
+ "input": 0,
431
+ "output": 0,
432
+ "cache_read": 0,
329
433
  "cache_write": 0
330
434
  }
331
435
  },
332
- "glm-4.7": {
333
- "id": "glm-4.7",
334
- "name": "GLM-4.7",
335
- "family": "glm",
436
+ "glm-4.5-flash": {
437
+ "id": "glm-4.5-flash",
438
+ "name": "GLM-4.5-Flash",
439
+ "description": "Efficient GLM model for fast reasoning, coding, and agent workflows",
440
+ "family": "glm-flash",
336
441
  "attachment": false,
337
442
  "reasoning": true,
443
+ "reasoning_options": [
444
+ {
445
+ "type": "toggle"
446
+ }
447
+ ],
338
448
  "tool_call": true,
339
- "interleaved": {
340
- "field": "reasoning_content"
341
- },
342
449
  "temperature": true,
343
450
  "knowledge": "2025-04",
344
- "release_date": "2025-12-22",
345
- "last_updated": "2025-12-22",
451
+ "release_date": "2025-07-28",
452
+ "last_updated": "2025-07-28",
346
453
  "modalities": {
347
454
  "input": [
348
455
  "text"
@@ -353,29 +460,35 @@
353
460
  },
354
461
  "open_weights": true,
355
462
  "limit": {
356
- "context": 204800,
357
- "output": 131072
463
+ "context": 131072,
464
+ "output": 98304
358
465
  },
359
466
  "cost": {
360
- "input": 0.6,
361
- "output": 2.2,
362
- "cache_read": 0.11,
467
+ "input": 0,
468
+ "output": 0,
469
+ "cache_read": 0,
363
470
  "cache_write": 0
364
471
  }
365
472
  },
366
473
  "glm-5": {
367
474
  "id": "glm-5",
368
475
  "name": "GLM-5",
476
+ "description": "General GLM flagship for coding, analysis, and tool-heavy engineering workflows",
369
477
  "family": "glm",
370
478
  "attachment": false,
371
479
  "reasoning": true,
480
+ "reasoning_options": [
481
+ {
482
+ "type": "toggle"
483
+ }
484
+ ],
372
485
  "tool_call": true,
373
486
  "interleaved": {
374
487
  "field": "reasoning_content"
375
488
  },
376
489
  "temperature": true,
377
- "release_date": "2026-02-11",
378
- "last_updated": "2026-02-11",
490
+ "release_date": "2026-02-12",
491
+ "last_updated": "2026-02-12",
379
492
  "modalities": {
380
493
  "input": [
381
494
  "text"
@@ -396,35 +509,44 @@
396
509
  "cache_write": 0
397
510
  }
398
511
  },
399
- "glm-4.6v": {
400
- "id": "glm-4.6v",
401
- "name": "GLM-4.6V",
512
+ "glm-5-turbo": {
513
+ "id": "glm-5-turbo",
514
+ "name": "GLM-5-Turbo",
515
+ "description": "Faster GLM-5 lane for coding agents that need lower latency",
402
516
  "family": "glm",
403
- "attachment": true,
517
+ "attachment": false,
404
518
  "reasoning": true,
519
+ "reasoning_options": [
520
+ {
521
+ "type": "toggle"
522
+ }
523
+ ],
405
524
  "tool_call": true,
525
+ "interleaved": {
526
+ "field": "reasoning_content"
527
+ },
528
+ "structured_output": true,
406
529
  "temperature": true,
407
- "knowledge": "2025-04",
408
- "release_date": "2025-12-08",
409
- "last_updated": "2025-12-08",
530
+ "release_date": "2026-03-16",
531
+ "last_updated": "2026-03-16",
410
532
  "modalities": {
411
533
  "input": [
412
- "text",
413
- "image",
414
- "video"
534
+ "text"
415
535
  ],
416
536
  "output": [
417
537
  "text"
418
538
  ]
419
539
  },
420
- "open_weights": true,
540
+ "open_weights": false,
421
541
  "limit": {
422
- "context": 128000,
423
- "output": 32768
542
+ "context": 200000,
543
+ "output": 131072
424
544
  },
425
545
  "cost": {
426
- "input": 0.3,
427
- "output": 0.9
546
+ "input": 1.2,
547
+ "output": 4,
548
+ "cache_read": 0.24,
549
+ "cache_write": 0
428
550
  }
429
551
  }
430
552
  }