Prompt engineering is deliberate prompt design: give a language model instructions, context, constraints, or a requested format so its response better matches the job. It is less wizardry than communicating clearly with a very fast, occasionally overconfident assistant. section 6.1
Start with the outcome you need, then state relevant details. Ask the model to adopt a role, return CSV, explain a process step by step, or work from supplied background. Clear, specific, concise, and positive prompts are reliable defaults. section 6.1 section 6.15
Useful ways to shape a response include:
- Specify a role when expertise or perspective matters: “You are an expert investment counselor.” section 6.1
- Specify the output format, such as CSV, when the result must fit a later workflow. section 6.1
- Add the facts and assumptions the answer should use, rather than hoping the model guesses them. section 6.1
- Use few-shot prompting: include example inputs and desired results to indicate the pattern you want. section 6.15
- Iterate after an imperfect result; adjust the request in response to what the model actually did. section 6.1
Ask the question behind the question
A vague “How do I write a loop in Python?” can become “How do I iterate over a list using a for loop in Python?” Better still, describe the goal: “How do I get Python to apply an operation to each item in a long list?” The latter gives the model a task, not merely a keyword. section 7.4
When generated code fails, do not just repeat the original request and hope for magic dust. Share the failing code or error message, explain the wrong result, and try focused variations. Read the whole reply: setup steps, library requirements, and caveats can be hiding below the first code block. section 6.1 section 7.4
|
|
I’m looking for a fairly long and completely detailed description of each of the ten most popular passenger cars of the early 1970s (by domestic US sales). |
Compare an overstuffed request with a shorter version that keeps the actual task: listing and describing high-selling US cars from the early 1970s. section 6.5
|
|
Can you give me some Python code that will import a 4k MP4 video and convert it to 1080p? |
|
|
Certainly! You can use the moviepy library in Python to import a 4K MP4 video and convert it to 1080p resolution. Here’s an example code snippet to get you started: from moviepy.editor import VideoFileClip
# Define the input video file path
input_file = "4k-video.mp4"
# Define the output video file path
output_file = "1080p-video.mp4"
# Load the video clip
clip = VideoFileClip(input_file)
# Set the target resolution to 1080p
target_resolution = (1920, 1080)
# Resize the video clip to the target resolution
resized_clip = clip.resize(target_resolution)
# Write the resized clip to the output file
resized_clip.write_videofile(output_file, codec="libx264", \
audio_codec="aac") |
A focused request for 4K-to-1080p conversion produces a usable Python starting point, including file paths, resizing, and output encoding details. section 7.4
Prompt rules are not eternal commandments carved into a server rack. Stronger models can often recover from spelling mistakes, awkward wording, and even some technical errors. Still, explicit context and a precise request remain useful when you need dependable, task-specific output. section 6.0 section 7.4





































