0

Prompt engineering 101 for developers

 11 months ago
source link: https://www.pluralsight.com/resources/blog/software-development/prompt-engineering-for-developers
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Prompt engineering 101 for developers

Prompt engineering is the latest term thrown around when talking about generative AI systems. Far from a buzzword — like, say, the metaverse — prompt engineering is a crucial method for you to fine tune and optimize the responses you get from language models.

Prompt engineering can really be summed up as this: if you want better results, you need to ask better questions. This article will help you do just that.

Before we get started, the usual coding caveat applies: don't use code without validating it! You can and will get incorrect results, so make sure you understand what is being generated. Think of these tools as something to help your efficiency, rather than write all the code for you.

A bit more on Prompt Engineering

Have you ever got a vague brief from a client or coworker, with no scope or details (like the screenshot above)? It’s a recipe for disaster, right? You don’t know what they want, and if you proceed anyway, you’ll likely get it wrong. 

Normally, you’d ask some follow up questions and get some clarity around the brief. However, AI models aren’t that intuitive. Like any machine, they do exactly what you tell them to: garbage in, garbage out. So the onus is on the user to make sure they provide the right ‘brief’.

That’s what prompt engineering is in a nutshell: providing effective prompts or instructions to an AI model to get accurate, effective responses. As a developer, this allows you to get output suitable for specific applications and tasks. 

That said, no matter how good your prompt engineering skills are, you are still limited by the capabilities of the model itself. The quality and diversity of the model’s training data is crucial.

Wait, is prompt engineering just another word for Google-Fu?

For those familiar with the earlier days of the internet, this might sound an awful lot like “Google-Fu”, a term for your skill at creating a successful search engine query. These days, that’s pretty much second nature to everyone who uses the internet. 

There are a lot of similarities between the two: you’re putting in a prompt, and trying to get a certain result. However, one of the key differences between prompt engineering and Google-Fu is that an AI model will not give the same response every time, whereas a search engine will — it’s a bit of a lottery. Engineers can guide the response from the model with prompt engineering, and trial and error is required.

Just like with Google-Fu, it’s likely one day we’ll all intuitively be prompt engineers. However, since generative AI is in its early stages, the level of technical literacy isn’t there yet. 

The basics of prompt engineering

Right, now let’s get down to actually creating a great prompt. To maximize the effectiveness of prompt engineering, you should focus on the structure of the prompt, your phrasing, and context. We'll show examples of these principles in this article.

What your starting prompt should include

Introductions are important. While you don’t need to say “Hi, I’m Joe McHuman, nice to meet you”, your first prompt with the AI should contain the following structure:

  1. Introduction: Set up the context for which you're chatting in. It helps to give the AI an imaginary ‘role’ to think of themselves in. e.g. “Act as a software engineer. You're an expert in Python and …”
  2. Task: e.g. “I want you to develop software to manage my record collection.”
  3. Contextual Information: e.g. “I want it to be a web based application written in Python.”
  4. Instructions: e.g. “I want you to generate the code to write the program.”
  5. Closing: e.g. “I want to host it as an AWS Lambda function.”

So, putting all of the above together, our example prompt would look like this:

"Act as a software engineer. You're an expert in Python and AWS technologies. I want you to develop software to manage my record collection. Make it a web based application written in Python. Generate the code for the program, and I want to host it as a Lambda function."

And with a tool like ChatGPT, it immediately gets to work:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK