Sign up for our daily and weekly newsletters, featuring the latest updates and exclusive content on industry-leading AI reporting. Learn more
Prompt engineering, the discipline of creating inputs that are just right for large-scale language models (LLMs) to get the desired response, is a crucial new skill in the AI era. It is useful for everyday users of conversational AI, but it is essential for builders of next-generation AI-based applications.
Introducing Prompt Poet, the brainchild of Character.ai, a conversational LLM startup recently acquired by Google. Prompt Poet simplifies advanced prompt engineering by providing a user-friendly, low-code templating system that effectively manages context and seamlessly integrates external data. This opens up new horizons in AI interaction by allowing LLM-generated responses to be based on real-world data context.
Prompt Poet shines by seamlessly integrating “few-shot learning,” a powerful technique that allows you to quickly customize your LLM without the need for complex and expensive model tuning. In this article, we’ll explore how to leverage few-shot learning with Prompt Poet to easily and efficiently deliver personalized AI-based interactions.
Could Prompt Poet be a glimpse into Google’s future approach to prompt engineering across Gemini and other AI products? This intriguing potential is worth a closer look.
The Power of Few-Shot Learning
In few-shot learning, we give the AI a few examples of the type of response we want for a variety of possible prompts. We also give it a few ‘shots’ of how it should behave in similar scenarios.
The advantage of few-shot learning is efficiency. Fine-tuning a model involves retraining the model on a new data set, which can be computationally intensive, time-consuming, and expensive, especially when working with large models. Few-shot learning, on the other hand, provides a small set of examples with prompts that can adjust the model’s behavior to a specific context. Even fine-tuned models can adapt their behavior to more specific contexts through few-shot learning.
How Prompt Poet Makes Few-Shot Learning Approachable
Prompt Poet shines in its ability to simplify the implementation of few-shot learning. Using YAML and Jinja2 templates, Prompt Poet allows you to create complex and dynamic prompts that integrate few-shot examples directly into the prompt structure.
For example, let’s say you want to develop a customer service chatbot for a retailer. With Prompt Poet, you can easily include customer information such as 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 informative? By including “a few shots” of successful cases, you can fine-tune your chatbot’s responses to fit the unique voice of each brand.
Basic Guidelines
Here are some basic guidelines for chatbots:
- 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.
We also feed our models real customer data so they can accurately answer questions about your 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 your basic guidelines.
Setting the Mood: Friendly or Formal?
Some brands prefer a more casual, friendly and cheerful tone, while others go for a more sophisticated elegance.
For brands with a friendly, casual tone, here are some learning examples:
- 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. ?
For brands that emphasize a more formal and professional tone, giving different answers to the same question can lead models to different styles.
- 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.
bring it together
The code below uses Prompt Poet’s `Prompt` class to form a single, consistent prompt from individual elements of a basic instruction, a few-shot training examples, and real user data. This allows you to provide information accurately in purpose and style, and to invoke highly crafted AI responses.
# 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
)
Boosting AI with Prompt Poet
Prompt Poet is more than just a tool for managing context in AI prompts. It’s a gateway to advanced prompt engineering techniques like few-shot learning. By making it easy to write complex prompts using real-world data and the ability to customize the voice of few-shot examples, Prompt Poet helps you build sophisticated AI applications that are customized and rich in information for your brand.
As AI continues to evolve, mastering techniques like few-shot learning is crucial to staying ahead of the curve. Prompt Poet can help you unleash the full potential of your LLM to create powerful, practical solutions.