AI Content Generation
Relevant source files
The following files were used as context for generating this wiki page:
The AI Content Generation system in FusionOps is a specialized module designed to automate the creation of high-converting, policy-compliant landing page copy and metadata. It leverages advanced LLMs (Gemini and Anthropic) to produce marketing materials tailored to specific niches such as pet loans, auto financing, and debt consolidation.
The system is integrated into the Landing Page Wizard, allowing users to generate hero headlines, subheadlines, calls-to-action (CTA), and customer reviews with a single click. It enforces strict compliance rules to ensure all generated content passes Google Ads Financial Services policy reviews, specifically banning terms like "Personal Loans" and "guaranteed approval."
Sources: apps/api-worker/src/handlers/ai-generation.js:1-20, src/components/Wizard.jsx:310-330
Architecture and Provider Logic
The AI generation logic resides within the Cloudflare API Worker. It uses a tiered priority system for resolving API keys and selecting AI providers.
Provider Resolution
The system prioritizes Google Gemini as the primary provider, with Anthropic Claude serving as the fallback. API keys are resolved in the following order:
- Request Body: Keys passed directly from the frontend.
- Environment Variables: Keys stored in the Worker's secret environment variables (
GEMINI_API_KEY,ANTHROPIC_API_KEY). - D1 Settings: Keys retrieved from the
settingstable in the D1 database.
AI Generation Endpoints
The API Worker exposes several endpoints for specific content needs. Each requires a POST request and returns a structured JSON response.
| Endpoint | Purpose | Key Output Fields |
|---|---|---|
/api/ai/generate-copy | Above-the-fold hero copy | h1, title2, cta, sub, badge, mechanism |
/api/ai/generate-meta | SEO and PPC metadata | metaTitle, metaDesc |
/api/ai/generate-reviews | Social proof elements | Array of name, location, rating, text |
/api/ai/generate-description | Internal template documentation | description (Plain string) |
Sources: apps/api-worker/src/handlers/ai-generation.js:6-14, 252-258
Copywriting Frameworks and Niche Detection
The system does not generate generic text; it utilizes "Creative Seeds" to ensure variety and psychological impact.
Niche Mapping
The handler automatically detects the product niche based on the loanType to apply safe vocabulary and emotional hooks.
| Niche | Detected Keywords | Safe Vocabulary | Emotional Hook Example |
|---|---|---|---|
| Pet | pet, vet, dog, cat | Pet Funding, Care Financing | Unexpected vet bill? |
| Auto | auto, car, vehicle | Auto Cash, Vehicle Financing | Car broke down? |
| Payday | payday, cash advance | Quick Cash, Paycheck Advance | Short till payday? |
| Medical | medical, dental, health | Care Financing, Payment Plans | Medical bill surprise? |
Psychological Angle Selection
For every copy generation, the system randomly selects a pattern and tone to prevent "cookie-cutter" output across different sites. Patterns include Eugene Schwartz’s "Unique Mechanism" and Gary Halbert’s "Emotional Hook."
Sources: apps/api-worker/src/handlers/ai-generation.js:37-95
Compliance and Hard Rules
To protect accounts from being banned by ad networks, the AI generation handler enforces strict content restrictions.
- Banned Phrase: "Personal Loans" (must use alternatives like "fast cash" or "personal finance").
- Compliance Violations: "Guaranteed approval", "100% approved", "Instant money", "Free money".
- Credit Impact: Must use "soft credit check" instead of "no credit check".
- Jargon Ban: Terms like "amortization", "underwriting", or "FICO" are forbidden to keep copy accessible.
- Mobile Safety: H1 headlines are restricted to ≤48 characters to ensure they fit within two lines on a 375px viewport.
Frontend Integration (Wizard)
The Wizard.jsx component provides the interface for triggering these AI functions during the "Copy" step (Step 4).
Implementation Flow
- User clicks "Generate AI Copy" in the UI.
- The wizard sends the current brand, loan range, and language to
/api/ai/generate-copy. - The
handleAiGeneratefunction parses the response and updates the configuration state (setConfig). - The
template-router.jsthen detects these changes and re-renders the live mobile preview in an iframe.
// Example from src/components/Wizard.jsx:310
const handleAiGenerate = async () => {
setAiLoading(true);
try {
const p = await api.post("/ai/generate-copy", {
brand: config.brand,
loanType: config.loanType,
// ... keys and amounts
});
if (p && !p.error) {
if (p.h1) upd("h1", p.h1);
if (p.cta) upd("cta", p.cta);
notify("AI copy generated!");
}
} finally {
setAiLoading(false);
}
};
Sources: src/components/Wizard.jsx:310-340, src/utils/template-router.js:460-490
Customer Review Generation
The review generator creates three unique customer testimonials. To ensure realism, it requires that reviews have different names, different US states, and match the specific context of the loan (e.g., a pet loan review might mention an emergency surgery).
Sources: apps/api-worker/src/handlers/ai-generation.js:228-245
The generation logic is designed to be self-healing; if the AI returns prose or markdown fences, the extractJson utility identifies the start and end of the JSON object to ensure the frontend receives a parseable array.
Sources: apps/api-worker/src/handlers/ai-generation.js:235-240