-
Notifications
You must be signed in to change notification settings - Fork 4
Configuration
Nagendra Dhanakeerthi edited this page Oct 31, 2024
·
2 revisions
ChatGPT.configure do |config|
config.api_key = ENV['OPENAI_API_KEY']
config.api_version = 'v1'
config.default_engine = 'gpt-3.5-turbo' # For chat
config.request_timeout = 30
config.max_retries = 3
config.default_parameters = {
max_tokens: 16,
temperature: 0.5,
top_p: 1.0,
n: 1
}
end
ChatGPT.configure do |config|
config.api_key = ENV['OPENAI_API_KEY']
config.api_version = 'v1'
config.default_engine = 'gpt-3.5-turbo-instruct' # For completions
config.request_timeout = 30
config.max_retries = 3
config.default_parameters = {
max_tokens: 16,
temperature: 0.5,
top_p: 1.0,
n: 1
}
end
Option | Type | Default | Description |
---|---|---|---|
api_key |
String | nil | Your OpenAI API key |
api_version |
String | 'v1' | API version to use |
default_engine |
String | 'gpt-3.5-turbo' | Default model to use |
request_timeout |
Integer | 30 | Request timeout in seconds |
max_retries |
Integer | 3 | Maximum retry attempts |
default_parameters |
Hash | See below | Default parameters for requests |
{
max_tokens: 16,
temperature: 0.5,
top_p: 1.0,
n: 1
}
API Method | Compatible Models | Recommended Configuration |
---|---|---|
Chat | gpt-4, gpt-3.5-turbo | default_engine = 'gpt-3.5-turbo' |
Completions | gpt-3.5-turbo-instruct | default_engine = 'gpt-3.5-turbo-instruct' |
client = ChatGPT::Client.new(
api_key: 'different-key',
timeout: 60,
max_retries: 5
)
OPENAI_API_KEY=your-api-key
OPENAI_ORGANIZATION=your-org-id # Optional
# config/initializers/chatgpt.rb
ChatGPT.configure do |config|
config.api_key = Rails.application.credentials.openai[:api_key]
config.request_timeout = Rails.env.development? ? 60 : 30
# For Chat API (default)
config.default_engine = 'gpt-3.5-turbo'
# Or for Completions API
# config.default_engine = 'gpt-3.5-turbo-instruct'
end
- Use environment variables for sensitive data
- Configure timeouts based on your use case
- Set appropriate retry limits
- Use organization ID if applicable
- Choose the appropriate model based on your use case:
- Use Chat API (gpt-3.5-turbo) for conversational interactions
- Use Completions API (gpt-3.5-turbo-instruct) for simple text completions
- Configure different settings for development and production environments
- Use Rails credentials for secure API key storage in production
- 0.0: More focused and deterministic
- 0.5: Balanced creativity and consistency (default)
- 1.0: More creative and varied
- Consider your use case requirements
- Longer responses need higher values
- Default (16) is suitable for short responses
- Adjust based on expected response length
- Works alongside temperature
- Lower values (0.1) make output more focused
- Higher values (1.0) allow more diversity