Chapter 3. Prompt Engineering

Prompt engineering is a subfield of machine learning and natural language processing, which is the study of enabling computers to understand and interpret human language. The main goal is to figure out how to talk to large language models, sophisticated AI systems designed to process and generate human-like language responses, in just the right way so they generate the answer we’re looking for.

Think of it like this: You know how when you ask someone for advice, you’ve got to give them a bit of context and be clear about what you need? It’s like that with LLMs. You’ve got to craft your question or prompt carefully. Sometimes, you might even drop some hints or extra information in your question to make sure the LLM gets what you’re asking.

This is not just about asking one-off questions either. Sometimes it’s like having a whole conversation with the LLM, going back and forth, tweaking your questions until you get that golden nugget of information you need.

For instance, let’s say you’re using an AI-assisted programming tool to develop a web application. You start by asking how to create a simple user login system in JavaScript. The initial response might cover the basics, but then you realize you need more advanced features. So, you follow up with more specific prompts, asking about incorporating password encryption and connecting to a database securely. Each interaction with the AI hones its response, gradually shaping it to fit your project’s specific ...

Get AI-Assisted Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.