Welcome to the final installment of our prompt engineering for software developers series!
The previous article discussed text transformation using LLMs. This article will explore the power of expanding text using large language models (LLMs).
Text expansion involves generating longer, more detailed outputs from shorter inputs. This technique is incredibly useful for a variety of applications, from creating comprehensive emails to generating essays from a list of topics.
The Basics of Text Expanding With LLMS
The basics of text expansion involve taking a shorter piece of text, like a set of instructions or a list of topics, and having the LLM generate a longer piece of text, such as an email or an essay.
This method is great for tasks like brainstorming, where you can use the LLM as a creative partner. However, it’s essential to be aware of the potential for misuse, like generating large amounts of spam.
Always use these capabilities responsibly for the greater good of yourself and other people.
Personalized Email Generation

One practical application of text expansion is generating personalized emails.
For example, imagine you have a customer review and want to respond based on its sentiment. LLMs can help you generate a custom email that addresses specific details mentioned in the review.
Here’s a Step-by-Step Example of Personalized Email Generation
- Setup: First, we set up the OpenAI Python package and define our helper function get_completion.
- Customer Review: Let’s say we have a customer review for a laptop.
- Prompt: We’ll use the following prompt to generate the email:
# Sentiment from the lesson on "inferring"
sentiment = "positive"
# Review for a laptop
review = f"""
I bought this laptop during the holiday sale, and it was an amazing deal.
The performance is excellent, and it handles all my software without any issues.
The battery life is impressive, lasting me through a full workday without needing a recharge.
Customer service was very helpful when I had a question about the setup process.
Shipping was fast, and the packaging was secure.
Overall, I'm very satisfied with my purchase and would definitely recommend this laptop to others.
"""
# Prompt to generate a customized email reply
prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service.
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: ```{review}```
Review sentiment: {sentiment}
"""
response = get_completion(prompt)
print(response)Using this prompt, the LLM generates a professional email response that includes details from the customer review.
Dear valued customer,
Thank you for taking the time to share your positive review with us. We are thrilled to hear that you found the laptop to be an amazing deal during the holiday sale. It's great to know that the performance, battery life, customer service, shipping, and packaging all met your expectations. We are delighted that you are satisfied with your purchase and would recommend the laptop to others.
If you have any further questions or need assistance in the future, please feel free to reach out to our customer service team.
Thank you again for your feedback.
AI customer agentUsing the Temperature Parameter
The “temperature” parameter is a fascinating aspect of LLMs. It allows you to control the degree of randomness and creativity in the model’s responses.
At a lower temperature, the model’s output is more predictable and consistent, making it ideal for applications where reliability is critical.
The model’s responses become more varied and creative at a higher temperature. This can be helpful for tasks that benefit from a broader range of outputs.
For example, if you want to generate a creative response, you might set the temperature to 0.7:
prompt = f"""
You are a customer service AI assistant. Your task is to send an email reply to a valued customer.
Given the customer email delimited by three backticks, generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for their review.
If the sentiment is negative, apologize and suggest that they can reach out to customer service.
Make sure to use specific details from the review, write in a concise and professional tone, and sign the email as 'AI customer agent'.
"""
response = get_completion(prompt, temperature=0.7)
print(response)The output response looks like the following:
```
Subject: Thank you for your feedback!
Hi there,
I just wanted to reach out and thank you for taking the time to leave a review. We truly appreciate your feedback and are delighted to hear that you had a positive experience with our product/service.
Your kind words mean a lot to us and serve as motivation for our team to continue providing excellent customer service. If you have any further questions or concerns, please don't hesitate to reach out to us.
Thank you once again for your support!
AI customer agent
```You will notice that with the temperature set to 0.7, the responses are more varied and creative each time you run the prompt.
Practical Applications and Examples
To truly grasp the power of text expansion and the temperature parameter, let’s delve into some practical applications.
Let’s generate a personalized email response based on a customer review and adjust the temperature to see how the output changes.
Experimenting with different temperatures can help you find the right balance between creativity and consistency for your specific needs.
Here’s an example with a lower temperature for a more predictable response:
response = get_completion(prompt, temperature=0.0) print(response)
response:``
Subject: Thank you for your review!
Hi there,
I just wanted to take a moment to thank you for your recent review. We truly appreciate your feedback and are thrilled to hear that you had a positive experience with our product/service.
Your kind words mean a lot to us and we are glad that we were able to meet your expectations. If you have any further feedback or suggestions, please feel free to reach out to us.
Thank you once again for your review and for choosing our company. We look forward to serving you again in the future.
Best regards,
AI customer agent
```And here’s the same prompt with a higher temperature for more creative variations:
response = get_completion(prompt, temperature=0.7) print(response)```
Subject: Thank you for your review
Dear valued customer,
Thank you for taking the time to leave a review about your recent experience with our product/service. We truly appreciate your feedback.
Your positive feedback on the ease of use and effectiveness of our product/service is greatly appreciated. We are delighted to hear that you found it helpful.
If there is anything else we can assist you with, please do not hesitate to reach out to us.
Thank you once again for your review.
Best regards,
AI customer agent
```Notice the differences in the outputs as you change the temperature setting.
Exploring Different Temperatures
Experimenting with different temperature settings is a great way to understand their impact on the generated text.
Higher temperatures produce more diverse and creative outputs. Lower temperatures, on the other hand, yield more predictable and consistent responses.
Try using various temperatures to see how the outputs vary, and find the settings that work best for your application. This exploration can help you fine-tune the model to meet your specific requirements.
Final Thoughts
This article explored the transformative capabilities of large language models (LLMs) in expanding text.
We showed how LLMs can turn short inputs into extended, detailed outputs. For example, they can convert simple instructions into an entire email or transform a list of topics into a well-rounded essay.
We examined practical applications, including personalized email generation, and discussed the impact of the temperature parameter on the model’s responses.
By experimenting with different settings and understanding how to leverage the capabilities of LLMs, you can significantly enhance your text-generation processes, ensuring creativity and consistency as needed.
Thank you for following along with our series on prompt engineering. We hope you’ve gained valuable insights and techniques to apply to your AI projects. Keep experimenting, learning, and refining your skills to stay ahead in the ever-evolving field of AI application development. Happy Prompting!
Discover more from AI For Developers
Subscribe to get the latest posts sent to your email.