Advanced Prompt Generator

repository·main·Indexed 42 days ago

https://github.com/thunderhead-exe/advanced-prompt-generator

An LLM-based tool that automates prompt engineering by transforming simple user inputs into structured, agent-optimized prompts. It features an agentic workflow that generates enhanced prompts, reference suggestions, and detailed thought processes with subtasks. The tool can be deployed as a local Python script, a Gradio web interface, or a containerized FastAPI backend supporting gpt-4o and gpt-4o-mini.

Tokens
1.9K
Snippets
7
Records
9
Agent score
53%

What's inside Advanced Prompt Generator

  1. Overview of the Advanced Prompt Generator

    main

    The Advanced Prompt Generator is an LLM-based tool designed to automate prompt engineering. It takes a simple input prompt and uses AI agents to enhance it into a highly structured, detailed, and optimized prompt following established engineering principles.

    Key Capabilities:

    • Automated Enhancement: Transforms minimal user input into complex prompts with specific requirements, structures, and personas.
    • Agentic Workflow: Uses LLM agents to generate not just the prompt, but also reference suggestions and a detailed thought process (subtasks, reasoning, and success criteria).
    • Deployment Options: Available as a local script, a Gradio web interface, or a scalable FastAPI backend containerized with Docker.
  2. Understand the output format of enhanced prompts

    main

    When you provide an input prompt, the generator produces a multi-part response designed to provide maximum context to an LLM. The output typically includes:

    1. Enhanced Prompt: A detailed version of your input including a persona (e.g., "As a knowledgeable writing coach"), specific requirements, and a requested response structure.
    2. Reference Suggestions: A list of external resources, books, or documentation that would help the LLM fulfill the prompt, including the purpose and how to integrate them.
    3. Thought Process: A breakdown of the prompt engineering logic, organized into Subtasks. Each subtask contains:
      • Description: What needs to be done.
      • Reasoning: Why this step is necessary.
      • Success criteria: How to verify the step was completed correctly.
  3. Install and run the Advanced Prompt Generator locally

    main

    To use the tool on your local machine, clone the repository, install the required Python dependencies, and execute the test script.

    Prerequisites:

    • Python 3 installed
    • OpenAI API Key (the tool supports gpt-4o or gpt-4o-mini)

    Steps:

    1. Clone the repository.
    2. Install dependencies via pip.
    3. Run the Advancd_Prompt_Generator.py script to start testing.
    git clone https://github.com/Thunderhead-exe/Advanced-Prompt-Generator.git
    pip install -r requirements.txt
    python3 Advancd_Prompt_Generator.py
  4. Launch the Advanced Prompt Generator Gradio interface

    main

    The project includes a Gradio web interface for interacting with the prompt enhancement pipeline. When the script is executed, it launches a web UI with the following controls:

    • Input Prompt: A multi-line textbox for entering the raw prompt.
    • Select Model: A radio selection between gpt-4o-mini (recommended) and gpt-4o.
    • Temperature: A slider ranging from 0.0 to 1.0 (recommended: 0.0).

    Running the script directly via Python will start the local server.

    python Gradio-app/app.py
  5. Configure the OPENAI_API_KEY for the API

    main

    To use the advanced prompt generation service, you must provide an OpenAI API key. The recommended method is to create a .env file in the project root and add the following key:

    OPENAI_API_KEY = your_personal_api_key

    Alternatively, you can pass the key directly in pipeline.py, though this is not recommended for security reasons.

    OPENAI_API_KEY = the_personal_api_key
  6. Explore the repository structure

    main

    The repository is organized into different deployment versions:

    • Advancd_Prompt_Generator.py: The main script for local testing.
    • pipeline.py: The core logic responsible for prompt enhancement.
    • Docker-FastAPI-app/: Contains the backend implementation using FastAPI and a Dockerfile for containerized deployment.
    • Gradio-app/: Contains the web interface implementation using Gradio (app.py).
    ├── Advancd_Prompt_Generator.py    # Script to test the tool locally 
    ├── pipeline.py                    # Core logic for prompt enhancement
    ├── Docker-FastAPI-app             # Version deployed with FastAPI & Docker
    │   ├── app       
    │   │   ├── main.py       
    │   │   ├── pipeline.py   
    │   │   ├── Dockerfile        
    │   ├── requirements.txt  
    ├── Gradio-app                     # Version deployed with Gradio 
    │   ├── app.py            
    │   ├── pipeline.py       
    │   ├── requirements.txt  
  7. Use the advancedPromptPipeline function

    main

    The advancedPromptPipeline is an asynchronous function used to enhance a given input prompt using a specified LLM model and temperature setting. It wraps the PromptEnhancer logic to provide an enhanced prompt string.

    Parameters:

    • InputPrompt (str): The raw text prompt you wish to enhance.
    • model (str, optional): The LLM model to use. Supported values are "gpt-4o-mini" and "gpt-4o". Defaults to "gpt-4o-mini".
    • temperature (float, optional): The sampling temperature for the model. Defaults to 0.0.

    Returns:

    • str: The enhanced version of the input prompt.
    # Example usage of the pipeline function
    advanced_prompt = await advancedPromptPipeline("Your raw prompt here", model="gpt-4o-mini", temperature=0.0)
    print(advanced_prompt)
  8. Use the advancedPromptPipeline API endpoint

    main

    The API provides a POST endpoint /advanced_prompt_generation that accepts an InputPrompt JSON payload. It uses the PromptEnhancer to transform a simple input string into an advanced prompt using a specified LLM model (currently defaults to gpt-4o-mini).

    Request Body: Requires a JSON object with a text field:

    • text (string): The raw prompt you wish to enhance.

    Response Body: Returns a JSON object containing:

    • model (string): The model used for generation.
    • elapsed_time (float): Time taken for the operation in seconds.
    • prompt_tokens (int): Number of tokens in the input prompt.
    • completion_tokens (int): Number of tokens in the generated response.
    • approximate_cost (float): Calculated cost based on token usage.
    • input_prompt (string): The original text provided.
    • advanced_prompt (string): The enhanced version of the prompt.
    POST /advanced_prompt_generation
    {
      "text": "your simple prompt here"
    }
    
    // Response
    {
      "model": "gpt-4o-mini",
      "elapsed_time": 1.234,
      "prompt_tokens": 50,
      "completion_tokens": 150,
      "approximate_cost": 0.0000975,
      "input_prompt": "your simple prompt here",
      "advanced_prompt": "the enhanced prompt result"
    }