-
Notifications
You must be signed in to change notification settings - Fork 4
Installation
Nagendra Dhanakeerthi edited this page Oct 30, 2024
·
2 revisions
- Ruby 3.0 or higher
- An OpenAI API key
- Bundler installed (
gem install bundler
)
Add this line to your application's Gemfile:
gem 'chatgpt-ruby'
Then execute:
bundle install
Install the gem directly:
gem install chatgpt-ruby
# 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
require 'chatgpt'
ChatGPT.configure do |config|
config.api_key = ENV['OPENAI_API_KEY']
end
Create a .env
file:
OPENAI_API_KEY=your-api-key-here
Add to your .gitignore
:
echo ".env" >> .gitignore
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
- Linux
- macOS (Intel and Apple Silicon)
- Windows
- Check the Quick Start Guide
- Review Configuration Options
- Explore Usage Examples