Use a Specific Style
Be specific about the desired writing style1 that you want from the model using specific instructions to the model about tone, pacing among other factors.
By giving clear directions about these stylistic elements, you can guide the model to produce text that closely matches your intended style and format. We can implement this using instructor
as seen below.
import instructor
from pydantic import BaseModel
import openai
class Email(BaseModel):
message: str
client = instructor.from_openai(openai.OpenAI())
def create_email():
return client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": """Write an email addressed to Mr. John Smith
from Jane Doe. The email should be formal and the
message should be polite and respectful. The topic of
the email is to invite Mr Smith to a business meeting
on July 15, 2024 at 10:00 AM in Room 123.""",
}
],
response_model=Email,
)
return email.message
if __name__ == "__main__":
email_message = create_email()
print(email_message)
"""
Subject: Invitation to Business Meeting
Dear Mr. John Smith,
I hope this message finds you well. My name is Jane Doe, and I am
writing to cordially invite you to a business meeting that will be
held on July 15, 2024, at 10:00 AM in Room 123.
Your presence at this meeting would be greatly valued as we plan to
discuss important matters pertaining to our ongoing projects and
future collaborations. We believe your insights and experience will
greatly contribute to the success of our discussions.
Please let me know if this time and date are convenient for you, or
if any adjustments are necessary. We look forward to your
affirmative response.
Thank you for considering this invitation.
Warm regards,
Jane Doe
"""
Useful Tips¶
Here are some useful phrases that you might want to include when using style prompting to get the desired output that you want.
Category | Template | Example Phrases |
---|---|---|
Writing Style | 1. Write a style passage about topic 2. Write a passage with a style writing style about topic 3. Write a style passage about topic | style: functional, flowery, candid, prosaic, ornate, or poetic topic: sunsets, strawberries, or writing a paper |
Tone | 1. Write a tone passage about subject 2. Write a passage about subject with a tone tone 3. Create a tone passage about subject | tone: dramatic, humorous, optimistic, sad subject: love, life, humanity |
Emotional Tone | 1. Write a passage about subject that makes the reader feel emotion 2. Write a passage about subject with a emotion mood 3. Create a passage about subject that makes the reader feel emotion | subject: love, life, humanity emotion: angry, fearful, happy, sad, envious, anxious, proud, regretful, surprised, loved, disgusted |
Characterization | 1. Write a story about subject with indirect characterization 2. Write a story about subject with direct characterization 3. Create a story about subject where the characters are described indirectly 4. Create a story about subject where the characters are described directly | subject: lovers, cats, survivors |
Pacing | 1. Write a pace-paced story about subject 2. Write a story about subject that is pace-paced 3. Create a pace-paced story about subject | pace: fast, slow subject: lovers, cats, survivors |
References¶
1: Bounding the Capabilities of Large Language Models in Open Text Generation with Prompt Constraints
*: The Prompt Report: A Systematic Survey of Prompting Techniques