I decided I would create a variant of OpenAI’s quickstart tutorial written in Ruby. This is an example pet name generator app that returns creative names for a given animal using OpenAI’s text completion endpoint. It uses the Sinatra web framework. If you haven’t already, go to the OpenAI website and signup to create an account. Follow the instructions below to get set up or go right to the repo.

Setup

  1. If you don’t have Ruby 3.1.2 installed, I recommend you install it with rbenv

  2. Clone the repository

    $ git clone git@github.com:aliyeysides/openai-quickstart-ruby.git
    
  3. Navigate into the project directory

    $ cd openai-quickstart-ruby
    
  4. Install the bundler gem

    $ gem install bundler
    
  5. Install the requirements

    $ bundle install
    
  6. Make a copy of the example environment variables file

    $ cp .env.example .env
    
  7. Add your API key to the newly created .env file

  8. Run the app

    $ ruby app.rb
    

You should now be able to access the app at http://localhost:4567! For the full context behind this example app, check out the tutorial.