CREATE A LIST Prompt
Prompt Engineering: Generating Lists with LLMs
Section titled “Prompt Engineering: Generating Lists with LLMs”Large Language Models (LLMs) like ChatGPT are excellent at generating various kinds of lists, from recommendations and ideas to structured data. By crafting effective prompts, you can guide the LLM to produce well-organized, relevant, and useful lists tailored to your specific needs.
Instructing LLMs to Create Lists
Section titled “Instructing LLMs to Create Lists”To get an LLM to generate a list, you simply ask it to do so in your prompt. The key is to be clear about the type of list, the criteria for the items, the desired number of items, and any specific formatting.
The basic approach is to directly request a list within your prompt:
User: Can you create a list of 5 must-read science fiction books published in the 21st century?
LLM: Certainly! Here are 5 must-read science fiction books published in the 21st century:
1. **"Project Hail Mary" by Andy Weir (2021)** - A thrilling space adventure with a witty protagonist and fascinating scientific problem-solving.2. **"The Three-Body Problem" by Cixin Liu (2008, English translation 2014)** - A mind-bending epic dealing with humanity's first contact with an alien civilization.3. **"Klara and the Sun" by Kazuo Ishiguro (2021)** - A poignant story exploring themes of love, humanity, and artificial intelligence through the eyes of an 'Artificial Friend'.4. **"Exhalation: Stories" by Ted Chiang (2019)** - A collection of profound and thought-provoking short stories exploring philosophical and scientific concepts.5. **"Ancillary Justice" by Ann Leckie (2013)** - A unique space opera featuring an AI protagonist, exploring themes of identity, empire, and consciousness.In this example, the user’s prompt specifies the topic (must-read science fiction books), a constraint (published in the 21st century), and the desired quantity (5 items). The LLM generates a list that meets these criteria.
Best Practices for List Generation Prompts
Section titled “Best Practices for List Generation Prompts”To get the best results when asking an LLM to create a list, consider these best practices:
- Be Clear and Specific: Clearly state the subject of the list (e.g., ‘healthy breakfast ideas,’ ‘productivity tools for remote workers,’ ‘pros and cons of Python’).
- Specify Quantity: Indicate how many items you want in the list (e.g., ‘top 3,’ ‘around 10,’ ‘no more than 7’). If you don’t specify, the LLM will decide the length.
- Define Criteria or Constraints: Provide any specific criteria the list items should meet (e.g., ‘for beginners,’ ‘under $50,’ ‘open-source alternatives’).
- Request a Format: You can ask for the list in a particular format, such as bullet points (default for many LLMs), numbered lists, or even a simple comma-separated list if needed. For more complex data, you could ask for a table-like structure (using markdown) or even JSON.
- Add Context: Provide relevant background information if it helps the LLM generate a more targeted and useful list. For example, ‘I’m planning a trip to Italy in May, create a list of 5 essential items to pack.’
- Iterate and Refine: If the first list isn’t quite right, refine your prompt. Add more details, clarify constraints, or ask for variations.
Example Application: Python Implementation for Generating a List
Section titled “Example Application: Python Implementation for Generating a List”Let’s explore a practical Python example using the OpenAI API to generate a list of travel destinations based on user preferences.
This script defines a function generate_list_response() that takes a topic and criteria for the list and prompts ChatGPT to generate it.
from openai import OpenAIimport os
# client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))# For this example, use a placeholder. Replace with your actual key.client = OpenAI(api_key='YOUR_API_KEY')
def generate_list_from_llm(list_topic, criteria, number_of_items): prompt_content = f"Please generate a list of {number_of_items} {list_topic} that meet the following criteria: {criteria}. Present the list with a brief explanation for each item."
try: response = client.chat.completions.create( model="gpt-3.5-turbo", # Or a more current model messages=[ {"role": "system", "content": "You are an AI assistant skilled at creating well-structured and informative lists."}, {"role": "user", "content": prompt_content} ], max_tokens=400, # Adjust based on expected list length temperature=0.6, n=1 ) return response.choices[0].message.content except Exception as e: return f"An error occurred: {e}"
# Example usage:topic = "travel destinations in Southeast Asia"criteria_for_list = "suitable for budget travelers interested in culture and nature, avoiding major tourist traps"num_items = 3
generated_list = generate_list_from_llm(topic, criteria_for_list, num_items)print("Generated List of Travel Destinations:")print(generated_list)Example Output
Section titled “Example Output”When the script runs, it will send the request to the LLM, which will then generate a list based on the provided topic, criteria, and number of items.
Generated List of Travel Destinations:
Here are 3 travel destinations in Southeast Asia suitable for budget travelers interested in culture and nature, avoiding major tourist traps:
1. **Luang Prabang, Laos:** This charming town is a UNESCO World Heritage site, known for its stunning temples, serene atmosphere, and beautiful natural surroundings like the Kuang Si Falls. It offers affordable guesthouses, delicious street food, and opportunities for cultural immersion through alms giving ceremonies and local markets. It's less crowded than many other Southeast Asian hotspots.
2. **Northern Sumatra, Indonesia (e.g., Bukit Lawang, Lake Toba):** For nature lovers, this region offers incredible biodiversity, including opportunities to see orangutans in their natural habitat near Bukit Lawang. Lake Toba, a massive volcanic crater lake, provides stunning scenery and a unique Batak culture. Costs are generally low, especially outside of peak seasons.
3. **Central Vietnam (e.g., Phong Nha-Ke Bang National Park, Hue):** While parts of Vietnam are very touristy, the area around Phong Nha-Ke Bang National Park offers incredible cave systems (some of the world's largest) and lush jungle landscapes ideal for trekking, at a fraction of the cost of similar adventures elsewhere. Nearby, the historic city of Hue provides a deep dive into Vietnam's imperial past with its citadel and tombs, offering rich cultural experiences without the intense crowds of Hoi An or Hanoi.Conclusion
Section titled “Conclusion”In this chapter, we explored how to effectively prompt LLMs to generate lists. By providing clear instructions regarding the list’s topic, item criteria, desired quantity, and format, you can leverage the LLM’s vast knowledge to create curated lists for a wide array of purposes, from simple brainstorming to more structured data collection.