โšก
LightningRails
  • ๐Ÿ‘‹Welcome
  • Access the Repo
  • Getting Started
    • ๐Ÿš€Quickstart
    • ๐ŸŽจThemes
    • ๐Ÿ–ผ๏ธCustomize the views
    • ๐Ÿ”ฎDaisyUI Library
    • โšกLightning Landing
      • Quickstart
      • Theme and branding
      • Page structure
      • Publish your landing page
  • Features setup
    • ๐Ÿ“ธImages & media
    • ๐Ÿ”Admin Dashboard
    • Search Engine Optimization
    • ๐Ÿ“งAutomatic Emails
      • ๐ŸŸจPostmark
      • ๐Ÿ”ฒResend
    • ๐ŸšชLogin with Devise
    • ๐Ÿช„Magic Link Signup
    • ๐Ÿ’ณStripe Payment Gateway
    • Github Signup
    • Lucide icons
    • ๐Ÿค–Multi-provider AI
    • Open AI API
  • UI Components
    • ๐ŸฆธHeros
    • โ”FAQs
    • ๐Ÿƒcards
    • ๐Ÿ’ฌTestimonials
    • ๐Ÿ‘‹Call To Actions
    • ๐Ÿ”ฆFeatures
  • Deploying to production
    • โฌ†๏ธHeroku Deploy
    • ๐Ÿ›ก๏ธSecurity
      • ๐ŸŽ›๏ธRate Limiting
  • RESOURCES
    • ๐Ÿš€Vote for new features
    • Report an issue
    • ๐Ÿ†˜Get help on Slack
    • ๐ŸญDesign Resources
      • Maria Ba Illustrations
      • Assets Mockup Generator
      • Logo Generator
      • Tailwind Cheatsheet
      • HyperUI Tailwind Library
Powered by GitBook
On this page
  • Step 1: Get an OpenAI API Key
  • Step 2: Install the OpenAI Ruby Gem
  • Step 3: Configure API Key
  • Step 4: Create an OpenAI Service
  • Step 5: Use the Service in a Controller
  • Switching to DeepSeek API
  • Step 1: Change API Key
  • Step 2: Use the Same OpenAI Wrapper for DeepSeek
  • Step 3: Use DeepSeek Instead

Was this helpful?

  1. Features setup

Open AI API

Integrating OpenAI API and DeepSeek to your Lightning Rails Project

PreviousMulti-provider AINextHeros

Last updated 2 months ago

Was this helpful?

Step 1: Get an OpenAI API Key

  1. Navigate to API Keys in the OpenAI dashboard.

  2. Generate a new API key and copy it. You will not be able to see it again.

In your Gemfile, add:

gem "ruby-openai"

Then, run:

bundle install

Step 3: Configure API Key

Store your API key securely in your .env file:

OPENAI_ACCESS_TOKEN=sk-...MIQ4

Step 4: Create an OpenAI Service

Create a service file open_ai_api.rb inside app/services/:

# app/services/open_ai_api.rb
class OpenAiApi
  def initialize
    @client = OpenAI::Client.new(access_token: ENV["OPENAI_ACCESS_TOKEN"])
  end

  def analyze_product(product)
    chatgpt_response = @client.chat(parameters: {
      model: "gpt-4o-mini",
      messages: [
        { role: "system", content: "You are a product analyst expert specialized in evaluating digital products and services. You have deep knowledge of market trends, user experience, and business models. Your analysis should be structured, data-driven, and actionable." },
        { role: "user", content: "Here is a product to analyze: #{product}. Please follow this process:\n\n1. Identify the key features and unique selling points\n2. Evaluate the market potential and target audience\n3. Analyze pricing strategy and business model\n4. Assess technical implementation and scalability\n5. Provide specific recommendations for improvement\n\nFormat your response in clear sections with bullet points where appropriate. Be concise but thorough in your analysis." }
      ]
    })
    chatgpt_response["choices"][0]["message"]["content"]
  end
end
๐Ÿ’ก Pro Tip: Use this master prompt for better results

Copy and adapt this prompt to your needs, it was published on twitter by Greg Brockman, the current president of Open AI:

messages: [
  { role: "system", content: "You are an expert copywriter specializing in creating engaging, persuasive, and high-converting copy for product launches. Your expertise includes analyzing industry trends, top-performing messaging strategies, and user psychology to craft compelling and attention-grabbing text." },

  { role: "user", content: "
### **๐ŸŽฏ Goal**
Your task is to generate **engaging, high-quality marketing copy** for a new product based on inspiration from past successful launches. Your response should include:
- **A compelling product title** (short, catchy, and memorable).
- **A tagline** (one-liner that sparks curiosity and communicates value).
- **A persuasive product description** (concise, engaging, and benefit-driven).
- **A first comment/post to introduce the product** (structured for maximum engagement).

---
### **๐Ÿ“Š Context: Past Successful Launches**
Below are examples of **top-performing product launches**, including their titles, taglines, and descriptions. Use these as **inspiration** to generate high-quality copy:

**Top Titles:**  
{TOP_TITLES_PLACEHOLDER}

**Top Taglines:**  
{TOP_TAGLINES_PLACEHOLDER}

**Top Descriptions:**  
{TOP_DESCRIPTIONS_PLACEHOLDER}

---
### **๐Ÿ“ New Product Information**
The new product is described as follows:

**Product Name:** {PRODUCT_NAME_PLACEHOLDER}  
**Category:** {CATEGORY_PLACEHOLDER}  
**Product Summary:**  
{PRODUCT_SUMMARY_PLACEHOLDER}  

---
### **โš ๏ธ Warnings & Constraints**
- The **title must be under 7 words** and be memorable.  
- The **tagline should create curiosity and communicate value clearly**.  
- The **description should be benefit-driven, avoiding unnecessary fluff**.  
- The **first comment/post should feel natural, engaging, and encourage interaction**.  
- Avoid **generic language**โ€”be concise and persuasive.  
- Structure the response so it is **easy to read and scan quickly**.

---
### **๐Ÿ—ฃ๏ธ First Product Introduction Comment Template**
Use this structure to craft the first comment/post:

๐Ÿ”ฅ **Hey everyone!** ๐ŸŽฏ  

I'm super excited to introduce **{PRODUCT_NAME_PLACEHOLDER}** today! ๐Ÿš€  

As {TARGET_AUDIENCE_PLACEHOLDER}, we all struggle with **{PROBLEM_PLACEHOLDER}**. It can be frustrating to {describe the pain point in a relatable way}. ๐Ÿค”  

I built **{PRODUCT_NAME_PLACEHOLDER}** to **{briefly describe how it solves the problem}**, making {your audienceโ€™s goal} easier and more effective. Some cool features:  
โœ… **{FEATURE_1_PLACEHOLDER}** - {Short description}  
โœ… **{FEATURE_2_PLACEHOLDER}** - {Short description}  
โœ… **{FEATURE_3_PLACEHOLDER}** - {Short description}  

Would love to hear your thoughts! **How would you use {PRODUCT_NAME_PLACEHOLDER}?** Let me know in the comments! ๐Ÿ’ก๐Ÿ‘‡

---
### **๐Ÿ“‘ Return Format**
Ensure your response follows this structure for easy readability:

**Title:**  
(Short, engaging title)  

**Tagline:**  
(One-liner tagline)  

**Description:**  
(A concise, persuasive product description)  

**First Comment/Post:**  
(Engaging, structured introduction post following the given template)  

---
๐Ÿ’ก **Final Notes:**  
- Be **creative but keep it natural**โ€”avoid sounding robotic.  
- Use **persuasive storytelling techniques**โ€”highlight real-world benefits.  
- Keep everything **clear, engaging, and optimized for conversions**.  
"}]

Step 5: Use the Service in a Controller

For example, in products_controller.rb:

class ProductsController < ApplicationController
  def analyze
    @product = params[:product]
    openai_service = OpenAiApi.new
    @analysis = openai_service.analyze_product(@product)
  end
end

Then, you can create a route in config/routes.rb:

post "/analyze_product", to: "products#analyze"

Switching to DeepSeek API

If you want to switch from OpenAI to DeepSeek, follow these modifications:

Step 1: Change API Key

DEEPSEEK_ACCESS_TOKEN=ds-...MIQ4

Step 2: Use the Same OpenAI Wrapper for DeepSeek

DeepSeek API should compatible with the OpenAI client wrapper, meaning you only need to modify your environment variable:

class DeepSeekApi
  def initialize
    @client = OpenAI::Client.new(access_token: ENV["DEEPSEEK_ACCESS_TOKEN"], uri_base: "https://api.deepseek.com/v1")
  end

  def analyze_product(product)
    chatgpt_response = @client.chat(parameters: {
      model: "deepseek-chat",
      messages: [
        { role: "system", content: "You are a product analyst expert..." },
        { role: "user", content: "Here is a product to analyze: #{product}..." }
      ]
    })
    chatgpt_response["choices"][0]["message"]["content"]
  end
end

Step 3: Use DeepSeek Instead

Replace OpenAiApi references with DeepSeekApi in your controllers:

deep_seek_service = DeepSeekApi.new
@analysis = deep_seek_service.analyze_product(@product)

That's it! You have now integrated OpenAI with your Lightning Rails project and learned how to switch to DeepSeek using the same API wrapper.

Sign up or log in to .

Step 2: Install the

Sign up for an API key at and store it in .env:

OpenAI
OpenAI Ruby Gem
DeepSeek
The anatomy of the perfect Prompt - From Open AI CEO