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
Sign up for an API key at DeepSeek and store it in .env:
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: