You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
content:"How can I list all files in a directory using Python?"
172
-
}],
173
-
model:"gpt-4o",
173
+
messages: [{role::user, content:"How can I list all files in a directory using Python?"}],
174
+
model::"gpt-4.1",
174
175
request_options: {timeout:5}
175
176
)
176
177
```
177
178
178
-
## LSP Support
179
+
## Editor support
179
180
180
-
### Solargraph
181
+
Some editor language services like [Solargraph](https://github.com/castwide/solargraph?tab=readme-ov-file#gem-support) or [Sorbet](https://sorbet.org/docs/rbi#the-hidden-definitions-rbi) require a manually triggered indexing step before functionalities like auto-completion and go to definition can operate.
181
182
182
-
This library includes [Solargraph](https://solargraph.org) support for both auto completion and go to definition.
183
+
Please refer to their respective documentation for details. This library also includes a [short guide](https://github.com/openai/openai-ruby/tree/main/CONTRIBUTING.md#editor-support) on how to set up various editor services for internal development.
183
184
184
-
```ruby
185
-
gem "solargraph", group::development
186
-
```
185
+
## Advanced Concepts
187
186
188
-
After Solargraph is installed, **you must populate its index** either via the provided editor command, or by running the following in your terminal:
187
+
### Model DSL
189
188
190
-
```sh
191
-
bundle exec solargraph gems
192
-
```
189
+
This library uses a Model DSL to represent request parameters and response shapes in `lib/openai/models`.
193
190
194
-
Note: if you had installed the gem either using a `git:` or `github:` URL, or had vendored the gem using bundler, you will need to set up your [`.solargraph.yml`](https://solargraph.org/guides/configuration) to include the path to the gem's `lib` directory.
191
+
The model classes service as anchor points for both toolchain readable documentation, and language service assisted navigation links. This information also allows the SDK's internals to perform translation between plain and rich data types; e.g., conversion between a `Time` instance and an ISO8601 `String`, and vice versa.
Otherwise Solargraph will not be able to provide type information or auto-completion for any non-indexed libraries.
202
-
203
-
### Sorbet
204
-
205
-
This library is written with [Sorbet type definitions](https://sorbet.org/docs/rbi). However, there is no runtime dependency on the `sorbet-runtime`.
206
-
207
-
What this means is that while you can use Sorbet to type check your code statically, and benefit from the [Sorbet Language Server](https://sorbet.org/docs/lsp) in your editor, there is no runtime type checking and execution overhead from Sorbet itself.
208
-
209
-
Due to limitations with the Sorbet type system, where a method otherwise can take an instance of `OpenAI::BaseModel` class, you will need to use the `**` splat operator to pass the arguments:
210
-
211
-
Please follow Sorbet's [setup guides](https://sorbet.org/docs/adopting) for best experience.
193
+
In all places where a `BaseModel` type is specified, vanilla Ruby `Hash` can also be used. For example, the following are interchangeable as arguments:
212
194
213
195
```ruby
196
+
# This has tooling readability, for auto-completion, static analysis, and goto definition with supported language services
messages: [OpenAI::Models::Chat::ChatCompletionUserMessageParam.new(role::user, content:"Say this is a test")],
199
+
model::"gpt-4.1"
200
+
)
223
201
224
-
openai.chat.completions.create(**params)
202
+
# This also works
203
+
params = {
204
+
messages: [{role::user, content:"Say this is a test"}],
205
+
model::"gpt-4.1"
206
+
}
225
207
```
226
208
227
-
Note: **This library emits an intentional warning under the [`tapioca` toolchain](https://github.com/Shopify/tapioca)**. This is normal, and does not impact functionality.
228
-
229
-
### Ruby LSP
230
-
231
-
The Ruby LSP has [best effort support](https://shopify.github.io/ruby-lsp/#guessed-types) for inferring type information from Ruby code, and as such it may not always be able to provide accurate type information.
232
-
233
-
## Advanced
234
-
235
209
### Making custom/undocumented requests
236
210
237
-
This library is typed for convenient access to the documented API.
238
-
239
-
If you need to access undocumented endpoints, params, or response properties, the library can still be used.
240
-
241
211
#### Undocumented request params
242
212
243
213
If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a requests as seen in examples above.
@@ -248,15 +218,15 @@ To make requests to undocumented endpoints, you can make requests using `client.
248
218
249
219
```ruby
250
220
response = client.request(
251
-
method: :post,
252
-
path: '/undocumented/endpoint',
253
-
query: {"dog": "woof"},
254
-
headers: {"useful-header": "interesting-value"},
255
-
body: {"he": "llo"},
256
-
)
221
+
method::post,
222
+
path:'/undocumented/endpoint',
223
+
query: {"dog": "woof"},
224
+
headers: {"useful-header": "interesting-value"},
225
+
body: {"he": "llo"},
226
+
)
257
227
```
258
228
259
-
### Concurrency & Connection Pooling
229
+
### Concurrency & connection pooling
260
230
261
231
The `OpenAI::Client` instances are thread-safe, and should be re-used across multiple threads. By default, each `Client` have their own HTTP connection pool, with a maximum number of connections equal to thread count.
262
232
@@ -266,6 +236,33 @@ Unless otherwise specified, other classes in the SDK do not have locks protectin
266
236
267
237
Currently, `OpenAI::Client` instances are only fork-safe if there are no in-flight HTTP requests.
268
238
239
+
### Sorbet
240
+
241
+
#### Enums
242
+
243
+
Sorbet's typed enums require sub-classing of the [`T::Enum` class](https://sorbet.org/docs/tenum) from the `sorbet-runtime` gem.
244
+
245
+
Since this library does not depend on `sorbet-runtime`, it uses a [`T.all` intersection type](https://sorbet.org/docs/intersection-types) with a ruby primitive type to construct a "tagged alias" instead.
246
+
247
+
```ruby
248
+
moduleOpenAI::Models::ChatModel
249
+
# This alias aids language service driven navigation.
messages: [OpenAI::Models::Chat::ChatCompletionUserMessageParam.new(role::user, content:"Say this is a test")],
261
+
model::"gpt-4.1"
262
+
)
263
+
openai.chat.completions.create(**params)
264
+
```
265
+
269
266
## Versioning
270
267
271
268
This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
@@ -275,3 +272,7 @@ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` typ
275
272
## Requirements
276
273
277
274
Ruby 3.1.0 or higher.
275
+
276
+
## Contributing
277
+
278
+
See [the contributing documentation](https://github.com/openai/openai-ruby/tree/main/CONTRIBUTING.md).
0 commit comments