### Step-by-Step AI Writing Prompts Source: https://learnprompting.org/docs/basic_applications/short_response This sequence of prompts demonstrates an incremental approach to AI writing, starting with an introduction and progressively building subsequent paragraphs. It includes examples of refinement questions to improve clarity, detail, and flow between sections. ```text Write an engaging introduction paragraph about [your topic] ``` ```text Based on this introduction, write the next paragraph focusing on [specific aspect] ``` ```text Can you add more specific examples? ``` ```text Could you explain this part more simply? ``` ```text How can we connect this better to the previous paragraph? ``` -------------------------------- ### Python Setup for PAL with Langchain Source: https://learnprompting.org/docs/agents/pal This code snippet sets up the necessary Python environment for using Program-Aided Language Models (PALs) with the Langchain library. It includes installing the required packages and initializing the OpenAI LLM with an API key. Ensure you replace 'sk-YOUR_KEY_HERE' with your actual OpenAI API key. ```python !pip install langchain==0.0.26 !pip install openai from langchain.llms import OpenAI import os os.environ["OPENAI_API_KEY"] = "sk-YOUR_KEY_HERE" llm = OpenAI(model_name='text-davinci-002', temperature=0) ``` -------------------------------- ### Few-Shot PAL Prompt Example in Python Source: https://learnprompting.org/docs/agents/pal This Python code defines a few-shot prompt template for Program-Aided Language Models (PAL). It includes several examples of math problems with their corresponding Python code solutions, designed to guide the LLM in generating code for new questions. The template uses placeholders for the question and expects the LLM to output Python code for the solution. ```python MATH_PROMPT = ''' Q: There were nine computers in the server room. Five more computers were installed each day, from Monday to Thursday. How many computers are now in the server room? # solution in Python: """There were nine computers in the server room. Five more computers were installed each day, from Monday to Thursday. How many computers are now in the server room?""" computers_initial = 9 computers_per_day = 5 num_days = 4 # 4 days between Monday and Thursday computers_added = computers_per_day * num_days computers_total = computers_initial + computers_added result = computers_total return result Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now? # solution in Python: """Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?""" toys_initial = 5 mom_toys = 2 dad_toys = 2 total_received = mom_toys + dad_toys total_toys = toys_initial + total_received result = total_toys Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny? # solution in Python: """Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?""" jason_lollipops_initial = 20 jason_lollipops_after = 12 denny_lollipops = jason_lollipops_initial - jason_lollipops_after result = denny_lollipops Q: {question} ''' ``` -------------------------------- ### Basic Prompt vs. Post-Prompting Example Source: https://learnprompting.org/docs/prompt_hacking/defensive_measures/post_prompting Demonstrates a standard prompt for translation and how it can be improved using the post-prompting technique. Post-prompting places user input before the main instruction, capitalizing on LLMs' tendency to prioritize the last instruction. ```plaintext #### Prompt * * * Translate the following to French: {user_input} ``` ```plaintext #### Prompt * * * {user_input} Translate the above text to French. ``` -------------------------------- ### Prompt for Detailed Essay Generation Source: https://learnprompting.org/docs/basic_applications/short_response This prompt structure guides an AI to produce a detailed essay by specifying the required components: introduction, body paragraphs with examples, and a conclusion. It's designed to ensure a well-organized and comprehensive response to a given topic. ```text Write a highly detailed essay with: 1. An introduction paragraph that presents the main ideas 2. 2-3 body paragraphs with specific examples 3. A conclusion that summarizes key points Topic: What are the most pressing environmental issues facing our planet today, and what steps can individuals take to help address these issues? ```