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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3aad41c57654e1abef4c184da8904ae5840708e8f5ce937e1030279a5e5a240
4
- data.tar.gz: 9b03ac6a4f04190a57f2e4698eab923087febbab6a1ff8ad67f391fce4bd5c1e
3
+ metadata.gz: e042f679a5f682feed6726430dd1b28fd6728c9223cbd0e0499c92e8952a06e6
4
+ data.tar.gz: 0cb3f55e70a321bea3f1903261142bf3aa842fface494331a548f684aac520d8
5
5
  SHA512:
6
- metadata.gz: f429a75d5b612eb27968b6e6451bd231f2191b5b955262503c68baa7ca27f289c01ad564558e82d7fcc732393f635c32caf883a36815b41d86f6c1289cfffb61
7
- data.tar.gz: 90924b997b5d47d74c3df6e303c890fb5d1a771bae10e63c349436bcbd061241604184f62df87cb2dee7d85405fbd53f08d279ef6b4d3a85a12b0d59b7377229
6
+ metadata.gz: ba64ba9b87d1343f9d94a06b97cb6cc0ec0ca5d7a8c4b235e52c9ed489c5670848b44e0549e838b01b12be89d19005ba571a6dd9557a8f2f5f4e62a3ec018ec9
7
+ data.tar.gz: 81a489afa510edf608b74a3a83abc16b6d81c6f59f614df6460f638dbcf1e0a539d8d2b6b2e5a98a3772d5c9d7c7233d7b231bbf447dda7cfcf8df1861819c8d
data/CHANGELOG.md CHANGED
@@ -1,7 +1,248 @@
1
- # Changelog
1
+ <p align="center">
2
+ <a href="https://r.uby.dev">
3
+ <img
4
+ src="https://github.com/r-uby-dev/llm.rb/raw/main/rubydev.svg"
5
+ width="400"
6
+ height="200"
7
+ border="0"
8
+ alt="a r.uby.dev project"
9
+ >
10
+ </a>
11
+ </p>
12
+
13
+ > Changelog <br>
14
+ > a [r.uby.dev](https://r.uby.dev) project
2
15
 
3
16
  ## Unreleased
4
17
 
18
+ ## v12.0.0
19
+
20
+ Changes since `v11.3.1`.
21
+
22
+ This release relicenses the project under the Business Source License,
23
+ defaults OpenAI to the Responses API and gpt-image models, adds the
24
+ DeepInfra provider with audio and image support, introduces
25
+ DeepSeek vector-graphics generation and schema support, extends xAI
26
+ image editing, adds `LLM::Schema.defaults` and schema string rendering,
27
+ and makes ActiveRecord and Sequel agent wrappers yield `LLM::Agent`
28
+ instead of polluting the model namespace.
29
+
30
+ ### Breaking
31
+
32
+ * **License change** <br>
33
+ The llm.rb runtime has been developed primarily by one
34
+ person for 3 years. That was done on my own time, and
35
+ I haven't made a dime from that work.
36
+
37
+ So when I saw a multi-million dollar company benefit from
38
+ the work and for it to become the backbone of their AI
39
+ infrastructure and then see them not contribute back or
40
+ offer any kind of support, I decided this is not sustainable,
41
+ or fair.
42
+
43
+ I assumed good faith and for people to act in the spirit of
44
+ open source but sadly, that's just not the case. I
45
+ have to choose a license that respects my time and effort.
46
+
47
+ For those reasons, llm.rb is being relicensed under the
48
+ [Business Source license](https://mariadb.com/bsl11/).
49
+ So what does that mean?
50
+
51
+ In a nutshell:
52
+
53
+ * Free for personal use.
54
+ * Free for education.
55
+ * Free for evaluation, development, and testing.
56
+ * Commercial production use requires a commercial license.
57
+ * Exemptions on a case-by-case basis
58
+
59
+ After 4 years, the license expires and it will become
60
+ available under the 0BSDL as it was before v12.0.0.
61
+ These 4 years apply to a specific version, and not the
62
+ project overall.
63
+
64
+ Going forward, v12.0.0 will be relicensed to respect
65
+ my time, energy, and effort. llm.rb took an incredible
66
+ amount of time and effort, and continues to do so, so
67
+ I want to protect myself from companies who benefit
68
+ from my work but don't respect the time or effort that
69
+ was put into it.
70
+
71
+ * **OpenAI: default to the Responses API** <br>
72
+ The responses API has both models and features that are unavailable
73
+ on the chat completions API, and the responses API appears to be
74
+ the API of the future for OpenAI.
75
+
76
+ Worth noting: the llm.rb implementation does **not** store state
77
+ server-side by default. This can be changed with the `store: true`
78
+ option. The legacy chat completions API can be accessed with the
79
+ `mode: :completions` option.
80
+
81
+ llm.rb has had support for the responses API for quite
82
+ a while but it was not the default, and a number of bugs
83
+ were found and fixed during the process of making it the
84
+ default.
85
+
86
+ * **OpenAI: use gpt-image for image generation** <br>
87
+ The `dalle` models are in the process of being deprecated, and support
88
+ has been dropped from llm.rb. The `gpt-image` models are the next-generation
89
+ image-generation models from OpenAI.
90
+
91
+ * **xAI: provide images as base64-encoded data** <br>
92
+ Both xAI, and OpenAI had the option to generate images via a URL
93
+ you can fetch, or as a base64-encoded string embedded directly
94
+ in the response.
95
+
96
+ OpenAI is moving away from the URL transport since deprecating dalle,
97
+ and with that in mind, llm.rb has dropped support for the URL transport
98
+ across all providers that supported it.
99
+
100
+ Google, xAI, and OpenAI now consistently provide generated and modified
101
+ images as a base64-encoded string.
102
+
103
+ * **ActiveRecord: yield `LLM::Agent` to `acts_as_agent`** <br>
104
+ With this change we yield an instance of `LLM::Agent` to the `acts_as_agent`
105
+ method, and drop the methods (such as `model`, `instructions`, etc) that
106
+ were previously defined directly on the model. This keeps the number of
107
+ methods that llm.rb adds to an ActiveRecord model at a minimum and retains
108
+ the same capabilities as before.
109
+
110
+ * **Sequel: yield `LLM::Agent` to `plugin(:agent)`** <br>
111
+ Ditto as above but for Sequel.
112
+
113
+ * **Remove the langsmith tracer** <br>
114
+ This code was contributed by a third party but contains
115
+ many anti-patterns that are against llm.rb conventions
116
+ and best practices. It was merged without oversight or
117
+ review, and basically against the ethos of open source.
118
+
119
+ I also don't have a langsmith account to maintain the
120
+ code. The alternative is the `LLM::Tracer::Telemetry` class
121
+ that was originally written by me, and serves as a
122
+ general-purpose OTP tracer.
123
+
124
+ ### Add
125
+
126
+ * **Add a new provider: LLM::DeepInfra** <br>
127
+ [DeepInfra](https://deepinfra.com) provide OpenAI-compatible
128
+ endpoints for a large catalog of hosted open-source and
129
+ open-weight models. <br> Capabilities like tool calling, structured outputs, and
130
+ reasoning can depend on the model.
131
+
132
+ * **Add new image provider: LLM::DeepInfra::Images** <br>
133
+ [DeepInfra](https://deepinfra.com) provide access to
134
+ diverse set of text-to-image models. <br> Learn more about the
135
+ available models on their [text-to-image models](https://deepinfra.com/models/text-to-image)
136
+ page.
137
+
138
+ * **DeepSeek: add `LLM::DeepSeek::Images#create` and `#edit`** <br>
139
+ This new API can generate and edit vector graphics (SVGs). <br>
140
+ It is an experimental approach and API.
141
+
142
+ DeepSeek does not provide an image generation model however
143
+ its text-to-text models can generate SVG documents, and
144
+ that's the approach this feature takes. It is limited
145
+ to vector graphics rather than raster images.
146
+
147
+ * **DeepSeek: attach `LLM::Response#agent` to image responses** <br>
148
+ The DeepSeek image API is built on top of
149
+ [`LLM::Agent`](https://r.uby.dev/api-docs/llm.rb/LLM/Agent.html).
150
+ Image responses now expose that agent via `res.agent`, which makes
151
+ it possible to carry the same session across multiple generations
152
+ or edits.
153
+
154
+ * **xAI: add `LLM::XAI::Images#edit`** <br>
155
+ With this change it is possible to both generate images
156
+ from a prompt, and edit an existing image with a prompt.
157
+ xAI now has the same edit and create capabilities that
158
+ OpenAI has.
159
+
160
+ * **Add `LLM::Schema.defaults`** <br>
161
+ This method lets you map multiple property names to
162
+ different default values. It is similar to `LLM::Schema.required`
163
+ in the sense that it is called after the properties of
164
+ a schema have been defined.
165
+
166
+ * **Add `LLM::Schema#to_s` and `LLM::Schema.to_s`** <br>
167
+ Schemas can now be rendered as a prompt-friendly string.
168
+ This is useful when the shape of a schema needs to be
169
+ described in natural-language instructions rather than
170
+ passed through a native structured output interface.
171
+
172
+ * **DeepSeek: add `LLM::Schema` support** <br>
173
+ DeepSeek can now use `schema:` for structured output.
174
+ llm.rb handles this by setting `response_format: {type: "json_object"}`
175
+ and describing the schema in a system message.
176
+
177
+ * **OpenAI: add local file support to the Responses API** <br>
178
+ Our responses API implementation lacked local file support. <br>
179
+ This change fixes that by supporting both image, document,
180
+ and other media types that OpenAI may support.
181
+
182
+ * **Add `LLM::Response#id` across all providers** <br>
183
+ This method was previously implemented via `method_missing`,
184
+ and the field name could change depending on the provider.
185
+ The new method is a catch-all that provides a single method
186
+ that works across all providers.
187
+
188
+ * **Add `LLM::DeepInfra::Audio`** <br>
189
+ DeepInfra implements most of the llm.rb audio interface
190
+ with both the `create_speech` and `create_transcription`
191
+ methods. The `create_translation` method is not implemented,
192
+ and the available text-to-speech and speech-to-text models
193
+ are more varied than other providers.
194
+
195
+ * **OpenAI: normalize text-to-speech responses** <br>
196
+ The `res.audio` method now returns an
197
+ [`LLM::URIData`](https://r.uby.dev/api-docs/llm.rb/LLM/URIData.html)
198
+ object for OpenAI text-to-speech responses. The object provides
199
+ `encoded`, `decoded`, `content_type`, and `encoding_type`.
200
+
201
+ * **DeepInfra: normalize text-to-speech responses** <br>
202
+ The `res.audio` method now returns an
203
+ [`LLM::URIData`](https://r.uby.dev/api-docs/llm.rb/LLM/URIData.html)
204
+ object for DeepInfra text-to-speech responses. The object provides
205
+ `encoded`, `decoded`, `content_type`, and `encoding_type`.
206
+
207
+ ### Fix
208
+
209
+ * **Fix Google `temperature` parameter fall-through** <br>
210
+ Ensure provider-level `temperature` and other `generationConfig`
211
+ parameters are forwarded to the API correctly instead of being
212
+ silently dropped.
213
+
214
+ * **Fix Google `generationConfig` collisions** <br>
215
+ Prevent duplicate or conflicting `generationConfig` keys in the
216
+ Google request adapter.
217
+
218
+ ### Change
219
+
220
+ * **Change OpenAI defaults** <br>
221
+ The default chat model is now `gpt-5.4-mini`. <br>
222
+ The default image model is now `gpt-image`.
223
+
224
+ * **Change google defaults** <br>
225
+ The default chat model is now `gemini-3.1-flash-lite` <br>
226
+ The default embeddings model is now `gemini-embedding-2`
227
+
228
+ * **Change xAI defaults** <br>
229
+ The default chat model is now `grok-4.3`. <br>
230
+ The default image model is now `grok-imagine-image-quality`.
231
+
232
+ * **Return an `LLM::Object` from `LLM::Response#content!`** <br>
233
+ The Hash-like, indifferent access data structure known as
234
+ `LLM::Object` provides a convenient interface around a Hash
235
+ object. It allows method access via `obj.key`, and decays
236
+ into a Hash in many cases.
237
+
238
+ The `LLM::Response#content!` method now wraps its content
239
+ in an `LLM::Object` but only after it has parsed its
240
+ content (a JSON string) into a Ruby data structure.
241
+
242
+ * **Refresh model metadata** <br>
243
+ Update `data/*.json` files with current provider model listings,
244
+ pricing, and capabilities.
245
+
5
246
  ## v11.3.1
6
247
 
7
248
  Changes since `v11.3.0`.
data/LICENSE CHANGED
@@ -1,17 +1,92 @@
1
- Copyright (C) 2026
2
- Antar Azri <azantar@proton.me>
3
- 0x1eef <0x1eef@hardenedbsd.org>
4
-
5
- Permission to use, copy, modify, and/or distribute this
6
- software for any purpose with or without fee is hereby
7
- granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
10
- ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
11
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
12
- EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
14
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
16
- ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
- OF THIS SOFTWARE.
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2024 MariaDB plc, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB plc.
5
+
6
+ Parameters
7
+
8
+ Licensor: Robert Gleeson
9
+
10
+ Licensed Work: llm.rb
11
+
12
+ Additional Use Grant:
13
+ Free for personal use.
14
+ Free for education.
15
+ Free for evaluation, development, and testing.
16
+ Commercial production use requires a commercial license.
17
+
18
+ Change Date:
19
+ Four years after the first public release of each specific version of the
20
+ Licensed Work.
21
+
22
+ Change License:
23
+ BSD Zero Clause License (0BSD)
24
+
25
+ Terms
26
+
27
+ The Licensor hereby grants you the right to copy, modify, create derivative
28
+ works, redistribute, and make non-production use of the Licensed Work. The
29
+ Licensor may make an Additional Use Grant, above, permitting limited
30
+ production use.
31
+
32
+ Effective on the Change Date, or the fourth anniversary of the first publicly
33
+ available distribution of a specific version of the Licensed Work under this
34
+ License, whichever comes first, the Licensor hereby grants you rights under
35
+ the terms of the Change License, and the rights granted in the paragraph
36
+ above terminate.
37
+
38
+ If your use of the Licensed Work does not comply with the requirements
39
+ currently in effect as described in this License, you must purchase a
40
+ commercial license from the Licensor, its affiliated entities, or authorized
41
+ resellers, or you must refrain from using the Licensed Work.
42
+
43
+ All copies of the original and modified Licensed Work, and derivative works
44
+ of the Licensed Work, are subject to this License. This License applies
45
+ separately for each version of the Licensed Work and the Change Date may vary
46
+ for each version of the Licensed Work released by Licensor.
47
+
48
+ You must conspicuously display this License on each original or modified copy
49
+ of the Licensed Work. If you receive the Licensed Work in original or
50
+ modified form from a third party, the terms and conditions set forth in this
51
+ License apply to your use of that work.
52
+
53
+ Any use of the Licensed Work in violation of this License will automatically
54
+ terminate your rights under this License for the current and all other
55
+ versions of the Licensed Work.
56
+
57
+ This License does not grant you any right in any trademark or logo of
58
+ Licensor or its affiliates (provided that you may use a trademark or logo of
59
+ Licensor as expressly required by this License).
60
+
61
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
62
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
63
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
64
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
65
+ TITLE.
66
+
67
+ MariaDB hereby grants you permission to use this License's text to license
68
+ your works, and to refer to it using the trademark "Business Source
69
+ License", as long as you comply with the Covenants of Licensor below.
70
+
71
+ Covenants of Licensor
72
+
73
+ In consideration of the right to use this License's text and the "Business
74
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
75
+ other recipients of the licensed work to be provided by Licensor:
76
+
77
+ To specify as the Change License the GPL Version 2.0 or any later version, or
78
+ a license that is compatible with GPL Version 2.0 or a later version, where
79
+ "compatible" means that software provided under the Change License can be
80
+ included in a program with software provided under GPL Version 2.0 or a later
81
+ version. Licensor may specify additional Change Licenses without limitation.
82
+
83
+ To either: (a) specify an additional grant of rights to use that does not
84
+ impose any additional restriction on the right granted in this License, as
85
+ the Additional Use Grant; or (b) insert the text "None" to specify a Change
86
+ Date. Not to modify this License in any other way.
87
+
88
+ Notice
89
+
90
+ The Business Source License (this document, or the "License") is not an Open
91
+ Source license. However, the Licensed Work will eventually be made available
92
+ under an Open Source License, as stated in this License.