How to Install and Use PromptWizard?
Thursday, Jan 2, 2025 | 6 minute read
Unleashing AI Potential with This Innovative Framework! π An open-source tool that enhances prompt engineering through feedback-driven optimization, making it a game changer for efficiency and performance in Large Language Models! π‘π₯
Explore the Charm of PromptWizard β¨
βIn this era of rapidly developing smart technology, how can we enhance our work efficiency and creativity? π€β
Artificial Intelligence (AI) has become the core driving force in the modern tech landscape! More and more businesses and developers are seeking effective ways to utilize Large Language Models (LLMs) to tackle complex problems. Against this backdrop, PromptWizard as an emerging open-source framework is gaining increasing attention! π Its unique features and design philosophy showcase revolutionary potential in the fields of prompt engineering and example generation, making it irresistible to try! π
PromptWizard: What Makes It So Revolutionary? π
PromptWizard is an exciting open-source framework aimed at automating and optimizing the prompt engineering and example generation processes in Large Language Models (LLMs). π€ With its feedback-driven critique and synthesis mechanism, PromptWizard achieves iterative prompt optimization, ensuring a perfect balance between exploring new approaches and leveraging known effectiveness! This innovative approach not only significantly enhances task performance but also drastically reduces computational costs, paving the way for a variety of applications! π‘
Unique Features of PromptWizard: Disruptive Key Characteristics π
PromptWizardβs feedback-driven iterative optimization model allows the model to generate, evaluate, and improve its own prompts and examples, greatly enhancing the accuracy of instructions! β¨ Even cooler, it employs a joint optimization technique that simultaneously generates and refines complementary synthetic examples, facilitating their synergistic advancement, and considerably boosting overall performanceπ! Additionally, it integrates Chain-of-Thought (CoT) reasoning, enhancing the reasoning process and significantly elevating the model’s problem-solving abilities, leading to a rapid increase in efficiencyβ‘οΈ!
Developer’s Choice: Why Choose PromptWizard? π»
PromptWizardβs outstanding performance truly makes it an excellent choice for developers! π It not only enhances overall task performance while significantly lowering computational costs, it also optimizes the efficiency of prompt design! During the design of effective prompts, PromptWizard shows clear advantages, making prompt generation more precise and efficient. π Especially when facing continuously changing task and model requirements, PromptWizard provides sustainable solutions, ensuring users can smoothly adapt to the rapidly evolving technological landscape! π οΈ
With these revolutionary features and characteristics, PromptWizard is rethinking the application of Large Language Models, becoming a powerful tool for developers and researchers! π§
Steps to Install PromptWizard β
Before starting to use PromptWizard, we first need to install it! π
Step 1: Clone the Repository π
To get a local copy of PromptWizard, simply execute the following command in your terminal:
git clone https://github.com/microsoft/PromptWizard
cd PromptWizard
- The
git clone
command fetches the PromptWizard code from GitHub to create a local copy. cd PromptWizard
changes your current working directory to the newly cloned folder, allowing you to execute subsequent operations there.
Step 2: Create and Activate a Virtual Environment π
Using a virtual environment is a good practice as it helps you manage Python package dependencies and isolate different projects.
On Windows:
python -m venv venv
venv\Scripts\activate
- The
python -m venv venv
command creates a new virtual environment called “venv.” - The
venv\Scripts\activate
command activates the virtual environment, ensuring that packages installed in this environment do not conflict with global system packages.
On macOS/Linux:
python -m venv venv
source venv/bin/activate
- The same command creates a
venv
virtual environment. source venv/bin/activate
is used to activate this virtual environment, helping you focus on project dependency management.
Step 3: Install the Package in Editable Mode βοΈ
Next, you will need to install PromptWizard in editable mode, allowing you to modify the code conveniently without reinstalling it!
pip install -e .
- The
pip install -e .
command installs the PromptWizard package in editable mode, meaning any changes you make to the source code will take effect immediately in your environment.
Quick Start π
Once the installation is complete, you can begin using PromptWizard! β¨
Use Cases:
- Scenario 1: Optimize prompts without examples.
- Scenario 2: Generate synthetic examples to optimize prompts.
- Scenario 3: Optimize prompts using training data.
For more detailed instructions, you can check the provided notebook.
High-Level Overview π
Before diving in, you can follow these steps:
- Choose a Scenario: Select the scenario that suits your use case.
- Configure the Environment: Set up the required configurations and environment variables for API calls using a configuration file named
promptopt_config.yaml
. Hereβs an example configuration for the GSM8k dataset:
USE_OPENAI_API_KEY="XXXX"
OPENAI_API_KEY="XXXX"
OPENAI_MODEL_NAME ="XXXX"
AZURE_OPENAI_ENDPOINT="XXXXX"
OPENAI_API_VERSION="XXXX"
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME="XXXXX"
- In this YAML configuration file, you need to provide OpenAI API credentials and specify the model name and endpoint to use.
- Run the Code: Execute the corresponding code to start optimizing prompts.
Running PromptWizard with Training Data (Scenario 3) π
If you have training data, PromptWizard can support various datasets including:
Please note that optimization times may vary, but generally, most optimizations take about 20-30 minutes!
Running on GSM8k (AQUARAT/SVAMP)
To run optimizations on the GSM8k dataset:
- Configure the Azure endpoint in the
.env
file. - Follow the instructions in demo.ipynb to download the necessary data, and perform prompt optimization and inference.
Running on BBII
For the BBII dataset, adjust configurations in promptopt_config.yaml
. Pay particular attention to task_description
, base_instruction
, and answer_format
. For more details, refer to the demonstration in demo.ipynb.
Running Custom Datasets ποΈ
Creating Custom Datasets
Custom datasets must be formatted in .jsonl
, ensuring each sample includes the following fields:
question
: The complete question that you want the LLM to answer.answer
: The corresponding true answer, which could be a detailed explanation or a concise response.
Steps for Custom Datasets
-
Dataset Structure: Organize your directory structure to include essential files and folders:
configs
: Contains hyperparameters for optimization.data
: Housestrain.jsonl
andtest.jsonl
..env
: Stores environment variables for configuration.- A script file for executing the process (
.py
or.ipynb
).
-
Setting Hyperparameters: Define optimization hyperparameters in
[promptopt_config.yaml](demos/gsm8k/configs/promptopt_config.yaml)
. -
Dataset Specific Class: Create a class that inherits from
DatasetSpecificProcessing
to implement necessary answer extraction methods.
How PromptWizard Works π
PromptWizard uses task descriptions and initial prompts to model multiple variants and selects the best variant based on performance metrics. β¨ It further optimizes through evaluation and improvement, guiding subsequent optimizations by distinguishing between good and bad examples.
- The framework generates reasoning chains using the Chain-of-Thought (CoT) approach, enhancing LLMβs problem-solving capabilities.
- It adjusts prompts by integrating task intent with expert roles to ensure better context understanding.
Configuration βοΈ
All hyperparameters related to prompt optimization are configured in the file located at [demos/gsm8k/configs/promptopt_config.yaml](demos/gsm8k/configs/promptopt_config.yaml)
. Key hyperparameters include:
mutate_refine_iterations
mutation_rounds
refine_task_eg_iterations
style_variation
questions_batch_size
min_correct_count
max_eval_batches
top_n
seen_set_size
few_shot_count
These parameters will significantly affect the performance of your prompt optimization strategies!
Best Practices π‘
- Adjust the parameters in
promptopt_config.yaml
based on experimental results for optimal outcomes. - Apply user feedback effectively to enhance prompt optimization for specific tasks.
- Experiment with both synthetic and training context examples to see which provides best performance for your specific use case.
Results π
PromptWizard has demonstrated consistent performance across various tasks, achieving high accuracy! Performance overview curves illustrate its advantages over other leading methods, showcasing the immense potential of optimizing LLM use with prompts!βοΈ