For updates and announcements, follow @sferik on X.
Install the gem and add to the application’s Gemfile:
bundle add openai
Or, if Bundler is not being used to manage dependencies:
gem install openai
First, obtain an API key from https://platform.openai.com/api-keys.
require "openai"
# Initialize an OpenAI API client with your API secret key
openai_client = OpenAI::Client.new(bearer_token: "sk-thats1smallStep4man1giantLeap4mankind")
# Retrieve a model instance
openai_client.get("models/gpt-4")
# {"id"=>"gpt-4", "object"=>"model", "created"=>1687882411, "owned_by"=>"openai"}
By contributing to the project, you help:
⭐️ Bonus: Sponsors will get priority support and influence over the project roadmap. We will also list your name or your company’s logo on our GitHub page.
Building and maintaining an open-source project like this takes a considerable amount of time and effort. Your sponsorship can help sustain this project. Even a small monthly donation makes a huge difference!
Click here to sponsor this project.
Checkout and repo:
git checkout git@github.com:sferik/openai-ruby.git
Enter the repo’s directory:
cd openai-ruby
Install dependencies via Bundler:
bin/setup
Run the default Rake task to ensure all tests pass:
bundle exec rake
Create a new branch for your feature or bug fix:
git checkout -b my-new-branch
Bug reports and pull requests are welcome on GitHub at https://github.com/sferik/openai-ruby.
Pull requests will only be accepted if they meet all the following criteria:
Code must conform to Standard Ruby. This can be verified with:
bundle exec rake standard
Code must conform to the RuboCop rules. This can be verified with:
bundle exec rake rubocop
100% C0 code coverage. This can be verified with:
bundle exec rake test
100% mutation coverage. This can be verified with:
bundle exec rake mutant
RBS type signatures (in sig/openai.rbs
). This can be verified with:
bundle exec rake steep
The gem is available as open source under the terms of the MIT License.