Chapter 3. Standard Practices for Text Generation with ChatGPT

Simple prompting techniques will help you to maximize the output and formats from LLMs. You’ll start by tailoring the prompts to explore all of the common practices used for text generation.

Generating Lists

Automatically generating lists is incredibly powerful and enables you to focus on higher-level tasks while GPT can automatically generate, refine, rerank, and de-duplicate lists on your behalf.

Input:

Generate a list of Disney characters.

Output:

Sure, here is a list of some popular Disney characters:

1. Mickey Mouse
2. Minnie Mouse
...
30. Bagheera (The Jungle Book)

GPT-4 is perfectly capable of providing a list of characters. However, there are some pitfalls with this approach:

  • GPT has decided to provide 30 examples as a numbered list, separated by \n characters. However, if your downstream Python code was expecting to split on bullet points, then you’ll likely end up with undesirable results or a runtime error.

  • GPT has provided preceding commentary; removing any preceding/succeeding commentary would make parsing the output easier.

  • The list size wasn’t controlled and was left to the language model.

  • Some of the characters have the name of their corresponding film within brackets—for example, Bagheera (The Jungle Book)—and others don’t. This makes names harder to extract because you would need to remove the movie titles.

  • No filtering or selection has been applied to the LLM generation based on our desired ...

Get Prompt Engineering for Generative AI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.