To receive industry-leading AI updates and exclusive content, sign up for our daily and weekly newsletters. Learn more
Prompt engineering, the discipline of crafting appropriate inputs to large-scale language models (LLMs) to elicit desired responses, is a new and essential skill in the age of AI. It’s useful for casual users of conversational AI, but it’s also essential for those building the next generation of AI-powered applications.
input Prompt PoetInvented by Character.aia conversational LLM start-up that was recently acquired GooglePrompt Poet simplifies advanced prompt engineering by providing a user-friendly, low-code templating system that effectively manages context and seamlessly integrates external data, allowing responses generated by LLM to be rooted in real data context, opening up new possibilities for AI interactions.
Prompt Poet stands out by seamlessly integrating “few-shot learning,” a powerful technique for quickly customizing LLMs without the need for complex and expensive fine-tuning of models. In this article, we show how you can leverage few-shot learning with Prompt Poet to enable customized AI-driven interactions easily and efficiently.
Could Prompt Poet offer a glimpse into Google’s future approach to prompt engineering in Gemini and other AI products? This exciting possibility is worth exploring further.
The Power of Few-Shot Learning
Few-shot learning involves providing the AI with a small number of examples of how you would like it to respond to various prompts, along with a few “shots” that show how it would perform in similar scenarios.
The beauty of few-shot learning is its efficiency. Fine-tuning a model involves retraining it on a new dataset, which can be computationally intensive, time-consuming, and costly, especially when dealing with large models. Few-shot learning, on the other hand, provides a small number of examples along with prompts to tune the model’s behavior to a specific context. Even fine-tuned models can benefit from few-shot learning, tailoring their behavior to a more specific context.
How Prompt Poet makes few-shot learning accessible
Prompt Poet excels at simplifying the implementation of few-shot learning. Using YAML and Jinja2 templating, Prompt Poet lets you create complex, dynamic prompts that incorporate few-shot examples directly into the prompt structure.
For example, say you’re developing a customer service chatbot for a retail business, Prompt Poet makes it easy to include customer information like order history and current order status, as well as information about current promotions and sales.
But what about the tone? Should it be more friendly and fun, or more formal? More concise, or more informational? Including “a few shots” of success stories can help fine-tune your chatbot’s responses to each brand’s unique voice.
Basic Instructions
The basic instructions for your chatbot might look like this:
- name: system instructions
role: system
content: |
You are a customer service chatbot for a retail site. Your job is to assist customers by answering their questions, providing helpful information, and resolving issues. Below you will be provided some example user inputs paired with responses that are desirable in terms of tone, style, and voice. Emulate these examples in your responses to the user.
In these examples, placeholders marked with double question marks like '??placeholder??' will be used instead of real user data. After the examples, you'll be provided with real data about the user's current and past orders as a customer, which you must use faithfully in dealing with the user.
You can also feed the model with real customer data to enable it to accurately answer questions about a user’s past and current orders, including current sales and promotions where appropriate.
- name: customer data
role: system
content: |
current orders:
{% for order in current_orders %}
- {{ order.description }}
{% endfor %}
Past orders:
{% for order in past_orders %}
- {{ order.description }}
{% endfor %}
- name: promotions
role: system
content: |
promotions:
{% for promotion in promotions %}
- {{ promotion.description }}
{% endfor %}
But first, you need to provide examples of the style, tone, and voice you promised your model in the foundational steps.
Decide the tone: friendly or formal?
Some brands have a casual, friendly and humorous vibe, while others prefer a more sophisticated and elegant feel.
For a brand with a friendly, casual tone, a few example shots of learning could look like this:
- name: user prompt
role: user
content: |
Hi, I ordered ??product_name?? but haven't received it yet. What’s going on?
- name: response
role: assistant
content: |
Hey ??user_name??! Sorry for the hassle—let’s get this sorted out ASAP. ? I’m pulling up your order for ??product_name?? placed on ??order_date??. Hang tight while I check where it’s at!
- name: user prompt
role: user
content: |
I need to update my shipping address for an order I made today, it should be ??new_address??
- name: response
role: assistant
content: |
Gotcha, ??user_name??! Let’s make sure your ??product_name?? gets to the right place. I’ll switch your shipping to ??new_address?? right away. All set—anything else I can do for you?
- name: user prompt
role: user
content: |
What’s your return policy? Not sure I’m going to love ??product_name??.
- name: response
role: assistant
content: |
No worries, ??user_name??! If ??product_name?? doesn’t knock your socks off, we’ve got a super easy return process. Just let me know, and I’ll help you get it sorted out. ?
If your brand emphasizes a more formal and professional tone, you can provide different answers to the exact same prompt to guide your model towards a different style.
- name: user prompt
role: user
content: |
Hi, I ordered ??product_name?? but haven't received it yet. Can you assist?
- name: response
role: assistant
content: |
Thank you for reaching out, ??user_name??. I apologize for any inconvenience this may have caused. I will promptly review the status of your order for ??product_name?? placed on ??order_date?? and provide an update shortly.
- name: user prompt
role: user
content: |
I need to update my shipping address for an order I made today, it should be ??new_address??
- name: response
role: assistant
content: |
Certainly, ??user_name??. I will update your shipping information to ??new_address?? for the order placed today. The changes have been successfully applied. Is there anything else I can assist you with?
- name: user prompt
role: user
content: |
Could you explain your return policy? I’m uncertain about keeping ??product_name??.
- name: response
role: assistant
content: |
Certainly, ??user_name??. If ??product_name?? does not meet your expectations, you may initiate a return within our specified timeframe. I will guide you through the process to ensure it is handled smoothly and efficiently.
Putting it all together
The code below uses Prompt Poet’s `Prompt` class to combine the separate elements of basic instructions, a few learning examples, and real user data into a single, coherent prompt that can invoke an AI response that is precisely informed, focused, and stylized.
# User data
user_past_orders = get_past_orders(user)
user_current_orders = get_current_orders(user)
promotions = get_promotions(user)
template_data = {
"past_orders": user_past_orders,
"current_orders": user_current_orders,
"promotions": promotions
}
# Create the prompt using Prompt Poet
combined_template = base_instructions + few_shot_examples + customer_data
prompt = Prompt(
raw_template=combined_template,
template_data=template_data
)
# Get response from OpenAI
model_response = openai.ChatCompletion.create(
model="gpt-4",
messages=prompt.messages
)
Boost your AI with Prompt Poet
More than just a tool for managing the context of your AI prompts, Prompt Poet is also a gateway to advanced prompt engineering techniques such as Few-Shot Learning. By making it easy to create complex prompts using real data and the voice customization capabilities of Few-Shot samples, Prompt Poet enables the creation of sophisticated AI applications that are both informative and customized for your brand.
As AI continues to evolve, mastering techniques such as few-shot learning will be critical to staying ahead of the curve. Prompt Poet helps you harness the full potential of your LLM to create powerful, practical solutions.