Skip to content

Latest commit

 

History

History
125 lines (76 loc) · 3.51 KB

CONTRIBUTING.md

File metadata and controls

125 lines (76 loc) · 3.51 KB

Setting up the environment

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.

Modifying/Adding code

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.

Adding and running examples

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'

Using the repository from source

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 commands

Running rake by itself will show all runnable commands.

$ bundle exec rake

Running tests

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

Linting and formatting

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

Editor Support

Ruby LSP

Ruby LSP has quite good support for go to definition, but not auto-completion.

This can be installed along side Solargraph.

Solargraph

Solargraph has quite good support for auto-completion, but not go to definition.

This can be installed along side Ruby LSP.

Sorbet

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.

  1. For go to definition usages, sorbet might get confused and may not always navigate to the correct location.

  2. For each generic type in *.rbi files, a spurious "Duplicate type member" error is present.

Documentation Preview

To preview the documentation, run:

$ bundle exec rake docs:preview [PORT=8808]