• AI Unchained
  • Posts
  • AI Prompt Mastery: Develop Your Custom Prompt Generator

AI Prompt Mastery: Develop Your Custom Prompt Generator

Step-by-Step Guide to Building Your AI Prompt Generator

Hey there,

Joris here, and I'm excited to dive into the world of prompt engineering with you in this edition of AI Unchained.

Never worry about writing bad prompts anymore with your own Prompt Generator.

Let’s dive in.

Today's Unchained Insights

🔍 Prompting: Crafting Smart Prompts for AI Models.

🔧 LangChain Code Snippet: Your Own Prompt Generator in 10 Lines of Code.

💡 AI Project Idea: Elevate Your Prompt Generator with Advanced Features (With UI)

👏 Project of the Week: Hard Kothrari’s YouTube Summarizer.

📚 AI Research: Fairness-guided Few-shot Prompting for LLMs

Introduction

Prompt engineering is a crucial skill when it comes to harnessing the power of AI models.

Prompting lies at the heart of directing AI to generate the results we desire.

But crafting a top-notch prompt can be challenging and time-consuming.

We’re busy people, so we’ll be using AI to transform our louzy prompts into world class instructions.

Prompting: A Key to AI Mastery

Curious about making AI models generate the responses you need?

It all starts with a prompt.

A prompt is like a guide that tells the AI model what you're looking for.

A solid prompt has this structure:

  1. State expertise: Declare the AI as an expert in your task.

  2. Provide Instructions: Give clear guidance on what you want from the model.

  3. Show examples: Share an example of the output you're aiming for.

  4. Last instruction: Wrap up by reminding the model of your request.

Three more tips on getting your desired outputs:

  1. Clarity is King: Keep your prompts clear and concise. The AI needs to understand your intent without any ambiguity.

  2. Be Specific: The more specific your prompt, the better the results. Instead of "Summarize this article," try "Summarize this article on renewable energy technologies."

  3. Experiment and Iterate: Don't be afraid to experiment with different prompts and iterate. AI models often respond differently to slight variations.

With the LangChain Code Snippet, AI will be transforming this lazy prompt:

Generate a workout schedule

To this improved prompt:

As a certified fitness trainer, generate a comprehensive 4-week workout schedule for a beginner looking to improve overall fitness and strength.

### Instructions:

- The workout schedule should be designed for someone with little to no prior exercise experience.

- Include a variety of exercises targeting different muscle groups, such as cardio, strength training, and flexibility.

- Each week should consist of 5 workout days, with 2 rest days for recovery.

- Specify the duration and intensity level for each workout session.

- Provide clear instructions on how to perform each exercise, including proper form and technique.

- Include any necessary warm-up or cool-down exercises.

- The schedule should gradually progress in difficulty over the 4-week period.

- Consider incorporating modifications or alternatives for individuals with physical limitations or injuries.

- Format the schedule in a weekly format, with each day's workout plan clearly outlined.

Example:

Week 1:

Day 1:

- Warm-up: 5 minutes of light cardio (e.g., brisk walking or cycling)

- Strength Training: Bodyweight squats (3 sets of 10 reps), push-ups (3 sets of 8 reps), and lunges (3 sets of 12 reps)

- Cardio: 20 minutes of moderate-intensity jogging or cycling

- Cool-down: 5 minutes of stretching exercises targeting the lower body

Day 2:

- Rest day

Day 3:

- Warm-up: 5 minutes of dynamic stretching exercises

- Strength Training: Dumbbell bicep curls (3 sets of 10 reps), tricep dips (3 sets of 8 reps), and plank holds (3 sets of 30 seconds)

- Cardio: 15 minutes of interval training (alternating between 1 minute of high-intensity exercise and 1 minute of low-intensity exercise)

- Cool-down: 5 minutes of static stretching exercises for the upper body

...

The workout schedule should continue in a similar format for the remaining weeks, gradually increasing the intensity and incorporating new exercises to challenge the beginner's fitness level.

All in a matter of seconds.

Let me show you how!

LangChain Code Snippet

GitHub Repo

Grab the code from the GitHub Repo.

5 Steps to Prompt Improvement

  1. Import dependencies

  2. Provide initial prompt

  3. Initialize Large Language Model

  4. Create prompt for prompt improvement (Promptception!)

  5. Initialize LLM Chain

  6. Run the chain

Just 5 lines of code, and voilà – a prompt improver is at your fingertips.

Peek Under the Hood

Here's how it works:

  1. Initial prompt: Input your lazy prompt.

  2. Initialize LLM: Enter your OpenAI API Key and initialize the LLM.

    1. Model: Use the model you like, you could use GPT-4 for improved performance.

    2. Temperature: This is the model’s ‘creativity’ setting. Play around with this. (0 to 1, closer to 1 = more creative)

  3. Initialize LLMChain:

    1. LLM: Your initialized Large Language Model.

    2. Prompt: The prompt for improving the prompt. Check out the GitHub Repo for the prompt I’m using.

  4. Run the chain: Use the LLMChain to generate an improved version of your initial prompt.

You got this down?

Time to go down another level in this inception chain: Improve the Prompt Improver.

Unchained Project Idea: Prompt Generator

Each task benefits from a slightly different prompt.

Try to create a more advanced prompt generator which is based on a large list of prompt examples for different purposes.

Consider adding these functionalities:

Check out the GitHub Repo, where you’ll also find a kickstart to the Streamlit front-end.

Please share your project with me on Twitter and the best one will feature in next week’s AI Unchained.

Unchained Project of The Week

Last week’s AI Unchained Project Idea centered around creating a YouTube Chatbot.

Hard Kothari embarked on a journey by crafting a Streamlit YouTube Summarizer. This tool serves as the foundation for creating insightful summaries from YouTube videos.

Features of the Summarizer:

  • Enter your OpenAI API Key

  • Input any YouTube URL

  • Generate either a concise or detailed summary

Feel the innovation for yourself—try out the project here and show your appreciation on Twitter.

AI Research

Title: Fairness-guided Few-shot Prompting for Large Language Models

Short summary: This article explores the construction of an appropriate prompt to improve the performance of in-context learning for large language models. It introduces a metric to evaluate predictive bias and proposes a search strategy to identify the optimal prompt.

Interesting insight: The study shows that prompts with higher bias result in unsatisfactory predictive quality, highlighting the importance of fairness in prompting for language models.

Wrapping Up

From unraveling the art of effective prompts to creating your very own Prompt Generator with just a handful of lines of code, we've dived into the world of prompt engineering.

As we wrap up this edition of AI Unchained, remember that your feedback is the driving force behind our growth. Just hit reply or catch me on Twitter with your thoughts.

Stay curious and see you next week,

Joris