Prompt Engineering - INCLUDE Prompt



The INCLUDE prompt allows us to include specific information in the response generated by ChatGPT. By using the INCLUDE directive, we can instruct the language model to include certain details, facts, or phrases in its output, thereby enhancing control over the generated response.

Understanding the INCLUDE Directive

The INCLUDE directive is a special instruction that can be embedded within the prompt to guide ChatGPT's behavior. It enables us to specify the content that we want the model to incorporate into its response. When the model encounters the INCLUDE directive, it interprets it as a signal to include the following information in its generated output.

The basic syntax for the INCLUDE directive is as follows −

User: How does photosynthesis work?
ChatGPT: Photosynthesis is a process by which plants convert sunlight into energy. [INCLUDE: Chlorophyll, Carbon dioxide, and Water]

In this example, the user asks a question about photosynthesis, and the response from ChatGPT includes the content specified within the INCLUDE directive, namely "Chlorophyll, Carbon dioxide, and Water." By using the INCLUDE directive, we can ensure that specific details are included in the response, providing a more comprehensive answer.

Best Practices for Using the INCLUDE Directive

To make the most of the INCLUDE directive, here are some best practices to keep in mind −

  • Be Specific − Specify the exact details, facts, or phrases that we want to include in the response. This helps ensure that the model includes the desired information accurately.

  • Limit the Length − While the INCLUDE directive can be useful for including additional information, be mindful of the response length. Including too much content may result in excessively long or verbose responses. Strike a balance and include only the most relevant details.

  • Use Contextual Prompts − Incorporate the INCLUDE directive within a contextually rich prompt. By providing relevant context along with the directive, we can guide the model's understanding and produce more accurate and coherent responses.

  • Experiment and Iterate − Prompt engineering is an iterative process. Test different variations of the INCLUDE directive and observe how the model responds. Adjust and refine our prompts based on the results we obtain.

Example − Python Implementation

Let's explore a practical example of using the INCLUDE directive in a Python script. We will utilize the OpenAI API to interact with ChatGPT.

In this example, the user asks "How does photosynthesis work?" and he specifically mentions that the response should INCLUDE the words "Chlorophyll", "Carbon dioxide, and "Water".

import openai
# Set your API key here
openai.api_key = 'YOUR_API_KEY'

def generate_chat_response(prompt):
   response = openai.Completion.create(
      engine="text-davinci-003",
      prompt=prompt,
      max_tokens=50,
      temperature=0.8,
      n=1,
      stop=None
   )
   return response

user_prompt = "User: How does photosynthesis work?\n"
chat_prompt = user_prompt + "ChatGPT: Photosynthesis is a processby which plants convert sunlight into energy. [INCLUDE: Chlorophyll, Carbon dioxide, and Water]"

response = generate_chat_response(chat_prompt)
print(response)

Output

Sunlight is absorbed by chlorophyll, which is located in the leaves of a plant. The energy from the sunlight is then used to convert carbon dioxide and water into glucose (sugar) and oxygen. The glucose is then used by the plant to produce energy.

Conclusion

In this chapter, we explored the power of the INCLUDE directive in prompt engineering. By using the INCLUDE directive, we can guide ChatGPT to incorporate specific details, facts, or phrases into its generated responses.

We discussed the syntax of the INCLUDE directive and provided best practices for its usage, including being specific, limiting the length of included content, using contextual prompts, and iterating to refine our prompts.

Furthermore, we presented a practical Python implementation demonstrating how to use the INCLUDE directive with the OpenAI API to interact with ChatGPT and obtain responses that include the specified information.

Advertisements