Skip to content

Repository files navigation

πŸš€ Blogy AI Blog Engine

Groq-powered (llama-3.3-70b-versatile) multi-agent SEO blog generation engine. Built for Bizmark'26 β€” Prompt & Profit hackathon.


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        FastAPI Application                          β”‚
β”‚                                                                     β”‚
β”‚  POST /blog/generate  ←── Master pipeline (all agents in sequence) β”‚
β”‚  POST /keywords/cluster                                             β”‚
β”‚  POST /serp/analyze                                                 β”‚
β”‚  POST /seo/analyze   /detect-ai   /snippet   /links                β”‚
β”‚  POST /humanize                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚              Orchestration Layer                   β”‚
         β”‚    asyncio.gather() β€” parallel agent execution     β”‚
         β””β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”˜
            β”‚          β”‚          β”‚          β”‚          β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β” β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚Keyword  β”‚ β”‚  SERP   β”‚ β”‚  Blog  β”‚ β”‚   SEO   β”‚ β”‚Humanize β”‚
     β”‚Cluster  β”‚ β”‚  Gap    β”‚ β”‚  Gen   β”‚ β”‚Optimizerβ”‚ β”‚  Agent  β”‚
     β”‚  Agent  β”‚ β”‚ Agent   β”‚ β”‚ Agent  β”‚ β”‚  Agent  β”‚ β”‚         β”‚
     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚          β”‚         β”‚         β”‚         β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚   Groq LLM Service  β”‚
                        β”‚ llama-3.3-70b-vers. β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Metrics Covered

Metric Implementation
Prompt Architecture Clarity Modular prompt templates in prompts/prompts.py
Keyword Clustering Logic Intent-based clusters with traffic + difficulty
SERP Gap Identification DuckDuckGo scrape + competitor page fetch + LLM analysis
Projected Traffic Potential Weighted score β†’ monthly visit range estimate
SEO Optimization % Composite 0-100 score (density + readability + structure)
AI Detection % & Naturalness Heuristic: burstiness + perplexity + AI phrase flags
Snippet Readiness Probability 3-variant generation (paragraph/list/table) with scoring
Keyword Density Compliance Per-keyword density with optimal/under/over status
Internal Linking Logic LLM-powered semantic anchor text + placement suggestions
Scalability & Replicability Stateless agents, async parallel execution, env config

Project Structure

blogy-ai-engine/
β”‚
β”œβ”€β”€ main.py                    # FastAPI app + router registration
β”œβ”€β”€ config.py                  # All environment config
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example
β”‚
β”œβ”€β”€ agents/                    # One file per agent
β”‚   β”œβ”€β”€ keyword_agent.py       # Agent 1: Keyword clustering
β”‚   β”œβ”€β”€ serp_agent.py          # Agent 2: SERP gap analysis
β”‚   β”œβ”€β”€ blog_generator.py      # Agent 3: Blog generation
β”‚   β”œβ”€β”€ seo_optimizer.py       # Agent 4: SEO scoring (deterministic)
β”‚   β”œβ”€β”€ snippet_agent.py       # Agent 5: Featured snippet optimization
β”‚   β”œβ”€β”€ humanizer.py           # Agent 6: AI humanization
β”‚   └── internal_linking_agent.py  # Agent 7: Internal link suggestions
β”‚
β”œβ”€β”€ routers/                   # FastAPI route handlers
β”‚   β”œβ”€β”€ blog.py                # POST /blog/generate
β”‚   β”œβ”€β”€ keywords.py            # POST /keywords/cluster
β”‚   β”œβ”€β”€ serp.py                # POST /serp/analyze
β”‚   β”œβ”€β”€ seo.py                 # POST /seo/analyze|detect-ai|snippet|links
β”‚   └── humanize.py            # POST /humanize
β”‚
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ groq_service.py        # Groq async wrapper (chat_completion + json mode)
β”‚   └── ai_detection_service.py  # Heuristic AI detection
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ request_models.py      # Pydantic request schemas
β”‚   └── response_models.py     # Pydantic response schemas
β”‚
β”œβ”€β”€ prompts/
β”‚   └── prompts.py             # All LLM prompt templates (system + user)
β”‚
└── utils/
    β”œβ”€β”€ scraper.py             # Async DuckDuckGo scraper + page fetcher
    └── seo_utils.py           # Deterministic SEO calculations (no LLM)

Quick Start

1. Clone & Install

git clone <repo>
cd blogy-ai-engine

python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt

python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"

2. Configure

cp .env.example .env
# Edit .env and add your GROQ_API_KEY

3. Run

uvicorn main:app --reload --host 0.0.0.0 --port 8000

Open: http://localhost:8000/docs


API Reference

POST /blog/generate β€” Full Pipeline

{
  "keyword": "AI blog automation tool India",
  "secondary_keywords": ["blog automation", "SEO tool India", "AI content writer"],
  "target_location": "India",
  "word_count": 2500,
  "tone": "professional",
  "competitor_urls": [],
  "internal_links": [
    {
      "title": "How to Rank on Google in India",
      "url": "https://blogy.in/blog/rank-google-india",
      "topic": "SEO",
      "keywords": ["SEO", "Google ranking India"]
    }
  ],
  "enable_humanization": true
}

Response includes:

  • title, meta_description, slug, content
  • seo_score β€” Full SEO audit (0-100)
  • ai_detection β€” AI probability + naturalness + flags
  • snippet_optimization β€” 3 snippet variants + readiness score
  • internal_links β€” Semantic link suggestions
  • keyword_clusters β€” Intent-grouped keyword clusters
  • serp_analysis β€” Competitor gaps + winning angle
  • generation_time_seconds

POST /keywords/cluster

{
  "seed_keyword": "SEO tool",
  "target_location": "India",
  "cluster_count": 5
}

POST /serp/analyze

{
  "keyword": "best AI blog automation tool India",
  "target_location": "India",
  "max_results": 10
}

POST /seo/analyze

{
  "content": "# Your blog content here...",
  "keyword": "AI blog automation",
  "secondary_keywords": ["blog tool", "SEO automation"]
}

POST /seo/detect-ai

{
  "content": "Your blog content to check for AI patterns..."
}

POST /seo/snippet

{
  "content": "# Blog content...",
  "keyword": "AI blog automation tool"
}

POST /seo/links

{
  "content": "# Blog content...",
  "primary_keyword": "AI blog automation",
  "existing_blogs": [
    {
      "title": "How to Rank on Google",
      "url": "https://blogy.in/blog/rank-google",
      "topic": "SEO",
      "keywords": ["SEO", "Google ranking"]
    }
  ]
}

POST /humanize

{
  "content": "# AI-generated blog content...",
  "force": false
}

AI Detection Algorithm

The heuristic AI detector doesn't need a paid API. It scores on 4 signals:

Signal Weight What it measures
Burstiness 35% Sentence length variance β€” AI writes uniform lengths
Perplexity Proxy 25% Bigram uniqueness ratio β€” AI reuses transitions
AI Phrase Flags 30% 20 known AI clichΓ©s ("delve into", "in today's world", etc.)
Paragraph Uniformity 10% AI paragraphs are suspiciously equal in length

SEO Score Breakdown

Component Max Points How
Word count β‰₯ 2,500 20 Full marks for 2500+, partial for 1500+
Keyword density 0.5-2.5% 20 Optimal range = full marks
Readability β‰₯ 60 15 Flesch-Kincaid score
Headings β‰₯ 5 10 H2/H3 structure
Keyword in title 15 Binary check
Keyword in first 100 words 10 Binary check
Internal links β‰₯ 3 5 Markdown link count
LSI keywords β‰₯ 8 5 Top co-occurring non-stopword terms
Total 100

Environment Variables

Variable Required Description
GROQ_API_KEY βœ… Get from console.groq.com
SERPAPI_KEY ❌ Optional (uses DuckDuckGo scraper by default)
APP_ENV ❌ development / production
APP_HOST ❌ Default: 0.0.0.0
APP_PORT ❌ Default: 8000
CORS_ORIGINS ❌ Comma-separated frontend origins

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages