0.0
The project is in a healthy, maintained state
A gem that extends Rails helpers with AI-powered image generation. Current functionality includes a custom image_tag helper that generates images based on a description.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

RailsAiTag

<%= ai_image_tag("A cute cat with a barretina that likes ruby on rails") %>

alt text

RailsAiTag is a Ruby on Rails gem that provides custom HTML helpers for AI-powered image generation. Currently, it supports generating <img> tags with images created by OpenAI's image generation API, based on a given description. This gem is designed to be extendable, with plans for supporting other AI services.

Installation

Add this line to your Rails application's Gemfile:

gem 'rails_ai_tag'

Then, run:

bundle install

Configuration

Configure the gem by specifying your AI service provider and API key. Currently, only OpenAI is supported as the provider.

Add the configuration in an initializer (e.g., config/initializers/rails_ai_tag.rb):

RailsAiTag.configure do |config|
  config.provider = :openai        # Currently, only :openai is supported
  config.api_key = "YOUR_OPENAI_API_KEY"  # Replace with your actual OpenAI API key
end

Usage

Use the ai_image_tag helper in your Rails views.

Provide a description, and the helper will generate an image based on the description using OpenAI's API.

<%= ai_image_tag("A futuristic cityscape at sunset") %>

This helper method generates an tag with the AI-generated image URL and sets the alt attribute to the description. alt text alt text

Example

<%= ai_image_tag("A lush green forest with misty mountains in the background") %>

The above code will generate an image tag for an AI-generated image that matches the description provided. alt text

Testing

RailsAiTag uses RSpec and WebMock for testing. You can run the tests with:

rspec