This repository contains a .ruby-version
file, which should work with either rbenv or asdf with the ruby plugin.
Please follow the instructions for your preferred version manager to install the Ruby version specified in the .ruby-version
file.
To set up the repository, run:
$ ./scripts/bootstrap
This will install all the required dependencies.
Most of the SDK is generated code. Modifications to code will be persisted between generations, but may result in merge conflicts between manual patches and changes from the generator. The generator will never modify the contents examples/
directory.
All files in the examples/
directory are not modified by the generator and can be freely edited or added to.
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "../lib/openai"
# ...
$ chmod +x './examples/<your-example>.rb'
# run the example against your api
$ ruby './examples/<your-example>.rb'
If you’d like to use the repository from source, you can either install from git or reference a cloned repository:
To install via git in your Gemfile
:
gem "openai", git: "https://www.github.com/openai/openai-ruby"
Alternatively, reference local copy of the repo:
$ git clone -- 'https://www.github.com/openai/openai-ruby' '<path-to-repo>'
gem "openai", path: "<path-to-repo>"
Running rake
by itself will show all runnable commands.
$ bundle exec rake
Most tests require you to set up a mock server against the OpenAPI spec to run the tests.
$ npx prism mock path/to/your/openapi.yml
$ bundle exec rake test
This repository uses rubocop for linting and formatting of *.rb
and *.rbi
files. syntax_tree is used for formatting *.rbs
files.
There are two separate type checkers supported by this library: sorbet and steep are used for verifying *.rbi
and *.rbs
files respectively.
To lint and typecheck:
$ bundle exec rake lint
To format and fix all lint issues automatically:
$ bundle exec rake format
Ruby LSP has quite good support for go to definition, but not auto-completion.
This can be installed along side Solargraph.
Solargraph has quite good support for auto-completion, but not go to definition.
This can be installed along side Ruby LSP.
Sorbet should mostly work out of the box when editing this library directly. However, there are a some caveats due to the colocation of *.rb
and *.rbi
files in the same project. These issues should not otherwise manifest when this library is used as a dependency.
-
For go to definition usages, sorbet might get confused and may not always navigate to the correct location.
-
For each generic type in
*.rbi
files, a spurious "Duplicate type member" error is present.
To preview the documentation, run:
$ bundle exec rake docs:preview [PORT=8808]