Skip to content

pshort05/AICleanup

Repository files navigation

AICleanup

This project provides a structured prompt and a set of rules to create a specialized Gemini-powered editor. The goal is to "clean up" generic, AI-generated prose, transforming it into sharp, specific, and stylistically opinionated writing.

Project Goal

The primary objective is to develop reusable tools (a "Gemini Gem") that leverage the detailed stylistic rules found in this repository to automatically revise and improve text.

Core Components

  1. AI BANNED - THE DEFINITIVE LIST.md: The master style guide containing all rules and principles.
  2. master_prohibited_words.json: An extensive list of overused words and phrases.
  3. aic_prompt.json: A prompt for comprehensive, stylistic editing.
  4. ai_word_removal_prompt.json: A hyperfocused prompt for removing specific AI-associated vocabulary.

Manual Usage (Python)

The recommended approach for manual use is to create a function that loads a prompt and applies it to any text you provide.

import json
import os
# Make sure to install the Google AI Python SDK
# pip install google-generativeai
import google.generativeai as genai

# Configure your API key
# genai.configure(api_key="YOUR_API_KEY")

def load_prompt(prompt_path="aic_prompt.json"):
    """Loads the JSON prompt file."""
    with open(prompt_path, 'r') as f:
        return json.load(f)

def create_system_prompt(prompt_data):
    """Creates the full system instruction string from the JSON data."""
    persona = prompt_data.get('persona', {}).get('description', '')
    guardrails = "\n".join(f"- {g}" for g in prompt_data.get('persona', {}).get('hallucination_guardrails', []))
    principles = "\n".join(f"- {p}" for p in prompt_data.get('core_principles', []))
    task_instruction = prompt_data.get('task', {}).get('instruction', '')

    system_instruction = f"""
{persona}

**Hallucination Guardrails:**
{guardrails}

**Core Principles:**
{principles}

**Task:**
{task_instruction}
"""
    return system_instruction

def cleanup_text(text_to_revise: str, prompt_file: str = "aic_prompt.json", temperature: float = 0.4):
    """
    Uses the Gemini API and a specified AICleanup prompt to revise text.
    """
    if not text_to_revise.strip():
        return "Error: No text provided for revision."

    try:
        prompt_data = load_prompt(prompt_file)
        system_instruction = create_system_prompt(prompt_data)
        
        generation_config = {
            "temperature": temperature,
            "top_p": 1.0,
            "max_output_tokens": 8192,
        }

        model = genai.GenerativeModel(
            model_name='gemini-1.5-pro-latest',
            system_instruction=system_instruction,
            generation_config=generation_config
        )
        
        response = model.generate_content(text_to_revise)
        
        return response.text

    except FileNotFoundError:
        return f"Error: {prompt_file} not found."
    except Exception as e:
        return f"An error occurred: {e}"

# --- Example Usage ---
if __name__ == '__main__':
    ai_generated_text = """
    He stood up, then he walked to the window. The silence in the room stretched on. 
    Something shifted in his expression. It wasn't quite a smile. A wave of sadness 
    washed over him, hitting him like a physical blow. He knew this would change everything.
    """
    
    print("--- ORIGINAL TEXT ---")
    print(ai_generated_text)
    
    # Run the first, stylistic pass
    stage1_text = cleanup_text(ai_generated_text, prompt_file="aic_prompt.json", temperature=0.4)
    print("\n--- STAGE 1 (STYLISTIC) ---")
    print(stage1_text)

    # Run the second, word-removal pass
    stage2_text = cleanup_text(stage1_text, prompt_file="ai_word_removal_prompt.json", temperature=0.2)
    print("\n--- STAGE 2 (WORD REMOVAL) ---")
    print(stage2_text)

n8n Automation Workflows

This project includes pre-built n8n workflows to automate the text cleanup process.

Prerequisites

  • A running n8n instance: This can be on n8n.cloud, self-hosted, or a local desktop version.
  • Google Gemini API Key: You need an API key from Google AI Studio.
  • n8n Credentials: You must have your Google Gemini API key configured as credentials within your n8n instance.

Setup Instructions

  1. Place Project Files: Make sure all project files (.json, .md) are accessible to your n8n instance, preferably in the same directory.
  2. Create Input File: In that same directory, create a file named input.md and add the text you want to clean up.
  3. Import Workflow: In your n8n canvas, go to File > Import from File... and select the desired workflow .n8n.json file.
  4. Configure Credentials: In the imported workflow, click on each "Gemini" node. In the "Credentials" field, select your pre-configured Gemini credentials.
  5. Check File Paths: The workflows use relative paths (e.g., ./input.md). If your environment requires absolute paths, you must edit the file paths in all "Read" and "Write" nodes.

Available Workflows

1. Stylistic Cleanup (AICleanupWorkflow.n8n.json)

  • Purpose: Performs a comprehensive stylistic edit on the input text.
  • Prompt Used: aic_prompt.json
  • Use Case: Best for a first, deep pass on raw AI-generated text to fix structural issues, clichés, and weak prose.

2. Hyperfocused Word Removal (WordRemovalWorkflow.n8n.json)

  • Purpose: Specifically targets and removes overused, AI-associated words and phrases.
  • Prompt Used: ai_word_removal_prompt.json
  • Use Case: A surgical tool for lexical cleanup. Use it when the main goal is to remove "buzzwords" without altering the overall sentence structure.

3. Two-Stage Cleanup Pipeline (TwoStageCleanupWorkflow.n8n.json)

  • Purpose: A sequential, two-step editing pipeline for the most thorough cleanup.
  • Prompts Used: aic_prompt.json (Stage 1) -> ai_word_removal_prompt.json (Stage 2)
  • Use Case: The most powerful option. It first performs a deep stylistic edit, then runs a second pass to remove any remaining AI-associated vocabulary, resulting in a highly polished final text.

Running a Workflow

  1. Save: Click the Save button in n8n.
  2. Execute: Click Execute Workflow to run the process.
  3. Check Output: Once it completes, a new file named output.md will be created in the same directory, containing the revised text.

About

A single JSON project for Gemini that will be use to cleanup AI writing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors