$git clone https://github.com/jgravelle/GromptGrompt is a Python utility that uses the Groq LLM provider service to instantly refactor amazingly detailed and effective prompts. It's designed to optimize user prompts for better results when working with large language models.
| 1 | # Grompt Utility |
| 2 | |
| 3 | Grompt is a Python utility that uses the Groq LLM provider service to instantly refactor amazingly detailed and effective prompts. It's designed to optimize user prompts for better results when working with large language models. |
| 4 | |
| 5 |  |
| 6 | |
| 7 | |
| 8 | ## Features |
| 9 | |
| 10 | - Rephrase and optimize user prompts using Groq's LLM services |
| 11 | - Configurable via environment variables or .env file |
| 12 | - Can be used as a module in other Python scripts or run from the command line |
| 13 | - Supports various Groq models and customizable parameters |
| 14 | - Includes a separate Streamlit web app for easy demonstration and testing |
| 15 | - Streamlit app supports API key input for use in hosted environments |
| 16 | |
| 17 | ## Prerequisites |
| 18 | |
| 19 | - Python 3.6 or higher |
| 20 | - A Groq API key |
| 21 | |
| 22 | ## Installation |
| 23 | |
| 24 | 1. Clone this repository: |
| 25 | ``` |
| 26 | git clone https://github.com/jgravelle/Grompt.git |
| 27 | cd Grompt |
| 28 | ``` |
| 29 | |
| 30 | 2. Install the required dependencies: |
| 31 | ``` |
| 32 | pip install -r requirements.txt |
| 33 | ``` |
| 34 | |
| 35 | 3. Create a `.env` file in the project root directory and add your Groq API key: |
| 36 | ``` |
| 37 | GROQ_API_KEY=your_api_key_here |
| 38 | ``` |
| 39 | |
| 40 | ## Adding Grompt to Your Project |
| 41 | |
| 42 | To use Grompt in your project, you only need to include the `Grompt.py` file. Follow these steps: |
| 43 | |
| 44 | 1. Copy the `Grompt.py` file into your project directory. |
| 45 | 2. Install the required dependencies: |
| 46 | ``` |
| 47 | pip install groq python-dotenv |
| 48 | ``` |
| 49 | 3. Import and use the `rephrase_prompt` function in your Python scripts: |
| 50 | ```python |
| 51 | from Grompt import rephrase_prompt |
| 52 | |
| 53 | original_prompt = "Write a story about a robot" |
| 54 | rephrased_prompt = rephrase_prompt(original_prompt) |
| 55 | |
| 56 | print(rephrased_prompt) |
| 57 | ``` |
| 58 | |
| 59 | ## File Structure |
| 60 | |
| 61 | - `Grompt.py`: The main Grompt utility file |
| 62 | - `streamlit_app.py`: A separate Streamlit app for demonstrating Grompt's capabilities |
| 63 | - `.env`: Configuration file for environment variables |
| 64 | - `requirements.txt`: List of Python dependencies |
| 65 | - `README.md`: This file |
| 66 | |
| 67 | ## Configuration |
| 68 | |
| 69 | You can configure Grompt using environment variables or a `.env` file. Here are the available configuration options: |
| 70 | |
| 71 | - `GROQ_API_KEY`: Your Groq API key (required) |
| 72 | - `GROMPT_DEFAULT_MODEL`: The default Groq model to use (optional, default is 'llama-3.3-70b-versatile') |
| 73 | - `GROMPT_DEFAULT_TEMPERATURE`: The default temperature for text generation (optional, default is 0.5) |
| 74 | - `GROMPT_DEFAULT_MAX_TOKENS`: The default maximum number of tokens to generate (optional, default is 1024) |
| 75 | |
| 76 | Example `.env` file: |
| 77 | |
| 78 | ``` |
| 79 | GROQ_API_KEY=your_api_key_here |
| 80 | GROMPT_DEFAULT_MODEL=llama-3.3-70b-versatile |
| 81 | GROMPT_DEFAULT_TEMPERATURE=0.7 |
| 82 | GROMPT_DEFAULT_MAX_TOKENS=2048 |
| 83 | ``` |
| 84 | |
| 85 | ## Usage |
| 86 | |
| 87 | ### Streamlit Web App |
| 88 | |
| 89 | To run the Streamlit web app for an interactive demo: |
| 90 | |
| 91 | ``` |
| 92 | streamlit run streamlit_app.py |
| 93 | ``` |
| 94 | |
| 95 | This will start a local web server and open the Grompt demo in your default web browser. You can enter prompts, adjust parameters, and see the optimized results in real-time. |
| 96 | |
| 97 | When using the Streamlit app in a hosted environment: |
| 98 | |
| 99 | 1. Look for the sidebar on the left side of the app. |
| 100 | 2. Enter your Groq API key in the "Enter your GROQ API Key:" field. |
| 101 | 3. Your API key will be used only for the current session and is not stored. |
| 102 | |
| 103 | Note: Always keep your API keys confidential and do not share them publicly. |
| 104 | |
| 105 | ### As a Command-Line Tool |
| 106 | |
| 107 | Run Grompt from the command line: |
| 108 | |
| 109 | ``` |
| 110 | python Grompt.py "Your prompt here" [--model MODEL] [--temperature TEMP] [--max_tokens MAX_TOKENS] |
| 111 | ``` |
| 112 | |
| 113 | Options: |
| 114 | - `--model`: Specify the Groq model to use (overrides the default) |
| 115 | - `--temperature`: Set the temperature for text generation (overrides the default) |
| 116 | - `--max_tokens`: Set the maximum number of tokens to generate (overrides the default) |
| 117 | |
| 118 | Example: |
| 119 | ``` |
| 120 | python Grompt.py "Write a poem about AI" --model llama3-groq-8b-8192-tool-use-preview --temperature 0.8 --max_tokens 500 |
| 121 | ``` |
| 122 | |
| 123 | ### Practical Example |
| 124 | |
| 125 | Here's an example of Grompt in action: |
| 126 | |
| 127 | ``` |
| 128 | C:\ai\Grompt> python Grompt.py "Write an 11th grade level report on quantum physics" |
| 129 | Rephr |