/generate_image

The 'generate_image' gem provides a simple and easy-to-use interface for generating images using the DALL-E API. The gem is designed to be used in Ruby on Rails projects, but it can also be used in other Ruby projects.

Primary LanguageRubyMIT LicenseMIT

GenerateImage

The GenerateImage gem is a Ruby gem that provides a simple and easy-to-use interface for generating images using the OpenAI DALL-E API. This gem can be used in Ruby on Rails projects or any other Ruby projects.

Usage

The gem provides a generate_image method, which takes a text argument and returns the generated image URL as a hash. The method makes a request to the DALL-E API to generate an image based on the provided text.

Before using the generate_image method, you must set your OpenAI API key as an environment variable named DALL_E_API_KEY. The gem uses the Net::HTTP library to make API requests and includes error handling to ensure successful image generation. In case of any errors, the method will return a hash with an error key and a message.

Setting the API Key

Before you can use the generate_image method, you must set your OpenAI API key as an environment variable named DALL_E_API_KEY.

Here's an example of how you can set the environment variable

DALL_E_API_KEY=your_api_key

Example Usage

result = GenerateImage.generate_image('A three-story castle made of ice cream')
if result[:error]
  puts result[:error]
else
  puts result[:image_url]
end

Installation

Add this line to your application's Gemfile:

gem 'generate_image'

And then execute:

bundle install

Or install it directly by running:

gem install generate_image

Development

To contribute to the development of this gem, clone the repository and run the following commands to install dependencies and run tests:

bin/setup
rake spec

You can also run bin/console for an interactive prompt to experiment with the code.

To release a new version, update the version number in version.rb and run:

bundle exec rake release

This will create a git tag for the new version, push the git commits and tags, and upload the .gem file to RubyGems.org.

Contributing

Bug reports and pull requests are welcome on the GitHub repository. This project is intended to be a safe and welcoming space for collaboration, and all contributors are expected to adhere to the code of conduct.

License

The GenerateImage gem is open source software, released under the terms of the MIT License.