Skip to content

Installation

Nagendra Dhanakeerthi edited this page Oct 30, 2024 · 2 revisions

Installation

Requirements

  • Ruby 3.0 or higher
  • An OpenAI API key
  • Bundler installed (gem install bundler)

Installation Methods

Via Bundler (Recommended)

Add this line to your application's Gemfile:

gem 'chatgpt-ruby'

Then execute:

bundle install

Manual Installation

Install the gem directly:

gem install chatgpt-ruby

Configuration

Rails Applications

# config/initializers/chatgpt.rb
ChatGPT.configure do |config|
  config.api_key = ENV['OPENAI_API_KEY']
  config.request_timeout = 30
  config.max_retries = 3
  config.default_engine = 'text-davinci-002'
end

Non-Rails Applications

require 'chatgpt'

ChatGPT.configure do |config|
  config.api_key = ENV['OPENAI_API_KEY']
end

Environment Setup

Create a .env file:

OPENAI_API_KEY=your-api-key-here

Add to your .gitignore:

echo ".env" >> .gitignore

Verification

Test your installation:

require 'chatgpt'

begin
  client = ChatGPT::Client.new(ENV['OPENAI_API_KEY'])
  response = client.completions("Hello, World!")
  puts "Installation successful!"
rescue => e
  puts "Installation failed: #{e.message}"
end

Supported Platforms

  • Linux
  • macOS (Intel and Apple Silicon)
  • Windows

Next Steps

  1. Check the Quick Start Guide
  2. Review Configuration Options
  3. Explore Usage Examples

Need Help?

Clone this wiki locally